OpenVDB: Vec3.h Source File

OpenVDB 6.1.0

Vec3.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 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 <openvdb/Exceptions.h>
35 #include "Math.h"
36 #include "Tuple.h"
37 #include <algorithm>
38 #include <cmath>
39 #include <type_traits>
40
41
42 namespace openvdb {
43 OPENVDB_USE_VERSION_NAMESPACE
44 namespace OPENVDB_VERSION_NAME {
45 namespace math {
46
47 template<typename T> class Mat3;
48
49 template<typename T>
50 class Vec3: public Tuple<3, T>
51 {
52 public:
53 using value_type = T;
54 using ValueType = T;
55
57 Vec3() {}
58
60 explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
61
63 Vec3(T x, T y, T z)
64 {
65 this->mm[0] = x;
66 this->mm[1] = y;
67 this->mm[2] = z;
68 }
69
71 template <typename Source>
72 Vec3(Source *a)
73 {
74 this->mm[0] = static_cast<T>(a[0]);
75 this->mm[1] = static_cast<T>(a[1]);
76 this->mm[2] = static_cast<T>(a[2]);
77 }
78
81 template<typename Source>
82 explicit Vec3(const Tuple<3, Source> &v)
83 {
84 this->mm[0] = static_cast<T>(v[0]);
85 this->mm[1] = static_cast<T>(v[1]);
86 this->mm[2] = static_cast<T>(v[2]);
87 }
88
92 template<typename Other>
93 explicit Vec3(Other val,
94 typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
95 {
96 this->mm[0] = this->mm[1] = this->mm[2] = static_cast<T>(val);
97 }
98
101 template<typename Other>
102 Vec3(const Vec3<Other>& v)
103 {
104 this->mm[0] = static_cast<T>(v[0]);
105 this->mm[1] = static_cast<T>(v[1]);
106 this->mm[2] = static_cast<T>(v[2]);
107 }
108
110 T& x() { return this->mm[0]; }
111 T& y() { return this->mm[1]; }
112 T& z() { return this->mm[2]; }
113
115 T x() const { return this->mm[0]; }
116 T y() const { return this->mm[1]; }
117 T z() const { return this->mm[2]; }
118
119 T* asPointer() { return this->mm; }
120 const T* asPointer() const { return this->mm; }
121
123 T& operator()(int i) { return this->mm[i]; }
124
126 T operator()(int i) const { return this->mm[i]; }
127
130 const Vec3<T>& init(T x=0, T y=0, T z=0)
131 {
132 this->mm[0] = x; this->mm[1] = y; this->mm[2] = z;
133 return *this;
134 }
135
136
138 const Vec3<T>& setZero()
139 {
140 this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0;
141 return *this;
142 }
143
146 template<typename Source>
147 const Vec3<T>& operator=(const Vec3<Source> &v)
148 {
149 // note: don't static_cast because that suppresses warnings
150 this->mm[0] = v[0];
151 this->mm[1] = v[1];
152 this->mm[2] = v[2];
153
154 return *this;
155 }
156
158 bool eq(const Vec3<T> &v, T eps = static_cast<T>(1.0e-7)) const
159 {
160 return isRelOrApproxEqual(this->mm[0], v.mm[0], eps, eps) &&
161 isRelOrApproxEqual(this->mm[1], v.mm[1], eps, eps) &&
162 isRelOrApproxEqual(this->mm[2], v.mm[2], eps, eps);
163 }
164
165
167 Vec3<T> operator-() const { return Vec3<T>(-this->mm[0], -this->mm[1], -this->mm[2]); }
168
171 template <typename T0, typename T1>
172 const Vec3<T>& add(const Vec3<T0> &v1, const Vec3<T1> &v2)
173 {
174 this->mm[0] = v1[0] + v2[0];
175 this->mm[1] = v1[1] + v2[1];
176 this->mm[2] = v1[2] + v2[2];
177
178 return *this;
179 }
180
183 template <typename T0, typename T1>
184 const Vec3<T>& sub(const Vec3<T0> &v1, const Vec3<T1> &v2)
185 {
186 this->mm[0] = v1[0] - v2[0];
187 this->mm[1] = v1[1] - v2[1];
188 this->mm[2] = v1[2] - v2[2];
189
190 return *this;
191 }
192
195 template <typename T0, typename T1>
196 const Vec3<T>& scale(T0 scale, const Vec3<T1> &v)
197 {
198 this->mm[0] = scale * v[0];
199 this->mm[1] = scale * v[1];
200 this->mm[2] = scale * v[2];
201
202 return *this;
203 }
204
205 template <typename T0, typename T1>
206 const Vec3<T> &div(T0 scale, const Vec3<T1> &v)
207 {
208 this->mm[0] = v[0] / scale;
209 this->mm[1] = v[1] / scale;
210 this->mm[2] = v[2] / scale;
211
212 return *this;
213 }
214
216 T dot(const Vec3<T> &v) const
217 {
218 return
219 this->mm[0]*v.mm[0] +
220 this->mm[1]*v.mm[1] +
221 this->mm[2]*v.mm[2];
222 }
223
225 T length() const
226 {
227 return static_cast<T>(sqrt(double(
228 this->mm[0]*this->mm[0] +
229 this->mm[1]*this->mm[1] +
230 this->mm[2]*this->mm[2])));
231 }
232
233
236 T lengthSqr() const
237 {
238 return
239 this->mm[0]*this->mm[0] +
240 this->mm[1]*this->mm[1] +
241 this->mm[2]*this->mm[2];
242 }
243
245 Vec3<T> cross(const Vec3<T> &v) const
246 {
247 return Vec3<T>(this->mm[1]*v.mm[2] - this->mm[2]*v.mm[1],
248 this->mm[2]*v.mm[0] - this->mm[0]*v.mm[2],
249 this->mm[0]*v.mm[1] - this->mm[1]*v.mm[0]);
250 }
251
252
254 const Vec3<T>& cross(const Vec3<T> &v1, const Vec3<T> &v2)
255 {
256 // assert(this!=&v1);
257 // assert(this!=&v2);
258 this->mm[0] = v1.mm[1]*v2.mm[2] - v1.mm[2]*v2.mm[1];
259 this->mm[1] = v1.mm[2]*v2.mm[0] - v1.mm[0]*v2.mm[2];
260 this->mm[2] = v1.mm[0]*v2.mm[1] - v1.mm[1]*v2.mm[0];
261 return *this;
262 }
263
265 template <typename S>
266 const Vec3<T> &operator*=(S scalar)
267 {
268 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
269 const auto value0 = this->mm[0] * scalar;
270 const auto value1 = this->mm[1] * scalar;
271 const auto value2 = this->mm[2] * scalar;
272 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
273 this->mm[0] = static_cast<T>(value0);
274 this->mm[1] = static_cast<T>(value1);
275 this->mm[2] = static_cast<T>(value2);
276 return *this;
277 }
278
280 template <typename S>
281 const Vec3<T> &operator*=(const Vec3<S> &v1)
282 {
283 this->mm[0] *= v1[0];
284 this->mm[1] *= v1[1];
285 this->mm[2] *= v1[2];
286 return *this;
287 }
288
290 template <typename S>
291 const Vec3<T> &operator/=(S scalar)
292 {
293 this->mm[0] /= scalar;
294 this->mm[1] /= scalar;
295 this->mm[2] /= scalar;
296 return *this;
297 }
298
300 template <typename S>
301 const Vec3<T> &operator/=(const Vec3<S> &v1)
302 {
303 this->mm[0] /= v1[0];
304 this->mm[1] /= v1[1];
305 this->mm[2] /= v1[2];
306 return *this;
307 }
308
310 template <typename S>
311 const Vec3<T> &operator+=(S scalar)
312 {
313 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
314 const auto value0 = this->mm[0] + scalar;
315 const auto value1 = this->mm[1] + scalar;
316 const auto value2 = this->mm[2] + scalar;
317 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
318 this->mm[0] = static_cast<T>(value0);
319 this->mm[1] = static_cast<T>(value1);
320 this->mm[2] = static_cast<T>(value2);
321 return *this;
322 }
323
325 template <typename S>
326 const Vec3<T> &operator+=(const Vec3<S> &v1)
327 {
328 this->mm[0] += v1[0];
329 this->mm[1] += v1[1];
330 this->mm[2] += v1[2];
331 return *this;
332 }
333
335 template <typename S>
336 const Vec3<T> &operator-=(S scalar)
337 {
338 this->mm[0] -= scalar;
339 this->mm[1] -= scalar;
340 this->mm[2] -= scalar;
341 return *this;
342 }
343
345 template <typename S>
346 const Vec3<T> &operator-=(const Vec3<S> &v1)
347 {
348 this->mm[0] -= v1[0];
349 this->mm[1] -= v1[1];
350 this->mm[2] -= v1[2];
351 return *this;
352 }
353
356 inline const Vec3<T>& exp()
357 {
358 this->mm[0] = std::exp(this->mm[0]);
359 this->mm[1] = std::exp(this->mm[1]);
360 this->mm[2] = std::exp(this->mm[2]);
361 return *this;
362 }
363
366 inline const Vec3<T>& log()
367 {
368 this->mm[0] = std::log(this->mm[0]);
369 this->mm[1] = std::log(this->mm[1]);
370 this->mm[2] = std::log(this->mm[2]);
371 return *this;
372 }
373
375 inline T sum() const
376 {
377 return this->mm[0] + this->mm[1] + this->mm[2];
378 }
379
381 inline T product() const
382 {
383 return this->mm[0] * this->mm[1] * this->mm[2];
384 }
385
387 bool normalize(T eps = T(1.0e-7))
388 {
389 T d = length();
390 if (isApproxEqual(d, T(0), eps)) {
391 return false;
392 }
393 *this *= (T(1) / d);
394 return true;
395 }
396
397
399 Vec3<T> unit(T eps=0) const
400 {
401 T d;
402 return unit(eps, d);
403 }
404
406 Vec3<T> unit(T eps, T& len) const
407 {
408 len = length();
409 if (isApproxEqual(len, T(0), eps)) {
410 OPENVDB_THROW(ArithmeticError, "Normalizing null 3-vector");
411 }
412 return *this / len;
413 }
414
416 Vec3<T> unitSafe() const
417 {
418 T l2 = lengthSqr();
419 return l2 ? *this / static_cast<T>(sqrt(l2)) : Vec3<T>(1, 0 ,0);
420 }
421
422 // Number of cols, rows, elements
423 static unsigned numRows() { return 1; }
424 static unsigned numColumns() { return 3; }
425 static unsigned numElements() { return 3; }
426
429 T component(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
430 {
431 T l = onto.length();
432 if (isApproxEqual(l, T(0), eps)) return 0;
433
434 return dot(onto)*(T(1)/l);
435 }
436
439 Vec3<T> projection(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
440 {
441 T l = onto.lengthSqr();
442 if (isApproxEqual(l, T(0), eps)) return Vec3::zero();
443
444 return onto*(dot(onto)*(T(1)/l));
445 }
446
450 Vec3<T> getArbPerpendicular() const
451 {
452 Vec3<T> u;
453 T l;
454
455 if ( fabs(this->mm[0]) >= fabs(this->mm[1]) ) {
456 // v.x or v.z is the largest magnitude component, swap them
457 l = this->mm[0]*this->mm[0] + this->mm[2]*this->mm[2];
458 l = static_cast<T>(T(1)/sqrt(double(l)));
459 u.mm[0] = -this->mm[2]*l;
460 u.mm[1] = T(0);
461 u.mm[2] = +this->mm[0]*l;
462 } else {
463 // W.y or W.z is the largest magnitude component, swap them
464 l = this->mm[1]*this->mm[1] + this->mm[2]*this->mm[2];
465 l = static_cast<T>(T(1)/sqrt(double(l)));
466 u.mm[0] = T(0);
467 u.mm[1] = +this->mm[2]*l;
468 u.mm[2] = -this->mm[1]*l;
469 }
470
471 return u;
472 }
473
475 Vec3<T> sorted() const
476 {
477 Vec3<T> r(*this);
478 if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
479 if( r.mm[1] > r.mm[2] ) std::swap(r.mm[1], r.mm[2]);
480 if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
481 return r;
482 }
483
485 Vec3<T> reversed() const
486 {
487 return Vec3<T>(this->mm[2], this->mm[1], this->mm[0]);
488 }
489
491 static Vec3<T> zero() { return Vec3<T>(0, 0, 0); }
492 static Vec3<T> ones() { return Vec3<T>(1, 1, 1); }
493 };
494
495
497 template <typename T0, typename T1>
498 inline bool operator==(const Vec3<T0> &v0, const Vec3<T1> &v1)
499 {
500 return isExactlyEqual(v0[0], v1[0]) && isExactlyEqual(v0[1], v1[1])
501 && isExactlyEqual(v0[2], v1[2]);
502 }
503
505 template <typename T0, typename T1>
506 inline bool operator!=(const Vec3<T0> &v0, const Vec3<T1> &v1) { return !(v0==v1); }
507
509 template <typename S, typename T>
510 inline Vec3<typename promote<S, T>::type> operator*(S scalar, const Vec3<T> &v) { return v*scalar; }
511
513 template <typename S, typename T>
514 inline Vec3<typename promote<S, T>::type> operator*(const Vec3<T> &v, S scalar)
515 {
516 Vec3<typename promote<S, T>::type> result(v);
517 result *= scalar;
518 return result;
519 }
520
522 template <typename T0, typename T1>
523 inline Vec3<typename promote<T0, T1>::type> operator*(const Vec3<T0> &v0, const Vec3<T1> &v1)
524 {
525 Vec3<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1], v0[2] * v1[2]);
526 return result;
527 }
528
529
531 template <typename S, typename T>
532 inline Vec3<typename promote<S, T>::type> operator/(S scalar, const Vec3<T> &v)
533 {
534 return Vec3<typename promote<S, T>::type>(scalar/v[0], scalar/v[1], scalar/v[2]);
535 }
536
538 template <typename S, typename T>
539 inline Vec3<typename promote<S, T>::type> operator/(const Vec3<T> &v, S scalar)
540 {
541 Vec3<typename promote<S, T>::type> result(v);
542 result /= scalar;
543 return result;
544 }
545
547 template <typename T0, typename T1>
548 inline Vec3<typename promote<T0, T1>::type> operator/(const Vec3<T0> &v0, const Vec3<T1> &v1)
549 {
550 Vec3<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1], v0[2] / v1[2]);
551 return result;
552 }
553
555 template <typename T0, typename T1>
556 inline Vec3<typename promote<T0, T1>::type> operator+(const Vec3<T0> &v0, const Vec3<T1> &v1)
557 {
558 Vec3<typename promote<T0, T1>::type> result(v0);
559 result += v1;
560 return result;
561 }
562
564 template <typename S, typename T>
565 inline Vec3<typename promote<S, T>::type> operator+(const Vec3<T> &v, S scalar)
566 {
567 Vec3<typename promote<S, T>::type> result(v);
568 result += scalar;
569 return result;
570 }
571
573 template <typename T0, typename T1>
574 inline Vec3<typename promote<T0, T1>::type> operator-(const Vec3<T0> &v0, const Vec3<T1> &v1)
575 {
576 Vec3<typename promote<T0, T1>::type> result(v0);
577 result -= v1;
578 return result;
579 }
580
582 template <typename S, typename T>
583 inline Vec3<typename promote<S, T>::type> operator-(const Vec3<T> &v, S scalar)
584 {
585 Vec3<typename promote<S, T>::type> result(v);
586 result -= scalar;
587 return result;
588 }
589
592 template <typename T>
593 inline T angle(const Vec3<T> &v1, const Vec3<T> &v2)
594 {
595 Vec3<T> c = v1.cross(v2);
596 return static_cast<T>(atan2(c.length(), v1.dot(v2)));
597 }
598
599 template <typename T>
600 inline bool
601 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b)
602 {
603 return a.eq(b);
604 }
605 template <typename T>
606 inline bool
607 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& eps)
608 {
609 return isApproxEqual(a.x(), b.x(), eps.x()) &&
610 isApproxEqual(a.y(), b.y(), eps.y()) &&
611 isApproxEqual(a.z(), b.z(), eps.z());
612 }
613
614 template<typename T>
615 inline Vec3<T>
616 Abs(const Vec3<T>& v)
617 {
618 return Vec3<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]));
619 }
620
623 template <typename T>
624 inline void orthonormalize(Vec3<T> &v1, Vec3<T> &v2, Vec3<T> &v3)
625 {
626 // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
627 // orthonormalization produces vectors u0, u1, and u2 as follows,
628 //
629 // u0 = v0/|v0|
630 // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
631 // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
632 //
633 // where |A| indicates length of vector A and A*B indicates dot
634 // product of vectors A and B.
635
636 // compute u0
637 v1.normalize();
638
639 // compute u1
640 T d0 = v1.dot(v2);
641 v2 -= v1*d0;
642 v2.normalize();
643
644 // compute u2
645 T d1 = v2.dot(v3);
646 d0 = v1.dot(v3);
647 v3 -= v1*d0 + v2*d1;
648 v3.normalize();
649 }
650
655
657 template <typename T>
658 inline Vec3<T> minComponent(const Vec3<T> &v1, const Vec3<T> &v2)
659 {
660 return Vec3<T>(
661 std::min(v1.x(), v2.x()),
662 std::min(v1.y(), v2.y()),
663 std::min(v1.z(), v2.z()));
664 }
665
667 template <typename T>
668 inline Vec3<T> maxComponent(const Vec3<T> &v1, const Vec3<T> &v2)
669 {
670 return Vec3<T>(
671 std::max(v1.x(), v2.x()),
672 std::max(v1.y(), v2.y()),
673 std::max(v1.z(), v2.z()));
674 }
675
678 template <typename T>
679 inline Vec3<T> Exp(Vec3<T> v) { return v.exp(); }
680
683 template <typename T>
684 inline Vec3<T> Log(Vec3<T> v) { return v.log(); }
685
686 using Vec3i = Vec3<int32_t>;
687 using Vec3ui = Vec3<uint32_t>;
688 using Vec3s = Vec3<float>;
689 using Vec3d = Vec3<double>;
690
691 } // namespace math
692 } // namespace OPENVDB_VERSION_NAME
693 } // namespace openvdb
694
695 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
696
697 // Copyright (c) 2012-2018 DreamWorks Animation LLC
698 // All rights reserved. This software is distributed under the
699 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
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:223
openvdb::v6_1::math::Vec3< Real >::value_type
Real value_type
Definition: Vec3.h:53
openvdb::v6_1::math::Vec3::dot
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:216
openvdb::v6_1::math::Vec3::normalize
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:387
openvdb::v6_1::math::Vec3::numElements
static unsigned numElements()
Definition: Vec3.h:425
openvdb::v6_1::math::Vec3::numColumns
static unsigned numColumns()
Definition: Vec3.h:424
openvdb::v6_1::math::Vec3::scale
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:196
openvdb::v6_1::math::Vec3< Real >::ValueType
Real ValueType
Definition: Vec3.h:54
openvdb::v6_1::math::Vec3::sub
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:184
openvdb::v6_1::math::Vec3::y
T y() const
Definition: Vec3.h:116
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v6_1::math::Vec3::z
T z() const
Definition: Vec3.h:117
openvdb::v6_1::math::Vec3::Vec3
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
Definition: Vec3.h:102
openvdb::v6_1::math::Vec3::sum
T sum() const
Return the sum of all the vector components.
Definition: Vec3.h:375
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
openvdb::v6_1::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
openvdb::v6_1::math::Vec3::sorted
Vec3< T > sorted() const
Return a vector with the components of this in ascending order.
Definition: Vec3.h:475
openvdb::v6_1::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:82
openvdb::v6_1::math::Vec3::cross
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition: Vec3.h:245
openvdb::v6_1::math::isRelOrApproxEqual
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:405
openvdb::v6_1::math::Vec3::operator=
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition: Vec3.h:147
openvdb::v6_1::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:254
openvdb::v6_1::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:680
openvdb::v6_1::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:93
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition: Platform.h:224
openvdb::v6_1::math::Vec3::Vec3
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Definition: Vec3.h:63
openvdb::v6_1::math::Vec3::div
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:206
openvdb::v6_1::math::Vec3::unit
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec3.h:406
openvdb::v6_1::math::Vec3::asPointer
T * asPointer()
Definition: Vec3.h:119
openvdb::v6_1::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:346
openvdb::v6_1::math::Vec3::operator/=
const Vec3< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition: Vec3.h:291
openvdb::v6_1::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:523
openvdb::v6_1::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:158
openvdb::v6_1::math::maxComponent
Vec3< T > maxComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec3.h:668
openvdb::v6_1::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:583
openvdb::v6_1::math::Vec3::getArbPerpendicular
Vec3< T > getArbPerpendicular() const
Definition: Vec3.h:450
Exceptions.h
openvdb::v6_1::math::Vec3::operator()
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec3.h:126
openvdb::v6_1::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
openvdb::v6_1::math::Vec3::lengthSqr
T lengthSqr() const
Definition: Vec3.h:236
openvdb::v6_1::math::Vec3::setZero
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition: Vec3.h:138
openvdb::v6_1::math::Vec3::z
T & z()
Definition: Vec3.h:112
openvdb::v6_1::math::Abs
Vec3< T > Abs(const Vec3< T > &v)
Definition: Vec3.h:616
openvdb::v6_1::math::Vec3::y
T & y()
Definition: Vec3.h:111
openvdb
Definition: Exceptions.h:40
openvdb::v6_1::math::orthonormalize
void orthonormalize(Vec3< T > &v1, Vec3< T > &v2, Vec3< T > &v3)
Definition: Vec3.h:624
openvdb::v6_1::math::Vec3::operator-=
const Vec3< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition: Vec3.h:336
openvdb::v6_1::math::Tuple
Definition: Tuple.h:55
openvdb::v6_1::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:565
openvdb::v6_1::math::Vec3
Definition: Mat.h:197
openvdb::v6_1::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:679
openvdb::v6_1::math::Vec3::projection
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:439
openvdb::v6_1::math::Vec3::ones
static Vec3< T > ones()
Definition: Vec3.h:492
openvdb::v6_1::math::Vec3::length
T length() const
Length of the vector.
Definition: Vec3.h:225
openvdb::v6_1::math::scale
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
Definition: Mat.h:647
openvdb::v6_1::math::Vec3::Vec3
Vec3(T val)
Construct a vector all of whose components have the given value.
Definition: Vec3.h:60
openvdb::v6_1::math::Vec3::reversed
Vec3< T > reversed() const
Return the vector (z, y, x)
Definition: Vec3.h:485
openvdb::v6_1::math::Vec3::Vec3
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition: Vec3.h:72
openvdb::v6_1::math::isApproxEqual
bool isApproxEqual(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &eps)
Definition: Vec3.h:607
openvdb::v6_1::tools::composite::min
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
openvdb::v6_1::math::Vec3::init
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition: Vec3.h:130
openvdb::v6_1::math::Vec3::log
const Vec3< T > & log()
Definition: Vec3.h:366
openvdb::v6_1::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:326
openvdb::v6_1::math::Vec3::asPointer
const T * asPointer() const
Definition: Vec3.h:120
openvdb::v6_1::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:684
openvdb::v6_1::math::Vec3::unitSafe
Vec3< T > unitSafe() const
return normalized this, or (1, 0, 0) if this is null vector
Definition: Vec3.h:416
openvdb::v6_1::math::Vec3::numRows
static unsigned numRows()
Definition: Vec3.h:423
Tuple.h
openvdb::v6_1::ArithmeticError
Definition: Exceptions.h:83
openvdb::v6_1::math::Vec3::unit
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec3.h:399
openvdb::v6_1::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:548
openvdb::v6_1::math::Vec3::x
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec3.h:115
openvdb::v6_1::math::Vec3::product
T product() const
Return the product of all the vector components.
Definition: Vec3.h:381
openvdb::v6_1::math::Vec3::operator+=
const Vec3< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition: Vec3.h:311
openvdb::v6_1::math::Vec3::Vec3
Vec3()
Trivial constructor, the vector is NOT initialized.
Definition: Vec3.h:57
openvdb::v6_1::math::Vec3::exp
const Vec3< T > & exp()
Definition: Vec3.h:356
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
openvdb::v6_1::math::angle
T angle(const Vec3< T > &v1, const Vec3< T > &v2)
Definition: Vec3.h:593
openvdb::v6_1::math::operator==
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:498
openvdb::v6_1::math::Vec3::add
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:172
openvdb::v6_1::math::minComponent
Vec3< T > minComponent(const Vec3< T > &v1, const Vec3< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec3.h:658
openvdb::v6_1::math::Vec3::operator-
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec3.h:167
openvdb::v6_1::math::Vec3::operator()
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec3.h:123
openvdb::v6_1::math::operator!=
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:506
openvdb::v6_1::math::Vec3::component
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:429
openvdb::v6_1::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:301
openvdb::v6_1::math::Vec3::zero
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition: Vec3.h:491
openvdb::v6_1::math::Conversion
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:49
openvdb::v6_1::math::Vec3::x
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110