4#ifndef OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
5#define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
21template<
typename T>
class Mat3;
36 explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
48 template <
typename Source>
51 this->mm[0] =
static_cast<T
>(a[0]);
52 this->mm[1] =
static_cast<T
>(a[1]);
53 this->mm[2] =
static_cast<T
>(a[2]);
54 this->mm[3] =
static_cast<T
>(a[3]);
58 template<
typename Source>
61 this->mm[0] =
static_cast<T
>(v[0]);
62 this->mm[1] =
static_cast<T
>(v[1]);
63 this->mm[2] =
static_cast<T
>(v[2]);
64 this->mm[3] =
static_cast<T
>(v[3]);
70 template<
typename Other>
74 this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] =
static_cast<T
>(val);
78 T&
x() {
return this->mm[0]; }
79 T&
y() {
return this->mm[1]; }
80 T&
z() {
return this->mm[2]; }
81 T&
w() {
return this->mm[3]; }
84 T
x()
const {
return this->mm[0]; }
85 T
y()
const {
return this->mm[1]; }
86 T
z()
const {
return this->mm[2]; }
87 T
w()
const {
return this->mm[3]; }
105 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
112 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
117 template<
typename Source>
131 bool eq(
const Vec4<T> &v, T eps =
static_cast<T
>(1.0e-8))
const
151 template <
typename T0,
typename T1>
154 this->mm[0] = v1[0] + v2[0];
155 this->mm[1] = v1[1] + v2[1];
156 this->mm[2] = v1[2] + v2[2];
157 this->mm[3] = v1[3] + v2[3];
165 template <
typename T0,
typename T1>
168 this->mm[0] = v1[0] - v2[0];
169 this->mm[1] = v1[1] - v2[1];
170 this->mm[2] = v1[2] - v2[2];
171 this->mm[3] = v1[3] - v2[3];
178 template <
typename T0,
typename T1>
181 this->mm[0] =
scale * v[0];
182 this->mm[1] =
scale * v[1];
183 this->mm[2] =
scale * v[2];
184 this->mm[3] =
scale * v[3];
189 template <
typename T0,
typename T1>
192 this->mm[0] = v[0] / scalar;
193 this->mm[1] = v[1] / scalar;
194 this->mm[2] = v[2] / scalar;
195 this->mm[3] = v[3] / scalar;
203 return (this->mm[0]*v.
mm[0] + this->mm[1]*v.
mm[1]
204 + this->mm[2]*v.
mm[2] + this->mm[3]*v.
mm[3]);
211 this->mm[0]*this->mm[0] +
212 this->mm[1]*this->mm[1] +
213 this->mm[2]*this->mm[2] +
214 this->mm[3]*this->mm[3]);
222 return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]
223 + this->mm[2]*this->mm[2] + this->mm[3]*this->mm[3]);
230 this->mm[0] = std::exp(this->mm[0]);
231 this->mm[1] = std::exp(this->mm[1]);
232 this->mm[2] = std::exp(this->mm[2]);
233 this->mm[3] = std::exp(this->mm[3]);
241 this->mm[0] = std::log(this->mm[0]);
242 this->mm[1] = std::log(this->mm[1]);
243 this->mm[2] = std::log(this->mm[2]);
244 this->mm[3] = std::log(this->mm[3]);
251 return this->mm[0] + this->mm[1] + this->mm[2] + this->mm[3];
257 return this->mm[0] * this->mm[1] * this->mm[2] * this->mm[3];
292 return l2 ? *
this /
static_cast<T
>(sqrt(l2)) :
Vec4<T>(1, 0, 0, 0);
296 template <
typename S>
299 this->mm[0] *= scalar;
300 this->mm[1] *= scalar;
301 this->mm[2] *= scalar;
302 this->mm[3] *= scalar;
307 template <
typename S>
310 this->mm[0] *= v1[0];
311 this->mm[1] *= v1[1];
312 this->mm[2] *= v1[2];
313 this->mm[3] *= v1[3];
319 template <
typename S>
322 this->mm[0] /= scalar;
323 this->mm[1] /= scalar;
324 this->mm[2] /= scalar;
325 this->mm[3] /= scalar;
330 template <
typename S>
333 this->mm[0] /= v1[0];
334 this->mm[1] /= v1[1];
335 this->mm[2] /= v1[2];
336 this->mm[3] /= v1[3];
341 template <
typename S>
344 this->mm[0] += scalar;
345 this->mm[1] += scalar;
346 this->mm[2] += scalar;
347 this->mm[3] += scalar;
352 template <
typename S>
355 this->mm[0] += v1[0];
356 this->mm[1] += v1[1];
357 this->mm[2] += v1[2];
358 this->mm[3] += v1[3];
363 template <
typename S>
366 this->mm[0] -= scalar;
367 this->mm[1] -= scalar;
368 this->mm[2] -= scalar;
369 this->mm[3] -= scalar;
374 template <
typename S>
377 this->mm[0] -= v1[0];
378 this->mm[1] -= v1[1];
379 this->mm[2] -= v1[2];
380 this->mm[3] -= v1[3];
396template <
typename T0,
typename T1>
407template <
typename T0,
typename T1>
411template <
typename S,
typename T>
416template <
typename S,
typename T>
425template <
typename T0,
typename T1>
436template <
typename S,
typename T>
446template <
typename S,
typename T>
455template <
typename T0,
typename T1>
459 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
464template <
typename T0,
typename T1>
473template <
typename S,
typename T>
482template <
typename T0,
typename T1>
491template <
typename S,
typename T>
532 std::min(v1.
x(), v2.
x()),
533 std::min(v1.
y(), v2.
y()),
534 std::min(v1.
z(), v2.
z()),
535 std::min(v1.
w(), v2.
w()));
543 std::max(v1.
x(), v2.
x()),
544 std::max(v1.
y(), v2.
y()),
545 std::max(v1.
z(), v2.
z()),
546 std::max(v1.
w(), v2.
w()));
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
#define OPENVDB_IS_POD(Type)
Definition Math.h:56
Definition Exceptions.h:56
T mm[SIZE]
Copies this tuple into an array of a compatible type.
Definition Tuple.h:164
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition Vec4.h:59
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition Vec4.h:49
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition Vec4.h:78
const Vec4< T > & exp()
Definition Vec4.h:228
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition Vec4.h:99
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
Definition Vec4.h:261
const Vec4< T > & log()
Definition Vec4.h:239
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition Vec4.h:103
T length() const
Length of the vector.
Definition Vec4.h:208
T sum() const
Return the sum of all the vector components.
Definition Vec4.h:249
static Vec4< T > ones()
Definition Vec4.h:392
Vec4(T x, T y, T z, T w)
Constructor with four arguments, e.g. Vec4f v(1,2,3,4);.
Definition Vec4.h:39
static unsigned numColumns()
Definition Vec4.h:386
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition Vec4.h:152
const Vec4< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition Vec4.h:364
static Vec4< T > origin()
Definition Vec4.h:391
T * asPointer()
Definition Vec4.h:89
static unsigned numRows()
Definition Vec4.h:385
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition Vec4.h:190
T w() const
Definition Vec4.h:87
T & operator()(int i)
Alternative indexed reference to the elements.
Definition Vec4.h:93
T & y()
Definition Vec4.h:79
T & z()
Definition Vec4.h:80
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:331
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition Vec4.h:96
T product() const
Return the product of all the vector components.
Definition Vec4.h:255
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition Vec4.h:390
const T * asPointer() const
Definition Vec4.h:90
T lengthSqr() const
Definition Vec4.h:220
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:353
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition Vec4.h:272
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition Vec4.h:166
T x() const
Get the component, e.g. float f = v.y();.
Definition Vec4.h:84
const Vec4< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition Vec4.h:342
T dot(const Vec4< T > &v) const
Dot product.
Definition Vec4.h:201
T z() const
Definition Vec4.h:86
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
Definition Vec4.h:289
T y() const
Definition Vec4.h:85
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition Vec4.h:110
static unsigned numElements()
Definition Vec4.h:387
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition Vec4.h:179
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition Vec4.h:140
const Vec4< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition Vec4.h:320
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:71
bool eq(const Vec4< T > &v, T eps=static_cast< T >(1.0e-8)) const
Definition Vec4.h:131
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:375
Vec4(T val)
Construct a vector all of whose components have the given value.
Definition Vec4.h:36
T ValueType
Definition Vec4.h:28
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:308
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition Vec4.h:279
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition Vec4.h:118
T value_type
Definition Vec4.h:27
T & w()
Definition Vec4.h:81
const Vec4< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition Vec4.h:297
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition Vec2.h:528
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition Vec3.h:473
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition Mat3.h:597
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
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:553
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition Mat.h:615
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:527
Type Exp(const Type &x)
Return ex.
Definition Math.h:710
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:648
Coord Abs(const Coord &xyz)
Definition Coord.h:517
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Divide scalar by each element of the given vector and return the result.
Definition Vec2.h:385
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition Vec2.h:504
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition Vec3.h:481
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition Vec2.h:513
Definition Exceptions.h:13
Dummy class for tag dispatch of conversion constructors.
Definition Tuple.h:23
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212