31 #ifndef OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED 32 #define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED 39 #include <type_traits> 47 template<
typename T>
class Mat3;
50 class Vec4:
public Tuple<4, T>
60 explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
72 template <
typename Source>
82 template<
typename Source>
85 this->mm[0] =
static_cast<T
>(v[0]);
86 this->mm[1] =
static_cast<T
>(v[1]);
87 this->mm[2] =
static_cast<T
>(v[2]);
88 this->mm[3] =
static_cast<T
>(v[3]);
94 template<
typename Other>
98 this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] =
static_cast<T
>(val);
102 T&
x() {
return this->mm[0]; }
103 T&
y() {
return this->mm[1]; }
104 T&
z() {
return this->mm[2]; }
105 T&
w() {
return this->mm[3]; }
108 T
x()
const {
return this->mm[0]; }
109 T
y()
const {
return this->mm[1]; }
110 T
z()
const {
return this->mm[2]; }
111 T
w()
const {
return this->mm[3]; }
129 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
136 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
141 template<
typename Source>
175 template <
typename T0,
typename T1>
178 this->mm[0] = v1[0] + v2[0];
179 this->mm[1] = v1[1] + v2[1];
180 this->mm[2] = v1[2] + v2[2];
181 this->mm[3] = v1[3] + v2[3];
189 template <
typename T0,
typename T1>
192 this->mm[0] = v1[0] - v2[0];
193 this->mm[1] = v1[1] - v2[1];
194 this->mm[2] = v1[2] - v2[2];
195 this->mm[3] = v1[3] - v2[3];
202 template <
typename T0,
typename T1>
205 this->mm[0] =
scale * v[0];
206 this->mm[1] =
scale * v[1];
207 this->mm[2] =
scale * v[2];
208 this->mm[3] =
scale * v[3];
213 template <
typename T0,
typename T1>
216 this->mm[0] = v[0] / scalar;
217 this->mm[1] = v[1] / scalar;
218 this->mm[2] = v[2] / scalar;
219 this->mm[3] = v[3] / scalar;
227 return (this->mm[0]*v.mm[0] + this->mm[1]*v.mm[1]
228 + this->mm[2]*v.mm[2] + this->mm[3]*v.mm[3]);
235 this->mm[0]*this->mm[0] +
236 this->mm[1]*this->mm[1] +
237 this->mm[2]*this->mm[2] +
238 this->mm[3]*this->mm[3]);
246 return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]
247 + this->mm[2]*this->mm[2] + this->mm[3]*this->mm[3]);
254 this->mm[0] = std::exp(this->mm[0]);
255 this->mm[1] = std::exp(this->mm[1]);
256 this->mm[2] = std::exp(this->mm[2]);
257 this->mm[3] = std::exp(this->mm[3]);
265 this->mm[0] = std::log(this->mm[0]);
266 this->mm[1] = std::log(this->mm[1]);
267 this->mm[2] = std::log(this->mm[2]);
268 this->mm[3] = std::log(this->mm[3]);
275 return this->mm[0] + this->mm[1] + this->mm[2] + this->mm[3];
281 return this->mm[0] * this->mm[1] * this->mm[2] * this->mm[3];
316 return l2 ? *
this /
static_cast<T
>(sqrt(l2)) :
Vec4<T>(1, 0, 0, 0);
320 template <
typename S>
323 this->mm[0] *= scalar;
324 this->mm[1] *= scalar;
325 this->mm[2] *= scalar;
326 this->mm[3] *= scalar;
331 template <
typename S>
334 this->mm[0] *= v1[0];
335 this->mm[1] *= v1[1];
336 this->mm[2] *= v1[2];
337 this->mm[3] *= v1[3];
343 template <
typename S>
346 this->mm[0] /= scalar;
347 this->mm[1] /= scalar;
348 this->mm[2] /= scalar;
349 this->mm[3] /= scalar;
354 template <
typename S>
357 this->mm[0] /= v1[0];
358 this->mm[1] /= v1[1];
359 this->mm[2] /= v1[2];
360 this->mm[3] /= v1[3];
365 template <
typename S>
368 this->mm[0] += scalar;
369 this->mm[1] += scalar;
370 this->mm[2] += scalar;
371 this->mm[3] += scalar;
376 template <
typename S>
379 this->mm[0] += v1[0];
380 this->mm[1] += v1[1];
381 this->mm[2] += v1[2];
382 this->mm[3] += v1[3];
387 template <
typename S>
390 this->mm[0] -= scalar;
391 this->mm[1] -= scalar;
392 this->mm[2] -= scalar;
393 this->mm[3] -= scalar;
398 template <
typename S>
401 this->mm[0] -= v1[0];
402 this->mm[1] -= v1[1];
403 this->mm[2] -= v1[2];
404 this->mm[3] -= v1[3];
420 template <
typename T0,
typename T1>
431 template <
typename T0,
typename T1>
435 template <
typename S,
typename T>
440 template <
typename S,
typename T>
449 template <
typename T0,
typename T1>
461 template <
typename S,
typename T>
471 template <
typename S,
typename T>
480 template <
typename T0,
typename T1>
485 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
490 template <
typename T0,
typename T1>
499 template <
typename S,
typename T>
508 template <
typename T0,
typename T1>
517 template <
typename S,
typename T>
525 template <
typename T>
531 template <
typename T>
554 template <
typename T>
565 template <
typename T>
577 template <
typename T>
582 template <
typename T>
594 #endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED T value_type
Definition: Vec4.h:53
Vec4< float > Vec4s
Definition: Vec4.h:587
const Vec4< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec4.h:388
T & y()
Definition: Vec4.h:103
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:578
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition: Vec4.h:214
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:48
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec4.h:285
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:176
const Vec4< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec4.h:344
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
T ValueType
Definition: Vec4.h:54
Vec4< uint32_t > Vec4ui
Definition: Vec4.h:586
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:391
bool isApproxEqual(const Vec4< T > &a, const Vec4< T > &b, const Vec4< T > &eps)
Definition: Vec4.h:533
T & w()
Definition: Vec4.h:105
T sum() const
Return the sum of all the vector components.
Definition: Vec4.h:273
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
Definition: Exceptions.h:82
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition: Vec4.h:83
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec4.h:108
T y() const
Definition: Vec4.h:109
const T * asPointer() const
Definition: Vec4.h:114
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition: Vec4.h:203
Vec4< typename promote< T0, T1 >::type > operator/(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Returns V, where for .
Definition: Vec4.h:481
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:643
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec4.h:120
bool operator==(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec4.h:421
Vec4< T > maxComponent(const Vec4< T > &v1, const Vec4< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec4.h:566
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:95
T & z()
Definition: Vec4.h:104
const Vec4< T > & operator+=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:377
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec4.h:296
Vec4< int32_t > Vec4i
Definition: Vec4.h:585
#define OPENVDB_VERSION_NAME
Definition: version.h:43
T lengthSqr() const
Definition: Vec4.h:244
Vec4< typename promote< T0, T1 >::type > operator*(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Returns V, where for .
Definition: Vec4.h:450
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:190
T product() const
Return the product of all the vector components.
Definition: Vec4.h:279
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition: Vec4.h:73
static unsigned numRows()
Definition: Vec4.h:409
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition: Vec4.h:414
Definition: Exceptions.h:39
static Vec4< T > ones()
Definition: Vec4.h:416
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
Definition: Vec4.h:313
static unsigned numElements()
Definition: Vec4.h:411
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec4.h:303
Vec4< T > Abs(const Vec4< T > &v)
Definition: Vec4.h:543
T * asPointer()
Definition: Vec4.h:113
bool operator!=(const Vec4< T0 > &v0, const Vec4< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec4.h:432
Vec4(T val)
Construct a vector all of whose components have the given value.
Definition: Vec4.h:60
Vec4< typename promote< S, T >::type > operator-(const Vec4< T > &v, S scalar)
Returns V, where for .
Definition: Vec4.h:518
const Vec4< T > & log()
Definition: Vec4.h:263
T dot(const Vec4< T > &v) const
Dot product.
Definition: Vec4.h:225
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec4.h:164
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition: Vec4.h:127
Vec4()
Trivial constructor, the vector is NOT initialized.
Definition: Vec4.h:57
const Vec4< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec4.h:321
const Vec4< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec4.h:366
MatType unit(const MatType &mat, typename MatType::value_type eps=1.0e-8)
Return a copy of the given matrix with its upper 3x3 rows normalized.
Definition: Mat.h:676
static unsigned numColumns()
Definition: Vec4.h:410
Vec4< typename promote< S, T >::type > operator+(const Vec4< T > &v, S scalar)
Returns V, where for .
Definition: Vec4.h:500
Vec4< T > Log(Vec4< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec4.h:583
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec4.h:102
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition: Vec4.h:142
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec4.h:117
T w() const
Definition: Vec4.h:111
Vec4< double > Vec4d
Definition: Vec4.h:588
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
const Vec4< T > & operator*=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:332
Vec4(T x, T y, T z, T w)
Constructor with four arguments, e.g. Vec4f v(1,2,3,4);.
Definition: Vec4.h:63
static Vec4< T > origin()
Definition: Vec4.h:415
bool eq(const Vec4< T > &v, T eps=1.0e-8) const
Definition: Vec4.h:155
const Vec4< T > & operator/=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:355
T length() const
Length of the vector.
Definition: Vec4.h:232
T z() const
Definition: Vec4.h:110
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition: Vec4.h:123
Vec4< T > minComponent(const Vec4< T > &v1, const Vec4< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec4.h:555
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition: Vec4.h:134
const Vec4< T > & exp()
Definition: Vec4.h:252
const Vec4< T > & operator-=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:399