Go to the documentation of this file.
4 #ifndef OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
13 #include <type_traits>
21 template<
typename T>
class Mat3;
24 class Vec4:
public Tuple<4, T>
34 explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
46 template <
typename Source>
49 this->mm[0] =
static_cast<T
>(a[0]);
50 this->mm[1] =
static_cast<T
>(a[1]);
51 this->mm[2] =
static_cast<T
>(a[2]);
52 this->mm[3] =
static_cast<T
>(a[3]);
56 template<
typename Source>
59 this->mm[0] =
static_cast<T
>(v[0]);
60 this->mm[1] =
static_cast<T
>(v[1]);
61 this->mm[2] =
static_cast<T
>(v[2]);
62 this->mm[3] =
static_cast<T
>(v[3]);
68 template<
typename Other>
72 this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] =
static_cast<T
>(val);
76 T&
x() {
return this->mm[0]; }
77 T&
y() {
return this->mm[1]; }
78 T&
z() {
return this->mm[2]; }
79 T&
w() {
return this->mm[3]; }
82 T
x()
const {
return this->mm[0]; }
83 T
y()
const {
return this->mm[1]; }
84 T
z()
const {
return this->mm[2]; }
85 T
w()
const {
return this->mm[3]; }
103 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
110 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
115 template<
typename Source>
129 bool eq(
const Vec4<T> &v, T eps =
static_cast<T
>(1.0e-8))
const
149 template <
typename T0,
typename T1>
152 this->mm[0] = v1[0] + v2[0];
153 this->mm[1] = v1[1] + v2[1];
154 this->mm[2] = v1[2] + v2[2];
155 this->mm[3] = v1[3] + v2[3];
163 template <
typename T0,
typename T1>
166 this->mm[0] = v1[0] - v2[0];
167 this->mm[1] = v1[1] - v2[1];
168 this->mm[2] = v1[2] - v2[2];
169 this->mm[3] = v1[3] - v2[3];
176 template <
typename T0,
typename T1>
179 this->mm[0] =
scale * v[0];
180 this->mm[1] =
scale * v[1];
181 this->mm[2] =
scale * v[2];
182 this->mm[3] =
scale * v[3];
187 template <
typename T0,
typename T1>
190 this->mm[0] = v[0] / scalar;
191 this->mm[1] = v[1] / scalar;
192 this->mm[2] = v[2] / scalar;
193 this->mm[3] = v[3] / scalar;
201 return (this->mm[0]*v.mm[0] + this->mm[1]*v.mm[1]
202 + this->mm[2]*v.mm[2] + this->mm[3]*v.mm[3]);
209 this->mm[0]*this->mm[0] +
210 this->mm[1]*this->mm[1] +
211 this->mm[2]*this->mm[2] +
212 this->mm[3]*this->mm[3]);
220 return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]
221 + this->mm[2]*this->mm[2] + this->mm[3]*this->mm[3]);
228 this->mm[0] = std::exp(this->mm[0]);
229 this->mm[1] = std::exp(this->mm[1]);
230 this->mm[2] = std::exp(this->mm[2]);
231 this->mm[3] = std::exp(this->mm[3]);
239 this->mm[0] = std::log(this->mm[0]);
240 this->mm[1] = std::log(this->mm[1]);
241 this->mm[2] = std::log(this->mm[2]);
242 this->mm[3] = std::log(this->mm[3]);
249 return this->mm[0] + this->mm[1] + this->mm[2] + this->mm[3];
255 return this->mm[0] * this->mm[1] * this->mm[2] * this->mm[3];
290 return l2 ? *
this /
static_cast<T
>(sqrt(l2)) :
Vec4<T>(1, 0, 0, 0);
294 template <
typename S>
297 this->mm[0] *= scalar;
298 this->mm[1] *= scalar;
299 this->mm[2] *= scalar;
300 this->mm[3] *= scalar;
305 template <
typename S>
308 this->mm[0] *= v1[0];
309 this->mm[1] *= v1[1];
310 this->mm[2] *= v1[2];
311 this->mm[3] *= v1[3];
317 template <
typename S>
320 this->mm[0] /= scalar;
321 this->mm[1] /= scalar;
322 this->mm[2] /= scalar;
323 this->mm[3] /= scalar;
328 template <
typename S>
331 this->mm[0] /= v1[0];
332 this->mm[1] /= v1[1];
333 this->mm[2] /= v1[2];
334 this->mm[3] /= v1[3];
339 template <
typename S>
342 this->mm[0] += scalar;
343 this->mm[1] += scalar;
344 this->mm[2] += scalar;
345 this->mm[3] += scalar;
350 template <
typename S>
353 this->mm[0] += v1[0];
354 this->mm[1] += v1[1];
355 this->mm[2] += v1[2];
356 this->mm[3] += v1[3];
361 template <
typename S>
364 this->mm[0] -= scalar;
365 this->mm[1] -= scalar;
366 this->mm[2] -= scalar;
367 this->mm[3] -= scalar;
372 template <
typename S>
375 this->mm[0] -= v1[0];
376 this->mm[1] -= v1[1];
377 this->mm[2] -= v1[2];
378 this->mm[3] -= v1[3];
394 template <
typename T0,
typename T1>
405 template <
typename T0,
typename T1>
409 template <
typename S,
typename T>
414 template <
typename S,
typename T>
423 template <
typename T0,
typename T1>
434 template <
typename S,
typename T>
444 template <
typename S,
typename T>
453 template <
typename T0,
typename T1>
457 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
462 template <
typename T0,
typename T1>
471 template <
typename S,
typename T>
480 template <
typename T0,
typename T1>
489 template <
typename S,
typename T>
497 template <
typename T>
503 template <
typename T>
526 template <
typename T>
537 template <
typename T>
549 template <
typename T>
554 template <
typename T>
566 #endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:164
Vec4(Other val, typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type=Conversion{})
Construct a vector all of whose components have the given value, which may be of an arithmetic type d...
Definition: Vec4.h:69
T lengthSqr() const
Definition: Vec4.h:218
T dot(const Vec4< T > &v) const
Dot product.
Definition: Vec4.h:199
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec4.h:91
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition: Vec4.h:47
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition: Vec4.h:388
const Vec4< T > & operator*=(const Vec4< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
Definition: Vec4.h:306
T z() const
Definition: Vec4.h:84
static unsigned numRows()
Definition: Vec4.h:383
Vec4< T > Abs(const Vec4< T > &v)
Definition: Vec4.h:515
Vec4()
Trivial constructor, the vector is NOT initialized.
Definition: Vec4.h:31
const Vec4< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition: Vec4.h:295
Vec4< typename promote< T0, T1 >::type > operator/(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Divide corresponding elements of v0 and v1 and return the result.
Definition: Vec4.h:454
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec4.h:76
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition: Vec4.h:108
Vec4< T > maxComponent(const Vec4< T > &v1, const Vec4< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec4.h:538
Vec4< typename promote< T0, T1 >::type > operator*(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Multiply corresponding elements of v0 and v1 and return the result.
Definition: Vec4.h:424
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:22
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec4.h:270
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec4.h:138
T & w()
Definition: Vec4.h:79
const Vec4< T > & log()
Definition: Vec4.h:237
T w() const
Definition: Vec4.h:85
Vec4< T > Exp(Vec4< T > v)
Return a vector with the exponent applied to each of the components of the input vector.
Definition: Vec4.h:550
const Vec4< T > & operator-=(const Vec4< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
Definition: Vec4.h:373
static Vec4< T > ones()
Definition: Vec4.h:390
Vec4< typename promote< S, T >::type > operator-(const Vec4< T > &v, S scalar)
Subtract scalar from each element of the given vector and return the result.
Definition: Vec4.h:490
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
Definition: Vec4.h:259
const Vec4< T > & operator/=(const Vec4< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Definition: Vec4.h:329
const T * asPointer() const
Definition: Vec4.h:88
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition: Vec4.h:97
Vec4< T > Log(Vec4< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec4.h:555
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition: Vec4.h:188
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
static unsigned numElements()
Definition: Vec4.h:385
T y() const
Definition: Vec4.h:83
const Vec4< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition: Vec4.h:340
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec4.h:82
const Vec4< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition: Vec4.h:318
T value_type
Definition: Vec4.h:27
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition: Vec4.h:116
bool operator!=(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec4.h:406
Vec4(T x, T y, T z, T w)
Constructor with four arguments, e.g. Vec4f v(1,2,3,4);.
Definition: Vec4.h:37
T ValueType
Definition: Vec4.h:28
T product() const
Return the product of all the vector components.
Definition: Vec4.h:253
MatType unit(const MatType &mat, typename MatType::value_type eps=1.0e-8)
Return a copy of the given matrix with its upper 3×3 rows normalized.
Definition: Mat.h:653
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
Vec4< T > minComponent(const Vec4< T > &v1, const Vec4< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec4.h:527
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition: Vec4.h:177
T & z()
Definition: Vec4.h:78
const Vec4< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition: Vec4.h:362
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition: Vec4.h:101
T * asPointer()
Definition: Vec4.h:87
T & y()
Definition: Vec4.h:77
const Vec4< T > & operator+=(const Vec4< S > &v1)
Add each element of the given vector to the corresponding element of this vector.
Definition: Vec4.h:351
static unsigned numColumns()
Definition: Vec4.h:384
T sum() const
Return the sum of all the vector components.
Definition: Vec4.h:247
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:620
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
Definition: Vec4.h:287
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:150
bool operator==(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec4.h:395
static Vec4< T > origin()
Definition: Vec4.h:389
bool eq(const Vec4< T > &v, T eps=static_cast< T >(1.0e-8)) const
Definition: Vec4.h:129
Definition: Exceptions.h:13
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition: Vec4.h:57
T length() const
Length of the vector.
Definition: Vec4.h:206
bool isApproxEqual(const Vec4< T > &a, const Vec4< T > &b, const Vec4< T > &eps)
Definition: Vec4.h:505
Vec4< typename promote< S, T >::type > operator+(const Vec4< T > &v, S scalar)
Add scalar to each element of the given vector and return the result.
Definition: Vec4.h:472
Vec4(T val)
Construct a vector all of whose components have the given value.
Definition: Vec4.h:34
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec4.h:277
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec4.h:94
Definition: Exceptions.h:56
const Vec4< T > & exp()
Definition: Vec4.h:226