OpenVDB: openvdb/math/Vec4.h Source File

OpenVDB 12.1.1

Loading...
Searching...
No Matches
Vec4.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4#ifndef OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
5#define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
6
7#include <openvdb/Exceptions.h>
8#include "Math.h"
9#include "Tuple.h"
10#include "Vec3.h"
11#include <algorithm>
12#include <cmath>
13#include <type_traits>
14
15
16namespace openvdb {
17 OPENVDB_USE_VERSION_NAMESPACE
18namespace OPENVDB_VERSION_NAME {
19namespace math {
20
21template<typename T> class Mat3;
22
23template<typename T>
24 class Vec4: public Tuple<4, T>
25{
26public:
27 using value_type = T;
28 using ValueType = T;
29
30 /// Trivial constructor, the vector is NOT initialized
31 /// @note destructor, copy constructor, assignment operator and
32 /// move constructor are left to be defined by the compiler (default)
33 Vec4() = default;
34
35 /// @brief Construct a vector all of whose components have the given value.
36 explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
37
38 /// Constructor with four arguments, e.g. Vec4f v(1,2,3,4);
39 Vec4(T x, T y, T z, T w)
40 {
41 this->mm[0] = x;
42 this->mm[1] = y;
43 this->mm[2] = z;
44 this->mm[3] = w;
45 }
46
47 /// Constructor with array argument, e.g. float a[4]; Vec4f v(a);
48 template <typename Source>
49 Vec4(Source *a)
50 {
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]);
55 }
56
57 /// Conversion constructor
58 template<typename Source>
59 explicit Vec4(const Tuple<4, Source> &v)
60 {
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]);
65 }
66
67 /// @brief Construct a vector all of whose components have the given value,
68 /// which may be of an arithmetic type different from this vector's value type.
69 /// @details Type conversion warnings are suppressed.
70 template<typename Other>
71 explicit Vec4(Other val,
72 typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
73 {
74 this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = static_cast<T>(val);
75 }
76
77 /// Reference to the component, e.g. v.x() = 4.5f;
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]; }
82
83 /// Get the component, e.g. float f = v.y();
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]; }
88
89 T* asPointer() { return this->mm; }
90 const T* asPointer() const { return this->mm; }
91
92 /// Alternative indexed reference to the elements
93 T& operator()(int i) { return this->mm[i]; }
94
95 /// Alternative indexed constant reference to the elements,
96 T operator()(int i) const { return this->mm[i]; }
97
98 /// Returns a Vec3 with the first three elements of the Vec4.
99 Vec3<T> getVec3() const { return Vec3<T>(this->mm[0], this->mm[1], this->mm[2]); }
100
101 /// "this" vector gets initialized to [x, y, z, w],
102 /// calling v.init(); has same effect as calling v = Vec4::zero();
103 const Vec4<T>& init(T x=0, T y=0, T z=0, T w=0)
104 {
105 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
106 return *this;
107 }
108
109 /// Set "this" vector to zero
110 const Vec4<T>& setZero()
111 {
112 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
113 return *this;
114 }
115
116 /// Assignment operator
117 template<typename Source>
118 const Vec4<T>& operator=(const Vec4<Source> &v)
119 {
120 // note: don't static_cast because that suppresses warnings
121 this->mm[0] = v[0];
122 this->mm[1] = v[1];
123 this->mm[2] = v[2];
124 this->mm[3] = v[3];
125
126 return *this;
127 }
128
129 /// Test if "this" vector is equivalent to vector v with tolerance
130 /// of eps
131 bool eq(const Vec4<T> &v, T eps = static_cast<T>(1.0e-8)) const
132 {
133 return isApproxEqual(this->mm[0], v.mm[0], eps) &&
134 isApproxEqual(this->mm[1], v.mm[1], eps) &&
135 isApproxEqual(this->mm[2], v.mm[2], eps) &&
136 isApproxEqual(this->mm[3], v.mm[3], eps);
137 }
138
139 /// Negation operator, for e.g. v1 = -v2;
140 Vec4<T> operator-() const
141 {
142 return Vec4<T>(
143 -this->mm[0],
144 -this->mm[1],
145 -this->mm[2],
146 -this->mm[3]);
147 }
148
149 /// this = v1 + v2
150 /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
151 template <typename T0, typename T1>
152 const Vec4<T>& add(const Vec4<T0> &v1, const Vec4<T1> &v2)
153 {
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];
158
159 return *this;
160 }
161
162
163 /// this = v1 - v2
164 /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
165 template <typename T0, typename T1>
166 const Vec4<T>& sub(const Vec4<T0> &v1, const Vec4<T1> &v2)
167 {
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];
172
173 return *this;
174 }
175
176 /// this = scalar*v, v need not be a distinct object from "this",
177 /// e.g. v.scale(1.5,v1);
178 template <typename T0, typename T1>
179 const Vec4<T>& scale(T0 scale, const Vec4<T1> &v)
180 {
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];
185
186 return *this;
187 }
188
189 template <typename T0, typename T1>
190 const Vec4<T> &div(T0 scalar, const Vec4<T1> &v)
191 {
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;
196
197 return *this;
198 }
199
200 /// Dot product
201 T dot(const Vec4<T> &v) const
202 {
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]);
205 }
206
207 /// Length of the vector
208 T length() const
209 {
210 return std::sqrt(
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]);
215 }
216
217
218 /// Squared length of the vector, much faster than length() as it
219 /// does not involve square root
220 T lengthSqr() const
221 {
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]);
224 }
225
226 /// Return a reference to itself after the exponent has been
227 /// applied to all the vector components.
228 inline const Vec4<T>& exp()
229 {
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]);
234 return *this;
235 }
236
237 /// Return a reference to itself after log has been
238 /// applied to all the vector components.
239 inline const Vec4<T>& log()
240 {
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]);
245 return *this;
246 }
247
248 /// Return the sum of all the vector components.
249 inline T sum() const
250 {
251 return this->mm[0] + this->mm[1] + this->mm[2] + this->mm[3];
252 }
253
254 /// Return the product of all the vector components.
255 inline T product() const
256 {
257 return this->mm[0] * this->mm[1] * this->mm[2] * this->mm[3];
258 }
259
260 /// this = normalized this
261 bool normalize(T eps = static_cast<T>(1.0e-8))
262 {
263 T d = length();
264 if (isApproxEqual(d, T(0), eps)) {
265 return false;
266 }
267 *this *= (T(1) / d);
268 return true;
269 }
270
271 /// return normalized this, throws if null vector
272 Vec4<T> unit(T eps=0) const
273 {
274 T d;
275 return unit(eps, d);
276 }
277
278 /// return normalized this and length, throws if null vector
279 Vec4<T> unit(T eps, T& len) const
280 {
281 len = length();
282 if (isApproxEqual(len, T(0), eps)) {
283 throw ArithmeticError("Normalizing null 4-vector");
284 }
285 return *this / len;
286 }
287
288 /// return normalized this, or (1, 0, 0, 0) if this is null vector
289 Vec4<T> unitSafe() const
290 {
291 const T l2 = lengthSqr();
292 return !isApproxZero(l2) ? *this / static_cast<T>(sqrt(l2)) : Vec4<T>(1, 0, 0, 0);
293 }
294
295 /// Multiply each element of this vector by @a scalar.
296 template <typename S>
297 const Vec4<T> &operator*=(S scalar)
298 {
299 this->mm[0] *= scalar;
300 this->mm[1] *= scalar;
301 this->mm[2] *= scalar;
302 this->mm[3] *= scalar;
303 return *this;
304 }
305
306 /// Multiply each element of this vector by the corresponding element of the given vector.
307 template <typename S>
308 const Vec4<T> &operator*=(const Vec4<S> &v1)
309 {
310 this->mm[0] *= v1[0];
311 this->mm[1] *= v1[1];
312 this->mm[2] *= v1[2];
313 this->mm[3] *= v1[3];
314
315 return *this;
316 }
317
318 /// Divide each element of this vector by @a scalar.
319 template <typename S>
320 const Vec4<T> &operator/=(S scalar)
321 {
322 this->mm[0] /= scalar;
323 this->mm[1] /= scalar;
324 this->mm[2] /= scalar;
325 this->mm[3] /= scalar;
326 return *this;
327 }
328
329 /// Divide each element of this vector by the corresponding element of the given vector.
330 template <typename S>
331 const Vec4<T> &operator/=(const Vec4<S> &v1)
332 {
333 this->mm[0] /= v1[0];
334 this->mm[1] /= v1[1];
335 this->mm[2] /= v1[2];
336 this->mm[3] /= v1[3];
337 return *this;
338 }
339
340 /// Add @a scalar to each element of this vector.
341 template <typename S>
342 const Vec4<T> &operator+=(S scalar)
343 {
344 this->mm[0] += scalar;
345 this->mm[1] += scalar;
346 this->mm[2] += scalar;
347 this->mm[3] += scalar;
348 return *this;
349 }
350
351 /// Add each element of the given vector to the corresponding element of this vector.
352 template <typename S>
353 const Vec4<T> &operator+=(const Vec4<S> &v1)
354 {
355 this->mm[0] += v1[0];
356 this->mm[1] += v1[1];
357 this->mm[2] += v1[2];
358 this->mm[3] += v1[3];
359 return *this;
360 }
361
362 /// Subtract @a scalar from each element of this vector.
363 template <typename S>
364 const Vec4<T> &operator-=(S scalar)
365 {
366 this->mm[0] -= scalar;
367 this->mm[1] -= scalar;
368 this->mm[2] -= scalar;
369 this->mm[3] -= scalar;
370 return *this;
371 }
372
373 /// Subtract each element of the given vector from the corresponding element of this vector.
374 template <typename S>
375 const Vec4<T> &operator-=(const Vec4<S> &v1)
376 {
377 this->mm[0] -= v1[0];
378 this->mm[1] -= v1[1];
379 this->mm[2] -= v1[2];
380 this->mm[3] -= v1[3];
381 return *this;
382 }
383
384 // Number of cols, rows, elements
385 static unsigned numRows() { return 1; }
386 static unsigned numColumns() { return 4; }
387 static unsigned numElements() { return 4; }
388
389 /// Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();
390 static Vec4<T> zero() { return Vec4<T>(0, 0, 0, 0); }
391 static Vec4<T> origin() { return Vec4<T>(0, 0, 0, 1); }
392 static Vec4<T> ones() { return Vec4<T>(1, 1, 1, 1); }
393};
394
395/// Equality operator, does exact floating point comparisons
396template <typename T0, typename T1>
397 inline bool operator==(const Vec4<T0> &v0, const Vec4<T1> &v1)
398{
399 return
400 isExactlyEqual(v0[0], v1[0]) &&
401 isExactlyEqual(v0[1], v1[1]) &&
402 isExactlyEqual(v0[2], v1[2]) &&
403 isExactlyEqual(v0[3], v1[3]);
404}
405
406/// Inequality operator, does exact floating point comparisons
407template <typename T0, typename T1>
408 inline bool operator!=(const Vec4<T0> &v0, const Vec4<T1> &v1) { return !(v0==v1); }
409
410/// Multiply each element of the given vector by @a scalar and return the result.
411template <typename S, typename T>
412 inline Vec4<typename promote<S, T>::type> operator*(S scalar, const Vec4<T> &v)
413{ return v*scalar; }
414
415/// Multiply each element of the given vector by @a scalar and return the result.
416template <typename S, typename T>
417 inline Vec4<typename promote<S, T>::type> operator*(const Vec4<T> &v, S scalar)
418{
419 Vec4<typename promote<S, T>::type> result(v);
420 result *= scalar;
421 return result;
422}
423
424/// Multiply corresponding elements of @a v0 and @a v1 and return the result.
425template <typename T0, typename T1>
426 inline Vec4<typename promote<T0, T1>::type> operator*(const Vec4<T0> &v0, const Vec4<T1> &v1)
427{
428 Vec4<typename promote<T0, T1>::type> result(v0[0]*v1[0],
429 v0[1]*v1[1],
430 v0[2]*v1[2],
431 v0[3]*v1[3]);
432 return result;
433}
434
435/// Divide @a scalar by each element of the given vector and return the result.
436template <typename S, typename T>
437 inline Vec4<typename promote<S, T>::type> operator/(S scalar, const Vec4<T> &v)
438{
439 return Vec4<typename promote<S, T>::type>(scalar/v[0],
440 scalar/v[1],
441 scalar/v[2],
442 scalar/v[3]);
443}
444
445/// Divide each element of the given vector by @a scalar and return the result.
446template <typename S, typename T>
447 inline Vec4<typename promote<S, T>::type> operator/(const Vec4<T> &v, S scalar)
448{
449 Vec4<typename promote<S, T>::type> result(v);
450 result /= scalar;
451 return result;
452}
453
454/// Divide corresponding elements of @a v0 and @a v1 and return the result.
455template <typename T0, typename T1>
456 inline Vec4<typename promote<T0, T1>::type> operator/(const Vec4<T0> &v0, const Vec4<T1> &v1)
457{
458 Vec4<typename promote<T0, T1>::type>
459 result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
460 return result;
461}
462
463/// Add corresponding elements of @a v0 and @a v1 and return the result.
464template <typename T0, typename T1>
465 inline Vec4<typename promote<T0, T1>::type> operator+(const Vec4<T0> &v0, const Vec4<T1> &v1)
466{
467 Vec4<typename promote<T0, T1>::type> result(v0);
468 result += v1;
469 return result;
470}
471
472/// Add @a scalar to each element of the given vector and return the result.
473template <typename S, typename T>
474 inline Vec4<typename promote<S, T>::type> operator+(const Vec4<T> &v, S scalar)
475{
476 Vec4<typename promote<S, T>::type> result(v);
477 result += scalar;
478 return result;
479}
480
481/// Subtract corresponding elements of @a v0 and @a v1 and return the result.
482template <typename T0, typename T1>
483 inline Vec4<typename promote<T0, T1>::type> operator-(const Vec4<T0> &v0, const Vec4<T1> &v1)
484{
485 Vec4<typename promote<T0, T1>::type> result(v0);
486 result -= v1;
487 return result;
488}
489
490/// Subtract @a scalar from each element of the given vector and return the result.
491template <typename S, typename T>
492 inline Vec4<typename promote<S, T>::type> operator-(const Vec4<T> &v, S scalar)
493{
494 Vec4<typename promote<S, T>::type> result(v);
495 result -= scalar;
496 return result;
497}
498
499template <typename T>
500inline bool
501 isApproxEqual(const Vec4<T>& a, const Vec4<T>& b)
502{
503 return a.eq(b);
504}
505template <typename T>
506inline bool
507 isApproxEqual(const Vec4<T>& a, const Vec4<T>& b, const Vec4<T>& eps)
508{
509 return isApproxEqual(a[0], b[0], eps[0]) &&
510 isApproxEqual(a[1], b[1], eps[1]) &&
511 isApproxEqual(a[2], b[2], eps[2]) &&
512 isApproxEqual(a[3], b[3], eps[3]);
513}
514
515template<typename T>
516inline Vec4<T>
517 Abs(const Vec4<T>& v)
518{
519 return Vec4<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]), Abs(v[3]));
520}
521
522/// @remark We are switching to a more explicit name because the semantics
523/// are different from std::min/max. In that case, the function returns a
524/// reference to one of the objects based on a comparator. Here, we must
525/// fabricate a new object which might not match either of the inputs.
526
527/// Return component-wise minimum of the two vectors.
528template <typename T>
529 inline Vec4<T> minComponent(const Vec4<T> &v1, const Vec4<T> &v2)
530{
531 return Vec4<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()));
536}
537
538/// Return component-wise maximum of the two vectors.
539template <typename T>
540 inline Vec4<T> maxComponent(const Vec4<T> &v1, const Vec4<T> &v2)
541{
542 return Vec4<T>(
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()));
547}
548
549/// @brief Return a vector with the exponent applied to each of
550/// the components of the input vector.
551template <typename T>
552 inline Vec4<T> Exp(Vec4<T> v) { return v.exp(); }
553
554/// @brief Return a vector with log applied to each of
555/// the components of the input vector.
556template <typename T>
557 inline Vec4<T> Log(Vec4<T> v) { return v.log(); }
558
559 using Vec4i = Vec4<int32_t>;
560 using Vec4ui = Vec4<uint32_t>;
561 using Vec4s = Vec4<float>;
562 using Vec4d = Vec4<double>;
563
564 OPENVDB_IS_POD(Vec4i)
565 OPENVDB_IS_POD(Vec4ui)
566 OPENVDB_IS_POD(Vec4s)
567 OPENVDB_IS_POD(Vec4d)
568
569} // namespace math
570} // namespace OPENVDB_VERSION_NAME
571} // namespace openvdb
572
573#endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
OPENVDB_IS_POD
#define OPENVDB_IS_POD(Type)
Definition Math.h:56
Tuple.h
Vec3.h
openvdb::v12_1::ArithmeticError
Definition Exceptions.h:56
openvdb::v12_1::math::Vec4< Real >::mm
Real mm[SIZE]
Definition Tuple.h:165
openvdb::v12_1::math::Tuple< 4, T >::Tuple
Tuple()=default
openvdb::v12_1::math::Vec3
Definition Vec3.h:25
openvdb::v12_1::math::Vec4
Definition Vec4.h:25
openvdb::v12_1::math::Vec4::Vec4
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition Vec4.h:59
openvdb::v12_1::math::Vec4::Vec4
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition Vec4.h:49
openvdb::v12_1::math::Vec4< Real >::x
Real & x()
Definition Vec4.h:78
openvdb::v12_1::math::Vec4::exp
const Vec4< T > & exp()
Definition Vec4.h:228
openvdb::v12_1::math::Vec4::getVec3
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition Vec4.h:99
openvdb::v12_1::math::Vec4::normalize
bool normalize(T eps=static_cast< T >(1.0e-8))
this = normalized this
Definition Vec4.h:261
openvdb::v12_1::math::Vec4::log
const Vec4< T > & log()
Definition Vec4.h:239
openvdb::v12_1::math::Vec4::init
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition Vec4.h:103
openvdb::v12_1::math::Vec4::length
T length() const
Length of the vector.
Definition Vec4.h:208
openvdb::v12_1::math::Vec4::sum
T sum() const
Return the sum of all the vector components.
Definition Vec4.h:249
openvdb::v12_1::math::Vec4::ones
static Vec4< T > ones()
Definition Vec4.h:392
openvdb::v12_1::math::Vec4::Vec4
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
openvdb::v12_1::math::Vec4::numColumns
static unsigned numColumns()
Definition Vec4.h:386
openvdb::v12_1::math::Vec4::add
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition Vec4.h:152
openvdb::v12_1::math::Vec4::operator-=
const Vec4< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition Vec4.h:364
openvdb::v12_1::math::Vec4::origin
static Vec4< T > origin()
Definition Vec4.h:391
openvdb::v12_1::math::Vec4::asPointer
T * asPointer()
Definition Vec4.h:89
openvdb::v12_1::math::Vec4::numRows
static unsigned numRows()
Definition Vec4.h:385
openvdb::v12_1::math::Vec4::div
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition Vec4.h:190
openvdb::v12_1::math::Vec4::w
T w() const
Definition Vec4.h:87
openvdb::v12_1::math::Vec4::operator()
T & operator()(int i)
Alternative indexed reference to the elements.
Definition Vec4.h:93
openvdb::v12_1::math::Vec4< Real >::y
Real & y()
Definition Vec4.h:79
openvdb::v12_1::math::Vec4< Real >::z
Real & z()
Definition Vec4.h:80
openvdb::v12_1::math::Vec4::operator/=
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
openvdb::v12_1::math::Vec4::operator()
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition Vec4.h:96
openvdb::v12_1::math::Vec4::product
T product() const
Return the product of all the vector components.
Definition Vec4.h:255
openvdb::v12_1::math::Vec4::zero
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition Vec4.h:390
openvdb::v12_1::math::Vec4::asPointer
const T * asPointer() const
Definition Vec4.h:90
openvdb::v12_1::math::Vec4::lengthSqr
T lengthSqr() const
Definition Vec4.h:220
openvdb::v12_1::math::Vec4::operator+=
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
openvdb::v12_1::math::Vec4::unit
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition Vec4.h:272
openvdb::v12_1::math::Vec4::sub
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition Vec4.h:166
openvdb::v12_1::math::Vec4::x
T x() const
Get the component, e.g. float f = v.y();.
Definition Vec4.h:84
openvdb::v12_1::math::Vec4::operator+=
const Vec4< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition Vec4.h:342
openvdb::v12_1::math::Vec4::dot
T dot(const Vec4< T > &v) const
Dot product.
Definition Vec4.h:201
openvdb::v12_1::math::Vec4::z
T z() const
Definition Vec4.h:86
openvdb::v12_1::math::Vec4::unitSafe
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
Definition Vec4.h:289
openvdb::v12_1::math::Vec4::y
T y() const
Definition Vec4.h:85
openvdb::v12_1::math::Vec4::Vec4
Vec4()=default
openvdb::v12_1::math::Vec4::setZero
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition Vec4.h:110
openvdb::v12_1::math::Vec4::numElements
static unsigned numElements()
Definition Vec4.h:387
openvdb::v12_1::math::Vec4::scale
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition Vec4.h:179
openvdb::v12_1::math::Vec4::operator-
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition Vec4.h:140
openvdb::v12_1::math::Vec4::operator/=
const Vec4< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition Vec4.h:320
openvdb::v12_1::math::Vec4::Vec4
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
openvdb::v12_1::math::Vec4::eq
bool eq(const Vec4< T > &v, T eps=static_cast< T >(1.0e-8)) const
Definition Vec4.h:131
openvdb::v12_1::math::Vec4::operator-=
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
openvdb::v12_1::math::Vec4::Vec4
Vec4(T val)
Construct a vector all of whose components have the given value.
Definition Vec4.h:36
openvdb::v12_1::math::Vec4< Real >::ValueType
Real ValueType
Definition Vec4.h:28
openvdb::v12_1::math::Vec4::operator*=
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
openvdb::v12_1::math::Vec4::unit
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition Vec4.h:279
openvdb::v12_1::math::Vec4::operator=
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition Vec4.h:118
openvdb::v12_1::math::Vec4< Real >::value_type
Real value_type
Definition Vec4.h:27
openvdb::v12_1::math::Vec4< Real >::w
Real & w()
Definition Vec4.h:81
openvdb::v12_1::math::Vec4::operator*=
const Vec4< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition Vec4.h:297
openvdb::v12_1::math::Log
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
openvdb::v12_1::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition Vec3.h:474
openvdb::v12_1::math::Vec4ui
Vec4< uint32_t > Vec4ui
Definition Vec4.h:560
openvdb::v12_1::math::operator*
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
openvdb::v12_1::math::isApproxZero
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance.
Definition Math.h:349
openvdb::v12_1::math::isApproxEqual
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
openvdb::v12_1::math::Vec4s
Vec4< float > Vec4s
Definition Vec4.h:561
openvdb::v12_1::math::operator-
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:554
openvdb::v12_1::math::operator+
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:528
openvdb::v12_1::math::Exp
Type Exp(const Type &x)
Return ex.
Definition Math.h:710
openvdb::v12_1::math::Abs
Coord Abs(const Coord &xyz)
Definition Coord.h:518
openvdb::v12_1::math::operator/
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
openvdb::v12_1::math::Vec4i
Vec4< int32_t > Vec4i
Definition Vec4.h:559
openvdb::v12_1::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition Math.h:443
openvdb::v12_1::math::minComponent
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition Vec2.h:504
openvdb::v12_1::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition Vec3.h:482
openvdb::v12_1::math::maxComponent
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition Vec2.h:513
openvdb::v12_1::math::Vec4d
Vec4< double > Vec4d
Definition Vec4.h:562
openvdb
Definition Exceptions.h:13
Exceptions.h
openvdb::v12_1::math::Conversion
Dummy class for tag dispatch of conversion constructors.
Definition Tuple.h:24
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218