HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Vector4.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: Utility Library (C++)
7  *
8  * COMMENTS:
9  * This class handles fpreal vectors of dimension 4.
10  *
11  * WARNING:
12  * This class should NOT contain any virtual methods, nor should it
13  * define more member data. The size of UT_Vector4 must always be
14  * 16 bytes (4 floats).
15  *
16  */
17 
18 #pragma once
19 
20 #ifndef __UT_Vector4_h__
21 #define __UT_Vector4_h__
22 
23 #include "UT_API.h"
24 #include "UT_Assert.h"
25 #include "UT_FixedVector.h"
26 #include "UT_VectorTypes.h"
27 #include <SYS/SYS_Deprecated.h>
28 #include <SYS/SYS_Inline.h>
29 #include <SYS/SYS_Math.h>
30 #include <iosfwd>
31 #include <limits>
32 
33 #ifndef UT_DISABLE_VECTORIZE_MATRIX
34 #include <VM/VM_SIMD.h>
35 #endif
36 
37 class UT_IStream;
38 class UT_JSONWriter;
39 class UT_JSONValue;
40 class UT_JSONParser;
41 
42 // Free floating functions:
43 
44 // Right-multiply operators (M*v) have been removed. They had previously
45 // been defined to return v*M, which was too counterintuitive. Once HDK
46 // etc. users have a chance to update their code (post 7.0) we could
47 // reintroduce a right-multiply operator that does a colVecMult.
48 
49 template <typename T, typename S>
51 template <typename T>
53 template <typename T>
55 template <typename T, typename S>
56 inline UT_Vector4T<T> operator+(const UT_Vector4T<T> &v, S scalar);
57 template <typename T, typename S>
58 inline UT_Vector4T<T> operator-(const UT_Vector4T<T> &v, S scalar);
59 template <typename T, typename S>
60 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, S scalar);
61 template <typename T, typename S>
62 inline UT_Vector4T<T> operator/(const UT_Vector4T<T> &v, S scalar);
63 template <typename T, typename S>
64 inline UT_Vector4T<T> operator+(S scalar, const UT_Vector4T<T> &v);
65 template <typename T, typename S>
66 inline UT_Vector4T<T> operator-(S scalar, const UT_Vector4T<T> &v);
67 template <typename T, typename S>
68 inline UT_Vector4T<T> operator*(S scalar, const UT_Vector4T<T> &v);
69 template <typename T, typename S>
70 inline UT_Vector4T<T> operator/(S scalar, const UT_Vector4T<T> &v);
71 
72 /// Although the cross product is undefined for 4D vectors, we believe it's
73 /// useful in practice to define a function that takes two 4D vectors and
74 /// computes the cross-product of their first 3 components
75 template <typename T>
77 template <typename T>
79 template <typename T>
81 
82 /// The dot product between two vectors
83 // @{
84 template <typename T>
85 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
86 template <typename T>
87 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector3T<T> &v2);
88 template <typename T>
89 inline T dot(const UT_Vector3T<T> &v1, const UT_Vector4T<T> &v2);
90 // @}
91 
92 /// Componentwise min and maximum
93 template <typename T>
94 inline UT_Vector4T<T> SYSmin (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
95 template <typename T>
96 inline UT_Vector4T<T> SYSmax (const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2);
97 
98 /// Componentwise linear interpolation
99 template <typename T,typename S>
100 inline UT_Vector4T<T> SYSlerp(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S t);
101 
102 /// Bilinear interpolation
103 template <typename T,typename S>
104 inline UT_Vector4T<T> SYSbilerp(const UT_Vector4T<T> &u0v0, const UT_Vector4T<T> &u1v0,
105  const UT_Vector4T<T> &u0v1, const UT_Vector4T<T> &u1v1,
106  S u, S v)
107 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
108 
109 /// Barycentric interpolation
110 template <typename T, typename S>
112  const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2, S u, S v)
113 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
114 
115 
116 /// Multiplication of a row or column vector by a matrix (ie. right vs. left
117 /// multiplication respectively). The operator*() declared above is an alias
118 /// for rowVecMult().
119 // @{
120 //
121 // Notes on optimisation of matrix/vector multiplies:
122 // - multiply(dest, mat) functions have been deprecated in favour of
123 // rowVecMult/colVecMult routines, which produce temporaries. For these to
124 // offer comparable performance, the compiler has to optimize away the
125 // temporary, but most modern compilers can do this. Performance tests with
126 // gcc3.3 indicate that this is a realistic expectation for modern
127 // compilers.
128 // - since matrix/vector multiplies cannot be done without temporary data,
129 // the "primary" functions are the global matrix/vector
130 // rowVecMult/colVecMult routines, rather than the member functions.
131 // - inlining is explicitly requested only for functions involving the
132 // native types (UT_Vector4 and UT_Matrix4)
133 template <typename T, typename S>
135 template <typename T, typename S>
137 
138 template <typename T, typename S>
140 template <typename T, typename S>
142 // @}
143 
144 /// Compute the distance between two points
145 // @{
146 template <typename T>
147 inline T distance4(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
148 template <typename T>
149 inline T distance3(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2);
150 template <typename T>
151 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector4T<T> &p2)
152 { return distance3(p1, p2); }
153 template <typename T>
154 inline T distance3d(const UT_Vector3T<T> &p1, const UT_Vector4T<T> &p2)
155 { return distance3d(p1, UT_Vector3T<T>(p2)); }
156 template <typename T>
157 inline T distance3d(const UT_Vector4T<T> &p1, const UT_Vector3T<T> &p2)
158 { return distance3d(UT_Vector3T<T>(p1), p2); }
159 // @}
160 
161 /// 4D Vector class.
162 template <typename T>
163 class UT_API UT_Vector4T : public UT_FixedVector<T,4,true>
164 {
165 public:
167 
168  // These "using" statements are needed for operator= and operator*=
169  // so that the ones in UT_FixedVector aren't hidden by the additional
170  // ones here.
171  using Base::operator=;
172  using Base::operator*=;
173 
174  // These "using" statements are needed for GCC and Clang, because
175  // otherwise, they ignore all members of UT_FixedVector when
176  // checking validity of code in functions in this class.
177 private:
178  using Base::vec;
179 public:
180  using Base::data;
181  typedef T value_type;
182  static const int tuple_size = 4;
183 
184  /// Default constructor.
185  /// No data is initialized! Use it for extra speed.
186  SYS_FORCE_INLINE UT_Vector4T() = default;
187 
188  SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T<T> &that) = default;
189  SYS_FORCE_INLINE UT_Vector4T(UT_Vector4T<T> &&that) = default;
190 
191  SYS_FORCE_INLINE UT_Vector4T(T vx, T vy, T vz, T vw = 1.0f)
192  {
193  vec[0] = vx;
194  vec[1] = vy;
195  vec[2] = vz;
196  vec[3] = vw;
197  }
199  : Base(v)
200  {}
202  : Base(v)
203  {}
204  SYS_FORCE_INLINE UT_Vector4T(const int32 v[tuple_size])
205  : Base(v)
206  {}
207  SYS_FORCE_INLINE UT_Vector4T(const int64 v[tuple_size])
208  : Base(v)
209  {}
210 
211  // Initialises the vector as [x,y,0,1]
213  explicit UT_Vector4T(const UT_Vector2T<T> &v);
215  explicit UT_Vector4T(const UT_Vector3T<T> &v, T w = 1.f);
216 
217  /// Our own type of any given value_type.
218  template <typename S>
220  : Base(v)
221  {}
222 
223  /// Arbitrary UT_FixedVector of the same size
224  template <typename S,bool S_INSTANTIATED>
226  : Base(v)
227  {}
228 
231 
232  template <typename S>
234  { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; vec[3] = v[3];
235  return *this; }
236 
237 
238  // TODO: We could remove this. It's not as error-prone as some other
239  // conversions, but it might still be better to force the user to do
240  // an explicit cast i.e., v4 = UT_Vector4(v3)
241 
242  /// Assignment operator that creates a V4 from a V3 by adding a '1'
243  /// element.
244  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit UT_Vector4 constructor to avoid implicit conversion from UT_Vector3)
246 
247  int equalZero3(T tol = 0.00001f) const
248  {
249  return (vec[0] >= -tol && vec[0] <= tol) &&
250  (vec[1] >= -tol && vec[1] <= tol) &&
251  (vec[2] >= -tol && vec[2] <= tol);
252  }
253 
254  void clampZero(T tol = 0.00001f)
255  {
256  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
257  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
258  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
259  if (vec[3] >= -tol && vec[3] <= tol) vec[3] = 0;
260  }
261 
262  void clampZero3(T tol = 0.00001f)
263  {
264  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
265  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
266  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
267  }
268 
269  void negate3()
270  { vec[0]= -vec[0]; vec[1]= -vec[1]; vec[2]= -vec[2]; }
271 
273  {
274  vec[0] *= v.vec[0];
275  vec[1] *= v.vec[1];
276  vec[2] *= v.vec[2];
277  vec[3] *= v.vec[3];
278  }
279 
280  using Base::isEqual;
281 
282  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit conversion to UT_Vector3 followed by isEqual)
283  inline int isEqual(const UT_Vector3T<T> &vect, T tol = 0.00001f) const;
284 
285  /// If you need a multiplication operator that left multiplies the vector
286  /// by a matrix (M * v), use the following colVecMult() functions. If
287  /// you'd rather not use operator*=() for right-multiplications (v * M),
288  /// use the following rowVecMult() functions.
289  // @{
290  template <typename S>
291  inline void rowVecMult(const UT_Matrix4T<S> &m)
292  { operator=(::rowVecMult(*this, m)); }
293  template <typename S>
294  inline void colVecMult(const UT_Matrix4T<S> &m)
295  { operator=(::colVecMult(m, *this)); }
296  // @}
297 
298  /// This multiply will ignore the 4th component both in the vector an in
299  /// the matrix. This helps when you want to avoid affecting the 'w'
300  /// component. This in turns annihilates the translation components (row 4)
301  /// in mat, so be careful.
302  // @{
303  template <typename S>
305  { operator=(::rowVecMult3(*this, m)); }
306  // @}
307 
308  // The *= and multiply3 routines are provided for
309  // legacy reasons. They all assume that *this is a row vector. Generally,
310  // the rowVecMult and colVecMult methods are preferred, since they're
311  // more explicit about the row vector assumption.
312  // @{
313  template <typename S>
314  inline
316  { rowVecMult(mat); return *this; }
317 
318  template <typename S>
319  inline void multiply3(const UT_Matrix4T<S> &mat)
320  { rowVecMult3(mat); }
321  template <typename S>
322  inline void multiply3(UT_Vector4T<T> &dest, const UT_Matrix4T<S> &mat) const
323  { dest = ::rowVecMult3(*this, mat); }
324  // @}
325 
326  /// These allow you to find out what indices to use for different axes
327  // @{
328  int findMinAbsAxis() const
329  {
330  if (SYSabs(x()) < SYSabs(y()))
331  if (SYSabs(z()) < SYSabs(x()))
332  if (SYSabs(w()) < SYSabs(z()))
333  return 3;
334  else
335  return 2;
336  else
337  if (SYSabs(w()) < SYSabs(x()))
338  return 3;
339  else
340  return 0;
341  else
342  if (SYSabs(z()) < SYSabs(y()))
343  if (SYSabs(w()) < SYSabs(z()))
344  return 3;
345  else
346  return 2;
347  else
348  if (SYSabs(w()) < SYSabs(y()))
349  return 3;
350  else
351  return 1;
352  }
353  int findMaxAbsAxis() const
354  {
355  if (SYSabs(x()) >= SYSabs(y()))
356  if (SYSabs(z()) >= SYSabs(x()))
357  if (SYSabs(w()) >= SYSabs(z()))
358  return 3;
359  else
360  return 2;
361  else
362  if (SYSabs(w()) >= SYSabs(x()))
363  return 3;
364  else
365  return 0;
366  else
367  if (SYSabs(z()) >= SYSabs(y()))
368  if (SYSabs(w()) >= SYSabs(z()))
369  return 3;
370  else
371  return 2;
372  else
373  if (SYSabs(w()) >= SYSabs(y()))
374  return 3;
375  else
376  return 1;
377  }
378  // @}
379 
380  /// Return the components of the vector. The () operator does NOT check
381  /// for the boundary condition.
382  // @{
383  inline T &x(void) { return vec[0]; }
384  inline T x(void) const { return vec[0]; }
385  inline T &y(void) { return vec[1]; }
386  inline T y(void) const { return vec[1]; }
387  inline T &z(void) { return vec[2]; }
388  inline T z(void) const { return vec[2]; }
389  inline T &w(void) { return vec[3]; }
390  inline T w(void) const { return vec[3]; }
391  inline T &operator()(unsigned i)
392  {
393  UT_ASSERT_P(i < tuple_size);
394  return vec[i];
395  }
396  inline T operator()(unsigned i) const
397  {
398  UT_ASSERT_P(i < tuple_size);
399  return vec[i];
400  }
401  // @}
402 
403  /// Compute a hash
404  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
405 
406  // TODO: eliminate these methods. They're redundant, given good inline
407  // constructors.
408  /// Set the values of the vector components
409  void assign(T xx = 0.0f, T yy = 0.0f, T zz = 0.0f,
410  T ww = 1.0f)
411  {
412  vec[0] = xx; vec[1] = yy; vec[2] = zz; vec[3] = ww;
413  }
414  /// Set the values of the vector components
415  void assign(const T *v, int size = tuple_size)
416  {
417  vec[0] = v[0];
418  vec[1] = v[1];
419  vec[2] = v[2];
420  if (size == tuple_size) vec[3] = v[3];
421  }
422 
423  /// Express the point in homogeneous coordinates or vice-versa
424  // @{
425  void homogenize(void)
426  {
427  vec[0] *= vec[3];
428  vec[1] *= vec[3];
429  vec[2] *= vec[3];
430  }
431  void dehomogenize(void)
432  {
433  if (vec[3] != 0)
434  {
435  T denom = 1.0f / vec[3];
436  vec[0] *= denom;
437  vec[1] *= denom;
438  vec[2] *= denom;
439  }
440  }
441  // @}
442 
443  void save(std::ostream &os, int binary=0) const;
444  bool load(UT_IStream &is);
445 
446  /// @{
447  /// Methods to serialize to a JSON stream. The vector is stored as an
448  /// array of 4 reals.
449  bool save(UT_JSONWriter &w) const;
450  bool save(UT_JSONValue &v) const;
451  bool load(UT_JSONParser &p);
452  /// @}
453 
454  /// Returns the vector size
455  static int entries() { return tuple_size; }
456 
457 private:
458  /// I/O friends
459  // @{
460  friend std::ostream &operator<<(std::ostream &os, const UT_Vector4T<T> &v)
461  {
462  v.save(os);
463  return os;
464  }
465  // @}
466 
467  /// The negate operator is not provided, because of potentially
468  /// unintuitive behaviour: you very rarely actually want to negate the
469  /// w component.
470  UT_Vector4T<T> operator-() const
471  {
472  UT_ASSERT(0);
473  UT_Vector4T a(*this);
474  a.negate();
475  return a;
476  }
477 };
478 
479 #include "UT_Vector2.h"
480 #include "UT_Vector3.h"
481 
482 template <typename T>
484 {
485  vec[0] = v.x();
486  vec[1] = v.y();
487  vec[2] = T(0);
488  vec[3] = T(1);
489 }
490 template <typename T>
492 {
493  vec[0] = v.x();
494  vec[1] = v.y();
495  vec[2] = v.z();
496  vec[3] = vw;
497 }
498 
499 #ifndef UT_DISABLE_VECTORIZE_MATRIX
500 template <> inline void
502 {
503  v4uf l(this->data());
504  const v4uf r(v.data());
505  l *= r;
506 
507  vm_store(this->data(), l.vector);
508 }
509 #endif
510 
511 template <typename T>
512 inline int
513 UT_Vector4T<T>::isEqual(const UT_Vector3T<T> &vect, T tol) const
514 {
515  return ((vec[0]>=vect.x()-tol) && (vec[0]<=vect.x()+tol) &&
516  (vec[1]>=vect.y()-tol) && (vec[1]<=vect.y()+tol) &&
517  (vec[2]>=vect.z()-tol) && (vec[2]<=vect.z()+tol));
518 }
519 
520 // Free floating functions:
521 template <typename T>
523 {
524  return UT_Vector4T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
525  v1.z()+v2.z(), v1.w()+v2.w());
526 }
527 template <typename T>
529 {
530  return UT_Vector3T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
531  v1.z()+v2.z());
532 }
533 template <typename T>
535 {
536  return UT_Vector3T<T>(v1.x()+v2.x(), v1.y()+v2.y(),
537  v1.z()+v2.z());
538 }
539 template <typename T>
541 {
542  return UT_Vector4T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
543  v1.z()-v2.z(), v1.w()-v2.w());
544 }
545 template <typename T>
547 {
548  return UT_Vector3T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
549  v1.z()-v2.z());
550 }
551 template <typename T>
553 {
554  return UT_Vector3T<T>(v1.x()-v2.x(), v1.y()-v2.y(),
555  v1.z()-v2.z());
556 }
557 template <typename T>
559 {
560  return UT_Vector4T<T>(v1.x()*v2.x(), v1.y()*v2.y(), v1.z()*v2.z(), v1.w()*v2.w());
561 }
562 
563 template <typename T>
565 {
566  return UT_Vector4T<T>(v1.x()/v2.x(), v1.y()/v2.y(), v1.z()/v2.z(), v1.w()/v2.w());
567 }
568 #ifndef UT_DISABLE_VECTORIZE_MATRIX
569 template <>
571 {
572  const v4uf l(v1.data());
573  const v4uf r(v2.data());
574  const v4uf result = l * r;
575  return UT_Vector4T<float>((float*) &result);
576 }
577 template <>
579 {
580  const v4uf l(v1.data());
581  const v4uf r(v2.data());
582  const v4uf result = l / r;
583  return UT_Vector4T<float>((float*) &result);
584 }
585 #endif
586 
587 template <typename T, typename S>
588 inline UT_Vector4T<T> operator+(const UT_Vector4T<T> &v, S scalar)
589 {
590  return UT_Vector4T<T>(v.x()+scalar, v.y()+scalar, v.z()+scalar, v.w()+scalar);
591 }
592 template <typename T, typename S>
593 inline UT_Vector4T<T> operator+(S scalar, const UT_Vector4T<T> &v)
594 {
595  return UT_Vector4T<T>(v.x()+scalar, v.y()+scalar, v.z()+scalar, v.w()+scalar);
596 }
597 template <typename T, typename S>
598 inline UT_Vector4T<T> operator-(const UT_Vector4T<T> &v, S scalar)
599 {
600  return UT_Vector4T<T>(v.x()-scalar, v.y()-scalar, v.z()-scalar, v.w()-scalar);
601 }
602 template <typename T, typename S>
603 inline UT_Vector4T<T> operator-(S scalar, const UT_Vector4T<T> &v)
604 {
605  return UT_Vector4T<T>(scalar-v.x(), scalar-v.y(), scalar-v.z(), v.w()-scalar);
606 }
607 template <typename T, typename S>
608 inline UT_Vector4T<T> operator*(const UT_Vector4T<T> &v, S scalar)
609 {
610  return UT_Vector4T<T>(v.x()*scalar, v.y()*scalar, v.z()*scalar, v.w()*scalar);
611 }
612 template <typename T, typename S>
613 inline UT_Vector4T<T> operator*(S scalar, const UT_Vector4T<T> &v)
614 {
615  return UT_Vector4T<T>(v.x()*scalar, v.y()*scalar, v.z()*scalar, v.w()*scalar);
616 }
617 template <typename T, typename S>
618 inline UT_Vector4T<T> operator/(const UT_Vector4T<T> &v, S scalar)
619 {
620  // This has to be T because S may be int for "v = v/2" code
621  // For the same reason we must cast the 1
622  T inv = ((T)1) / scalar;
623  return UT_Vector4T<T>(v.x()*inv, v.y()*inv, v.z()*inv, v.w()*inv);
624 }
625 template <typename T, typename S>
626 inline UT_Vector4T<T> operator/(S scalar, const UT_Vector4T<T> &v)
627 {
628  return UT_Vector4T<T>(scalar/v.x(), scalar/v.y(), scalar/v.z(), scalar/v.w());
629 }
630 template <typename T>
631 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2)
632 {
633  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z() + v1.w()*v2.w();
634 }
635 #ifndef UT_DISABLE_VECTORIZE_MATRIX
636 template <>
637 inline float dot(const UT_Vector4T<float> &v1, const UT_Vector4T<float> &v2)
638 {
639  return dot4(v4uf(v1.data()), v4uf(v2.data()));
640 }
641 #endif
642 
643 template <typename T>
644 inline T dot(const UT_Vector4T<T> &v1, const UT_Vector3T<T> &v2)
645 {
646  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
647 }
648 template <typename T>
649 inline T dot(const UT_Vector3T<T> &v1, const UT_Vector4T<T> &v2)
650 {
651  return v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z();
652 }
653 template <typename T>
654 inline
656 {
657  return UT_Vector4T<T>(
658  SYSabs(v.x()),
659  SYSabs(v.y()),
660  SYSabs(v.z()),
661  SYSabs(v.w())
662  );
663 }
664 
665 template <typename T>
666 inline
668 {
669  return UT_Vector4T<T>(
670  SYSmin(v1.x(), v2.x()),
671  SYSmin(v1.y(), v2.y()),
672  SYSmin(v1.z(), v2.z()),
673  SYSmin(v1.w(), v2.w())
674  );
675 }
676 
677 template <typename T>
678 inline
680 {
681  return UT_Vector4T<T>(
682  SYSmax(v1.x(), v2.x()),
683  SYSmax(v1.y(), v2.y()),
684  SYSmax(v1.z(), v2.z()),
685  SYSmax(v1.w(), v2.w())
686  );
687 }
688 
689 template <typename T,typename S>
690 inline
692 {
693  return UT_Vector4T<T>(
694  SYSlerp(v1.x(), v2.x(), t),
695  SYSlerp(v1.y(), v2.y(), t),
696  SYSlerp(v1.z(), v2.z(), t),
697  SYSlerp(v1.w(), v2.w(), t));
698 }
699 #ifndef UT_DISABLE_VECTORIZE_MATRIX
700 template <>
701 inline
703 {
704  const v4uf l(v1.data());
705  const v4uf r(v2.data());
706  const v4uf result = SYSlerp(l, r, t);
707  return UT_Vector4T<float>((float*) &result);
708 }
709 #endif
710 
711 
712 template <typename T, typename S>
714 {
715  return rowVecMult(v, m);
716 }
717 template <typename T>
718 inline T distance(const UT_Vector4T<T> &v1, const UT_Vector4T<T> &v2)
719 {
720  T x = v1.x()-v2.x();
721  T y = v1.y()-v2.y();
722  T z = v1.z()-v2.z();
723  T w = v1.w()-v2.w();
724  return SYSsqrt(x*x + y*y + z*z + w*w);
725 }
726 template <typename T>
728 {
729  T x = v1.x()-v2.x();
730  T y = v1.y()-v2.y();
731  T z = v1.z()-v2.z();
732  return SYSsqrt(x*x + y*y + z*z);
733 }
734 
735 #ifndef UT_DISABLE_VECTORIZE_MATRIX
736 template <>
737 inline float distance(const UT_Vector4T<float> &v1, const UT_Vector4T<float> &v2)
738 {
739  const v4uf l(v1.data());
740  const v4uf r(v2.data());
741  v4uf result = l - r;
742  result *= result;
743 
744  return SYSsqrt(result[0] + result[1] + result[2] + result[3]);
745 }
746 template <>
748 {
749  const v4uf l(v1.data());
750  const v4uf r(v2.data());
751  v4uf result = l - r;
752  result *= result;
753 
754  return SYSsqrt(result[0] + result[1] + result[2]);
755 }
756 #endif
757 
758 template <typename T>
759 inline size_t hash_value(const UT_Vector4T<T> &val)
760 {
761  return val.hash();
762 }
763 
764 // Overload for custom formatting of UT_Vector4T<T> with UTformat.
765 template<typename T>
766 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T<T> &v);
767 
768 
769 template<typename T>
771 {
773  typedef T DataType;
774  static const exint TupleSize = 4;
775  static const bool isVectorType = true;
776 };
777 
778 #endif
SYS_FORCE_INLINE constexpr const T * data() const noexcept
SYS_FORCE_INLINE UT_FixedVector< T, SIZE > operator-() const
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector4T< T > &v)
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:609
UT_Vector4T< T > operator/(const UT_Vector4T< T > &v, S scalar)
Definition: UT_Vector4.h:618
GLsizeiptr size
Definition: glew.h:1681
class UT_API UT_Vector4T
T & z(void)
Definition: UT_Vector4.h:387
UT_Vector4T< T > SYSlerp(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S t)
Componentwise linear interpolation.
Definition: UT_Vector4.h:691
UT_Vector4T< T > SYSmin(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Componentwise min and maximum.
Definition: UT_Vector4.h:667
unsigned hash() const
Compute a hash.
Definition: UT_Vector4.h:404
T operator()(unsigned i) const
Definition: UT_Vector4.h:396
SYS_FORCE_INLINE UT_Vector4T(const UT_FixedVector< S, tuple_size, S_INSTANTIATED > &v)
Arbitrary UT_FixedVector of the same size.
Definition: UT_Vector4.h:225
void multiplyComponents(const UT_Vector4T< T > &v)
Definition: UT_Vector4.h:272
SYS_FORCE_INLINE ThisType & operator=(const ThisType &that)=default
GLuint const GLfloat * val
Definition: glew.h:2794
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:625
SYS_FORCE_INLINE UT_Vector4T(const UT_Vector4T< S > &v)
Our own type of any given value_type.
Definition: UT_Vector4.h:219
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
void colVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:294
T & x(void)
Definition: UT_Vector2.h:292
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#define UT_API
Definition: UT_API.h:13
const GLdouble * m
Definition: glew.h:9124
GLdouble l
Definition: glew.h:9122
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
const GLdouble * v
Definition: glew.h:1391
int isEqual(const UT_Vector3T< T > &vect, T tol=0.00001f) const
Definition: UT_Vector4.h:513
static const exint TupleSize
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:507
size_t hash_value(const UT_Vector4T< T > &val)
Definition: UT_Vector4.h:759
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:163
2D Vector class.
Definition: UT_Vector2.h:145
SYS_FORCE_INLINE UT_Vector4T(const fpreal64 v[tuple_size])
Definition: UT_Vector4.h:201
SYS_FORCE_INLINE UT_Vector4T()=default
void negate3()
Definition: UT_Vector4.h:269
GLdouble GLdouble z
Definition: glew.h:1559
UT_Vector4T< T > SYSmax(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:679
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:511
long long int64
Definition: SYS_Types.h:111
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
UT_API UT_Vector4T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
UT_API UT_Vector4T< T > rowVecMult3(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
GLclampf f
Definition: glew.h:3499
void clampZero(T tol=0.00001f)
Definition: UT_Vector4.h:254
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:635
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:718
int64 exint
Definition: SYS_Types.h:120
GLuint buffer
Definition: glew.h:1680
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:134
const GLuint GLenum const void * binary
Definition: glew.h:3502
double fpreal64
Definition: SYS_Types.h:196
static const bool isVectorType
void multiply3(UT_Vector4T< T > &dest, const UT_Matrix4T< S > &mat) const
Definition: UT_Vector4.h:322
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
Definition: VM_SIMD.h:188
SYS_FORCE_INLINE UT_Vector4T(const int64 v[tuple_size])
Definition: UT_Vector4.h:207
UT_API UT_Vector3T< T > cross(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
UT_API UT_Vector4T< T > colVecMult(const UT_Matrix4T< S > &m, const UT_Vector4T< T > &v)
T & operator()(unsigned i)
Definition: UT_Vector4.h:391
T z(void) const
Definition: UT_Vector4.h:388
int int32
Definition: SYS_Types.h:39
T & y(void)
Definition: UT_Vector4.h:385
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector4.h:328
UT_Vector4T< T > & operator*=(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:315
T distance4(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
GLfloat GLfloat p
Definition: glew.h:16321
SYS_FORCE_INLINE UT_Vector4T< T > & operator=(const UT_Vector4T< S > &v)
Definition: UT_Vector4.h:233
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f, T ww=1.0f)
Set the values of the vector components.
Definition: UT_Vector4.h:409
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:509
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector4.h:353
UT_Vector4T< T > SYSbilerp(const UT_Vector4T< T > &u0v0, const UT_Vector4T< T > &u1v0, const UT_Vector4T< T > &u0v1, const UT_Vector4T< T > &u1v1, S u, S v)
Bilinear interpolation.
Definition: UT_Vector4.h:104
UT_FixedVector< T, 4 > FixedVectorType
Definition: UT_Vector4.h:772
void rowVecMult(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:291
SYS_FORCE_INLINE bool isEqual(const UT_FixedVector< S, SIZE, S_INSTANTIATED > &that, S tol=S(SYS_FTOLERANCE)) const
static int entries()
Returns the vector size.
Definition: UT_Vector4.h:455
T w(void) const
Definition: UT_Vector4.h:390
T y(void) const
Definition: UT_Vector4.h:386
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
UT_API UT_Vector4T< T > rowVecMult(const UT_Vector4T< T > &v, const UT_Matrix4T< S > &m)
UT_Vector4T< T > SYSabs(const UT_Vector4T< T > &v)
Definition: UT_Vector4.h:655
void assign(const T *v, int size=tuple_size)
Set the values of the vector components.
Definition: UT_Vector4.h:415
void homogenize(void)
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:425
GLfloat v0
Definition: glew.h:1848
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:76
void multiply3(const UT_Matrix4T< S > &mat)
Definition: UT_Vector4.h:319
T & x(void)
Definition: UT_Vector4.h:383
GLuint64EXT * result
Definition: glew.h:14007
UT_Vector4T< T > SYSbarycentric(const UT_Vector4T< T > &v0, const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2, S u, S v)
Barycentric interpolation.
Definition: UT_Vector4.h:111
SYS_FORCE_INLINE UT_Vector4T(const fpreal32 v[tuple_size])
Definition: UT_Vector4.h:198
T & y(void)
Definition: UT_Vector2.h:294
T distance3d(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:151
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:135
T dot(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
The dot product between two vectors.
Definition: UT_Vector4.h:631
SYS_FORCE_INLINE UT_Vector4T(const int32 v[tuple_size])
Definition: UT_Vector4.h:204
void clampZero3(T tol=0.00001f)
Definition: UT_Vector4.h:262
T & w(void)
Definition: UT_Vector4.h:389
int equalZero3(T tol=0.00001f) const
Definition: UT_Vector4.h:247
T x(void) const
Definition: UT_Vector4.h:384
SYS_FORCE_INLINE UT_Vector4T(T vx, T vy, T vz, T vw=1.0f)
Definition: UT_Vector4.h:191
void rowVecMult3(const UT_Matrix4T< S > &m)
Definition: UT_Vector4.h:304
float fpreal32
Definition: SYS_Types.h:195
GLdouble GLdouble t
Definition: glew.h:1398
GLfloat GLfloat v1
Definition: glew.h:1852
void dehomogenize(void)
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector4.h:431
T distance3(const UT_Vector4T< T > &p1, const UT_Vector4T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector4.h:727
UT_FixedVector< T, 4, true > Base
Definition: UT_Vector4.h:166