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