HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vec3.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
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 //
29 ///////////////////////////////////////////////////////////////////////////
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 {
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 
56  /// Trivial constructor, the vector is NOT initialized
57  Vec3() {}
58 
59  /// @brief Construct a vector all of whose components have the given value.
60  explicit Vec3(T val) { this->mm[0] = this->mm[1] = this->mm[2] = val; }
61 
62  /// Constructor with three arguments, e.g. Vec3d v(1,2,3);
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 
70  /// Constructor with array argument, e.g. double a[3]; Vec3d v(a);
71  template <typename Source>
72  Vec3(Source *a)
73  {
74  this->mm[0] = a[0];
75  this->mm[1] = a[1];
76  this->mm[2] = a[2];
77  }
78 
79  /// @brief Construct a Vec3 from a 3-Tuple with a possibly different value type.
80  /// @details Type conversion warnings are suppressed.
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 
89  /// @brief Construct a vector all of whose components have the given value,
90  /// which may be of an arithmetic type different from this vector's value type.
91  /// @details Type conversion warnings are suppressed.
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 
99  /// @brief Construct a Vec3 from another Vec3 with a possibly different value type.
100  /// @details Type conversion warnings are suppressed.
101  template<typename Other>
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 
109  /// Reference to the component, e.g. v.x() = 4.5f;
110  T& x() { return this->mm[0]; }
111  T& y() { return this->mm[1]; }
112  T& z() { return this->mm[2]; }
113 
114  /// Get the component, e.g. float f = v.y();
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 
122  /// Alternative indexed reference to the elements
123  T& operator()(int i) { return this->mm[i]; }
124 
125  /// Alternative indexed constant reference to the elements,
126  T operator()(int i) const { return this->mm[i]; }
127 
128  /// "this" vector gets initialized to [x, y, z],
129  /// calling v.init(); has same effect as calling v = Vec3::zero();
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 
137  /// Set "this" vector to zero
138  const Vec3<T>& setZero()
139  {
140  this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0;
141  return *this;
142  }
143 
144  /// @brief Assignment operator
145  /// @details Type conversion warnings are not suppressed.
146  template<typename Source>
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 
157  /// Test if "this" vector is equivalent to vector v with tolerance of eps
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 
166  /// Negation operator, for e.g. v1 = -v2;
167  Vec3<T> operator-() const { return Vec3<T>(-this->mm[0], -this->mm[1], -this->mm[2]); }
168 
169  /// this = v1 + v2
170  /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
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 
181  /// this = v1 - v2
182  /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
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 
193  /// this = scalar*v, v need not be a distinct object from "this",
194  /// e.g. v.scale(1.5,v1);
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 
215  /// Dot product
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 
224  /// Length of the vector
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 
234  /// Squared length of the vector, much faster than length() as it
235  /// does not involve square root
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 
244  /// Return the cross product of "this" vector and v;
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 
253  /// this = v1 cross v2, v1 and v2 must be distinct objects than "this"
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 
264  /// Multiply each element of this vector by @a scalar.
265  template <typename S>
266  const Vec3<T> &operator*=(S scalar)
267  {
268  this->mm[0] = static_cast<T>(this->mm[0] * scalar);
269  this->mm[1] = static_cast<T>(this->mm[1] * scalar);
270  this->mm[2] = static_cast<T>(this->mm[2] * scalar);
271  return *this;
272  }
273 
274  /// Multiply each element of this vector by the corresponding element of the given vector.
275  template <typename S>
276  const Vec3<T> &operator*=(const Vec3<S> &v1)
277  {
278  this->mm[0] *= v1[0];
279  this->mm[1] *= v1[1];
280  this->mm[2] *= v1[2];
281  return *this;
282  }
283 
284  /// Divide each element of this vector by @a scalar.
285  template <typename S>
286  const Vec3<T> &operator/=(S scalar)
287  {
288  this->mm[0] /= scalar;
289  this->mm[1] /= scalar;
290  this->mm[2] /= scalar;
291  return *this;
292  }
293 
294  /// Divide each element of this vector by the corresponding element of the given vector.
295  template <typename S>
296  const Vec3<T> &operator/=(const Vec3<S> &v1)
297  {
298  this->mm[0] /= v1[0];
299  this->mm[1] /= v1[1];
300  this->mm[2] /= v1[2];
301  return *this;
302  }
303 
304  /// Add @a scalar to each element of this vector.
305  template <typename S>
306  const Vec3<T> &operator+=(S scalar)
307  {
308  this->mm[0] = static_cast<T>(this->mm[0] + scalar);
309  this->mm[1] = static_cast<T>(this->mm[1] + scalar);
310  this->mm[2] = static_cast<T>(this->mm[2] + scalar);
311  return *this;
312  }
313 
314  /// Add each element of the given vector to the corresponding element of this vector.
315  template <typename S>
316  const Vec3<T> &operator+=(const Vec3<S> &v1)
317  {
318  this->mm[0] += v1[0];
319  this->mm[1] += v1[1];
320  this->mm[2] += v1[2];
321  return *this;
322  }
323 
324  /// Subtract @a scalar from each element of this vector.
325  template <typename S>
326  const Vec3<T> &operator-=(S scalar)
327  {
328  this->mm[0] -= scalar;
329  this->mm[1] -= scalar;
330  this->mm[2] -= scalar;
331  return *this;
332  }
333 
334  /// Subtract each element of the given vector from the corresponding element of this vector.
335  template <typename S>
336  const Vec3<T> &operator-=(const Vec3<S> &v1)
337  {
338  this->mm[0] -= v1[0];
339  this->mm[1] -= v1[1];
340  this->mm[2] -= v1[2];
341  return *this;
342  }
343 
344  /// Return a reference to itself after the exponent has been
345  /// applied to all the vector components.
346  inline const Vec3<T>& exp()
347  {
348  this->mm[0] = std::exp(this->mm[0]);
349  this->mm[1] = std::exp(this->mm[1]);
350  this->mm[2] = std::exp(this->mm[2]);
351  return *this;
352  }
353 
354  /// Return a reference to itself after log has been
355  /// applied to all the vector components.
356  inline const Vec3<T>& log()
357  {
358  this->mm[0] = std::log(this->mm[0]);
359  this->mm[1] = std::log(this->mm[1]);
360  this->mm[2] = std::log(this->mm[2]);
361  return *this;
362  }
363 
364  /// Return the sum of all the vector components.
365  inline T sum() const
366  {
367  return this->mm[0] + this->mm[1] + this->mm[2];
368  }
369 
370  /// Return the product of all the vector components.
371  inline T product() const
372  {
373  return this->mm[0] * this->mm[1] * this->mm[2];
374  }
375 
376  /// this = normalized this
377  bool normalize(T eps = T(1.0e-7))
378  {
379  T d = length();
380  if (isApproxEqual(d, T(0), eps)) {
381  return false;
382  }
383  *this *= (T(1) / d);
384  return true;
385  }
386 
387 
388  /// return normalized this, throws if null vector
389  Vec3<T> unit(T eps=0) const
390  {
391  T d;
392  return unit(eps, d);
393  }
394 
395  /// return normalized this and length, throws if null vector
396  Vec3<T> unit(T eps, T& len) const
397  {
398  len = length();
399  if (isApproxEqual(len, T(0), eps)) {
400  OPENVDB_THROW(ArithmeticError, "Normalizing null 3-vector");
401  }
402  return *this / len;
403  }
404 
405  /// return normalized this, or (1, 0, 0) if this is null vector
407  {
408  T l2 = lengthSqr();
409  return l2 ? *this / static_cast<T>(sqrt(l2)) : Vec3<T>(1, 0 ,0);
410  }
411 
412  // Number of cols, rows, elements
413  static unsigned numRows() { return 1; }
414  static unsigned numColumns() { return 3; }
415  static unsigned numElements() { return 3; }
416 
417  /// Returns the scalar component of v in the direction of onto, onto need
418  /// not be unit. e.g double c = Vec3d::component(v1,v2);
419  T component(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
420  {
421  T l = onto.length();
422  if (isApproxEqual(l, T(0), eps)) return 0;
423 
424  return dot(onto)*(T(1)/l);
425  }
426 
427  /// Return the projection of v onto the vector, onto need not be unit
428  /// e.g. Vec3d a = vprojection(n);
429  Vec3<T> projection(const Vec3<T> &onto, T eps = static_cast<T>(1.0e-7)) const
430  {
431  T l = onto.lengthSqr();
432  if (isApproxEqual(l, T(0), eps)) return Vec3::zero();
433 
434  return onto*(dot(onto)*(T(1)/l));
435  }
436 
437  /// Return an arbitrary unit vector perpendicular to v
438  /// Vector this must be a unit vector
439  /// e.g. v = v.normalize(); Vec3d n = v.getArbPerpendicular();
441  {
442  Vec3<T> u;
443  T l;
444 
445  if ( fabs(this->mm[0]) >= fabs(this->mm[1]) ) {
446  // v.x or v.z is the largest magnitude component, swap them
447  l = this->mm[0]*this->mm[0] + this->mm[2]*this->mm[2];
448  l = static_cast<T>(T(1)/sqrt(double(l)));
449  u.mm[0] = -this->mm[2]*l;
450  u.mm[1] = T(0);
451  u.mm[2] = +this->mm[0]*l;
452  } else {
453  // W.y or W.z is the largest magnitude component, swap them
454  l = this->mm[1]*this->mm[1] + this->mm[2]*this->mm[2];
455  l = static_cast<T>(T(1)/sqrt(double(l)));
456  u.mm[0] = T(0);
457  u.mm[1] = +this->mm[2]*l;
458  u.mm[2] = -this->mm[1]*l;
459  }
460 
461  return u;
462  }
463 
464  /// Return a vector with the components of this in ascending order
465  Vec3<T> sorted() const
466  {
467  Vec3<T> r(*this);
468  if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
469  if( r.mm[1] > r.mm[2] ) std::swap(r.mm[1], r.mm[2]);
470  if( r.mm[0] > r.mm[1] ) std::swap(r.mm[0], r.mm[1]);
471  return r;
472  }
473 
474  /// Return the vector (z, y, x)
476  {
477  return Vec3<T>(this->mm[2], this->mm[1], this->mm[0]);
478  }
479 
480  /// Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();
481  static Vec3<T> zero() { return Vec3<T>(0, 0, 0); }
482  static Vec3<T> ones() { return Vec3<T>(1, 1, 1); }
483 };
484 
485 
486 /// Equality operator, does exact floating point comparisons
487 template <typename T0, typename T1>
488 inline bool operator==(const Vec3<T0> &v0, const Vec3<T1> &v1)
489 {
490  return isExactlyEqual(v0[0], v1[0]) && isExactlyEqual(v0[1], v1[1])
491  && isExactlyEqual(v0[2], v1[2]);
492 }
493 
494 /// Inequality operator, does exact floating point comparisons
495 template <typename T0, typename T1>
496 inline bool operator!=(const Vec3<T0> &v0, const Vec3<T1> &v1) { return !(v0==v1); }
497 
498 /// Multiply each element of the given vector by @a scalar and return the result.
499 template <typename S, typename T>
500 inline Vec3<typename promote<S, T>::type> operator*(S scalar, const Vec3<T> &v) { return v*scalar; }
501 
502 /// Multiply each element of the given vector by @a scalar and return the result.
503 template <typename S, typename T>
505 {
507  result *= scalar;
508  return result;
509 }
510 
511 /// Multiply corresponding elements of @a v0 and @a v1 and return the result.
512 template <typename T0, typename T1>
514 {
515  Vec3<typename promote<T0, T1>::type> result(v0[0] * v1[0], v0[1] * v1[1], v0[2] * v1[2]);
516  return result;
517 }
518 
519 
520 /// Divide @a scalar by each element of the given vector and return the result.
521 template <typename S, typename T>
523 {
524  return Vec3<typename promote<S, T>::type>(scalar/v[0], scalar/v[1], scalar/v[2]);
525 }
526 
527 /// Divide each element of the given vector by @a scalar and return the result.
528 template <typename S, typename T>
530 {
532  result /= scalar;
533  return result;
534 }
535 
536 /// Divide corresponding elements of @a v0 and @a v1 and return the result.
537 template <typename T0, typename T1>
539 {
540  Vec3<typename promote<T0, T1>::type> result(v0[0] / v1[0], v0[1] / v1[1], v0[2] / v1[2]);
541  return result;
542 }
543 
544 /// Add corresponding elements of @a v0 and @a v1 and return the result.
545 template <typename T0, typename T1>
547 {
549  result += v1;
550  return result;
551 }
552 
553 /// Add @a scalar to each element of the given vector and return the result.
554 template <typename S, typename T>
556 {
558  result += scalar;
559  return result;
560 }
561 
562 /// Subtract corresponding elements of @a v0 and @a v1 and return the result.
563 template <typename T0, typename T1>
565 {
567  result -= v1;
568  return result;
569 }
570 
571 /// Subtract @a scalar from each element of the given vector and return the result.
572 template <typename S, typename T>
574 {
576  result -= scalar;
577  return result;
578 }
579 
580 /// Angle between two vectors, the result is between [0, pi],
581 /// e.g. double a = Vec3d::angle(v1,v2);
582 template <typename T>
583 inline T angle(const Vec3<T> &v1, const Vec3<T> &v2)
584 {
585  Vec3<T> c = v1.cross(v2);
586  return static_cast<T>(atan2(c.length(), v1.dot(v2)));
587 }
588 
589 template <typename T>
590 inline bool
591 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b)
592 {
593  return a.eq(b);
594 }
595 template <typename T>
596 inline bool
597 isApproxEqual(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& eps)
598 {
599  return isApproxEqual(a.x(), b.x(), eps.x()) &&
600  isApproxEqual(a.y(), b.y(), eps.y()) &&
601  isApproxEqual(a.z(), b.z(), eps.z());
602 }
603 
604 template<typename T>
605 inline Vec3<T>
606 Abs(const Vec3<T>& v)
607 {
608  return Vec3<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]));
609 }
610 
611 /// Orthonormalize vectors v1, v2 and v3 and store back the resulting
612 /// basis e.g. Vec3d::orthonormalize(v1,v2,v3);
613 template <typename T>
615 {
616  // If the input vectors are v0, v1, and v2, then the Gram-Schmidt
617  // orthonormalization produces vectors u0, u1, and u2 as follows,
618  //
619  // u0 = v0/|v0|
620  // u1 = (v1-(u0*v1)u0)/|v1-(u0*v1)u0|
621  // u2 = (v2-(u0*v2)u0-(u1*v2)u1)/|v2-(u0*v2)u0-(u1*v2)u1|
622  //
623  // where |A| indicates length of vector A and A*B indicates dot
624  // product of vectors A and B.
625 
626  // compute u0
627  v1.normalize();
628 
629  // compute u1
630  T d0 = v1.dot(v2);
631  v2 -= v1*d0;
632  v2.normalize();
633 
634  // compute u2
635  T d1 = v2.dot(v3);
636  d0 = v1.dot(v3);
637  v3 -= v1*d0 + v2*d1;
638  v3.normalize();
639 }
640 
641 /// @remark We are switching to a more explicit name because the semantics
642 /// are different from std::min/max. In that case, the function returns a
643 /// reference to one of the objects based on a comparator. Here, we must
644 /// fabricate a new object which might not match either of the inputs.
645 
646 /// Return component-wise minimum of the two vectors.
647 template <typename T>
648 inline Vec3<T> minComponent(const Vec3<T> &v1, const Vec3<T> &v2)
649 {
650  return Vec3<T>(
651  std::min(v1.x(), v2.x()),
652  std::min(v1.y(), v2.y()),
653  std::min(v1.z(), v2.z()));
654 }
655 
656 /// Return component-wise maximum of the two vectors.
657 template <typename T>
658 inline Vec3<T> maxComponent(const Vec3<T> &v1, const Vec3<T> &v2)
659 {
660  return Vec3<T>(
661  std::max(v1.x(), v2.x()),
662  std::max(v1.y(), v2.y()),
663  std::max(v1.z(), v2.z()));
664 }
665 
666 /// @brief Return a vector with the exponent applied to each of
667 /// the components of the input vector.
668 template <typename T>
669 inline Vec3<T> Exp(Vec3<T> v) { return v.exp(); }
670 
671 /// @brief Return a vector with log applied to each of
672 /// the components of the input vector.
673 template <typename T>
674 inline Vec3<T> Log(Vec3<T> v) { return v.log(); }
675 
680 
681 } // namespace math
682 } // namespace OPENVDB_VERSION_NAME
683 } // namespace openvdb
684 
685 #endif // OPENVDB_MATH_VEC3_HAS_BEEN_INCLUDED
686 
687 // Copyright (c) 2012-2018 DreamWorks Animation LLC
688 // All rights reserved. This software is distributed under the
689 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Vec2< T > minComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise minimum of the two vectors.
Definition: Vec2.h:530
SYS_API double atan2(double y, double x)
Definition: SYS_FPUMath.h:79
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:395
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:377
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1519
const GLdouble * v
Definition: glcorearb.h:836
void orthonormalize(Vec2< T > &v1, Vec2< T > &v2)
Definition: Vec2.h:502
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:549
Vec3(const Vec3< Other > &v)
Construct a Vec3 from another Vec3 with a possibly different value type.
Definition: Vec3.h:102
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
Definition: Mat3.h:645
T sum() const
Return the sum of all the vector components.
Definition: Vec3.h:365
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
Vec3< T > projection(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:429
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:189
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec2.h:554
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:49
Vec3< T > unitSafe() const
return normalized this, or (1, 0, 0) if this is null vector
Definition: Vec3.h:406
GLint y
Definition: glcorearb.h:102
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:818
const Vec3< T > & operator+=(S scalar)
Add scalar to each element of this vector.
Definition: Vec3.h:306
static Vec3< T > zero()
Predefined constants, e.g. Vec3d v = Vec3d::xNegAxis();.
Definition: Vec3.h:481
T dot(const Vec3< T > &v) const
Dot product.
Definition: Vec3.h:216
T product() const
Return the product of all the vector components.
Definition: Vec3.h:371
png_uint_32 i
Definition: png.h:2877
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Divide scalar by each element of the given vector and return the result.
Definition: Vec2.h:411
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec3.h:115
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec3.h:126
SYS_API double log(double x)
Definition: SYS_FPUMath.h:87
const Vec3< T > & setZero()
Set "this" vector to zero.
Definition: Vec3.h:138
Vec3(Source *a)
Constructor with array argument, e.g. double a[3]; Vec3d v(a);.
Definition: Vec3.h:72
const Vec3< T > & scale(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:196
Vec3< T > reversed() const
Return the vector (z, y, x)
Definition: Vec3.h:475
T component(const Vec3< T > &onto, T eps=static_cast< T >(1.0e-7)) const
Definition: Vec3.h:419
Coord Abs(const Coord &xyz)
Definition: Coord.h:513
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
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:133
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
const Vec3< T > & div(T0 scale, const Vec3< T1 > &v)
Definition: Vec3.h:206
SYS_API double exp(double x)
Definition: SYS_FPUMath.h:97
Vec3< T > cross(const Vec3< T > &v) const
Return the cross product of "this" vector and v;.
Definition: Vec3.h:245
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:316
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:472
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
Definition: Math.h:405
Vec3< T > sorted() const
Return a vector with the components of this in ascending order.
Definition: Vec3.h:465
Vec3< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec3.h:389
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
Vec3< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec3.h:396
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:358
GLfloat v0
Definition: glcorearb.h:815
Vec3< T > getArbPerpendicular() const
Definition: Vec3.h:440
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:496
GLsizei const GLfloat * value
Definition: glcorearb.h:823
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:296
Vec3< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec3.h:167
const Vec3< T > & operator/=(S scalar)
Divide each element of this vector by scalar.
Definition: Vec3.h:286
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
const Vec3< T > & operator=(const Vec3< Source > &v)
Assignment operator.
Definition: Vec3.h:147
const Vec3< T > & add(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:172
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec3.h:110
Vec3(T x, T y, T z)
Constructor with three arguments, e.g. Vec3d v(1,2,3);.
Definition: Vec3.h:63
Vec3(const Tuple< 3, Source > &v)
Construct a Vec3 from a 3-Tuple with a possibly different value type.
Definition: Vec3.h:82
const Vec3< T > & init(T x=0, T y=0, T z=0)
Definition: Vec3.h:130
Vec3(T val)
Construct a vector all of whose components have the given value.
Definition: Vec3.h:60
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLuint GLfloat * val
Definition: glcorearb.h:1607
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:539
Vec3()
Trivial constructor, the vector is NOT initialized.
Definition: Vec3.h:57
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Vec3< typename promote< T, typename Coord::ValueType >::type > operator+(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be added to or subtracted from a Vec3.
Definition: Coord.h:523
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
GLboolean r
Definition: glcorearb.h:1221
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:336
const Vec3< T > & operator*=(S scalar)
Multiply each element of this vector by scalar.
Definition: Vec3.h:266
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:276
const std::enable_if<!VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:129
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:135
const Vec3< T > & operator-=(S scalar)
Subtract scalar from each element of this vector.
Definition: Vec3.h:326
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
T length() const
Length of the vector.
Definition: Vec3.h:225
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
const Vec3< T > & sub(const Vec3< T0 > &v1, const Vec3< T1 > &v2)
Definition: Vec3.h:184
Type Exp(const Type &x)
Return ex.
Definition: Math.h:664
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec3.h:123