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>
31 #if OPENVDB_ABI_VERSION_NUMBER >= 8
52 template <
typename Source>
55 this->
mm[0] =
static_cast<T>(a[0]);
56 this->
mm[1] =
static_cast<T>(a[1]);
57 this->
mm[2] =
static_cast<T>(a[2]);
58 this->
mm[3] =
static_cast<T>(a[3]);
62 template<
typename Source>
65 this->
mm[0] =
static_cast<T>(v[0]);
66 this->
mm[1] =
static_cast<T>(v[1]);
67 this->
mm[2] =
static_cast<T>(v[2]);
68 this->
mm[3] =
static_cast<T>(v[3]);
74 template<
typename Other>
78 this->
mm[0] = this->
mm[1] = this->
mm[2] = this->
mm[3] =
static_cast<T>(
val);
82 T&
x() {
return this->
mm[0]; }
83 T&
y() {
return this->
mm[1]; }
84 T&
z() {
return this->
mm[2]; }
85 T&
w() {
return this->
mm[3]; }
88 T x()
const {
return this->
mm[0]; }
89 T y()
const {
return this->
mm[1]; }
90 T z()
const {
return this->
mm[2]; }
91 T w()
const {
return this->
mm[3]; }
109 this->
mm[0] =
x; this->
mm[1] =
y; this->
mm[2] =
z; this->
mm[3] =
w;
116 this->
mm[0] = 0; this->
mm[1] = 0; this->
mm[2] = 0; this->
mm[3] = 0;
121 template<
typename Source>
135 bool eq(
const Vec4<T> &
v, T eps = static_cast<T>(1.0e-8))
const
155 template <
typename T0,
typename T1>
158 this->
mm[0] = v1[0] + v2[0];
159 this->
mm[1] = v1[1] + v2[1];
160 this->
mm[2] = v1[2] + v2[2];
161 this->
mm[3] = v1[3] + v2[3];
169 template <
typename T0,
typename T1>
172 this->
mm[0] = v1[0] - v2[0];
173 this->
mm[1] = v1[1] - v2[1];
174 this->
mm[2] = v1[2] - v2[2];
175 this->
mm[3] = v1[3] - v2[3];
182 template <
typename T0,
typename T1>
185 this->
mm[0] = scale * v[0];
186 this->
mm[1] = scale * v[1];
187 this->
mm[2] = scale * v[2];
188 this->
mm[3] = scale * v[3];
193 template <
typename T0,
typename T1>
196 this->
mm[0] = v[0] / scalar;
197 this->
mm[1] = v[1] / scalar;
198 this->
mm[2] = v[2] / scalar;
199 this->
mm[3] = v[3] / scalar;
207 return (this->
mm[0]*v.
mm[0] +
this->mm[1]*v.
mm[1]
215 this->
mm[0]*this->
mm[0] +
216 this->
mm[1]*this->
mm[1] +
217 this->
mm[2]*this->
mm[2] +
218 this->
mm[3]*this->
mm[3]);
226 return (this->
mm[0]*this->
mm[0] + this->
mm[1]*this->
mm[1]
227 + this->
mm[2]*this->
mm[2] + this->
mm[3]*this->
mm[3]);
234 this->
mm[0] = std::exp(this->
mm[0]);
235 this->
mm[1] = std::exp(this->
mm[1]);
236 this->
mm[2] = std::exp(this->
mm[2]);
237 this->
mm[3] = std::exp(this->
mm[3]);
255 return this->
mm[0] + this->
mm[1] + this->
mm[2] + this->
mm[3];
261 return this->
mm[0] * this->
mm[1] * this->
mm[2] * this->
mm[3];
287 throw ArithmeticError(
"Normalizing null 4-vector");
296 return l2 ? *
this /
static_cast<T>(
sqrt(l2)) :
Vec4<T>(1, 0, 0, 0);
300 template <
typename S>
303 this->
mm[0] *= scalar;
304 this->
mm[1] *= scalar;
305 this->
mm[2] *= scalar;
306 this->
mm[3] *= scalar;
311 template <
typename S>
314 this->
mm[0] *= v1[0];
315 this->
mm[1] *= v1[1];
316 this->
mm[2] *= v1[2];
317 this->
mm[3] *= v1[3];
323 template <
typename S>
326 this->
mm[0] /= scalar;
327 this->
mm[1] /= scalar;
328 this->
mm[2] /= scalar;
329 this->
mm[3] /= scalar;
334 template <
typename S>
337 this->
mm[0] /= v1[0];
338 this->
mm[1] /= v1[1];
339 this->
mm[2] /= v1[2];
340 this->
mm[3] /= v1[3];
345 template <
typename S>
348 this->
mm[0] += scalar;
349 this->
mm[1] += scalar;
350 this->
mm[2] += scalar;
351 this->
mm[3] += scalar;
356 template <
typename S>
359 this->
mm[0] += v1[0];
360 this->
mm[1] += v1[1];
361 this->
mm[2] += v1[2];
362 this->
mm[3] += v1[3];
367 template <
typename S>
370 this->
mm[0] -= scalar;
371 this->
mm[1] -= scalar;
372 this->
mm[2] -= scalar;
373 this->
mm[3] -= scalar;
378 template <
typename S>
381 this->
mm[0] -= v1[0];
382 this->
mm[1] -= v1[1];
383 this->
mm[2] -= v1[2];
384 this->
mm[3] -= v1[3];
400 template <
typename T0,
typename T1>
411 template <
typename T0,
typename T1>
415 template <
typename S,
typename T>
420 template <
typename S,
typename T>
429 template <
typename T0,
typename T1>
440 template <
typename S,
typename T>
450 template <
typename S,
typename T>
459 template <
typename T0,
typename T1>
463 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
468 template <
typename T0,
typename T1>
477 template <
typename S,
typename T>
486 template <
typename T0,
typename T1>
495 template <
typename S,
typename T>
503 template <
typename T>
509 template <
typename T>
532 template <
typename T>
543 template <
typename T>
555 template <
typename T>
560 template <
typename T>
568 #if OPENVDB_ABI_VERSION_NUMBER >= 8
579 #endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
T x() const
Get the component, e.g. float f = v.y();.
Vec4(T val)
Construct a vector all of whose components have the given value.
static unsigned numElements()
GLboolean GLboolean GLboolean b
static Vec4< T > origin()
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
const Vec4< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
GLenum GLenum GLenum GLenum GLenum scale
const Vec4< T > & operator-=(const Vec4< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
const Vec4< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
vfloat4 sqrt(const vfloat4 &a)
const Vec4< T > & operator*=(const Vec4< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
const Vec4< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
#define OPENVDB_USE_VERSION_NAMESPACE
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Dummy class for tag dispatch of conversion constructors.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
const Vec4< T > & operator/=(const Vec4< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
**But if you need a or simply need to know when the task has note that the like this
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Vec4()
Trivial constructor, the vector is NOT initialized.
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
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.
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
GLubyte GLubyte GLubyte GLubyte w
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
#define OPENVDB_IS_POD(Type)
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
static unsigned numColumns()
Coord Abs(const Coord &xyz)
GLfloat GLfloat GLfloat v2
T sum() const
Return the sum of all the vector components.
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
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...
GLboolean GLboolean GLboolean GLboolean a
const Vec4< T > & operator+=(const Vec4< S > &v1)
Add each element of the given vector to the corresponding element of this vector. ...
GLdouble GLdouble GLdouble z
const Vec4< T > & setZero()
Set "this" vector to zero.
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Vec4(T x, T y, T z, T w)
Constructor with four arguments, e.g. Vec4f v(1,2,3,4);.
const T * asPointer() const
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
T & operator()(int i)
Alternative indexed reference to the elements.
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
T length() const
Length of the vector.
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
T product() const
Return the product of all the vector components.
const Vec4< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
GLsizei const GLfloat * value
T dot(const Vec4< T > &v) const
Dot product.
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.
static unsigned numRows()
OIIO_FORCEINLINE T log(const T &v)
bool eq(const Vec4< T > &v, T eps=static_cast< T >(1.0e-8)) const
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Type Exp(const Type &x)
Return ex.
T operator()(int i) const
Alternative indexed constant reference to the elements,.