HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Vector3.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 3.
10  *
11  * WARNING:
12  * This class should NOT contain any virtual methods, nor should it
13  * define more member data. The size of UT_Vector3 must always be
14  * 12 bytes (3 floats).
15  */
16 
17 #pragma once
18 
19 #ifndef __UT_Vector3_h__
20 #define __UT_Vector3_h__
21 
22 #include "UT_API.h"
23 #include "UT_Assert.h"
24 #include "UT_FixedVector.h"
25 #include "UT_FixedVectorTraits.h"
26 #include "UT_Storage.h"
27 #include "UT_FixedArrayMath.h"
28 #include "UT_VectorTypes.h"
29 #include "UT_Vector2.h"
30 #include <SYS/SYS_Deprecated.h>
31 #include <SYS/SYS_Inline.h>
32 #include <SYS/SYS_Math.h>
33 #include <SYS/SYS_TypeTraits.h>
34 #include <iosfwd>
35 #include <limits>
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, typename S>
53 template <typename T>
54 constexpr UT_Vector3T<T> operator+(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
55 template <typename T>
56 constexpr UT_Vector3T<T> operator-(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
57 template <typename T, typename S>
58 constexpr UT_Vector3T<T> operator+(const UT_Vector3T<T> &v, S scalar) noexcept;
59 template <typename T, typename S>
60 constexpr UT_Vector3T<T> operator-(const UT_Vector3T<T> &v, S scalar) noexcept;
61 template <typename T, typename S>
62 constexpr UT_Vector3T<T> operator*(const UT_Vector3T<T> &v, S scalar) noexcept;
63 template <typename T, typename S>
64 constexpr UT_Vector3T<T> operator/(const UT_Vector3T<T> &v, S scalar) noexcept;
65 template <typename T, typename S>
66 constexpr UT_Vector3T<T> operator+(S scalar, const UT_Vector3T<T> &v) noexcept;
67 template <typename T, typename S>
68 constexpr UT_Vector3T<T> operator-(S scalar, const UT_Vector3T<T> &v) noexcept;
69 template <typename T, typename S>
70 constexpr UT_Vector3T<T> operator*(S scalar, const UT_Vector3T<T> &v) noexcept;
71 template <typename T, typename S>
72 constexpr UT_Vector3T<T> operator/(S scalar, const UT_Vector3T<T> &v) noexcept;
73 
74 /// The dot and cross products between two vectors (see operator*() too)
75 // @{
76 template <typename T>
77 constexpr UT::FA::DotReturn_t< T, 3 > dot( const UT_Vector3T< T >& a, const UT_Vector3T< T >& b ) noexcept;
78 
79 template <typename T>
80 constexpr UT_Vector3T<T> cross(const UT_Vector3T<T> &a, const UT_Vector3T<T> &b) noexcept;
81 // @}
82 
83 /// The angle between two vectors in radians
84 // @{
85 template <typename T>
87 // @}
88 
89 /// Componentwise min and maximum
90 template <typename T>
92 template <typename T>
94 
95 /// Componentwise integer test
96 template <typename T>
97 inline bool SYSisInteger(const UT_Vector3T<T> &v1)
98 { return SYSisInteger(v1.x()) && SYSisInteger(v1.y()) && SYSisInteger(v1.z()); }
99 
100 /// Componentwise linear interpolation
101 template <typename T,typename S>
102 inline UT_Vector3T<T> SYSlerp(const UT_Vector3T<T> &v1, const UT_Vector3T<T> &v2, S t);
103 
104 /// Componentwise inverse linear interpolation
105 template <typename T>
107 
108 /// Bilinear interpolation
109 template <typename T,typename S>
110 inline UT_Vector3T<T> SYSbilerp(const UT_Vector3T<T> &u0v0, const UT_Vector3T<T> &u1v0,
111  const UT_Vector3T<T> &u0v1, const UT_Vector3T<T> &u1v1,
112  S u, S v)
113 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
114 
115 /// Barycentric interpolation
116 template <typename T, typename S>
118  const UT_Vector3T<T> &v1, const UT_Vector3T<T> &v2, S u, S v)
119 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
120 
121 
122 /// Trilinear hat function over kernel widths in s.
123 template <typename T>
124 inline T SYStrihat(const UT_Vector3T<T> &v, const UT_Vector3T<T> &s);
125 
126 /// Gradient of trilinear hat function over kernel widths in s.
127 template <typename T>
129 
130 /// The orthogonal projection of a vector u onto a vector v
131 template <typename T>
132 inline UT_Vector3T<T> project(const UT_Vector3T<T> &u, const UT_Vector3T<T> &v);
133 
134 // TODO: make UT_Vector4 versions of these:
135 
136 /// Compute the distance between two points
137 template <typename T>
138 inline T distance3d(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &p2);
139 /// Compute the distance squared
140 template <typename T>
141 inline T distance2(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &p2);
142 template <typename T>
143 inline T segmentPointDist2(const UT_Vector3T<T> &pos,
144  const UT_Vector3T<T> &pt1,
145  const UT_Vector3T<T> &pt2 );
146 
147 /// Intersect the lines p1 + v1 * t1 and p2 + v2 * t2.
148 /// t1 and t2 are set so that the lines intersect when
149 /// projected to the plane defined by the two lines.
150 /// This function returns a value which indicates how close
151 /// to being parallel the lines are. Closer to zero means
152 /// more parallel. This is done so that the user of this
153 /// function can decide what epsilon they want to use.
154 template <typename T>
155 UT_API double intersectLines(const UT_Vector3T<T> &p1,
156  const UT_Vector3T<T> &v1,
157  const UT_Vector3T<T> &p2,
158  const UT_Vector3T<T> &v2,
159  T &t1, T &t2);
160 
161 /// Returns true if the segments from p0 to p1 and from a to b intersect, and
162 /// t will contain the parametric value of the intersection on the segment a-b.
163 /// Otherwise returns false. Parallel segments will return false. T is
164 /// close to being between 0.0 and 1.0 if this function returns true.
165 /// NOTE: Does not test the actual distance of the projected points
166 /// on each segment, merely that they are parmetrically within the
167 /// segment!
168 template <typename T>
170  const UT_Vector3T<T> &p1,
171  const UT_Vector3T<T> &a,
172  const UT_Vector3T<T> &b, T &t);
173 
174 /// Returns the U coordinates of the closest points on each of the two
175 /// parallel line segments
176 template <typename T>
178  const UT_Vector3T<T> &p1,
179  const UT_Vector3T<T> &a,
180  const UT_Vector3T<T> &b);
181 /// Returns the U coordinates of the closest points on each of the two
182 /// line segments
183 template <typename T>
185  const UT_Vector3T<T> &p1,
186  const UT_Vector3T<T> &a,
187  const UT_Vector3T<T> &b);
188 /// Returns the U coordinate of the point on line segment p0->p1
189 /// that is closest to a.
190 template <typename T>
192  const UT_Vector3T<T> &p0,
193  const UT_Vector3T<T> &p1,
194  const UT_Vector3T<T> &a);
195 
196 /// Returns the squared distance between two line segments: p0-p1 and a-b
197 template <typename T>
198 inline T segmentDistance2(const UT_Vector3T<T> &p0,
199  const UT_Vector3T<T> &p1,
200  const UT_Vector3T<T> &a,
201  const UT_Vector3T<T> &b);
202 /// Returns the distance between two line segments: p0-p1 and a-b
203 template <typename T>
204 inline T segmentDistance(const UT_Vector3T<T> &p0,
205  const UT_Vector3T<T> &p1,
206  const UT_Vector3T<T> &a,
207  const UT_Vector3T<T> &b);
208 
209 /// 3D Vector class.
210 template <typename T>
211 class UT_API UT_Vector3T
212 {
213 public:
214  typedef T value_type;
215  static constexpr int tuple_size = 3;
216 
217  /// Default constructor.
218  /// No data is initialized! Use it for extra speed.
219  SYS_FORCE_INLINE UT_Vector3T() = default;
220 
221  constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T<T> &that) = default;
222  constexpr SYS_FORCE_INLINE UT_Vector3T(UT_Vector3T<T> &&that) = default;
223 
224  constexpr SYS_FORCE_INLINE UT_Vector3T(const T vx, const T vy, const T vz) noexcept :
225  vec{ vx, vy, vz }
226  {}
227 
228  constexpr explicit SYS_FORCE_INLINE UT_Vector3T(const T v) noexcept :
229  UT_Vector3T( v, v, v )
230  {}
231 
232  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept :
233  UT_Vector3T( v[0], v[1], v[2] )
234  {}
235  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal32 v[tuple_size]) noexcept :
236  UT_Vector3T( v[0], v[1], v[2] )
237  {}
238  constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept :
239  UT_Vector3T( v[0], v[1], v[2] )
240  {}
241  constexpr SYS_FORCE_INLINE UT_Vector3T(const int32 v[tuple_size]) noexcept :
242  UT_Vector3T( v[0], v[1], v[2] )
243  {}
244  constexpr SYS_FORCE_INLINE UT_Vector3T(const int64 v[tuple_size]) noexcept :
245  UT_Vector3T( v[0], v[1], v[2] )
246  {}
247 
248  SYS_FORCE_INLINE explicit UT_Vector3T(const UT_Vector2T<T> &v);
249  SYS_FORCE_INLINE explicit UT_Vector3T(const UT_Vector4T<T> &v);
250 
251  /// Our own type of any given value_type.
252  template <typename S>
253  constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T<S>& v) noexcept :
254  UT_Vector3T( v[0], v[1], v[2] )
255  {}
256 
257  /// UT_FixedVector of the same size
258  constexpr explicit SYS_FORCE_INLINE UT_Vector3T(const UT_FixedVector<T,tuple_size>& v) noexcept :
259  UT_Vector3T( v[0], v[1], v[2] )
260  {}
261 
262  constexpr SYS_FORCE_INLINE UT_Vector3T<T> &operator=(const UT_Vector3T<T> &that) = default;
263  constexpr SYS_FORCE_INLINE UT_Vector3T<T> &operator=(UT_Vector3T<T> &&that) = default;
264 
265  template <typename S>
267  { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
268 
269  constexpr SYS_FORCE_INLINE const T& operator[]( exint i ) const noexcept
270  {
271  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
272 
273  return vec[ i ];
274  }
275 
276  constexpr SYS_FORCE_INLINE T& operator[]( exint i ) noexcept
277  {
278  UT_ASSERT_P( ( 0 <= i ) && ( i < tuple_size ) );
279 
280  return vec[ i ];
281  }
282 
283  constexpr SYS_FORCE_INLINE const T* data() const noexcept
284  {
285  return vec;
286  }
287 
288  constexpr SYS_FORCE_INLINE T* data() noexcept
289  {
290  return vec;
291  }
292 
293  constexpr SYS_FORCE_INLINE UT_Vector3T& operator+=( const UT_Vector3T& a ) noexcept
294  {
295  UT::FA::Add< T, tuple_size >{}( vec, a.vec );
296  return *this;
297  }
298 
299  constexpr SYS_FORCE_INLINE UT_Vector3T& operator-=( const UT_Vector3T& a ) noexcept
300  {
301  UT::FA::Subtract< T, tuple_size >{}( vec, a.vec );
302  return *this;
303  }
304 
305  constexpr SYS_FORCE_INLINE UT_Vector3T& operator+=( const T& a ) noexcept
306  {
308  return *this;
309  }
310 
311  constexpr SYS_FORCE_INLINE UT_Vector3T& operator-=( const T& a ) noexcept
312  {
314  return *this;
315  }
316 
317  constexpr SYS_FORCE_INLINE UT_Vector3T& operator*=( const T& a ) noexcept
318  {
320  return *this;
321  }
322 
323  constexpr SYS_FORCE_INLINE UT_Vector3T& operator/=( const T& a ) noexcept
324  {
325  using MF = UT_StorageMathFloat_t< T >;
326  UT::FA::Scale< T, tuple_size, MF >{}( vec, MF{1} / a );
327  return *this;
328  }
329 
330  constexpr SYS_FORCE_INLINE UT_Vector3T& operator*=( const UT_Vector3T& a ) noexcept
331  {
333  return *this;
334  }
335 
336  constexpr SYS_FORCE_INLINE UT_Vector3T& operator/=( const UT_Vector3T& a ) noexcept
337  {
339  return *this;
340  }
341 
342  constexpr SYS_FORCE_INLINE void negate() noexcept
343  {
345  }
346 
347  constexpr SYS_FORCE_INLINE T length2() const noexcept
348  {
349  return UT::FA::Length2< T, tuple_size >{}( vec );
350  }
351 
352  constexpr SYS_FORCE_INLINE T length() const noexcept
353  {
354  return SYSsqrt( length2() );
355  }
356 
357  constexpr SYS_FORCE_INLINE T distance2( const UT_Vector3T& b ) const noexcept
358  {
359  return UT::FA::Distance2< T, tuple_size >{}( vec, b.vec );
360  }
361 
362  constexpr SYS_FORCE_INLINE T distance( const UT_Vector3T& b ) const noexcept
363  {
364  return SYSsqrt( distance2( b ) );
365  }
366 
368  {
369  using MF = UT_StorageMathFloat_t< T >;
372  }
373 
374  constexpr SYS_FORCE_INLINE bool isNan() const noexcept
375  {
376  return UT::FA::AnyOf< T, tuple_size >{}( vec, [ & ]( const T& a ) { return SYSisNan( a ); } );
377  }
378 
379  constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
380  {
381  return UT::FA::AllOf< T, tuple_size >{}( vec, [ & ]( const T& a ) { return SYSisFinite( a ); } );
382  }
383 
384  constexpr SYS_FORCE_INLINE bool isZero() const noexcept
385  {
387  }
388 
389  constexpr SYS_FORCE_INLINE bool equalZero( const T tolerance = SYS_FTOLERANCE ) const noexcept
390  {
391  return UT::FA::MaxNormIsLEQ< T, tuple_size >{}( vec, tolerance );
392  }
393 
394  constexpr SYS_FORCE_INLINE bool isEqual( const UT_Vector3T& b, const T tolerance = SYS_FTOLERANCE ) const noexcept
395  {
396  return UT::FA::MaxMetricIsLEQ< T, tuple_size >{}( vec, b.vec, tolerance );
397  }
398 
399  constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
400  {
401  return UT::FA::Max< T, tuple_size >{}( vec );
402  }
403 
404  constexpr SYS_FORCE_INLINE T minComponent() const noexcept
405  {
406  return UT::FA::Min< T, tuple_size >{}( vec );
407  }
408 
409  constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
410  {
411  return UT::FA::Sum< T, tuple_size >{}( vec ) / T{ tuple_size };
412  }
413 
414  /// Assignment operator that truncates a V4 to a V3.
415  /// TODO: remove this. This should require an explicit UT_Vector3()
416  /// construction, since it's unsafe.
417  SYS_DEPRECATED_HDK_REPLACE(16.0,explicit UT_Vector3 constructor to avoid implicit conversion from UT_Vector4)
418  UT_Vector3T<T> &operator=(const UT_Vector4T<T> &v);
419 
420  constexpr SYS_FORCE_INLINE UT_Vector3T& operator=( const T a ) noexcept;
421 
423  {
424  return UT_Vector3T<T>(-vec[0], -vec[1], -vec[2]);
425  }
426 
427  void clampZero(T tol = T(0.00001f))
428  {
429  if (vec[0] >= -tol && vec[0] <= tol) vec[0] = 0;
430  if (vec[1] >= -tol && vec[1] <= tol) vec[1] = 0;
431  if (vec[2] >= -tol && vec[2] <= tol) vec[2] = 0;
432  }
433 
436  {
437  vec[0] *= v.vec[0];
438  vec[1] *= v.vec[1];
439  vec[2] *= v.vec[2];
440  }
441 
442  /// If you need a multiplication operator that left multiplies the vector
443  /// by a matrix (M * v), use the following colVecMult() functions. If
444  /// you'd rather not use operator*=() for right-multiplications (v * M),
445  /// use the following rowVecMult() functions. The methods that take a 4x4
446  /// matrix first extend this vector to 4D by adding an element equal to 1.0.
447  /// @internal These are implemented in UT_Matrix3.h and UT_Matrix4.h
448  // @{
457  // @}
458 
459 
460  /// This multiply will not extend the vector by adding a fourth element.
461  /// Instead, it converts the Matrix4 to a Matrix3. This means that
462  /// the translate component of the matrix is not applied to the vector
463  /// @internal These are implemented in UT_Matrix4.h
464  // @{
469  // @}
470 
471 
472 
473  /// The *=, multiply, multiply3 and multiplyT routines are provided for
474  /// legacy reasons. They all assume that *this is a row vector. Generally,
475  /// the rowVecMult and colVecMult methods are preferred, since they're
476  /// more explicit about the row vector assumption.
477  // @{
478  template <typename S>
480  template <typename S>
482 
483  template <typename S>
484  SYS_FORCE_INLINE void multiply3(const UT_Matrix4T<S> &mat);
485  // @}
486 
487  /// This multiply will multiply the (row) vector by the transpose of the
488  /// matrix instead of the matrix itself. This is faster than
489  /// transposing the matrix, then multiplying (as well there's potentially
490  /// less storage requirements).
491  // @{
492  template <typename S>
493  SYS_FORCE_INLINE void multiplyT(const UT_Matrix3T<S> &mat);
494  template <typename S>
495  SYS_FORCE_INLINE void multiply3T(const UT_Matrix4T<S> &mat);
496  // @}
497 
498  /// The following methods implement multiplies (row) vector by a matrix,
499  /// however, the resulting vector is specified by the dest parameter
500  /// These operations are safe even if "dest" is the same as "this".
501  // @{
502  template <typename S>
503  SYS_FORCE_INLINE void multiply3(UT_Vector3T<T> &dest,
504  const UT_Matrix4T<S> &mat) const;
505  template <typename S>
506  SYS_FORCE_INLINE void multiplyT(UT_Vector3T<T> &dest,
507  const UT_Matrix3T<S> &mat) const;
508  template <typename S>
509  SYS_FORCE_INLINE void multiply3T(UT_Vector3T<T> &dest,
510  const UT_Matrix4T<S> &mat) const;
511  template <typename S>
513  const UT_Matrix4T<S> &mat) const;
514  template <typename S>
516  const UT_Matrix3T<S> &mat) const;
517  // @}
518 
519  constexpr SYS_FORCE_INLINE T dot(const UT_Vector3T& b) const noexcept
520  {
521  return UT::FA::Dot< T, tuple_size >{}( vec, b.vec );
522  }
523 
524  constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T<T> &v) noexcept
525  {
526  operator=(::cross(*this, v));
527  }
528 
530  {
531  vec[0] += (va.vec[2]+vb.vec[2])*(vb.vec[1]-va.vec[1]);
532  vec[1] += (va.vec[0]+vb.vec[0])*(vb.vec[2]-va.vec[2]);
533  vec[2] += (va.vec[1]+vb.vec[1])*(vb.vec[0]-va.vec[0]);
534  }
535 
536  /// Finds an arbitrary perpendicular to v, and sets this to it.
537  void arbitraryPerp(const UT_Vector3T<T> &v);
538  /// Makes this orthogonal to the given vector. If they are colinear,
539  /// does an arbitrary perp
540  void makeOrthonormal(const UT_Vector3T<T> &v);
541 
542  /// These allow you to find out what indices to use for different axes
543  // @{
544  int findMinAbsAxis() const
545  {
546  T ax = SYSabs(x()), ay = SYSabs(y());
547  if (ax < ay)
548  return (SYSabs(z()) < ax) ? 2 : 0;
549  else
550  return (SYSabs(z()) < ay) ? 2 : 1;
551  }
552  int findMaxAbsAxis() const
553  {
554  T ax = SYSabs(x()), ay = SYSabs(y());
555  if (ax >= ay)
556  return (SYSabs(z()) >= ax) ? 2 : 0;
557  else
558  return (SYSabs(z()) >= ay) ? 2 : 1;
559  }
560  // @}
561 
562  /// Given this vector as the z-axis, get a frame of reference such that the
563  /// X and Y vectors are orthonormal to the vector. This vector should be
564  /// normalized.
566  {
567  if (SYSabs(x()) < 0.6F) Y = UT_Vector3T<T>(1, 0, 0);
568  else if (SYSabs(z()) < 0.6F) Y = UT_Vector3T<T>(0, 1, 0);
569  else Y = UT_Vector3T<T>(0, 0, 1);
570  X = ::cross(Y, *this);
571  X.normalize();
572  Y = ::cross(*this, X);
573  }
574 
575  /// Calculates the orthogonal projection of a vector u on the *this vector
576  UT_Vector3T<T> project(const UT_Vector3T<T> &u) const;
577 
578  /// Create a matrix of projection onto this vector: the matrix transforms
579  /// a vector v into its projection on the direction of (*this) vector,
580  /// ie. dot(*this, v) * this->normalize();
581  /// If we need to be normalized, set norm to non-false.
582  template <typename S>
583  UT_Matrix3T<S> project(bool norm=true);
584 
585  /// Vector p (representing a point in 3-space) and vector v define
586  /// a line. This member returns the projection of "this" onto the
587  /// line (the point on the line that is closest to this point).
588  UT_Vector3T<T> projection(const UT_Vector3T<T> &p,
589  const UT_Vector3T<T> &v) const;
590 
591  /// Projects this onto the line segement [a,b]. The returned point
592  /// will lie between a and b.
593  UT_Vector3T<T> projectOnSegment(const UT_Vector3T<T> &va,
594  const UT_Vector3T<T> &vb) const;
595  /// Projects this onto the line segment [a, b]. The fpreal t is set
596  /// to the parametric position of intersection, a being 0 and b being 1.
597  UT_Vector3T<T> projectOnSegment(const UT_Vector3T<T> &va, const UT_Vector3T<T> &vb,
598  T &t) const;
599 
600  /// Create a matrix of symmetry around this vector: the matrix transforms
601  /// a vector v into its symmetry around (*this), ie. two times the
602  /// projection of v onto (*this) minus v.
603  /// If we need to be normalized, set norm to non-false.
604  UT_Matrix3 symmetry(bool norm=true);
605 
606  /// This method stores in (*this) the intersection between two 3D lines,
607  /// p1+t*v1 and p2+u*v2. If the two lines do not actually intersect, we
608  /// shift the 2nd line along the perpendicular on both lines (along the
609  /// line of min distance) and return the shifted intersection point; this
610  /// point thus lies on the 1st line.
611  /// If we find an intersection point (shifted or not) we return 0; if
612  /// the two lines are parallel we return -1; and if they intersect
613  /// behind our back we return -2. When we return -2 there still is a
614  /// valid intersection point in (*this).
615  int lineIntersect(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1,
616  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2);
617 
618  /// Compute the intersection of vector p2+t*v2 and the line segment between
619  /// points pa and pb. If the two lines do not intersect we shift the
620  /// (p2, v2) line along the line of min distance and return the point
621  /// where it intersects the segment. If we find an intersection point
622  /// along the stretch between pa and pb, we return 0. If the lines are
623  /// parallel we return -1. If they intersect before pa we return -2, and
624  /// if after pb, we return -3. The intersection point is valid with
625  /// return codes 0,-2,-3.
626  int segLineIntersect(const UT_Vector3T<T> &pa, const UT_Vector3T<T> &pb,
627  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2);
628 
629  /// Determines whether or not the points p0, p1 and "this" are collinear.
630  /// If they are t contains the parametric value of where "this" is found
631  /// on the segment from p0 to p1 and returns true. Otherwise returns
632  /// false. If p0 and p1 are equal, t is set to
633  /// std::numeric_limits<T>::max() and true is returned.
634  bool areCollinear(const UT_Vector3T<T> &p0, const UT_Vector3T<T> &p1,
635  T *t = 0, T tol = 1e-5) const;
636 
637  /// Compute (homogeneous) barycentric co-ordinates of this point
638  /// relative to the triangle defined by t0, t1 and t2. (The point is
639  /// projected into the triangle's plane.)
640  UT_Vector3T<T> getBary(const UT_Vector3T<T> &t0, const UT_Vector3T<T> &t1,
641  const UT_Vector3T<T> &t2, bool *degen = NULL) const;
642 
643 
644  /// Compute the signed distance from us to a line.
645  T distance(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1) const;
646  /// Compute the signed distance between two lines.
647  T distance(const UT_Vector3T<T> &p1, const UT_Vector3T<T> &v1,
648  const UT_Vector3T<T> &p2, const UT_Vector3T<T> &v2) const;
649 
650  /// Return the components of the vector. The () operator does NOT check
651  /// for the boundary condition.
652  /// @{
653  constexpr SYS_FORCE_INLINE T &x() noexcept { return vec[0]; }
654  constexpr SYS_FORCE_INLINE T x() const noexcept { return vec[0]; }
655  constexpr SYS_FORCE_INLINE T &y() noexcept { return vec[1]; }
656  constexpr SYS_FORCE_INLINE T y() const noexcept { return vec[1]; }
657  constexpr SYS_FORCE_INLINE T &z() noexcept { return vec[2]; }
658  constexpr SYS_FORCE_INLINE T z() const noexcept { return vec[2]; }
659  constexpr SYS_FORCE_INLINE T &r() noexcept { return vec[0]; }
660  constexpr SYS_FORCE_INLINE T r() const noexcept { return vec[0]; }
661  constexpr SYS_FORCE_INLINE T &g() noexcept { return vec[1]; }
662  constexpr SYS_FORCE_INLINE T g() const noexcept { return vec[1]; }
663  constexpr SYS_FORCE_INLINE T &b() noexcept { return vec[2]; }
664  constexpr SYS_FORCE_INLINE T b() const noexcept { return vec[2]; }
665 
666  constexpr SYS_FORCE_INLINE T &operator()(unsigned i) noexcept
667  {
668  UT_ASSERT_P(i < tuple_size);
669  return vec[i];
670  }
671  constexpr SYS_FORCE_INLINE T operator()(unsigned i) const noexcept
672  {
673  UT_ASSERT_P( i < tuple_size );
674  return vec[i];
675  }
676  /// @}
677 
678  /// Compute a hash
679  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
680 
681  // TODO: eliminate these methods. They're redundant, given good inline
682  // constructors.
683  /// Set the values of the vector components
684  void assign(T xx = 0.0f, T yy = 0.0f, T zz = 0.0f)
685  {
686  vec[0] = xx; vec[1] = yy; vec[2] = zz;
687  }
688  /// Set the values of the vector components
689  void assign(const T *v)
690  {
691  vec[0]=v[0]; vec[1]=v[1]; vec[2]=v[2];
692  }
693 
694  /// Express the point in homogeneous coordinates or vice-versa
695  // @{
696  void homogenize()
697  {
698  vec[0] *= vec[2];
699  vec[1] *= vec[2];
700  }
702  {
703  if (vec[2] != 0)
704  {
705  T denom = 1.0f / vec[2];
706  vec[0] *= denom;
707  vec[1] *= denom;
708  }
709  }
710  // @}
711 
712  /// assuming that "this" is a rotation (in radians, of course), the
713  /// equivalent set of rotations which are closest to the "base" rotation
714  /// are found. The equivalent rotations are the same as the original
715  /// rotations +2*n*PI
716  void roundAngles(const UT_Vector3T<T> &base);
717 
718  /// conversion between degrees and radians
719  // @{
720  void degToRad();
721  void radToDeg();
722  // @}
723 
724  /// It seems that given any rotation matrix and transform order,
725  /// there are two distinct triples of rotations that will result in
726  /// the same overall rotation. This method will find the closest of
727  /// the two after finding the closest using the above method.
728  void roundAngles(const UT_Vector3T<T> &b, const UT_XformOrder &o);
729 
730  /// Return the dual of the vector
731  /// The dual is a matrix which acts like the cross product when
732  /// multiplied by other vectors.
733  /// The following are equivalent:
734  /// a.getDual(A); c = colVecMult(A, b)
735  /// c = cross(a, b)
736  template <typename S>
737  void getDual(UT_Matrix3T<S> &dual) const;
738 
739  /// Protected I/O methods
740  // @{
741  void save(std::ostream &os, bool binary = false) const;
742  bool load(UT_IStream &is);
743  // @}
744 
745  /// @{
746  /// Methods to serialize to a JSON stream. The vector is stored as an
747  /// array of 3 reals.
748  bool save(UT_JSONWriter &w) const;
749  bool save(UT_JSONValue &v) const;
750  bool load(UT_JSONParser &p);
751  /// @}
752 
753  /// @{
754  /// Method to return the angle (in radians) between this and another vector
756  {
757  return ::UTangleBetween(*this, v);
758  }
759  /// @}
760 
761  /// Returns the vector size
762  static int entries() { return tuple_size; }
763 
764  T vec[tuple_size];
765 
766 private:
767 
768  friend constexpr bool isZero( const UT_Vector3T& a ) noexcept
769  {
771  }
772 
773  friend constexpr T length2( const UT_Vector3T& a ) noexcept
774  {
775  return UT::FA::Length2< T, tuple_size >{}( a.vec );
776  }
777 
778  friend constexpr T distance2( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
779  {
780  return UT::FA::Distance2< T, tuple_size >{}( a.vec, b.vec );
781  }
782 
783  friend constexpr bool operator==( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
784  {
785  return UT::FA::AreEqual< T, tuple_size >{}( a.vec, b.vec );
786  }
787 
788  friend constexpr bool operator!=( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
789  {
790  return ! UT::FA::AreEqual< T, tuple_size >{}( a.vec, b.vec );
791  }
792 
793  /// Lexicographic order comparison operators
794  /// @{
795  friend constexpr bool operator<( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
796  {
797  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) < 0;
798  }
799 
800  friend constexpr bool operator<=( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
801  {
802  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) <= 0;
803  }
804 
805  friend constexpr bool operator>( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
806  {
807  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) > 0;
808  }
809 
810  friend constexpr bool operator>=( const UT_Vector3T& a, const UT_Vector3T& b ) noexcept
811  {
812  return UT::FA::TernaryOrder< T, tuple_size >{}( a.vec, b.vec ) >= 0;
813  }
814  /// @}
815 
816  /// I/O friends
817  // @{
818  friend std::ostream &operator<<(std::ostream &os, const UT_Vector3T<T> &v)
819  {
820  v.save(os);
821  return os;
822  }
823  // @}
824 };
825 
826 // Required for constructor
827 #include "UT_Vector2.h"
828 #include "UT_Vector4.h"
829 
830 template <typename T>
832 {
833  vec[0] = v.x();
834  vec[1] = v.y();
835  vec[2] = T(0);
836 }
837 template <typename T>
839 {
840  vec[0] = v.x();
841  vec[1] = v.y();
842  vec[2] = v.z();
843 }
844 
845 template <typename T>
847 {
848  for ( int i = 0; i != tuple_size; ++i )
849  {
850  vec[i] = a;
851  }
852 
853  return *this;
854 }
855 
856 // Free floating functions:
857 template <typename T>
858 constexpr
860 {
861  return UT_Vector3T<T>(a.vec[0]+b.vec[0], a.vec[1]+b.vec[1], a.vec[2]+b.vec[2]);
862 }
863 
864 template <typename T>
865 constexpr
867 {
868  return UT_Vector3T<T>(a.vec[0]-b.vec[0], a.vec[1]-b.vec[1], a.vec[2]-b.vec[2]);
869 }
870 
871 template <typename T, typename S>
872 constexpr
873 UT_Vector3T<T> operator+(const UT_Vector3T<T> &v, S scalar) noexcept
874 {
875  return UT_Vector3T<T>(v.vec[0]+scalar, v.vec[1]+scalar, v.vec[2]+scalar);
876 }
877 
878 template <typename T>
879 constexpr
881 {
882  return UT_Vector3T<T>(v1.vec[0]*v2.vec[0], v1.vec[1]*v2.vec[1], v1.vec[2]*v2.vec[2]);
883 }
884 
885 template <typename T>
886 constexpr
888 {
889  return UT_Vector3T<T>(v1.vec[0]/v2.vec[0], v1.vec[1]/v2.vec[1], v1.vec[2]/v2.vec[2]);
890 }
891 
892 template <typename T, typename S>
893 constexpr
894 UT_Vector3T<T> operator+(S scalar, const UT_Vector3T<T> &v) noexcept
895 {
896  return UT_Vector3T<T>(v.vec[0]+scalar, v.vec[1]+scalar, v.vec[2]+scalar);
897 }
898 
899 template <typename T, typename S>
900 constexpr
901 UT_Vector3T<T> operator-(const UT_Vector3T<T> &v, S scalar) noexcept
902 {
903  return UT_Vector3T<T>(v.vec[0]-scalar, v.vec[1]-scalar, v.vec[2]-scalar);
904 }
905 
906 template <typename T, typename S>
907 constexpr
908 UT_Vector3T<T> operator-(S scalar, const UT_Vector3T<T> &v) noexcept
909 {
910  return UT_Vector3T<T>(scalar-v.vec[0], scalar-v.vec[1], scalar-v.vec[2]);
911 }
912 
913 template <typename T, typename S>
914 constexpr
915 UT_Vector3T<T> operator*(const UT_Vector3T<T> &v, S scalar) noexcept
916 {
917  return UT_Vector3T<T>(v.vec[0]*scalar, v.vec[1]*scalar, v.vec[2]*scalar);
918 }
919 
920 template <typename T, typename S>
921 constexpr
922 UT_Vector3T<T> operator*(S scalar, const UT_Vector3T<T> &v) noexcept
923 {
924  return UT_Vector3T<T>(v.vec[0]*scalar, v.vec[1]*scalar, v.vec[2]*scalar);
925 }
926 
927 template <typename T, typename S>
928 constexpr
929 UT_Vector3T<T> operator/(const UT_Vector3T<T> &v, S scalar) noexcept
930 {
931  //TODO: in C++17, this can be "if constexpr"
932  if ( SYS_IsFloatingPoint_v< T > )
933  {
934  // This has to be T because S may be int for "v = v/2" code
935  // For the same reason we must cast the 1
936  T inv = T(1) / scalar;
937  return UT_Vector3T<T>(v.vec[0]*inv, v.vec[1]*inv, v.vec[2]*inv);
938  }
939  return UT_Vector3T<T>(v.vec[0]/scalar, v.vec[1]/scalar, v.vec[2]/scalar);
940 }
941 
942 template <typename T, typename S>
943 constexpr
944 UT_Vector3T<T> operator/(S scalar, const UT_Vector3T<T> &v) noexcept
945 {
946  return UT_Vector3T<T>(scalar/v.vec[0], scalar/v.vec[1], scalar/v.vec[2]);
947 }
948 
949 template <typename T>
951 {
952  return UT::FA::Dot< T, 3 >{}( a.vec, b.vec );
953 }
954 
955 template <typename T>
956 constexpr
958 {
959  return UT_Vector3T<T>(
960  a.vec[1]*b.vec[2] - a.vec[2]*b.vec[1],
961  a.vec[2]*b.vec[0] - a.vec[0]*b.vec[2],
962  a.vec[0]*b.vec[1] - a.vec[1]*b.vec[0]
963  );
964 }
965 
966 template <typename T>
967 inline
969 {
970  UT_Vector3T<fpreal64> v1crossv2 = cross(v1, v2);
971  fpreal v1dotv2 = dot(v1, v2);
972  return SYSatan2(v1crossv2.length(), v1dotv2);
973 }
974 
975 template <typename T>
976 inline
978 {
979  return UT_Vector3T<T>(SYSabs(v.x()), SYSabs(v.y()), SYSabs(v.z()));
980 }
981 
982 template <typename T>
983 inline
985 {
986  return UT_Vector3T<T>(
987  SYSmin(v1.x(), v2.x()),
988  SYSmin(v1.y(), v2.y()),
989  SYSmin(v1.z(), v2.z())
990  );
991 }
992 
993 template <typename T>
994 inline
996 {
997  return UT_Vector3T<T>(
998  SYSmax(v1.x(), v2.x()),
999  SYSmax(v1.y(), v2.y()),
1000  SYSmax(v1.z(), v2.z())
1001  );
1002 }
1003 
1004 template <typename T,typename S>
1005 inline
1007 {
1008  return UT_Vector3T<T>(
1009  SYSlerp(v1.x(), v2.x(), t),
1010  SYSlerp(v1.y(), v2.y(), t),
1011  SYSlerp(v1.z(), v2.z(), t));
1012 }
1013 
1014 template <typename T>
1015 inline
1017  const UT_Vector3T<T> &v2,
1018  const UT_Vector3T<T> &t)
1019 {
1020  return UT_Vector3T<T>(
1021  SYSlerp(v1.x(), v2.x(), t.x()),
1022  SYSlerp(v1.y(), v2.y(), t.y()),
1023  SYSlerp(v1.z(), v2.z(), t.z()));
1024 }
1025 
1026 template <typename T>
1027 inline
1029  const UT_Vector3T<T> &v1,
1030  const UT_Vector3T<T> &v2)
1031 {
1032  return UT_Vector3T<T>(
1033  SYSinvlerp(a.x(), v1.x(), v2.x()),
1034  SYSinvlerp(a.y(), v1.y(), v2.y()),
1035  SYSinvlerp(a.z(), v1.z(), v2.z()));
1036 }
1037 
1038 template <typename T>
1039 inline
1041  const UT_Vector3T<T> &min,
1042  const UT_Vector3T<T> &max)
1043 {
1044  return UT_Vector3T<T>(
1045  SYSclamp(v.x(), min.x(), max.x()),
1046  SYSclamp(v.y(), min.y(), max.y()),
1047  SYSclamp(v.z(), min.z(), max.z()));
1048 }
1049 
1050 template <typename T>
1051 inline
1053 {
1054  return SYSequalZero(v.x()) && SYSequalZero(v.y()) && SYSequalZero(v.z());
1055 }
1056 
1057 template <typename T>
1058 inline
1060 {
1061  return SYSisFinite(v.x()) && SYSisFinite(v.y()) && SYSisFinite(v.z());
1062 }
1063 
1064 template <typename T>
1065 inline
1067 {
1068  return UT_Vector3T<T>(SYSrecip(v[0]), SYSrecip(v[1]), SYSrecip(v[2]));
1069 }
1070 
1071 template <typename T>
1072 inline
1074 {
1075  return SYShat(v.x(), s.x()) * SYShat(v.y(), s.y()) * SYShat(v.z(), s.z());
1076 }
1077 
1078 template <typename T>
1079 inline
1081 {
1082  const T xhat = SYShat(v.x(), s.x());
1083  const T yhat = SYShat(v.y(), s.y());
1084  const T zhat = SYShat(v.z(), s.z());
1085  return UT_Vector3T<T>(SYSdhat(v.x(), s.x()) * yhat * zhat,
1086  xhat * SYSdhat(v.y(), s.y()) * zhat,
1087  xhat * yhat * SYSdhat(v.z(), s.z()));
1088 }
1089 
1090 template <typename T>
1091 inline
1093 {
1094  return dot(u, v) / v.length2() * v;
1095 }
1096 
1097 template <typename T>
1098 inline
1100 {
1101  return (v1 - v2).length();
1102 }
1103 template <typename T>
1104 inline
1106 {
1107  return (v1 - v2).length2();
1108 }
1109 
1110 // calculate distance squared of pos to the line segment defined by pt1 to pt2
1111 template <typename T>
1112 inline
1114  const UT_Vector3T<T> &pt1, const UT_Vector3T<T> &pt2 )
1115 {
1116  UT_Vector3T<T> vec;
1117  T proj_t;
1118  T veclen2;
1119 
1120  vec = pt2 - pt1;
1121  proj_t = vec.dot( pos - pt1 );
1122  veclen2 = vec.length2();
1123 
1124  if( proj_t <= (T)0.0 )
1125  {
1126  // in bottom cap region, calculate distance from pt1
1127  vec = pos - pt1;
1128  }
1129  else if( proj_t >= veclen2 )
1130  {
1131  // in top cap region, calculate distance from pt2
1132  vec = pos - pt2;
1133  }
1134  else
1135  {
1136  // middle region, calculate distance from projected pt
1137  proj_t /= veclen2;
1138  vec = (pt1 + (proj_t * vec)) - pos;
1139  }
1140 
1141  return dot(vec, vec);
1142 }
1143 
1144 // TODO: review the effiency of the following routine, there is a faster
1145 // way to get just the distance.
1146 template <typename T>
1147 inline
1149  const UT_Vector3T<T> &q0, const UT_Vector3T<T> &q1)
1150 {
1151  UT_Vector2 t = segmentClosest(p0, p1, q0, q1);
1152  UT_Vector3 a = p0 + (p1 - p0) * t[0];
1153  UT_Vector3 b = q0 + (q1 - q0) * t[1];
1154  return distance2(a, b);
1155 }
1156 
1157 template <typename T>
1158 inline
1160  const UT_Vector3T<T> &q0, const UT_Vector3T<T> &q1)
1161 {
1162  return SYSsqrt(segmentDistance2(p0, p1, q0, q1));
1163 }
1164 
1165 /// Given a 3D position, input, and a 3D parallelpiped with corner p0 and
1166 /// directions du, dv, and dw, finds the 0 or 1 locations in the parameter
1167 /// space of that parallelpiped that correspond with the input position.
1168 /// Only a parameter location approximately between 0 and 1
1169 /// is accepted. The return value is the number of accepted parameter locations,
1170 /// i.e. 0 or 1.
1171 template <typename T>
1173  const UT_Vector3T<T> &p0,
1174  const UT_Vector3T<T> &du, const UT_Vector3T<T> &dv, const UT_Vector3T<T> &dw,
1175  UT_Vector3T<T> &output)
1176 {
1177  const UT_Vector3T<T> orig = input - p0;
1178 
1179  const UT_Matrix3T<T> matrix(
1180  du.x(), dv.x(), dw.x(),
1181  du.y(), dv.y(), dw.y(),
1182  du.z(), dv.z(), dw.z()
1183  );
1184 
1185  bool failed = matrix.solve(orig.x(), orig.y(), orig.z(), output);
1186  return !failed &&
1187  SYSisGreaterOrEqual(output.x(), 0) && SYSisLessOrEqual(output.x(), 1) &&
1188  SYSisGreaterOrEqual(output.y(), 0) && SYSisLessOrEqual(output.y(), 1) &&
1189  SYSisGreaterOrEqual(output.z(), 0) && SYSisLessOrEqual(output.z(), 1);
1190 }
1191 
1192 template <typename T>
1193 inline size_t hash_value(const UT_Vector3T<T> &val)
1194 {
1195  return val.hash();
1196 }
1197 
1198 // Overload for custom formatting of UT_Vector3T<T> with UTformat.
1199 template<typename T>
1200 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector3T<T> &v);
1201 
1202 template< typename T, exint D >
1203 class UT_FixedVector;
1204 
1205 template<typename T>
1207 {
1209  typedef T DataType;
1210  static const exint TupleSize = 3;
1211  static const bool isVectorType = true;
1212 };
1213 
1214 // UT_Vector3T in the role of a fixed array-like type.
1215 
1216 template< typename T >
1218 
1219 template< typename T >
1221 
1222 template< typename T >
1223 struct SYS_FixedArraySizeNoCVRef< UT_Vector3T< T > > : std::integral_constant< std::size_t, 3 > {};
1224 
1225 // UT_Vector3TFromFixed<T> is a function object that
1226 // creates a UT_Vector3T<T> from a fixed array-like type TS,
1227 // examples of which include T[3], UT_FixedVector<T,3> and UT_FixedArray<T,3> (AKA std::array<T,3>)
1228 template <typename T>
1230 {
1231  template< typename TS >
1232  constexpr SYS_FORCE_INLINE UT_Vector3T<T> operator()(const TS& as) const noexcept
1233  {
1234  SYS_STATIC_ASSERT( SYS_IsFixedArrayOf_v< TS, T, 3 > );
1235 
1236  return UT_Vector3T<T>{as[0], as[1], as[2]};
1237  }
1238 };
1239 
1240 // Convert a fixed array-like type TS into a UT_Vector3T< T >.
1241 // This allows conversion to UT_Vector3T without fixing T.
1242 // Instead, the element type of TS determines the type T.
1243 template< typename TS >
1245 UTmakeVector3T( const TS& as ) noexcept
1246 {
1248 
1249  return UT_Vector3TFromFixed< T >{}( as );
1250 }
1251 
1252 // UT_FromFixed<V> creates a V from a flat, fixed array-like representation
1253 
1254 // Primary
1255 template <typename V >
1256 struct UT_FromFixed;
1257 
1258 // Partial specialization for UT_Vector3T
1259 template <typename T>
1261 
1262 // Relocation traits for UT_Vector3T are defined in UT_VectorTypes.h
1263 
1264 #endif
UT_Vector3T< T > rowVecMult(const UT_Vector3T< T > &v, const UT_Matrix3T< S > &m)
Definition: UT_Matrix3.h:1500
UT_Vector3T< T > SYSlerp(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S t)
Componentwise linear interpolation.
Definition: UT_Vector3.h:1006
constexpr SYS_FORCE_INLINE T length2() const noexcept
Definition: UT_Vector3.h:347
constexpr SYS_FORCE_INLINE T operator()(unsigned i) const noexcept
Definition: UT_Vector3.h:671
UT_API double intersectLines(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &p2, const UT_Vector3T< T > &v2, T &t1, T &t2)
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:575
constexpr UT_Vector3T< T > cross(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
Definition: UT_Vector3.h:957
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
constexpr SYS_FORCE_INLINE UT_Vector3T(const int32 v[tuple_size]) noexcept
Definition: UT_Vector3.h:241
constexpr SYS_FORCE_INLINE T dot(const UT_Vector3T &b) const noexcept
Definition: UT_Vector3.h:519
typename UT_StorageNum< T >::MathFloat UT_StorageMathFloat_t
Definition: UT_Storage.h:176
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal32 v[tuple_size]) noexcept
Definition: UT_Vector3.h:235
#define SYS_STATIC_ASSERT(expr)
int findMaxAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector3.h:552
friend constexpr bool isZero(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:768
UT_Vector3T< T > SYSrecip(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1066
int int32
Definition: SYS_Types.h:39
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator()(const TS &as) const noexcept
Definition: UT_Vector3.h:1232
UT_Vector3T< T > SYSbilerp(const UT_Vector3T< T > &u0v0, const UT_Vector3T< T > &u1v0, const UT_Vector3T< T > &u0v1, const UT_Vector3T< T > &u1v1, S u, S v)
Bilinear interpolation.
Definition: UT_Vector3.h:110
T distance2(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance squared.
Definition: UT_Vector3.h:1105
T distance3d(const UT_Vector3T< T > &p1, const UT_Vector3T< T > &p2)
Compute the distance between two points.
Definition: UT_Vector3.h:1099
constexpr SYS_FORCE_INLINE T y() const noexcept
Definition: UT_Vector3.h:656
int UTinverseTrilerpFlat(const UT_Vector3T< T > &input, const UT_Vector3T< T > &p0, const UT_Vector3T< T > &du, const UT_Vector3T< T > &dv, const UT_Vector3T< T > &dw, UT_Vector3T< T > &output)
Definition: UT_Vector3.h:1172
UT_Vector3T< T > SYSabs(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:977
constexpr SYS_FORCE_INLINE UT_Vector3T(const int64 v[tuple_size]) noexcept
Definition: UT_Vector3.h:244
Transformation order of scales, rotates, and translates.
Definition: UT_XformOrder.h:23
void assign(const T *v)
Set the values of the vector components.
Definition: UT_Vector3.h:689
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:591
T vec[tuple_size]
Definition: UT_Vector3.h:764
#define SYS_DEPRECATED_HDK_REPLACE(__V__, __R__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
GLenum GLenum GLenum input
Definition: glew.h:14162
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
fpreal64 UTangleBetween(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
The angle between two vectors in radians.
Definition: UT_Vector3.h:968
friend constexpr T distance2(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Compute the distance squared.
Definition: UT_Vector3.h:778
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:657
int64 exint
Definition: SYS_Types.h:125
UT_Vector3T< T > SYSmin(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise min and maximum.
Definition: UT_Vector3.h:984
constexpr bool SYSisNan(const F f)
Definition: SYS_Math.h:178
T segmentDistance(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the distance between two line segments: p0-p1 and a-b.
Definition: UT_Vector3.h:1159
constexpr SYS_FORCE_INLINE UT_Vector3T & operator-=(const T &a) noexcept
Definition: UT_Vector3.h:311
unsigned hash() const
Compute a hash.
Definition: UT_Vector3.h:679
constexpr SYS_FORCE_INLINE T b() const noexcept
Definition: UT_Vector3.h:664
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
#define UT_API
Definition: UT_API.h:14
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Definition: glew.h:12900
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
constexpr SYS_FORCE_INLINE T length() const noexcept
Definition: UT_Vector3.h:352
static const exint TupleSize
UT_Vector3T< T > SYStrihatgrad(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Gradient of trilinear hat function over kernel widths in s.
Definition: UT_Vector3.h:1080
T SYStrihat(const UT_Vector3T< T > &v, const UT_Vector3T< T > &s)
Trilinear hat function over kernel widths in s.
Definition: UT_Vector3.h:1073
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:172
constexpr SYS_FORCE_INLINE UT_Vector3T & operator*=(const T &a) noexcept
Definition: UT_Vector3.h:317
2D Vector class.
Definition: UT_Vector2.h:157
float fpreal32
Definition: SYS_Types.h:200
GLdouble GLdouble t
Definition: glew.h:1403
constexpr SYS_FORCE_INLINE UT_Vector3T(const T v) noexcept
Definition: UT_Vector3.h:228
constexpr SYS_FORCE_INLINE T & operator()(unsigned i) noexcept
Definition: UT_Vector3.h:666
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector3.h:283
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal16 v[tuple_size]) noexcept
Definition: UT_Vector3.h:232
friend constexpr bool operator>(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:805
constexpr SYS_FORCE_INLINE T avgComponent() const noexcept
Definition: UT_Vector3.h:409
T segmentPointDist2(const UT_Vector3T< T > &pos, const UT_Vector3T< T > &pt1, const UT_Vector3T< T > &pt2)
Definition: UT_Vector3.h:1113
GLint GLenum GLint x
Definition: glcorearb.h:409
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
double fpreal64
Definition: SYS_Types.h:201
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_FixedVector< T, tuple_size > &v) noexcept
UT_FixedVector of the same size.
Definition: UT_Vector3.h:258
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
Definition: UT_Vector3.h:404
void getFrameOfReference(UT_Vector3T< T > &X, UT_Vector3T< T > &Y) const
Definition: UT_Vector3.h:565
constexpr SYS_FORCE_INLINE void cross(const UT_Vector3T< T > &v) noexcept
Definition: UT_Vector3.h:524
constexpr SYS_FORCE_INLINE T & operator[](exint i) noexcept
Definition: UT_Vector3.h:276
Definition: core.h:760
constexpr SYS_FORCE_INLINE UT_Vector3T(const UT_Vector3T< S > &v) noexcept
Our own type of any given value_type.
Definition: UT_Vector3.h:253
constexpr UT_Vector3T< T > operator/(const UT_Vector3T< T > &v, S scalar) noexcept
Definition: UT_Vector3.h:929
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:601
UT_API UT_Vector2T< T > segmentClosest(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GLsizei GLsizei GLfloat distance
Definition: glew.h:13923
void clampZero(T tol=T(0.00001f))
Definition: UT_Vector3.h:427
typename UT_StorageAtLeast32Bit< T0, T1 >::type UT_StorageAtLeast32Bit_t
Definition: UT_Storage.h:265
constexpr SYS_FORCE_INLINE void negate() noexcept
Definition: UT_Vector3.h:342
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:152
constexpr SYS_FORCE_INLINE const T & operator[](exint i) const noexcept
Definition: UT_Vector3.h:269
friend constexpr bool operator<(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:795
constexpr SYS_FORCE_INLINE UT_Vector3T & operator-=(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:299
const GLdouble * v
Definition: glcorearb.h:837
size_t hash_value(const UT_Vector3T< T > &val)
Definition: UT_Vector3.h:1193
constexpr SYS_FORCE_INLINE T x() const noexcept
Definition: UT_Vector3.h:654
static const bool isVectorType
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:1040
typename Dot< T, SIZE >::R DotReturn_t
static int entries()
Returns the vector size.
Definition: UT_Vector3.h:762
constexpr SYS_FORCE_INLINE UT_Vector3T & operator+=(const T &a) noexcept
Definition: UT_Vector3.h:305
constexpr SYS_FORCE_INLINE UT_Vector3T(const T vx, const T vy, const T vz) noexcept
Definition: UT_Vector3.h:224
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
UT_Vector3T< T > SYSmax(const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Definition: UT_Vector3.h:995
constexpr SYS_FORCE_INLINE T & r() noexcept
Definition: UT_Vector3.h:659
UT_Vector3T< T > SYSbarycentric(const UT_Vector3T< T > &v0, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2, S u, S v)
Barycentric interpolation.
Definition: UT_Vector3.h:117
class UT_API UT_Vector3T
long long int64
Definition: SYS_Types.h:116
UT_API UT_Vector2T< T > segmentClosestParallel(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
friend constexpr bool operator==(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:783
GLfloat GLfloat p
Definition: glew.h:16656
T segmentDistance2(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b)
Returns the squared distance between two line segments: p0-p1 and a-b.
Definition: UT_Vector3.h:1148
constexpr SYS_FORCE_INLINE T & g() noexcept
Definition: UT_Vector3.h:661
UT_Vector3T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix4.h:1906
constexpr SYS_FORCE_INLINE UT_Vector3T & operator*=(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:330
GLfloat v0
Definition: glcorearb.h:816
constexpr SYS_FORCE_INLINE UT_Vector3T(const fpreal64 v[tuple_size]) noexcept
Definition: UT_Vector3.h:238
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:4660
constexpr SYS_FORCE_INLINE UT_Vector3T & operator/=(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:336
friend constexpr T length2(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:773
constexpr UT::FA::DotReturn_t< T, 3 > dot(const UT_Vector3T< T > &a, const UT_Vector3T< T > &b) noexcept
The dot and cross products between two vectors (see operator*() too)
Definition: UT_Vector3.h:950
constexpr SYS_FORCE_INLINE bool isNan() const noexcept
Definition: UT_Vector3.h:374
GLuint GLenum matrix
Definition: glew.h:15055
constexpr SYS_FORCE_INLINE T g() const noexcept
Definition: UT_Vector3.h:662
void dehomogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector3.h:701
bool SYSisFinite(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1059
bool SYSequalZero(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1052
GLboolean * data
Definition: glcorearb.h:131
void assign(T xx=0.0f, T yy=0.0f, T zz=0.0f)
Set the values of the vector components.
Definition: UT_Vector3.h:684
SYS_FORCE_INLINE UT_Vector3T< T > & operator=(const UT_Vector3T< S > &v)
Definition: UT_Vector3.h:266
void homogenize()
Express the point in homogeneous coordinates or vice-versa.
Definition: UT_Vector3.h:696
GLuint GLfloat * val
Definition: glcorearb.h:1608
UT_Vector3T< T > SYSinvlerp(const UT_Vector3T< T > &a, const UT_Vector3T< T > &v1, const UT_Vector3T< T > &v2)
Componentwise inverse linear interpolation.
Definition: UT_Vector3.h:1028
constexpr SYS_FORCE_INLINE T r() const noexcept
Definition: UT_Vector3.h:660
bool SYSisInteger(const UT_Vector3T< T > &v1)
Componentwise integer test.
Definition: UT_Vector3.h:97
UT_API bool intersectSegments(const UT_Vector3T< T > &p0, const UT_Vector3T< T > &p1, const UT_Vector3T< T > &a, const UT_Vector3T< T > &b, T &t)
constexpr SYS_FORCE_INLINE UT_Vector3T< T > operator-() const noexcept
Definition: UT_Vector3.h:422
constexpr SYS_FORCE_INLINE T distance2(const UT_Vector3T &b) const noexcept
Definition: UT_Vector3.h:357
UT_Vector3T< T > rowVecMult3(const UT_Vector3T< T > &v, const UT_Matrix4T< S > &m)
Definition: UT_Matrix4.h:1884
constexpr UT_Vector3T< SYS_FixedArrayElement_t< TS > > UTmakeVector3T(const TS &as) noexcept
Definition: UT_Vector3.h:1245
constexpr SYS_FORCE_INLINE T & b() noexcept
Definition: UT_Vector3.h:663
fpreal64 fpreal
Definition: SYS_Types.h:277
constexpr SYS_FORCE_INLINE UT_Vector3T & operator+=(const UT_Vector3T &a) noexcept
Definition: UT_Vector3.h:293
UT_FixedVector< T, 3 > FixedVectorType
Definition: UT_Vector3.h:1208
constexpr SYS_FORCE_INLINE UT_Vector3T< T > & operator=(const UT_Vector3T< T > &that)=default
constexpr SYS_FORCE_INLINE bool isEqual(const UT_Vector3T &b, const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector3.h:394
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition: glew.h:12900
constexpr SYS_FORCE_INLINE bool isZero() const noexcept
Definition: UT_Vector3.h:384
UT_Vector3T< T > colVecMult(const UT_Matrix3T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix3.h:1518
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const GLdouble * m
Definition: glew.h:9166
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:77
GLfloat f
Definition: glcorearb.h:1926
constexpr SYS_FORCE_INLINE bool isFinite() const noexcept
Definition: UT_Vector3.h:379
constexpr SYS_FORCE_INLINE T distance(const UT_Vector3T &b) const noexcept
Definition: UT_Vector3.h:362
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
constexpr SYS_FORCE_INLINE UT_Vector3T & operator/=(const T &a) noexcept
Definition: UT_Vector3.h:323
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
Definition: UT_Vector3.h:367
SYS_FORCE_INLINE UT_Vector3T()=default
friend constexpr bool operator<=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:800
friend constexpr bool operator>=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:810
#define const
Definition: zconf.h:214
GLfloat GLfloat v1
Definition: glcorearb.h:817
UT_Vector3T< T > project(const UT_Vector3T< T > &u, const UT_Vector3T< T > &v)
The orthogonal projection of a vector u onto a vector v.
Definition: UT_Vector3.h:1092
constexpr SYS_FORCE_INLINE T z() const noexcept
Definition: UT_Vector3.h:658
SYS_FORCE_INLINE void normal(const UT_Vector3T< T > &va, const UT_Vector3T< T > &vb)
Definition: UT_Vector3.h:529
constexpr SYS_FORCE_INLINE T * data() noexcept
Definition: UT_Vector3.h:288
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:655
SYS_FORCE_INLINE void multiplyComponents(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:435
constexpr SYS_FORCE_INLINE T maxComponent() const noexcept
Definition: UT_Vector3.h:399
constexpr SYS_FORCE_INLINE bool equalZero(const T tolerance=SYS_FTOLERANCE) const noexcept
Definition: UT_Vector3.h:389
GLdouble s
Definition: glew.h:1395
friend constexpr bool operator!=(const UT_Vector3T &a, const UT_Vector3T &b) noexcept
Definition: UT_Vector3.h:788
uint64_t multiply(uint64_t lhs, uint64_t rhs)
Definition: format-inl.h:258
GLint y
Definition: glcorearb.h:103
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Vector3T< T > &v)
fpreal64 angleTo(const UT_Vector3T< T > &v) const
Definition: UT_Vector3.h:755
int findMinAbsAxis() const
These allow you to find out what indices to use for different axes.
Definition: UT_Vector3.h:544
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:653