OpenVDB: Vec3.h Source File

OpenVDB 7.0.0

Vec3.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_VEC3_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
6
7 #include <openvdb/Exceptions.h>
8 #include "Math.h"
9 #include "Tuple.h"
10 #include <algorithm>
11 #include <cmath>
12 #include <type_traits>
13
14
15 namespace openvdb {
16 OPENVDB_USE_VERSION_NAMESPACE
17 namespace OPENVDB_VERSION_NAME {
18 namespace math {
19
20 template<typename T> class Mat3;
21
22 template<typename T>
23 class Vec3: public Tuple<3, T>
24 {
25 public:
26 using value_type = T;
27 using ValueType = T;
28
30 Vec3() {}
31
33 explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
34
36 Vec3(T x, T y, T z)
37 {
38 this->mm[0] = x;
39 this->mm[1] = y;
40 this->mm[2] = z;
41 }
42
44 template <typename Source>
45 Vec3(Source *a)
46 {
47 this->mm[0] = static_cast<T>(a[0]);
48 this->mm[1] = static_cast<T>(a[1]);
49 this->mm[2] = static_cast<T>(a[2]);
50 }
51
54 template<typename Source>
55 explicit Vec3(const Tuple<3, Source> &v)
56 {
57 this->mm[0] = static_cast<T>(v[0]);
58 this->mm[1] = static_cast<T>(v[1]);
59 this->mm[2] = static_cast<T>(v[2]);
60 }
61
65 template<typename Other>
66 explicit Vec3(Other val,
67 typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
68 {
69 this->mm[0] = this->mm[1] = this->mm[2] = static_cast<T>(val);
70 }
71
74 template<typename Other>
75 Vec3(const Vec3<Other>& v)
76 {
77 this->mm[0] = static_cast<T>(v[0]);
78 this->mm[1] = static_cast<T>(v[1]);
79 this->mm[2] = static_cast<T>(v[2]);
80 }
81
83 T& x() { return this->mm[0]; }
84 T& y() { return this->mm[1]; }
85 T& z() { return this->mm[2]; }
86
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
92 T* asPointer() { return this->mm; }
93 const T* asPointer() const { return this->mm; }
94
96 T& operator()(int i) { return this->mm[i]; }
97
99 T operator()(int i) const { return this->mm[i]; }
100
103 const Vec3<T>& init(T x=0, T y=0, T z=0)
104 {
105 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z;
106 return *this;
107 }
108
109
111 const Vec3<T>& setZero()
112 {
113 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0;
114 return *this;
115 }
116
119 template<typename Source>
120 const Vec3<T>& operator=(const Vec3<Source> &v)
121 {
122 // note: don't static_cast because that suppresses warnings
123 this->mm[0] = v[0];
124 this->mm[1] = v[1];
125 this->mm[2] = v[2];
126
127 return *this;
128 }
129
131 bool eq(const Vec3<T> &v, T eps = static_cast<T>(1.0e-7)) const
132 {
133 return isRelOrApproxEqual(this->mm[0], v.mm[0], eps, eps) &&
134 isRelOrApproxEqual(this->mm[1], v.mm[1], eps, eps) &&
135 isRelOrApproxEqual(this->mm[2], v.mm[2], eps, eps);
136 }
137
138
140 Vec3<T> operator-() const { return Vec3<T>(-this->mm[0], -this->mm[1], -this->mm[2]); }
141
144 template <typename T0, typename T1>
145 const Vec3<T>& add(const Vec3<T0> &v1, const Vec3<T1> &v2)
146 {
147 this->mm[0] = v1[0] + v2[0];
148 this->mm[1] = v1[1] + v2[1];
149 this->mm[2] = v1[2] + v2[2];
150
151 return *this;
152 }
153
156 template <typename T0, typename T1>
157 const Vec3<T>& sub(const Vec3<T0> &v1, const Vec3<T1> &v2)
158 {
159 this->mm[0] = v1[0] - v2[0];
160 this->mm[1] = v1[1] - v2[1];
161 this->mm[2] = v1[2] - v2[2];
162
163 return *this;
164 }
165
168 template <typename T0, typename T1>
169 const Vec3<T>& scale(T0 scale, const Vec3<T1> &v)
170 {
171 this->mm[0] = scale * v[0];
172 this->mm[1] = scale * v[1];
173 this->mm[2] = scale * v[2];
174
175 return *this;
176 }
177
178 template <typename T0, typename T1>
179 const Vec3<T> &div(T0 scale, const Vec3<T1> &v)
180 {
181 this->mm[0] = v[0] / scale;
182 this->mm[1] = v[1] / scale;
183 this->mm[2] = v[2] / scale;
184
185 return *this;
186 }
187
189 T dot(const Vec3<T> &v) const
190 {
191 return
192 this->mm[0]*v.mm[0] +
193 this->mm[1]*v.mm[1] +
194 this->mm[2]*v.mm[2];
195 }
196
198 T length() const
199 {
200 return static_cast<T>(sqrt(double(
201 this->mm[0]*this->mm[0] +
202 this->mm[1]*this->mm[1] +
203 this->mm[2]*this->mm[2])));
204 }
205
206
209 T lengthSqr() const
210 {
211 return
212 this->mm[0]*this->mm[0] +
213 this->mm[1]*this->mm[1] +
214 this->mm[2]*this->mm[2];
215 }
216
218 Vec3<T> cross(const Vec3<T> &v) const
219 {
220 return Vec3<T>(this->mm[1]*v.mm[2] - this->mm[2]*v.mm[1],
221 this->mm[2]*v.mm[0] - this->mm[0]*v.mm[2],
222 this->mm[0]*v.mm[1] - this->mm[1]*v.mm[0]);
223 }
224
225
227 const Vec3<T>& cross(const Vec3<T> &v1, const Vec3<T> &v2)
228 {
229 // assert(this!=&v1);
230 // assert(this!=&v2);
231 this->mm[0] = v1.mm[1]*v2.mm[2] - v1.mm[2]*v2.mm[1];
232 this->mm[1] = v1.mm[2]*v2.mm[0] - v1.mm[0]*v2.mm[2];
233 this->mm[2] = v1.mm[0]*v2.mm[1] - v1.mm[1]*v2.mm[0];
234 return *this;
235 }
236
238 template <typename S>
239 const Vec3<T> &operator*=(S scalar)
240 {
241 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
242 const auto value0 = this->mm[0] * scalar;
243 const auto value1 = this->mm[1] * scalar;
244 const auto value2 = this->mm[2] * scalar;
245 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
246 this->mm[0] = static_cast<T>(value0);
247 this->mm[1] = static_cast<T>(value1);
248 this->mm[2] = static_cast<T>(value2);
249 return *this;
250 }
251
253 template <typename S>
254 const Vec3<T> &operator*=(const Vec3<S> &v1)
255 {
256 this->mm[0] *= v1[0];
257 this->mm[1] *= v1[1];
258 this->mm[2] *= v1[2];
259 return *this;
260 }
261
263 template <typename S>
264 const Vec3<T> &operator/=(S scalar)
265 {
266 this->mm[0] /= scalar;
267 this->mm[1] /= scalar;
268 this->mm[2] /= scalar;
269 return *this;
270 }
271
273 template <typename S>
274 const Vec3<T> &operator/=(const Vec3<S> &v1)
275 {
276 this->mm[0] /= v1[0];
277 this->mm[1] /= v1[1];
278 this->mm[2] /= v1[2];
279 return *this;
280 }
281
283 template <typename S>
284 const Vec3<T> &operator+=(S scalar)
285 {
286 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
287 const auto value0 = this->mm[0] + scalar;
288 const auto value1 = this->mm[1] + scalar;
289 const auto value2 = this->mm[2] + scalar;
290 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
291 this->mm[0] = static_cast<T>(value0);
292 this->mm[1] = static_cast<T>(value1);
293 this->mm[2] = static_cast<T>(value2);
294 return *this;
295 }
296
298 template <typename S>
299 const Vec3<T> &operator+=(const Vec3<S> &v1)
300 {
301 this->mm[0] += v1[0];
302 this->mm[1] += v1[1];
303 this->mm[2] += v1[2];
304 return *this;
305 }
306
308 template <typename S>
309 const Vec3<T> &operator-=(S scalar)
310 {
311 this->mm[0] -= scalar;
312 this->mm[1] -= scalar;
313 this->mm[2] -= scalar;
314 return *this;
315 }
316
318 template <typename S>
319 const Vec3<T> &operator-=(const Vec3<S> &v1)
320 {
321 this->mm[0] -= v1[0];
322 this->mm[1] -= v1[1];
323 this->mm[2] -= v1[2];
324 return *this;
325 }
326
329 inline const Vec3<T>& exp()
330 {
331 this->mm[0] = std::exp(this->mm[0]);
332 this->mm[1] = std::exp(this->mm[1]);
333 this->mm[2] = std::exp(this->mm[2]);
334 return *this;
335 }
336
339 inline const Vec3<T>& log()
340 {
341 this->mm[0] = std::log(this->mm[0]);
342 this->mm[1] = std::log(this->mm[1]);
343 this->mm[2] = std::log(this->mm[2]);
344 return *this;
345 }
346
348 inline T sum() const
349 {
350 return this->mm[0] + this->mm[1] + this->mm[2];
351 }
352
354 inline T product() const
355 {
356 return this->mm[0] * this->mm[1] * this->mm[2];
357 }
358
360 bool normalize(T eps = T(1.0e-7))
361 {
362 T d = length();
363 if (isApproxEqual(d, T(0), eps)) {
364 return false;
365 }
366 *this *= (T(1) / d);
367 return true;
368 }
369
370
372 Vec3<T> unit(T eps=0) const
373 {
374 T d;
375 return unit(eps, d);
376 }
377
379 Vec3<T> unit(T eps, T& len) const
380 {
381 len = length();
382 if (isApproxEqual(len, T(0), eps)) {
383 OPENVDB_THROW(ArithmeticError, "Normalizing null 3-vector");
384 }
385 return *this / len;
386 }
387
389 Vec3<T> unitSafe() const
390 {
391 T l2 = lengthSqr();
392 return l2 ? *this / static_cast<T>(sqrt(l2)) : Vec3<T>(1, 0 ,0);
393 }
394
395 // Number of cols, rows, elements
396 static unsigned numRows() { return 1; }
397 static unsigned numColumns() { return 3; }
398 static unsigned numElements() { return 3; }
399
402 T component(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
403 {
404 T l = onto.length();
405 if (isApproxEqual(l, T(0), eps)) return 0;
406
407 return dot(onto)*(T(1)/l);
408 }
409
412 Vec3<T> projection(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
413 {
414 T l = onto.lengthSqr();
415 if (isApproxEqual(l, T(0), eps)) return Vec3::zero();
416
417 return onto*(dot(onto)*(T(1)/l));
418 }
419
423 Vec3<T> getArbPerpendicular() const
424 {
425 Vec3<T> u;
426 T l;
427
428 if ( fabs(this->mm[0]) >= fabs(this->mm[1]) ) {
429 // v.x or v.z is the largest magnitude component, swap them
430 l = this->mm[0]*this->mm[0] + this->mm[2]*this->mm[2];
431 l = static_cast<T>(T(1)/sqrt(double(l)));
432 u.mm[0] = -this->mm[2]*l;
433 u.mm[1] = T(0);
434 u.mm[2] = +this->mm[0]*l;
435 } else {
436 // W.y or W.z is the largest magnitude component, swap them
437 l = this->mm[1]*this->mm[1] + this->mm[2]*this->mm[2];
438 l = static_cast<T>(T(1)/sqrt(double(l)));
439 u.mm[0] = T(0);
440 u.mm[1] = +this->mm[2]*l;
441 u.mm[2] = -this->mm[1]*l;
442 }
443
444 return u;
445 }
446
448 Vec3<T> sorted() const
449 {
450 Vec3<T> r(*this);
451 if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
452 if( r.mm[1] > r.mm[2] ) std::swap(r.mm[1], r.mm[2]);
453 if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
454 return r;
455 }
456
458 Vec3<T> reversed() const
459 {
460 return Vec3<T>(this->mm[2], this->mm[1], this->mm[0]);
461 }
462
464 static Vec3<T> zero() { return Vec3<T>(0, 0, 0); }
465 static Vec3<T> ones() { return Vec3<T>(1, 1, 1); }
466 };
467
468
470 template <typename T0, typename T1>
471 inline bool operator==(const Vec3<T0> &v0, const Vec3<T1> &v1)
472 {
473 return isExactlyEqual(v0[0], v1[0]) && isExactlyEqual(v0[1], v1[1])
474 && isExactlyEqual(v0[2], v1[2]);
475 }
476
478 template <typename T0, typename T1>
479 inline bool operator!=(const Vec3<T0> &v0, const Vec3<T1> &v1) { return !(v0==v1); }
480
482 template <typename S, typename T>
483 inline Vec3<typename promote<S, T>::type> operator*(S scalar, const Vec3<T> &v) { return v*scalar; }
484
486 template <typename S, typename T>
487 inline Vec3<typename promote<S, T>::type> operator*(const Vec3<T> &v, S scalar)
488 {
489 Vec3<typename promote<S, T>::type> result(v);
490 result *= scalar;
491 return result;
492 }
493
495 template <typename T0, typename T1>
496 inline Vec3<typename promote<T0, T1>::type> operator*(const Vec3<T0> &v0, const Vec3<T1> &v1)
497 {
498 Vec3<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1], v0[2] * v1[2]);
499 return result;
500 }
501
502
504 template <typename S, typename T>
505 inline Vec3<typename promote<S, T>::type> operator/(S scalar, const Vec3<T> &v)
506 {
507 return Vec3<typename promote<S, T>::type>(scalar/v[0], scalar/v[1], scalar/v[2]);
508 }
509
511 template <typename S, typename T>
512 inline Vec3<typename promote<S, T>::type> operator/(const Vec3<T> &v, S scalar)
513 {
514 Vec3<typename promote<S, T>::type> result(v);
515 result /= scalar;
516 return result;
517 }
518
520 template <typename T0, typename T1>
521 inline Vec3<typename promote<T0, T1>::type> operator/(const Vec3<T0> &v0, const Vec3<T1> &v1)
522 {
523 Vec3<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1], v0[2] / v1[2]);
524 return result;
525 }
526
528 template <typename T0, typename T1>
529 inline Vec3<typename promote<T0, T1>::type> operator+(const Vec3<T0> &v0, const Vec3<T1> &v1)
530 {
531 Vec3<typename promote<T0, T1>::type> result(v0);
532 result += v1;
533 return result;
534 }
535
537 template <typename S, typename T>
538 inline Vec3<typename promote<S, T>::type> operator+(const Vec3<T> &v, S scalar)
539 {
540 Vec3<typename promote<S, T>::type> result(v);
541 result += scalar;
542 return result;
543 }
544
546 template <typename T0, typename T1>
547 inline Vec3<typename promote<T0, T1>::type> operator-(const Vec3<T0> &v0, const Vec3<T1> &v1)
548 {
549 Vec3<typename promote<T0, T1>::type> result(v0);
550 result -= v1;
551 return result;
552 }
553
555 template <typename S, typename T>
556 inline Vec3<typename promote<S, T>::type> operator-(const Vec3<T> &v, S scalar)
557 {
558 Vec3<typename promote<S, T>::type> result(v);
559 result -= scalar;
560 return result;
561 }
562
565 template <typename T>
566 inline T angle(const Vec3<T> &v1, const Vec3<T> &v2)
567 {
568 Vec3<T> c = v1.cross(v2);
569 return static_cast<T>(atan2(c.length(), v1.dot(v2)));
570 }
571
572 template <typename T>
573 inline bool
574 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b)
575 {
576 return a.eq(b);
577 }
578 template <typename T>
579 inline bool
580 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& eps)
581 {
582 return isApproxEqual(a.x(), b.x(), eps.x()) &&
583 isApproxEqual(a.y(), b.y(), eps.y()) &&
584 isApproxEqual(a.z(), b.z(), eps.z());
585 }
586
587 template<typename T>
588 inline Vec3<T>
589 Abs(const Vec3<T>& v)
590 {
591 return Vec3<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]));
592 }
593
596 template <typename T>
597 inline void orthonormalize(Vec3<T> &v1, Vec3<T> &v2, Vec3<T> &v3)
598 {
599 // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
600 // orthonormalization produces vectors u0, u1, and u2 as follows,
601 //
602 // u0 = v0/|v0|
603 // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
604 // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
605 //
606 // where |A| indicates length of vector A and A*B indicates dot
607 // product of vectors A and B.
608
609 // compute u0
610 v1.normalize();
611
612 // compute u1
613 T d0 = v1.dot(v2);
614 v2 -= v1*d0;
615 v2.normalize();
616
617 // compute u2
618 T d1 = v2.dot(v3);
619 d0 = v1.dot(v3);
620 v3 -= v1*d0 + v2*d1;
621 v3.normalize();
622 }
623
628
630 template <typename T>
631 inline Vec3<T> minComponent(const Vec3<T> &v1, const Vec3<T> &v2)
632 {
633 return Vec3<T>(
634 std::min(v1.x(), v2.x()),
635 std::min(v1.y(), v2.y()),
636 std::min(v1.z(), v2.z()));
637 }
638
640 template <typename T>
641 inline Vec3<T> maxComponent(const Vec3<T> &v1, const Vec3<T> &v2)
642 {
643 return Vec3<T>(
644 std::max(v1.x(), v2.x()),
645 std::max(v1.y(), v2.y()),
646 std::max(v1.z(), v2.z()));
647 }
648
651 template <typename T>
652 inline Vec3<T> Exp(Vec3<T> v) { return v.exp(); }
653
656 template <typename T>
657 inline Vec3<T> Log(Vec3<T> v) { return v.log(); }
658
659 using Vec3i = Vec3<int32_t>;
660 using Vec3ui = Vec3<uint32_t>;
661 using Vec3s = Vec3<float>;
662 using Vec3d = Vec3<double>;
663
664 } // namespace math
665 } // namespace OPENVDB_VERSION_NAME
666 } // namespace openvdb
667
668 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
openvdb::v7_0::math::Vec3::operator+=
const Vec3< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition: Vec3.h:284
openvdb::v7_0::math::Vec3::sub
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:157
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition: Platform.h:197
openvdb::v7_0::math::Vec3::x
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:83
openvdb::v7_0::math::Vec3::numElements
static unsigned numElements()
Definition: Vec3.h:398
openvdb::v7_0::math::Vec3::cross
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition: Vec3.h:218
openvdb::v7_0::math::Vec3::y
T y() const
Definition: Vec3.h:89
openvdb::v7_0::math::Tuple
Definition: Tuple.h:28
openvdb::v7_0::math::Vec3::zero
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition: Vec3.h:464
openvdb::v7_0::math::Vec3::Vec3
Vec3(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: Vec3.h:66
openvdb::v7_0::math::Exp
Vec3< T > Exp(Vec3< T > v)
Return a vector with the exponent applied to each of the components of the input vector.
Definition: Vec3.h:652
openvdb::v7_0::math::Vec3::numColumns
static unsigned numColumns()
Definition: Vec3.h:397
openvdb::v7_0::math::Vec3::Vec3
Vec3(const Tuple< 3, Source > &v)
Construct a Vec3 from a 3-Tuple with a possibly different value type.
Definition: Vec3.h:55
openvdb::v7_0::math::Vec3::sum
T sum() const
Return the sum of all the vector components.
Definition: Vec3.h:348
openvdb::v7_0::math::Vec3::getArbPerpendicular
Vec3< T > getArbPerpendicular() const
Definition: Vec3.h:423
openvdb::v7_0::math::Conversion
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:22
openvdb::v7_0::math::Vec3::setZero
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition: Vec3.h:111
openvdb::v7_0::math::Vec3::Vec3
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Definition: Vec3.h:36
openvdb::v7_0::math::Vec3::unit
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec3.h:379
openvdb::v7_0::math::Vec3::operator*=
const Vec3< T > & operator*=(const Vec3< S > &v1)
Multiply each element of this vector by the corresponding element of the given vector.
Definition: Vec3.h:254
openvdb::v7_0::math::Vec3::Vec3
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
Definition: Vec3.h:75
openvdb::v7_0::math::Vec3::operator/=
const Vec3< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition: Vec3.h:264
openvdb::v7_0::math::Vec3::cross
const Vec3< T > & cross(const Vec3< T > &v1, const Vec3< T > &v2)
this = v1 cross v2, v1 and v2 must be distinct objects than "this"
Definition: Vec3.h:227
openvdb::v7_0::math::operator-
Vec3< typename promote< S, T >::type > operator-(const Vec3< T > &v, S scalar)
Subtract scalar from each element of the given vector and return the result.
Definition: Vec3.h:556
openvdb::v7_0::math::Vec3::y
T & y()
Definition: Vec3.h:84
openvdb::v7_0::math::Vec3::div
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:179
openvdb::v7_0::math::Vec3::operator-=
const Vec3< T > & operator-=(const Vec3< S > &v1)
Subtract each element of the given vector from the corresponding element of this vector.
Definition: Vec3.h:319
openvdb::v7_0::math::Vec3::operator()
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec3.h:99
openvdb::v7_0::math::isRelOrApproxEqual
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:398
openvdb::v7_0::math::Vec3::sorted
Vec3< T > sorted() const
Return a vector with the components of this in ascending order.
Definition: Vec3.h:448
openvdb::v7_0::math::minComponent
Vec3< T > minComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec3.h:631
openvdb::v7_0::math::operator+
Vec3< typename promote< S, T >::type > operator+(const Vec3< T > &v, S scalar)
Add scalar to each element of the given vector and return the result.
Definition: Vec3.h:538
openvdb::v7_0::math::Vec3::eq
bool eq(const Vec3< T > &v, T eps=static_cast< T >(1.0e-7)) const
Test if "this" vector is equivalent to vector v with tolerance of eps.
Definition: Vec3.h:131
openvdb::v7_0::math::Log
Vec3< T > Log(Vec3< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec3.h:657
openvdb::v7_0::math::Vec3::operator=
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition: Vec3.h:120
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v7_0::math::Vec3::lengthSqr
T lengthSqr() const
Definition: Vec3.h:209
openvdb::v7_0::math::Abs
Vec3< T > Abs(const Vec3< T > &v)
Definition: Vec3.h:589
openvdb::v7_0::math::Vec3::z
T & z()
Definition: Vec3.h:85
openvdb::v7_0::math::angle
T angle(const Vec3< T > &v1, const Vec3< T > &v2)
Definition: Vec3.h:566
openvdb::v7_0::math::maxComponent
Vec3< T > maxComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec3.h:641
openvdb::v7_0::math::Vec3::asPointer
T * asPointer()
Definition: Vec3.h:92
openvdb::v7_0::math::Vec3::operator-=
const Vec3< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition: Vec3.h:309
openvdb::v7_0::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:106
openvdb::v7_0::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
openvdb::v7_0::math::Vec3
Definition: Mat.h:170
openvdb::v7_0::math::orthonormalize
void orthonormalize(Vec3< T > &v1, Vec3< T > &v2, Vec3< T > &v3)
Definition: Vec3.h:597
openvdb::v7_0::math::Vec3::unit
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec3.h:372
openvdb::v7_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:653
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::math::Vec3::init
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition: Vec3.h:103
openvdb::v7_0::math::Vec3::projection
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:412
openvdb::v7_0::math::Vec3::add
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:145
openvdb::v7_0::math::Vec3::length
T length() const
Length of the vector.
Definition: Vec3.h:198
openvdb::v7_0::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:102
openvdb::v7_0::math::Vec3::reversed
Vec3< T > reversed() const
Return the vector (z, y, x)
Definition: Vec3.h:458
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END, to inhibit warnings about type conve...
Definition: Platform.h:196
openvdb::v7_0::math::Vec3::Vec3
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition: Vec3.h:45
openvdb::v7_0::math::operator/
Vec3< typename promote< T0, T1 >::type > operator/(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Divide corresponding elements of v0 and v1 and return the result.
Definition: Vec3.h:521
openvdb::v7_0::math::Vec3::operator/=
const Vec3< T > & operator/=(const Vec3< S > &v1)
Divide each element of this vector by the corresponding element of the given vector.
Definition: Vec3.h:274
openvdb::v7_0::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:479
openvdb::v7_0::math::Vec3::x
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec3.h:88
openvdb::v7_0::math::Vec3::Vec3
Vec3()
Trivial constructor, the vector is NOT initialized.
Definition: Vec3.h:30
openvdb::v7_0::math::Vec3::log
const Vec3< T > & log()
Definition: Vec3.h:339
openvdb::v7_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:388
openvdb::v7_0::math::Vec3::asPointer
const T * asPointer() const
Definition: Vec3.h:93
openvdb::v7_0::math::Vec3::operator+=
const Vec3< T > & operator+=(const Vec3< S > &v1)
Add each element of the given vector to the corresponding element of this vector.
Definition: Vec3.h:299
openvdb::v7_0::math::Vec3::unitSafe
Vec3< T > unitSafe() const
return normalized this, or (1, 0, 0) if this is null vector
Definition: Vec3.h:389
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:108
openvdb::v7_0::math::scale
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:620
openvdb::v7_0::math::Vec3< Real >::value_type
Real value_type
Definition: Vec3.h:26
openvdb::v7_0::math::Vec3::ones
static Vec3< T > ones()
Definition: Vec3.h:465
openvdb::v7_0::math::Vec3::dot
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:189
openvdb::v7_0::math::Vec3::normalize
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:360
openvdb::v7_0::math::Vec3::Vec3
Vec3(T val)
Construct a vector all of whose components have the given value.
Definition: Vec3.h:33
openvdb::v7_0::math::Vec3< Real >::ValueType
Real ValueType
Definition: Vec3.h:27
openvdb::v7_0::math::Vec3::product
T product() const
Return the product of all the vector components.
Definition: Vec3.h:354
openvdb::v7_0::math::Vec3::operator()
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec3.h:96
openvdb::v7_0::math::operator*
Vec3< typename promote< T0, T1 >::type > operator*(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Multiply corresponding elements of v0 and v1 and return the result.
Definition: Vec3.h:496
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::math::Vec3::exp
const Vec3< T > & exp()
Definition: Vec3.h:329
openvdb::v7_0::math::Vec3::operator*=
const Vec3< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition: Vec3.h:239
openvdb::v7_0::math::isApproxEqual
bool isApproxEqual(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &eps)
Definition: Vec3.h:580
openvdb::v7_0::math::Vec3::z
T z() const
Definition: Vec3.h:90
Tuple.h
openvdb::v7_0::math::Vec3::operator-
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec3.h:140
openvdb::v7_0::math::Vec3::numRows
static unsigned numRows()
Definition: Vec3.h:396
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
Exceptions.h
openvdb::v7_0::math::Vec3::component
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:402
openvdb::v7_0::ArithmeticError
Definition: Exceptions.h:56
openvdb::v7_0::math::Vec3::scale
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:169