OpenVDB: openvdb/math/Vec4.h Source File

OpenVDB 9.0.0

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