31 #ifndef OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
35 #include <openvdb/Exceptions.h>
46 template<
typename T>
class Mat3;
49 class Vec4:
public Tuple<4, T>
59 explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
71 template <
typename Source>
81 template<
typename Source>
84 this->mm[0] =
static_cast<T
>(v[0]);
85 this->mm[1] =
static_cast<T
>(v[1]);
86 this->mm[2] =
static_cast<T
>(v[2]);
87 this->mm[3] =
static_cast<T
>(v[3]);
91 T&
x() {
return this->mm[0]; }
92 T&
y() {
return this->mm[1]; }
93 T&
z() {
return this->mm[2]; }
94 T&
w() {
return this->mm[3]; }
97 T
x()
const {
return this->mm[0]; }
98 T
y()
const {
return this->mm[1]; }
99 T
z()
const {
return this->mm[2]; }
100 T
w()
const {
return this->mm[3]; }
118 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
125 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
130 template<
typename Source>
164 template <
typename T0,
typename T1>
167 this->mm[0] = v1[0] + v2[0];
168 this->mm[1] = v1[1] + v2[1];
169 this->mm[2] = v1[2] + v2[2];
170 this->mm[3] = v1[3] + v2[3];
178 template <
typename T0,
typename T1>
181 this->mm[0] = v1[0] - v2[0];
182 this->mm[1] = v1[1] - v2[1];
183 this->mm[2] = v1[2] - v2[2];
184 this->mm[3] = v1[3] - v2[3];
191 template <
typename T0,
typename T1>
194 this->mm[0] = scale * v[0];
195 this->mm[1] = scale * v[1];
196 this->mm[2] = scale * v[2];
197 this->mm[3] = scale * v[3];
202 template <
typename T0,
typename T1>
205 this->mm[0] = v[0] / scalar;
206 this->mm[1] = v[1] / scalar;
207 this->mm[2] = v[2] / scalar;
208 this->mm[3] = v[3] / scalar;
216 return (this->mm[0]*v.mm[0] + this->mm[1]*v.mm[1]
217 + this->mm[2]*v.mm[2] + this->mm[3]*v.mm[3]);
224 this->mm[0]*this->mm[0] +
225 this->mm[1]*this->mm[1] +
226 this->mm[2]*this->mm[2] +
227 this->mm[3]*this->mm[3]);
235 return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]
236 + this->mm[2]*this->mm[2] + this->mm[3]*this->mm[3]);
268 template <
typename S>
271 this->mm[0] *= scalar;
272 this->mm[1] *= scalar;
273 this->mm[2] *= scalar;
274 this->mm[3] *= scalar;
279 template <
typename S>
282 this->mm[0] *= v1[0];
283 this->mm[1] *= v1[1];
284 this->mm[2] *= v1[2];
285 this->mm[3] *= v1[3];
291 template <
typename S>
294 this->mm[0] /= scalar;
295 this->mm[1] /= scalar;
296 this->mm[2] /= scalar;
297 this->mm[3] /= scalar;
302 template <
typename S>
305 this->mm[0] /= v1[0];
306 this->mm[1] /= v1[1];
307 this->mm[2] /= v1[2];
308 this->mm[3] /= v1[3];
313 template <
typename S>
316 this->mm[0] += scalar;
317 this->mm[1] += scalar;
318 this->mm[2] += scalar;
319 this->mm[3] += scalar;
324 template <
typename S>
327 this->mm[0] += v1[0];
328 this->mm[1] += v1[1];
329 this->mm[2] += v1[2];
330 this->mm[3] += v1[3];
335 template <
typename S>
338 this->mm[0] -= scalar;
339 this->mm[1] -= scalar;
340 this->mm[2] -= scalar;
341 this->mm[3] -= scalar;
346 template <
typename S>
349 this->mm[0] -= v1[0];
350 this->mm[1] -= v1[1];
351 this->mm[2] -= v1[2];
352 this->mm[3] -= v1[3];
364 return isnan(this->mm[0]) || isnan(this->mm[1])
365 || isnan(this->mm[2]) || isnan(this->mm[3]);
371 return isinf(this->mm[0]) || isinf(this->mm[1])
372 || isinf(this->mm[2]) || isinf(this->mm[3]);
378 return finite(this->mm[0]) && finite(this->mm[1])
379 && finite(this->mm[2]) && finite(this->mm[3]);
388 template <
typename T0,
typename T1>
399 template <
typename T0,
typename T1>
403 template <
typename S,
typename T>
408 template <
typename S,
typename T>
417 template <
typename T0,
typename T1>
429 template <
typename S,
typename T>
439 template <
typename S,
typename T>
448 template <
typename T0,
typename T1>
453 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
458 template <
typename T0,
typename T1>
467 template <
typename S,
typename T>
476 template <
typename T0,
typename T1>
485 template <
typename S,
typename T>
499 template <
typename T>
510 template <
typename T>
530 #endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Vec4< float > Vec4s
Definition: Vec4.h:523
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition: Vec4.h:123
const Vec4< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec4.h:336
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec4.h:258
T & y()
Definition: Vec4.h:92
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:165
T w() const
Definition: Vec4.h:100
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const Vec4< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec4.h:292
Vec4< uint32_t > Vec4ui
Definition: Vec4.h:522
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec4.h:97
T lengthSqr() const
Definition: Vec4.h:233
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Returns V, where for .
Definition: Vec2.h:370
Definition: Exceptions.h:78
T ValueType
Definition: Vec4.h:53
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec4.h:369
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition: Vec4.h:82
T & w()
Definition: Vec4.h:94
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition: Vec4.h:192
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:482
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec4.h:251
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec4.h:376
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
T & z()
Definition: Vec4.h:93
bool eq(const Vec4< T > &v, T eps=1.0e-8) const
Definition: Vec4.h:144
Vec4< int32_t > Vec4i
Definition: Vec4.h:521
#define OPENVDB_VERSION_NAME
Definition: version.h:45
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition: Vec4.h:383
T dot(const Vec4< T > &v) const
Dot product.
Definition: Vec4.h:214
MatType unit(const MatType &mat, typename MatType::value_type eps=1.0e-8)
Definition: Mat.h:629
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec4.h:153
const Vec4< T > & operator+=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:325
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:491
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition: Vec4.h:72
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:179
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:382
static unsigned numRows()
Definition: Vec4.h:357
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
T length() const
Length of the vector.
Definition: Vec4.h:221
T * asPointer()
Definition: Vec4.h:102
static unsigned numElements()
Definition: Vec4.h:359
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition: Vec4.h:112
const T * asPointer() const
Definition: Vec4.h:103
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:353
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition: Vec4.h:116
Vec4()
Trivial constructor, the vector is NOT initialized.
Definition: Vec4.h:56
static unsigned numColumns()
Definition: Vec4.h:358
MatType scale(const Vec3< typename MatType::value_type > &scaling)
Definition: Mat.h:595
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:438
T z() const
Definition: Vec4.h:99
Vec4(T val)
Constructor with one argument, e.g. Vec4f v(0);.
Definition: Vec4.h:59
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec4.h:91
T y() const
Definition: Vec4.h:98
const Vec4< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec4.h:269
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:408
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition: Vec4.h:131
Vec4(T x, T y, T z, T w)
Constructor with three arguments, e.g. Vec4f v(1,2,3);.
Definition: Vec4.h:62
const Vec4< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec4.h:314
bool isNan() const
True if a Nan is present in vector.
Definition: Vec4.h:362
Vec4< double > Vec4d
Definition: Vec4.h:524
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
static Vec4< T > origin()
Definition: Vec4.h:384
const Vec4< T > & operator/=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:303
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec4.h:109
const Vec4< T > & operator*=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:280
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec4.h:106
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:608
const Vec4< T > & operator-=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:347
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition: Vec4.h:203
T value_type
Definition: Vec4.h:52
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec4.h:240