OpenVDB 3.2.0

Vec3.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30
31 #ifndef OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
33
34 #include <cmath>
35 #include <openvdb/Exceptions.h>
36 #include "Math.h"
37 #include "Tuple.h"
38
39 namespace openvdb {
40 OPENVDB_USE_VERSION_NAMESPACE
41 namespace OPENVDB_VERSION_NAME {
42 namespace math {
43
44 template<typename T> class Mat3;
45
46 template<typename T>
47 class Vec3: public Tuple<3, T>
48 {
49 public:
50 typedef T value_type;
51 typedef T ValueType;
52
54 Vec3() {}
55
57 explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
58
60 Vec3(T x, T y, T z)
61 {
62 this->mm[0] = x;
63 this->mm[1] = y;
64 this->mm[2] = z;
65 }
66
68 template <typename Source>
69 Vec3(Source *a)
70 {
71 this->mm[0] = a[0];
72 this->mm[1] = a[1];
73 this->mm[2] = a[2];
74 }
75
78 template<typename Source>
79 explicit Vec3(const Tuple<3, Source> &v)
80 {
81 this->mm[0] = static_cast<T>(v[0]);
82 this->mm[1] = static_cast<T>(v[1]);
83 this->mm[2] = static_cast<T>(v[2]);
84 }
85
88 template<typename Other>
89 Vec3(const Vec3<Other>& v)
90 {
91 this->mm[0] = static_cast<T>(v[0]);
92 this->mm[1] = static_cast<T>(v[1]);
93 this->mm[2] = static_cast<T>(v[2]);
94 }
95
97 T& x() { return this->mm[0]; }
98 T& y() { return this->mm[1]; }
99 T& z() { return this->mm[2]; }
100
102 T x() const { return this->mm[0]; }
103 T y() const { return this->mm[1]; }
104 T z() const { return this->mm[2]; }
105
106 T* asPointer() { return this->mm; }
107 const T* asPointer() const { return this->mm; }
108
110 T& operator()(int i) { return this->mm[i]; }
111
113 T operator()(int i) const { return this->mm[i]; }
114
117 const Vec3<T>& init(T x=0, T y=0, T z=0)
118 {
119 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z;
120 return *this;
121 }
122
123
125 const Vec3<T>& setZero()
126 {
127 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0;
128 return *this;
129 }
130
133 template<typename Source>
134 const Vec3<T>& operator=(const Vec3<Source> &v)
135 {
136 // note: don't static_cast because that suppresses warnings
137 this->mm[0] = v[0];
138 this->mm[1] = v[1];
139 this->mm[2] = v[2];
140
141 return *this;
142 }
143
145 bool eq(const Vec3<T> &v, T eps = static_cast<T>(1.0e-7)) const
146 {
147 return isRelOrApproxEqual(this->mm[0], v.mm[0], eps, eps) &&
148 isRelOrApproxEqual(this->mm[1], v.mm[1], eps, eps) &&
149 isRelOrApproxEqual(this->mm[2], v.mm[2], eps, eps);
150 }
151
152
154 Vec3<T> operator-() const { return Vec3<T>(-this->mm[0], -this->mm[1], -this->mm[2]); }
155
158 template <typename T0, typename T1>
159 const Vec3<T>& add(const Vec3<T0> &v1, const Vec3<T1> &v2)
160 {
161 this->mm[0] = v1[0] + v2[0];
162 this->mm[1] = v1[1] + v2[1];
163 this->mm[2] = v1[2] + v2[2];
164
165 return *this;
166 }
167
170 template <typename T0, typename T1>
171 const Vec3<T>& sub(const Vec3<T0> &v1, const Vec3<T1> &v2)
172 {
173 this->mm[0] = v1[0] - v2[0];
174 this->mm[1] = v1[1] - v2[1];
175 this->mm[2] = v1[2] - v2[2];
176
177 return *this;
178 }
179
182 template <typename T0, typename T1>
183 const Vec3<T>& scale(T0 scale, const Vec3<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
189 return *this;
190 }
191
192 template <typename T0, typename T1>
193 const Vec3<T> &div(T0 scale, const Vec3<T1> &v)
194 {
195 this->mm[0] = v[0] / scale;
196 this->mm[1] = v[1] / scale;
197 this->mm[2] = v[2] / scale;
198
199 return *this;
200 }
201
203 T dot(const Vec3<T> &v) const
204 {
205 return
206 this->mm[0]*v.mm[0] +
207 this->mm[1]*v.mm[1] +
208 this->mm[2]*v.mm[2];
209 }
210
212 T length() const
213 {
214 return static_cast<T>(sqrt(double(
215 this->mm[0]*this->mm[0] +
216 this->mm[1]*this->mm[1] +
217 this->mm[2]*this->mm[2])));
218 }
219
220
223 T lengthSqr() const
224 {
225 return
226 this->mm[0]*this->mm[0] +
227 this->mm[1]*this->mm[1] +
228 this->mm[2]*this->mm[2];
229 }
230
232 Vec3<T> cross(const Vec3<T> &v) const
233 {
234 return Vec3<T>(this->mm[1]*v.mm[2] - this->mm[2]*v.mm[1],
235 this->mm[2]*v.mm[0] - this->mm[0]*v.mm[2],
236 this->mm[0]*v.mm[1] - this->mm[1]*v.mm[0]);
237 }
238
239
241 const Vec3<T>& cross(const Vec3<T> &v1, const Vec3<T> &v2)
242 {
243 // assert(this!=&v1);
244 // assert(this!=&v2);
245 this->mm[0] = v1.mm[1]*v2.mm[2] - v1.mm[2]*v2.mm[1];
246 this->mm[1] = v1.mm[2]*v2.mm[0] - v1.mm[0]*v2.mm[2];
247 this->mm[2] = v1.mm[0]*v2.mm[1] - v1.mm[1]*v2.mm[0];
248 return *this;
249 }
250
252 template <typename S>
253 const Vec3<T> &operator*=(S scalar)
254 {
255 this->mm[0] = static_cast<T>(this->mm[0] * scalar);
256 this->mm[1] = static_cast<T>(this->mm[1] * scalar);
257 this->mm[2] = static_cast<T>(this->mm[2] * scalar);
258 return *this;
259 }
260
262 template <typename S>
263 const Vec3<T> &operator*=(const Vec3<S> &v1)
264 {
265 this->mm[0] *= v1[0];
266 this->mm[1] *= v1[1];
267 this->mm[2] *= v1[2];
268 return *this;
269 }
270
272 template <typename S>
273 const Vec3<T> &operator/=(S scalar)
274 {
275 this->mm[0] /= scalar;
276 this->mm[1] /= scalar;
277 this->mm[2] /= scalar;
278 return *this;
279 }
280
282 template <typename S>
283 const Vec3<T> &operator/=(const Vec3<S> &v1)
284 {
285 this->mm[0] /= v1[0];
286 this->mm[1] /= v1[1];
287 this->mm[2] /= v1[2];
288 return *this;
289 }
290
292 template <typename S>
293 const Vec3<T> &operator+=(S scalar)
294 {
295 this->mm[0] = static_cast<T>(this->mm[0] + scalar);
296 this->mm[1] = static_cast<T>(this->mm[1] + scalar);
297 this->mm[2] = static_cast<T>(this->mm[2] + scalar);
298 return *this;
299 }
300
302 template <typename S>
303 const Vec3<T> &operator+=(const Vec3<S> &v1)
304 {
305 this->mm[0] += v1[0];
306 this->mm[1] += v1[1];
307 this->mm[2] += v1[2];
308 return *this;
309 }
310
312 template <typename S>
313 const Vec3<T> &operator-=(S scalar)
314 {
315 this->mm[0] -= scalar;
316 this->mm[1] -= scalar;
317 this->mm[2] -= scalar;
318 return *this;
319 }
320
322 template <typename S>
323 const Vec3<T> &operator-=(const Vec3<S> &v1)
324 {
325 this->mm[0] -= v1[0];
326 this->mm[1] -= v1[1];
327 this->mm[2] -= v1[2];
328 return *this;
329 }
330
333 inline const Vec3<T>& exp()
334 {
335 this->mm[0] = std::exp(this->mm[0]);
336 this->mm[1] = std::exp(this->mm[1]);
337 this->mm[2] = std::exp(this->mm[2]);
338 return *this;
339 }
340
342 inline T sum() const
343 {
344 return this->mm[0] + this->mm[1] + this->mm[2];
345 }
346
348 bool normalize(T eps = T(1.0e-7))
349 {
350 T d = length();
351 if (isApproxEqual(d, T(0), eps)) {
352 return false;
353 }
354 *this *= (T(1) / d);
355 return true;
356 }
357
358
360 Vec3<T> unit(T eps=0) const
361 {
362 T d;
363 return unit(eps, d);
364 }
365
367 Vec3<T> unit(T eps, T& len) const
368 {
369 len = length();
370 if (isApproxEqual(len, T(0), eps)) {
371 OPENVDB_THROW(ArithmeticError, "Normalizing null 3-vector");
372 }
373 return *this / len;
374 }
375
376 // Number of cols, rows, elements
377 static unsigned numRows() { return 1; }
378 static unsigned numColumns() { return 3; }
379 static unsigned numElements() { return 3; }
380
383 T component(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
384 {
385 T l = onto.length();
386 if (isApproxEqual(l, T(0), eps)) return 0;
387
388 return dot(onto)*(T(1)/l);
389 }
390
393 Vec3<T> projection(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
394 {
395 T l = onto.lengthSqr();
396 if (isApproxEqual(l, T(0), eps)) return Vec3::zero();
397
398 return onto*(dot(onto)*(T(1)/l));
399 }
400
404 Vec3<T> getArbPerpendicular() const
405 {
406 Vec3<T> u;
407 T l;
408
409 if ( fabs(this->mm[0]) >= fabs(this->mm[1]) ) {
410 // v.x or v.z is the largest magnitude component, swap them
411 l = this->mm[0]*this->mm[0] + this->mm[2]*this->mm[2];
412 l = static_cast<T>(T(1)/sqrt(double(l)));
413 u.mm[0] = -this->mm[2]*l;
414 u.mm[1] = (T)0.0;
415 u.mm[2] = +this->mm[0]*l;
416 } else {
417 // W.y or W.z is the largest magnitude component, swap them
418 l = this->mm[1]*this->mm[1] + this->mm[2]*this->mm[2];
419 l = static_cast<T>(T(1)/sqrt(double(l)));
420 u.mm[0] = (T)0.0;
421 u.mm[1] = +this->mm[2]*l;
422 u.mm[2] = -this->mm[1]*l;
423 }
424
425 return u;
426 }
427
429 bool isNan() const { return isnan(this->mm[0]) || isnan(this->mm[1]) || isnan(this->mm[2]); }
430
432 bool isInfinite() const
433 {
434 return isinf(this->mm[0]) || isinf(this->mm[1]) || isinf(this->mm[2]);
435 }
436
438 bool isFinite() const
439 {
440 return finite(this->mm[0]) && finite(this->mm[1]) && finite(this->mm[2]);
441 }
442
444 static Vec3<T> zero() { return Vec3<T>(0, 0, 0); }
445 };
446
447
449 template <typename T0, typename T1>
450 inline bool operator==(const Vec3<T0> &v0, const Vec3<T1> &v1)
451 {
452 return isExactlyEqual(v0[0], v1[0]) && isExactlyEqual(v0[1], v1[1])
453 && isExactlyEqual(v0[2], v1[2]);
454 }
455
457 template <typename T0, typename T1>
458 inline bool operator!=(const Vec3<T0> &v0, const Vec3<T1> &v1) { return !(v0==v1); }
459
461 template <typename S, typename T>
462 inline Vec3<typename promote<S, T>::type> operator*(S scalar, const Vec3<T> &v) { return v*scalar; }
463
465 template <typename S, typename T>
466 inline Vec3<typename promote<S, T>::type> operator*(const Vec3<T> &v, S scalar)
467 {
468 Vec3<typename promote<S, T>::type> result(v);
469 result *= scalar;
470 return result;
471 }
472
474 template <typename T0, typename T1>
475 inline Vec3<typename promote<T0, T1>::type> operator*(const Vec3<T0> &v0, const Vec3<T1> &v1)
476 {
477 Vec3<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1], v0[2] * v1[2]);
478 return result;
479 }
480
481
483 template <typename S, typename T>
484 inline Vec3<typename promote<S, T>::type> operator/(S scalar, const Vec3<T> &v)
485 {
486 return Vec3<typename promote<S, T>::type>(scalar/v[0], scalar/v[1], scalar/v[2]);
487 }
488
490 template <typename S, typename T>
491 inline Vec3<typename promote<S, T>::type> operator/(const Vec3<T> &v, S scalar)
492 {
493 Vec3<typename promote<S, T>::type> result(v);
494 result /= scalar;
495 return result;
496 }
497
499 template <typename T0, typename T1>
500 inline Vec3<typename promote<T0, T1>::type> operator/(const Vec3<T0> &v0, const Vec3<T1> &v1)
501 {
502 Vec3<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1], v0[2] / v1[2]);
503 return result;
504 }
505
507 template <typename T0, typename T1>
508 inline Vec3<typename promote<T0, T1>::type> operator+(const Vec3<T0> &v0, const Vec3<T1> &v1)
509 {
510 Vec3<typename promote<T0, T1>::type> result(v0);
511 result += v1;
512 return result;
513 }
514
516 template <typename S, typename T>
517 inline Vec3<typename promote<S, T>::type> operator+(const Vec3<T> &v, S scalar)
518 {
519 Vec3<typename promote<S, T>::type> result(v);
520 result += scalar;
521 return result;
522 }
523
525 template <typename T0, typename T1>
526 inline Vec3<typename promote<T0, T1>::type> operator-(const Vec3<T0> &v0, const Vec3<T1> &v1)
527 {
528 Vec3<typename promote<T0, T1>::type> result(v0);
529 result -= v1;
530 return result;
531 }
532
534 template <typename S, typename T>
535 inline Vec3<typename promote<S, T>::type> operator-(const Vec3<T> &v, S scalar)
536 {
537 Vec3<typename promote<S, T>::type> result(v);
538 result -= scalar;
539 return result;
540 }
541
544 template <typename T>
545 inline T angle(const Vec3<T> &v1, const Vec3<T> &v2)
546 {
547 Vec3<T> c = v1.cross(v2);
548 return static_cast<T>(atan2(c.length(), v1.dot(v2)));
549 }
550
551 template <typename T>
552 inline bool
553 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b)
554 {
555 return a.eq(b);
556 }
557 template <typename T>
558 inline bool
559 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& eps)
560 {
561 return isApproxEqual(a.x(), b.x(), eps.x()) &&
562 isApproxEqual(a.y(), b.y(), eps.y()) &&
563 isApproxEqual(a.z(), b.z(), eps.z());
564 }
565
566 template<typename T>
567 inline bool
568 isFinite(const Vec3<T>& v)
569 {
570 return isFinite(v[0]) && isFinite(v[1]) && isFinite(v[2]);
571 }
572
574 template<typename T>
575 inline bool
576 isZero(const Vec3<T>& v)
577 {
578 return isZero(v[0]) && isZero(v[1]) && isZero(v[2]);
579 }
580
581 template<typename T>
582 inline Vec3<T>
583 Abs(const Vec3<T>& v)
584 {
585 return Vec3<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]));
586 }
587
590 template <typename T>
591 inline void orthonormalize(Vec3<T> &v1, Vec3<T> &v2, Vec3<T> &v3)
592 {
593 // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
594 // orthonormalization produces vectors u0, u1, and u2 as follows,
595 //
596 // u0 = v0/|v0|
597 // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
598 // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
599 //
600 // where |A| indicates length of vector A and A*B indicates dot
601 // product of vectors A and B.
602
603 // compute u0
604 v1.normalize();
605
606 // compute u1
607 T d0 = v1.dot(v2);
608 v2 -= v1*d0;
609 v2.normalize();
610
611 // compute u2
612 T d1 = v2.dot(v3);
613 d0 = v1.dot(v3);
614 v3 -= v1*d0 + v2*d1;
615 v3.normalize();
616 }
617
622
624 template <typename T>
625 inline Vec3<T> minComponent(const Vec3<T> &v1, const Vec3<T> &v2)
626 {
627 return Vec3<T>(
628 std::min(v1.x(), v2.x()),
629 std::min(v1.y(), v2.y()),
630 std::min(v1.z(), v2.z()));
631 }
632
634 template <typename T>
635 inline Vec3<T> maxComponent(const Vec3<T> &v1, const Vec3<T> &v2)
636 {
637 return Vec3<T>(
638 std::max(v1.x(), v2.x()),
639 std::max(v1.y(), v2.y()),
640 std::max(v1.z(), v2.z()));
641 }
642
645 template <typename T>
646 inline Vec3<T> Exp(Vec3<T> v) { return v.exp(); }
647
648 typedef Vec3<int32_t> Vec3i;
649 typedef Vec3<uint32_t> Vec3ui;
650 typedef Vec3<float> Vec3s;
651 typedef Vec3<double> Vec3d;
652
653 } // namespace math
654 } // namespace OPENVDB_VERSION_NAME
655 } // namespace openvdb
656
657 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
658
659 // Copyright (c) 2012-2016 DreamWorks Animation LLC
660 // All rights reserved. This software is distributed under the
661 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v3_2_0::math::Vec3::operator*=
const Vec3< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec3.h:253
openvdb::v3_2_0::math::Vec3s
Vec3< float > Vec3s
Definition: Vec3.h:650
openvdb::v3_2_0::math::Vec3::dot
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:203
openvdb::v3_2_0::math::isZero
bool isZero(const Vec3< T > &v)
Return true if all components are exactly equal to zero.
Definition: Vec3.h:576
openvdb::v3_2_0::math::Vec3::z
T & z()
Definition: Vec3.h:99
openvdb::v3_2_0::math::Vec3::numElements
static unsigned numElements()
Definition: Vec3.h:379
openvdb::v3_2_0::math::Vec3::unit
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec3.h:367
openvdb::v3_2_0::math::angle
T angle(const Vec3< T > &v1, const Vec3< T > &v2)
Definition: Vec3.h:545
openvdb::v3_2_0::math::Vec3::projection
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:393
openvdb::v3_2_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
openvdb::v3_2_0::math::isFinite
bool isFinite(const Vec3< T > &v)
Definition: Vec3.h:568
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v3_2_0::math::Vec3::operator+=
const Vec3< T > & operator+=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:303
openvdb::v3_2_0::math::Vec3::value_type
T value_type
Definition: Vec3.h:50
openvdb::v3_2_0::math::orthonormalize
void orthonormalize(Vec3< T > &v1, Vec3< T > &v2, Vec3< T > &v3)
Definition: Vec3.h:591
openvdb::v3_2_0::math::operator*
Vec3< typename promote< T0, T1 >::type > operator*(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Returns V, where for .
Definition: Vec3.h:475
openvdb::v3_2_0::math::Vec3::Vec3
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
Definition: Vec3.h:89
openvdb::v3_2_0::math::Vec3::Vec3
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition: Vec3.h:69
openvdb::v3_2_0::math::Vec3::unit
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec3.h:360
openvdb::v3_2_0::math::Vec3
Definition: Mat.h:146
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
openvdb::v3_2_0::math::Vec3::numRows
static unsigned numRows()
Definition: Vec3.h:377
openvdb::v3_2_0::ArithmeticError
Definition: Exceptions.h:78
openvdb::v3_2_0::math::Vec3::sub
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:171
openvdb::v3_2_0::math::operator-
Vec3< typename promote< S, T >::type > operator-(const Vec3< T > &v, S scalar)
Returns V, where for .
Definition: Vec3.h:535
openvdb::v3_2_0::tools::composite::max
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
openvdb::v3_2_0::math::operator+
Vec3< typename promote< S, T >::type > operator+(const Vec3< T > &v, S scalar)
Returns V, where for .
Definition: Vec3.h:517
openvdb::v3_2_0::math::Vec3::isInfinite
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec3.h:432
openvdb::v3_2_0::math::Vec3::isNan
bool isNan() const
True if a Nan is present in vector.
Definition: Vec3.h:429
openvdb::v3_2_0::math::Vec3::asPointer
T * asPointer()
Definition: Vec3.h:106
openvdb::v3_2_0::math::Vec3::numColumns
static unsigned numColumns()
Definition: Vec3.h:378
openvdb::v3_2_0::math::Vec3i
Vec3< int32_t > Vec3i
Definition: Vec3.h:648
openvdb::v3_2_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:635
openvdb::v3_2_0::math::Vec3::isFinite
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec3.h:438
openvdb::v3_2_0::math::Vec3::x
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec3.h:102
openvdb::v3_2_0::math::Vec3::operator/=
const Vec3< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec3.h:273
openvdb::v3_2_0::math::Tuple
Definition: Tuple.h:50
Exceptions.h
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_2_0::math::Vec3d
Vec3< double > Vec3d
Definition: Vec3.h:651
openvdb::v3_2_0::math::Vec3::ValueType
T ValueType
Definition: Vec3.h:51
openvdb::v3_2_0::math::Vec3::x
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:97
openvdb::v3_2_0::math::Vec3::sum
T sum() const
Return the sum of all the vector components.
Definition: Vec3.h:342
openvdb::v3_2_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:145
openvdb
Definition: Exceptions.h:39
openvdb::v3_2_0::math::scale
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:594
openvdb::v3_2_0::math::Vec3::length
T length() const
Length of the vector.
Definition: Vec3.h:212
openvdb::v3_2_0::math::Vec3::div
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:193
openvdb::v3_2_0::math::Vec3::Vec3
Vec3()
Trivial constructor, the vector is NOT initialized.
Definition: Vec3.h:54
openvdb::v3_2_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:79
openvdb::v3_2_0::math::Vec3::operator*=
const Vec3< T > & operator*=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:263
openvdb::v3_2_0::math::isApproxEqual
bool isApproxEqual(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &eps)
Definition: Vec3.h:559
openvdb::v3_2_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:625
openvdb::v3_2_0::math::Vec3::operator-
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec3.h:154
openvdb::v3_2_0::math::Vec3::normalize
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:348
openvdb::v3_2_0::math::Vec3::zero
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition: Vec3.h:444
openvdb::v3_2_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:241
openvdb::v3_2_0::math::Vec3::operator=
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition: Vec3.h:134
openvdb::v3_2_0::math::Vec3::operator()
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec3.h:113
openvdb::v3_2_0::math::Vec3::cross
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition: Vec3.h:232
openvdb::v3_2_0::math::Vec3::component
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:383
openvdb::v3_2_0::math::Vec3::exp
const Vec3< T > & exp()
Definition: Vec3.h:333
openvdb::v3_2_0::math::Vec3::operator()
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec3.h:110
openvdb::v3_2_0::math::Vec3::y
T & y()
Definition: Vec3.h:98
openvdb::v3_2_0::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:450
openvdb::v3_2_0::math::Vec3::init
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition: Vec3.h:117
openvdb::v3_2_0::math::Abs
Vec3< T > Abs(const Vec3< T > &v)
Definition: Vec3.h:583
openvdb::v3_2_0::math::Vec3::getArbPerpendicular
Vec3< T > getArbPerpendicular() const
Definition: Vec3.h:404
Tuple.h
openvdb::v3_2_0::math::Vec3::setZero
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition: Vec3.h:125
openvdb::v3_2_0::math::Vec3::z
T z() const
Definition: Vec3.h:104
openvdb::v3_2_0::math::isRelOrApproxEqual
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:417
openvdb::v3_2_0::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:458
openvdb::v3_2_0::math::Vec3::operator/=
const Vec3< T > & operator/=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:283
openvdb::v3_2_0::math::Vec3::lengthSqr
T lengthSqr() const
Definition: Vec3.h:223
openvdb::v3_2_0::math::Vec3::asPointer
const T * asPointer() const
Definition: Vec3.h:107
openvdb::v3_2_0::math::operator/
Vec3< typename promote< T0, T1 >::type > operator/(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Returns V, where for .
Definition: Vec3.h:500
openvdb::v3_2_0::math::Vec3ui
Vec3< uint32_t > Vec3ui
Definition: Vec3.h:649
openvdb::v3_2_0::math::Vec3::operator-=
const Vec3< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec3.h:313
openvdb::v3_2_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:646
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_2_0::math::Vec3::operator-=
const Vec3< T > & operator-=(const Vec3< S > &v1)
Returns v0, where for .
Definition: Vec3.h:323
openvdb::v3_2_0::math::Vec3::add
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:159
openvdb::v3_2_0::math::Vec3::Vec3
Vec3(T val)
Constructor with one argument, e.g. Vec3f v(0);.
Definition: Vec3.h:57
openvdb::v3_2_0::math::Vec3::operator+=
const Vec3< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec3.h:293
openvdb::v3_2_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 3x3 rows normalized.
Definition: Mat.h:627
openvdb::v3_2_0::math::Vec3::scale
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:183
openvdb::v3_2_0::math::Vec3::y
T y() const
Definition: Vec3.h:103
openvdb::v3_2_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:60
openvdb::v3_2_0::tools::composite::min
const boost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128