HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec4.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2012-2017 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_VEC4_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
33 
34 #include <openvdb/Exceptions.h>
35 #include "Math.h"
36 #include "Tuple.h"
37 #include "Vec3.h"
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 Vec4: public Tuple<4, T>
51 {
52 public:
53  typedef T value_type;
54  typedef T ValueType;
55 
56  /// Trivial constructor, the vector is NOT initialized
57  Vec4() {}
58 
59  /// @brief Construct a vector all of whose components have the given value.
60  explicit Vec4(T val) { this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = val; }
61 
62  /// Constructor with four arguments, e.g. Vec4f v(1,2,3,4);
63  Vec4(T x, T y, T z, T w)
64  {
65  this->mm[0] = x;
66  this->mm[1] = y;
67  this->mm[2] = z;
68  this->mm[3] = w;
69  }
70 
71  /// Constructor with array argument, e.g. float a[4]; Vec4f v(a);
72  template <typename Source>
73  Vec4(Source *a)
74  {
75  this->mm[0] = a[0];
76  this->mm[1] = a[1];
77  this->mm[2] = a[2];
78  this->mm[3] = a[3];
79  }
80 
81  /// Conversion constructor
82  template<typename Source>
83  explicit Vec4(const Tuple<4, Source> &v)
84  {
85  this->mm[0] = static_cast<T>(v[0]);
86  this->mm[1] = static_cast<T>(v[1]);
87  this->mm[2] = static_cast<T>(v[2]);
88  this->mm[3] = static_cast<T>(v[3]);
89  }
90 
91  /// @brief Construct a vector all of whose components have the given value,
92  /// which may be of an arithmetic type different from this vector's value type.
93  /// @details Type conversion warnings are suppressed.
94  template<typename Other>
95  explicit Vec4(Other val,
96  typename std::enable_if<std::is_arithmetic<Other>::value, Conversion>::type = Conversion{})
97  {
98  this->mm[0] = this->mm[1] = this->mm[2] = this->mm[3] = static_cast<T>(val);
99  }
100 
101  /// Reference to the component, e.g. v.x() = 4.5f;
102  T& x() { return this->mm[0]; }
103  T& y() { return this->mm[1]; }
104  T& z() { return this->mm[2]; }
105  T& w() { return this->mm[3]; }
106 
107  /// Get the component, e.g. float f = v.y();
108  T x() const { return this->mm[0]; }
109  T y() const { return this->mm[1]; }
110  T z() const { return this->mm[2]; }
111  T w() const { return this->mm[3]; }
112 
113  T* asPointer() { return this->mm; }
114  const T* asPointer() const { return this->mm; }
115 
116  /// Alternative indexed reference to the elements
117  T& operator()(int i) { return this->mm[i]; }
118 
119  /// Alternative indexed constant reference to the elements,
120  T operator()(int i) const { return this->mm[i]; }
121 
122  /// Returns a Vec3 with the first three elements of the Vec4.
123  Vec3<T> getVec3() const { return Vec3<T>(this->mm[0], this->mm[1], this->mm[2]); }
124 
125  /// "this" vector gets initialized to [x, y, z, w],
126  /// calling v.init(); has same effect as calling v = Vec4::zero();
127  const Vec4<T>& init(T x=0, T y=0, T z=0, T w=0)
128  {
129  this->mm[0] = x; this->mm[1] = y; this->mm[2] = z; this->mm[3] = w;
130  return *this;
131  }
132 
133  /// Set "this" vector to zero
134  const Vec4<T>& setZero()
135  {
136  this->mm[0] = 0; this->mm[1] = 0; this->mm[2] = 0; this->mm[3] = 0;
137  return *this;
138  }
139 
140  /// Assignment operator
141  template<typename Source>
143  {
144  // note: don't static_cast because that suppresses warnings
145  this->mm[0] = v[0];
146  this->mm[1] = v[1];
147  this->mm[2] = v[2];
148  this->mm[3] = v[3];
149 
150  return *this;
151  }
152 
153  /// Test if "this" vector is equivalent to vector v with tolerance
154  /// of eps
155  bool eq(const Vec4<T> &v, T eps=1.0e-8) const
156  {
157  return isApproxEqual(this->mm[0], v.mm[0], eps) &&
158  isApproxEqual(this->mm[1], v.mm[1], eps) &&
159  isApproxEqual(this->mm[2], v.mm[2], eps) &&
160  isApproxEqual(this->mm[3], v.mm[3], eps);
161  }
162 
163  /// Negation operator, for e.g. v1 = -v2;
165  {
166  return Vec4<T>(
167  -this->mm[0],
168  -this->mm[1],
169  -this->mm[2],
170  -this->mm[3]);
171  }
172 
173  /// this = v1 + v2
174  /// "this", v1 and v2 need not be distinct objects, e.g. v.add(v1,v);
175  template <typename T0, typename T1>
176  const Vec4<T>& add(const Vec4<T0> &v1, const Vec4<T1> &v2)
177  {
178  this->mm[0] = v1[0] + v2[0];
179  this->mm[1] = v1[1] + v2[1];
180  this->mm[2] = v1[2] + v2[2];
181  this->mm[3] = v1[3] + v2[3];
182 
183  return *this;
184  }
185 
186 
187  /// this = v1 - v2
188  /// "this", v1 and v2 need not be distinct objects, e.g. v.sub(v1,v);
189  template <typename T0, typename T1>
190  const Vec4<T>& sub(const Vec4<T0> &v1, const Vec4<T1> &v2)
191  {
192  this->mm[0] = v1[0] - v2[0];
193  this->mm[1] = v1[1] - v2[1];
194  this->mm[2] = v1[2] - v2[2];
195  this->mm[3] = v1[3] - v2[3];
196 
197  return *this;
198  }
199 
200  /// this = scalar*v, v need not be a distinct object from "this",
201  /// e.g. v.scale(1.5,v1);
202  template <typename T0, typename T1>
203  const Vec4<T>& scale(T0 scale, const Vec4<T1> &v)
204  {
205  this->mm[0] = scale * v[0];
206  this->mm[1] = scale * v[1];
207  this->mm[2] = scale * v[2];
208  this->mm[3] = scale * v[3];
209 
210  return *this;
211  }
212 
213  template <typename T0, typename T1>
214  const Vec4<T> &div(T0 scalar, const Vec4<T1> &v)
215  {
216  this->mm[0] = v[0] / scalar;
217  this->mm[1] = v[1] / scalar;
218  this->mm[2] = v[2] / scalar;
219  this->mm[3] = v[3] / scalar;
220 
221  return *this;
222  }
223 
224  /// Dot product
225  T dot(const Vec4<T> &v) const
226  {
227  return (this->mm[0]*v.mm[0] + this->mm[1]*v.mm[1]
228  + this->mm[2]*v.mm[2] + this->mm[3]*v.mm[3]);
229  }
230 
231  /// Length of the vector
232  T length() const
233  {
234  return sqrt(
235  this->mm[0]*this->mm[0] +
236  this->mm[1]*this->mm[1] +
237  this->mm[2]*this->mm[2] +
238  this->mm[3]*this->mm[3]);
239  }
240 
241 
242  /// Squared length of the vector, much faster than length() as it
243  /// does not involve square root
244  T lengthSqr() const
245  {
246  return (this->mm[0]*this->mm[0] + this->mm[1]*this->mm[1]
247  + this->mm[2]*this->mm[2] + this->mm[3]*this->mm[3]);
248  }
249 
250  /// Return a reference to itself after the exponent has been
251  /// applied to all the vector components.
252  inline const Vec4<T>& exp()
253  {
254  this->mm[0] = std::exp(this->mm[0]);
255  this->mm[1] = std::exp(this->mm[1]);
256  this->mm[2] = std::exp(this->mm[2]);
257  this->mm[3] = std::exp(this->mm[3]);
258  return *this;
259  }
260 
261  /// Return a reference to itself after log has been
262  /// applied to all the vector components.
263  inline const Vec4<T>& log()
264  {
265  this->mm[0] = std::log(this->mm[0]);
266  this->mm[1] = std::log(this->mm[1]);
267  this->mm[2] = std::log(this->mm[2]);
268  this->mm[3] = std::log(this->mm[3]);
269  return *this;
270  }
271 
272  /// Return the sum of all the vector components.
273  inline T sum() const
274  {
275  return this->mm[0] + this->mm[1] + this->mm[2] + this->mm[3];
276  }
277 
278  /// Return the product of all the vector components.
279  inline T product() const
280  {
281  return this->mm[0] * this->mm[1] * this->mm[2] * this->mm[3];
282  }
283 
284  /// this = normalized this
285  bool normalize(T eps=1.0e-8)
286  {
287  T d = length();
288  if (isApproxEqual(d, T(0), eps)) {
289  return false;
290  }
291  *this *= (T(1) / d);
292  return true;
293  }
294 
295  /// return normalized this, throws if null vector
296  Vec4<T> unit(T eps=0) const
297  {
298  T d;
299  return unit(eps, d);
300  }
301 
302  /// return normalized this and length, throws if null vector
303  Vec4<T> unit(T eps, T& len) const
304  {
305  len = length();
306  if (isApproxEqual(len, T(0), eps)) {
307  throw ArithmeticError("Normalizing null 4-vector");
308  }
309  return *this / len;
310  }
311 
312  /// return normalized this, or (1, 0, 0, 0) if this is null vector
314  {
315  T l2 = lengthSqr();
316  return l2 ? *this / static_cast<T>(sqrt(l2)) : Vec4<T>(1, 0, 0, 0);
317  }
318 
319  /// Returns v, where \f$v_i *= scalar\f$ for \f$i \in [0, 3]\f$
320  template <typename S>
321  const Vec4<T> &operator*=(S scalar)
322  {
323  this->mm[0] *= scalar;
324  this->mm[1] *= scalar;
325  this->mm[2] *= scalar;
326  this->mm[3] *= scalar;
327  return *this;
328  }
329 
330  /// Returns v0, where \f$v0_i *= v1_i\f$ for \f$i \in [0, 3]\f$
331  template <typename S>
332  const Vec4<T> &operator*=(const Vec4<S> &v1)
333  {
334  this->mm[0] *= v1[0];
335  this->mm[1] *= v1[1];
336  this->mm[2] *= v1[2];
337  this->mm[3] *= v1[3];
338 
339  return *this;
340  }
341 
342  /// Returns v, where \f$v_i /= scalar\f$ for \f$i \in [0, 3]\f$
343  template <typename S>
344  const Vec4<T> &operator/=(S scalar)
345  {
346  this->mm[0] /= scalar;
347  this->mm[1] /= scalar;
348  this->mm[2] /= scalar;
349  this->mm[3] /= scalar;
350  return *this;
351  }
352 
353  /// Returns v0, where \f$v0_i /= v1_i\f$ for \f$i \in [0, 3]\f$
354  template <typename S>
355  const Vec4<T> &operator/=(const Vec4<S> &v1)
356  {
357  this->mm[0] /= v1[0];
358  this->mm[1] /= v1[1];
359  this->mm[2] /= v1[2];
360  this->mm[3] /= v1[3];
361  return *this;
362  }
363 
364  /// Returns v, where \f$v_i += scalar\f$ for \f$i \in [0, 3]\f$
365  template <typename S>
366  const Vec4<T> &operator+=(S scalar)
367  {
368  this->mm[0] += scalar;
369  this->mm[1] += scalar;
370  this->mm[2] += scalar;
371  this->mm[3] += scalar;
372  return *this;
373  }
374 
375  /// Returns v0, where \f$v0_i += v1_i\f$ for \f$i \in [0, 3]\f$
376  template <typename S>
377  const Vec4<T> &operator+=(const Vec4<S> &v1)
378  {
379  this->mm[0] += v1[0];
380  this->mm[1] += v1[1];
381  this->mm[2] += v1[2];
382  this->mm[3] += v1[3];
383  return *this;
384  }
385 
386  /// Returns v, where \f$v_i += scalar\f$ for \f$i \in [0, 3]\f$
387  template <typename S>
388  const Vec4<T> &operator-=(S scalar)
389  {
390  this->mm[0] -= scalar;
391  this->mm[1] -= scalar;
392  this->mm[2] -= scalar;
393  this->mm[3] -= scalar;
394  return *this;
395  }
396 
397  /// Returns v0, where \f$v0_i -= v1_i\f$ for \f$i \in [0, 3]\f$
398  template <typename S>
399  const Vec4<T> &operator-=(const Vec4<S> &v1)
400  {
401  this->mm[0] -= v1[0];
402  this->mm[1] -= v1[1];
403  this->mm[2] -= v1[2];
404  this->mm[3] -= v1[3];
405  return *this;
406  }
407 
408  // Number of cols, rows, elements
409  static unsigned numRows() { return 1; }
410  static unsigned numColumns() { return 4; }
411  static unsigned numElements() { return 4; }
412 
413  /// True if a Nan is present in vector
414  bool isNan() const
415  {
416  return isnan(this->mm[0]) || isnan(this->mm[1])
417  || isnan(this->mm[2]) || isnan(this->mm[3]);
418  }
419 
420  /// True if an Inf is present in vector
421  bool isInfinite() const
422  {
423  return isinf(this->mm[0]) || isinf(this->mm[1])
424  || isinf(this->mm[2]) || isinf(this->mm[3]);
425  }
426 
427  /// True if all no Nan or Inf values present
428  bool isFinite() const
429  {
430  return finite(this->mm[0]) && finite(this->mm[1])
431  && finite(this->mm[2]) && finite(this->mm[3]);
432  }
433 
434  /// Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();
435  static Vec4<T> zero() { return Vec4<T>(0, 0, 0, 0); }
436  static Vec4<T> origin() { return Vec4<T>(0, 0, 0, 1); }
437  static Vec4<T> ones() { return Vec4<T>(1, 1, 1, 1); }
438 };
439 
440 /// Equality operator, does exact floating point comparisons
441 template <typename T0, typename T1>
442 inline bool operator==(const Vec4<T0> &v0, const Vec4<T1> &v1)
443 {
444  return
445  isExactlyEqual(v0[0], v1[0]) &&
446  isExactlyEqual(v0[1], v1[1]) &&
447  isExactlyEqual(v0[2], v1[2]) &&
448  isExactlyEqual(v0[3], v1[3]);
449 }
450 
451 /// Inequality operator, does exact floating point comparisons
452 template <typename T0, typename T1>
453 inline bool operator!=(const Vec4<T0> &v0, const Vec4<T1> &v1) { return !(v0==v1); }
454 
455 /// Returns V, where \f$V_i = v_i * scalar\f$ for \f$i \in [0, 3]\f$
456 template <typename S, typename T>
458 { return v*scalar; }
459 
460 /// Returns V, where \f$V_i = v_i * scalar\f$ for \f$i \in [0, 3]\f$
461 template <typename S, typename T>
463 {
465  result *= scalar;
466  return result;
467 }
468 
469 /// Returns V, where \f$V_i = v0_i * v1_i\f$ for \f$i \in [0, 3]\f$
470 template <typename T0, typename T1>
472  const Vec4<T1> &v1)
473 {
474  Vec4<typename promote<T0, T1>::type> result(v0[0]*v1[0],
475  v0[1]*v1[1],
476  v0[2]*v1[2],
477  v0[3]*v1[3]);
478  return result;
479 }
480 
481 /// Returns V, where \f$V_i = scalar / v_i\f$ for \f$i \in [0, 3]\f$
482 template <typename S, typename T>
484 {
485  return Vec4<typename promote<S, T>::type>(scalar/v[0],
486  scalar/v[1],
487  scalar/v[2],
488  scalar/v[3]);
489 }
490 
491 /// Returns V, where \f$V_i = v_i / scalar\f$ for \f$i \in [0, 3]\f$
492 template <typename S, typename T>
494 {
496  result /= scalar;
497  return result;
498 }
499 
500 /// Returns V, where \f$V_i = v0_i / v1_i\f$ for \f$i \in [0, 3]\f$
501 template <typename T0, typename T1>
503  const Vec4<T1> &v1)
504 {
506  result(v0[0]/v1[0], v0[1]/v1[1], v0[2]/v1[2], v0[3]/v1[3]);
507  return result;
508 }
509 
510 /// Returns V, where \f$V_i = v0_i + v1_i\f$ for \f$i \in [0, 3]\f$
511 template <typename T0, typename T1>
513 {
515  result += v1;
516  return result;
517 }
518 
519 /// Returns V, where \f$V_i = v_i + scalar\f$ for \f$i \in [0, 3]\f$
520 template <typename S, typename T>
522 {
524  result += scalar;
525  return result;
526 }
527 
528 /// Returns V, where \f$V_i = v0_i - v1_i\f$ for \f$i \in [0, 3]\f$
529 template <typename T0, typename T1>
531 {
533  result -= v1;
534  return result;
535 }
536 
537 /// Returns V, where \f$V_i = v_i - scalar\f$ for \f$i \in [0, 3]\f$
538 template <typename S, typename T>
540 {
542  result -= scalar;
543  return result;
544 }
545 
546 template <typename T>
547 inline bool
548 isApproxEqual(const Vec4<T>& a, const Vec4<T>& b)
549 {
550  return a.eq(b);
551 }
552 template <typename T>
553 inline bool
554 isApproxEqual(const Vec4<T>& a, const Vec4<T>& b, const Vec4<T>& eps)
555 {
556  return isApproxEqual(a[0], b[0], eps[0]) &&
557  isApproxEqual(a[1], b[1], eps[1]) &&
558  isApproxEqual(a[2], b[2], eps[2]) &&
559  isApproxEqual(a[3], b[3], eps[3]);
560 }
561 
562 template<typename T>
563 inline bool
565 {
566  return isFinite(v[0]) && isFinite(v[1]) && isFinite(v[2]) && isFinite(v[3]);
567 }
568 
569 /// Return @c true if all components are exactly equal to zero.
570 template<typename T>
571 inline bool
572 isZero(const Vec4<T>& v)
573 {
574  return isZero(v[0]) && isZero(v[1]) && isZero(v[2]) && isZero(v[3]);
575 }
576 
577 template<typename T>
578 inline Vec4<T>
579 Abs(const Vec4<T>& v)
580 {
581  return Vec4<T>(Abs(v[0]), Abs(v[1]), Abs(v[2]), Abs(v[3]));
582 }
583 
584 /// @remark We are switching to a more explicit name because the semantics
585 /// are different from std::min/max. In that case, the function returns a
586 /// reference to one of the objects based on a comparator. Here, we must
587 /// fabricate a new object which might not match either of the inputs.
588 
589 /// Return component-wise minimum of the two vectors.
590 template <typename T>
591 inline Vec4<T> minComponent(const Vec4<T> &v1, const Vec4<T> &v2)
592 {
593  return Vec4<T>(
594  std::min(v1.x(), v2.x()),
595  std::min(v1.y(), v2.y()),
596  std::min(v1.z(), v2.z()),
597  std::min(v1.w(), v2.w()));
598 }
599 
600 /// Return component-wise maximum of the two vectors.
601 template <typename T>
602 inline Vec4<T> maxComponent(const Vec4<T> &v1, const Vec4<T> &v2)
603 {
604  return Vec4<T>(
605  std::max(v1.x(), v2.x()),
606  std::max(v1.y(), v2.y()),
607  std::max(v1.z(), v2.z()),
608  std::max(v1.w(), v2.w()));
609 }
610 
611 /// @brief Return a vector with the exponent applied to each of
612 /// the components of the input vector.
613 template <typename T>
614 inline Vec4<T> Exp(Vec4<T> v) { return v.exp(); }
615 
616 /// @brief Return a vector with log applied to each of
617 /// the components of the input vector.
618 template <typename T>
619 inline Vec4<T> Log(Vec4<T> v) { return v.log(); }
620 
625 
626 } // namespace math
627 } // namespace OPENVDB_VERSION_NAME
628 } // namespace openvdb
629 
630 #endif // OPENVDB_MATH_VEC4_HAS_BEEN_INCLUDED
631 
632 // Copyright (c) 2012-2017 DreamWorks Animation LLC
633 // All rights reserved. This software is distributed under the
634 // 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:553
T x() const
Get the component, e.g. float f = v.y();.
Definition: Vec4.h:108
Vec4(T val)
Construct a vector all of whose components have the given value.
Definition: Vec4.h:60
Vec4(const Tuple< 4, Source > &v)
Conversion constructor.
Definition: Vec4.h:83
const Vec4< T > & operator*=(S scalar)
Returns v, where for .
Definition: Vec4.h:321
const Vec4< T > & operator-=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:399
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const Vec4< T > & operator+=(S scalar)
Returns v, where for .
Definition: Vec4.h:366
const GLdouble * v
Definition: glcorearb.h:836
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:527
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
const Vec4< T > & operator*=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:332
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Matrix multiplication.
Definition: Mat3.h:654
Vec4(Source *a)
Constructor with array argument, e.g. float a[4]; Vec4f v(a);.
Definition: Vec4.h:73
const Vec4< T > & operator/=(S scalar)
Returns v, where for .
Definition: Vec4.h:344
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
Vec2< T > Log(Vec2< T > v)
Return a vector with log applied to each of the components of the input vector.
Definition: Vec2.h:577
Dummy class for tag dispatch of conversion constructors.
Definition: Tuple.h:47
const Vec4< T > & div(T0 scalar, const Vec4< T1 > &v)
Definition: Vec4.h:214
const Vec4< T > & operator/=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:355
GLint y
Definition: glcorearb.h:102
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:817
Vec4< T > unit(T eps=0) const
return normalized this, throws if null vector
Definition: Vec4.h:296
Vec4()
Trivial constructor, the vector is NOT initialized.
Definition: Vec4.h:57
const Vec4< T > & init(T x=0, T y=0, T z=0, T w=0)
Definition: Vec4.h:127
png_uint_32 i
Definition: png.h:2877
Vec2< typename promote< S, T >::type > operator/(S scalar, const Vec2< T > &v)
Returns V, where for .
Definition: Vec2.h:419
const Vec4< T > & scale(T0 scale, const Vec4< T1 > &v)
Definition: Vec4.h:203
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
Vec4< T > unit(T eps, T &len) const
return normalized this and length, throws if null vector
Definition: Vec4.h:303
SYS_API double log(double x)
const Vec4< T > & sub(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:190
bool isInfinite() const
True if an Inf is present in vector.
Definition: Vec4.h:421
bool eq(const Vec4< T > &v, T eps=1.0e-8) const
Definition: Vec4.h:155
Coord Abs(const Coord &xyz)
Definition: Coord.h:254
bool isFinite(const Type &x)
Return true if x is finite.
Definition: Math.h:363
T sum() const
Return the sum of all the vector components.
Definition: Vec4.h:273
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Vec4< T > operator-() const
Negation operator, for e.g. v1 = -v2;.
Definition: Vec4.h:164
static Vec4< T > zero()
Predefined constants, e.g. Vec4f v = Vec4f::xNegAxis();.
Definition: Vec4.h:435
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Vec4(Other val, typename std::enable_if< std::is_arithmetic< Other >::value, Conversion >::type=Conversion{})
Construct a vector all of whose components have the given value, which may be of an arithmetic type d...
Definition: Vec4.h:95
bool normalize(T eps=1.0e-8)
this = normalized this
Definition: Vec4.h:285
const Vec4< T > & operator+=(const Vec4< S > &v1)
Returns v0, where for .
Definition: Vec4.h:377
SYS_API double exp(double x)
const Vec4< T > & setZero()
Set "this" vector to zero.
Definition: Vec4.h:134
T & x()
Reference to the component, e.g. v.x() = 4.5f;.
Definition: Vec4.h:102
Vec4(T x, T y, T z, T w)
Constructor with four arguments, e.g. Vec4f v(1,2,3,4);.
Definition: Vec4.h:63
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
const Vec4< T > & operator=(const Vec4< Source > &v)
Assignment operator.
Definition: Vec4.h:142
Vec3< T > getVec3() const
Returns a Vec3 with the first three elements of the Vec4.
Definition: Vec4.h:123
T & operator()(int i)
Alternative indexed reference to the elements.
Definition: Vec4.h:117
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:370
GLfloat v0
Definition: glcorearb.h:815
const Vec4< T > & add(const Vec4< T0 > &v1, const Vec4< T1 > &v2)
Definition: Vec4.h:176
T length() const
Length of the vector.
Definition: Vec4.h:232
bool operator!=(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Inequality operator, does exact floating point comparisons.
Definition: Vec3.h:510
T product() const
Return the product of all the vector components.
Definition: Vec4.h:279
GLsizei const GLfloat * value
Definition: glcorearb.h:823
const Vec4< T > & operator-=(S scalar)
Returns v, where for .
Definition: Vec4.h:388
Vec4< T > unitSafe() const
return normalized this, or (1, 0, 0, 0) if this is null vector
Definition: Vec4.h:313
GLint GLenum GLint x
Definition: glcorearb.h:408
GLfloat GLfloat v1
Definition: glcorearb.h:816
GLuint GLfloat * val
Definition: glcorearb.h:1607
bool isFinite() const
True if all no Nan or Inf values present.
Definition: Vec4.h:428
Vec2< T > maxComponent(const Vec2< T > &v1, const Vec2< T > &v2)
Return component-wise maximum of the two vectors.
Definition: Vec2.h:562
T dot(const Vec4< T > &v) const
Dot product.
Definition: Vec4.h:225
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:501
bool isNan() const
True if a Nan is present in vector.
Definition: Vec4.h:414
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:502
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:324
Type Exp(const Type &x)
Return .
Definition: Math.h:676
T operator()(int i) const
Alternative indexed constant reference to the elements,.
Definition: Vec4.h:120