HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Matrix2.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  */
7 
8 #pragma once
9 
10 #ifndef __UT_Matrix2_h__
11 #define __UT_Matrix2_h__
12 
13 #include "UT_API.h"
14 #include "UT_Assert.h"
15 #include "UT_FixedVectorTraits.h"
16 #include "UT_VectorTypes.h"
17 
18 #include <SYS/SYS_Types.h>
19 #include <SYS/SYS_Math.h>
20 #include <SYS/SYS_StaticAssert.h>
21 #include <iosfwd>
22 
23 class UT_IStream;
24 class UT_JSONWriter;
25 class UT_JSONValue;
26 class UT_JSONParser;
27 
28 // Free floating operators that return a UT_Matrix2T<T> object.
29 template <typename T> UT_API
31 template <typename T, typename S> UT_API
33 template <typename T, typename S> static inline
35 template <typename T> UT_API
37 template <typename T> static inline
39 
40 template <typename T> UT_API
42 template <typename T, typename S> UT_API
44 template <typename T, typename S> UT_API
46 template <typename T> static inline
48 template <typename T> UT_API
50 
51 template <typename T> UT_API
53 template <typename T,typename S> UT_API
55 template <typename T,typename S> static inline
57 
58 template <typename T> static inline
60 template <typename T> UT_API
62 
63 template <typename T>
64 inline UT_Matrix2T<T> SYSmin (const UT_Matrix2T<T> &v1, const UT_Matrix2T<T> &v2);
65 template <typename T>
66 inline UT_Matrix2T<T> SYSmax (const UT_Matrix2T<T> &v1, const UT_Matrix2T<T> &v2);
67 template <typename T,typename S>
68 inline UT_Matrix2T<T> SYSlerp(const UT_Matrix2T<T> &v1, const UT_Matrix2T<T> &v2, S t);
69 
70 /// Bilinear interpolation
71 template <typename T,typename S>
72 inline UT_Matrix2T<T> SYSbilerp(const UT_Matrix2T<T> &u0v0, const UT_Matrix2T<T> &u1v0,
73  const UT_Matrix2T<T> &u0v1, const UT_Matrix2T<T> &u1v1,
74  S u, S v)
75 { return SYSlerp(SYSlerp(u0v0, u0v1, v), SYSlerp(u1v0, u1v1, v), u); }
76 
77 /// Barycentric interpolation
78 template <typename T, typename S>
80  const UT_Matrix2T<T> &v1, const UT_Matrix2T<T> &v2, S u, S v)
81 { return v0 * (1 - u - v) + v1 * u + v2 *v; }
82 
83 
84 /// This class implements a 2x2 matrix in row-major order.
85 ///
86 /// Most of Houdini operates with row vectors that are left-multiplied with
87 /// matrices. e.g., z = v * M
88 template <typename T>
90 {
91 public:
92 
93  typedef T value_type;
94  static constexpr int tuple_size = 4;
95 
96  /// Construct uninitialized matrix.
97  SYS_FORCE_INLINE UT_Matrix2T() = default;
98 
99  /// Default copy constructor
100  constexpr UT_Matrix2T(const UT_Matrix2T &) = default;
101 
102  /// Default move constructor
103  constexpr UT_Matrix2T(UT_Matrix2T &&) = default;
104 
105  /// Construct identity matrix, multipled by scalar.
106  explicit constexpr UT_Matrix2T(T val) noexcept
107  : matx{{val,T(0)},{T(0),val}}
108  {
109  SYS_STATIC_ASSERT(sizeof(UT_Matrix2T<T>) == tuple_size * sizeof(T));
110  }
111  /// Construct a deep copy of the input row-major data.
112  /// @{
113  explicit constexpr UT_Matrix2T(const fpreal32 m[2][2]) noexcept
114  : matx{{T(m[0][0]),T(m[0][1])},{T(m[1][0]),T(m[1][1])}}
115  {}
116  explicit constexpr UT_Matrix2T(const fpreal64 m[2][2]) noexcept
117  : matx{{T(m[0][0]),T(m[0][1])},{T(m[1][0]),T(m[1][1])}}
118  {}
119  /// @}
120 
121  /// This constructor is for convenience.
122  constexpr UT_Matrix2T(T val00, T val01, T val10, T val11) noexcept
123  : matx{{val00,val01},{val10,val11}}
124  {}
125 
126  /// Base type conversion constructor
127  template <typename S>
128  UT_Matrix2T(const UT_Matrix2T<S> &m) noexcept
129  : matx{{T(m(0,0)),T(m(0,1))},{T(m(1,0)),T(m(1,1))}}
130  {}
131 
132  /// Conversion to a 2x2 from a 3x3 matrix by ignoring the
133  /// last row and last column.
134  template <typename S>
135  explicit UT_Matrix2T(const UT_Matrix3T<S> &m) noexcept
136  : matx{{T(m(0,0)),T(m(0,1))},{T(m(1,0)),T(m(1,1))}}
137  {}
138 
139  /// Default copy assignment operator
140  UT_Matrix2T<T> &operator=(const UT_Matrix2T<T> &m) = default;
141 
142  /// Default move assignment operator
143  UT_Matrix2T<T> &operator=(UT_Matrix2T<T> &&m) = default;
144 
145  /// Conversion operator that returns a 2x2 from a 3x3 matrix by ignoring the
146  /// last row and last column.
147  template <typename S>
148  UT_Matrix2T<T> &operator=(const UT_Matrix3T<S> &m);
149 
151  {
152  return UT_Matrix2T<T>(
153  -matx[0][0], -matx[0][1],
154  -matx[1][0], -matx[1][1]);
155  }
156 
158  {
159  matx[0][0]+=m.matx[0][0]; matx[0][1]+=m.matx[0][1];
160  matx[1][0]+=m.matx[1][0]; matx[1][1]+=m.matx[1][1];
161  return *this;
162  }
164  {
165  matx[0][0]-=m.matx[0][0]; matx[0][1]-=m.matx[0][1];
166  matx[1][0]-=m.matx[1][0]; matx[1][1]-=m.matx[1][1];
167  return *this;
168  }
170 
171  constexpr bool operator==(const UT_Matrix2T<T> &m) const noexcept
172  {
173  return (&m == this) || (
174  matx[0][0]==m(0,0) && matx[0][1]==m(0,1) &&
175  matx[1][0]==m(1,0) && matx[1][1]==m(1,1) );
176  }
177  constexpr bool operator!=(const UT_Matrix2T<T> &m) const noexcept
178  {
179  return !(*this == m);
180  }
181 
183  {
184  matx[0][0] = val; matx[0][1] = 0;
185  matx[1][0] = 0; matx[1][1] = val;
186  return *this;
187  }
189  {
190  matx[0][0]+=scalar; matx[0][1]+=scalar;
191  matx[1][0]+=scalar; matx[1][1]+=scalar;
192  return *this;
193  }
195  {
196  return operator+=(-scalar);
197  }
199  {
200  matx[0][0]*=scalar; matx[0][1]*=scalar;
201  matx[1][0]*=scalar; matx[1][1]*=scalar;
202  return *this;
203  }
205  {
206  return operator*=( T(1)/scalar );
207  }
208 
209  // Vector2 operators:
210  template <typename S>
211  inline
212  UT_Matrix2T<T> &operator=(const UT_Vector2T<S> &vec);
213  template <typename S>
214  inline
216  template <typename S>
217  inline
219 
220  constexpr T determinant() const noexcept
221  {
222  return matx[0][0]*matx[1][1] - matx[0][1]*matx[1][0];
223  }
224  constexpr T trace() const noexcept
225  { return matx[0][0] + matx[1][1]; }
226 
227  /// Returns eigenvalues of this matrix
228  template <typename S>
229  int eigenvalues(UT_Vector2T<S> &r, UT_Vector2T<S> &i) const;
230 
231  /// Invert this matrix and return 0 if OK, 1 if singular.
232  /// If singular, the matrix will be unchanged.
233  int invert()
234  {
235  // NOTE: The other invert function should work on *this,
236  // since it does all reading before all writing.
237  return invert(*this);
238  }
239 
240  /// Invert the matrix and return 0 if OK, 1 if singular.
241  /// Puts the inverted matrix in m, and leaves this matrix unchanged.
242  /// If singular, the matrix will be unchanged.
243  int invert(UT_Matrix2T<T> &m) const
244  {
245  // Effectively rescale the matrix for the determinant check,
246  // because if the whole matrix is close to zero, having a
247  // small determinant may be fine.
248  T scale2 = SYSmax(matx[0][0]*matx[0][0],
249  matx[0][1]*matx[0][1],
250  matx[1][0]*matx[1][0],
251  matx[1][1]*matx[1][1]);
252  T det = determinant();
253  if (!SYSequalZero(det, tolerance()*scale2))
254  {
255  // Finish all reading before writing to m,
256  // so that invert() can call invert(*this)
257  m = UT_Matrix2T<T>( matx[1][1],-matx[0][1],
258  -matx[1][0], matx[0][0]);
259  m *= (T(1)/det);
260 
261  return 0;
262  }
263  return 1;
264  }
265 
266  /// Returns the tolerance of our class.
267  T tolerance() const;
268 
269  // Solve a 2x2 system of equations Ax=b, where A is this matrix, b is
270  // given and x is unknown. The method returns 0 if the determinant is not
271  // 0, and 1 otherwise.
272  template <typename S>
273  int solve(const UT_Vector2T<S> &b, UT_Vector2T<S> &x) const
274  {
275  // Effectively rescale the matrix for the determinant check,
276  // because if the whole matrix is close to zero, having a
277  // small determinant may be fine.
278  T scale2 = SYSmax(matx[0][0]*matx[0][0],
279  matx[0][1]*matx[0][1],
280  matx[1][0]*matx[1][0],
281  matx[1][1]*matx[1][1]);
282  T det = determinant();
283  if (!SYSequalZero(det, tolerance()*scale2))
284  {
285  T recipdet = T(1)/det;
286  x = UT_Vector2T<S>(
287  recipdet * (matx[1][1]*b.x() - matx[0][1]*b.y()),
288  recipdet * (matx[0][0]*b.y() - matx[1][0]*b.x()));
289  return 0;
290  }
291  return 1;
292  }
293 
294  // Solve a 2x2 system of equations xA=b, where A is this matrix, b is
295  // given and x is unknown. The method returns 0 if the determinant is not
296  // 0, and 1 otherwise.
297  template <typename S>
299  {
300  // Effectively rescale the matrix for the determinant check,
301  // because if the whole matrix is close to zero, having a
302  // small determinant may be fine.
303  T scale2 = SYSmax(matx[0][0]*matx[0][0],
304  matx[0][1]*matx[0][1],
305  matx[1][0]*matx[1][0],
306  matx[1][1]*matx[1][1]);
307  T det = determinant();
308  if (!SYSequalZero(det, tolerance()*scale2))
309  {
310  T recipdet = T(1)/det;
311  x = UT_Vector2T<S>(
312  recipdet * (matx[1][1]*b.x() - matx[1][0]*b.y()),
313  recipdet * (matx[0][0]*b.y() - matx[0][1]*b.x()));
314  return 0;
315  }
316  return 1;
317  }
318 
319  // Diagonalize *this.
320  // *this should be symmetric.
321  // The matrix is factored into:
322  // *this = Rt D R
323  // The diagonalization is done with one jacobi rotation to 0 the diagonal elements
324  // *this is unchanged by the operations.
325  // Returns true if successful, false if reached maximum iterations rather
326  // than desired tolerance.
327  // Tolerance is with respect to the maximal element of the matrix.
328  void diagonalizeSymmetric(UT_Matrix2T<T> &R, UT_Matrix2T<T> &D, T tol=1e-6f) const;
329 
330  // Compute the SVD decomposition of *this
331  // The matrix is factored into
332  // *this = U * S * Vt
333  // Where S is diagonal, and U and Vt are both orthognal matrices
334  // Tolerance is with respect to the maximal element of the matrix
335  void svdDecomposition(UT_Matrix2T<T> &U, UT_Matrix2T<T> &S, UT_Matrix2T<T> &V, T tol=1e-6f) const;
336 
337  /// Check if symmetric up to a tolerance level to 0
338  bool isSymmetric(T tolerance = T(SYS_FTOLERANCE)) const
339  {
340  return SYSisEqual( matx[0][1], matx[1][0], tolerance );
341  }
342 
343  // Transpose this matrix or return its transpose.
344  void transpose()
345  {
346  T tmp;
347  tmp=matx[0][1]; matx[0][1]=matx[1][0]; matx[1][0]=tmp;
348  }
349  UT_Matrix2T<T> transpose() const;
350 
351  // check for equality within a tolerance level
352  bool isEqual( const UT_Matrix2T<T> &m,
353  T tolerance=T(SYS_FTOLERANCE) ) const
354  {
355  return (&m == this) || (
356  SYSisEqual( matx[0][0], m.matx[0][0], tolerance ) &&
357  SYSisEqual( matx[0][1], m.matx[0][1], tolerance ) &&
358 
359  SYSisEqual( matx[1][0], m.matx[1][0], tolerance ) &&
360  SYSisEqual( matx[1][1], m.matx[1][1], tolerance ) );
361  }
362 
363  // Matrix += b * v1 * v2T
364  template <typename S>
366  const UT_Vector2T<S> &v1, const UT_Vector2T<S> &v2)
367  {
368  T bv1;
369  bv1 = b * v1.x();
370  matx[0][0]+=bv1*v2.x();
371  matx[0][1]+=bv1*v2.y();
372  bv1 = b * v1.y();
373  matx[1][0]+=bv1*v2.x();
374  matx[1][1]+=bv1*v2.y();
375  }
376 
377  /// Set the matrix to identity
378  void identity()
379  {
380  matx[0][0]=(T)1;matx[0][1]=(T)0;
381  matx[1][0]=(T)0;matx[1][1]=(T)1;
382  }
383  /// Set the matrix to zero
384  void zero() { *this = 0; }
385 
386  bool isIdentity() const
387  {
388  // NB: DO NOT USE TOLERANCES
389  return(
390  matx[0][0]==1 && matx[0][1]==0 &&
391  matx[1][0]==0 && matx[1][1]==1);
392  }
393  bool isZero() const
394  {
395  // NB: DO NOT USE TOLERANCES
396  return (
397  matx[0][0]==0 && matx[0][1]==0 &&
398  matx[1][0]==0 && matx[1][1]==0);
399  }
400 
401  /// Create a rotation matrix for the given angle in radians
402  static UT_Matrix2T<T> rotationMat(T theta);
403 
404  /// Rotate by theta radians
405  void rotate(T theta)
406  { (*this) *= rotationMat(theta); }
407 
408  /// Multiply this matrix by a scale matrix with diagonal (sx, sy):
409  /// @{
410  void scale(T sx, T sy)
411  {
412  matx[0][0] *= sx; matx[0][1] *= sy;
413  matx[1][0] *= sx; matx[1][1] *= sy;
414  }
415  inline void scale(const UT_Vector2T<T> &s)
416  { scale(s(0), s(1)); }
417  /// @}
418 
419  /// Initialize this matrix to zero.
420  void initialize()
421  {
422  matx[0][0]=matx[0][1]= (T)0;
423  matx[1][0]=matx[1][1]= (T)0;
424  }
425 
426  /// Return a matrix entry. No bounds checking on subscripts.
427  // @{
428  SYS_FORCE_INLINE T &operator()(unsigned row, unsigned col) noexcept
429  {
430  UT_ASSERT_P(row < 2 && col < 2);
431  return matx[row][col];
432  }
433  SYS_FORCE_INLINE T operator()(unsigned row, unsigned col) const noexcept
434  {
435  UT_ASSERT_P(row < 2 && col < 2);
436  return matx[row][col];
437  }
438  // @}
439 
440  /// Return the raw matrix data.
441  // @{
442  const T *data() const { return myFloats; }
443  T *data() { return myFloats; }
444  // @}
445 
446  /// Compute a hash
447  unsigned hash() const { return SYSvector_hash(data(), tuple_size); }
448 
449  /// Return a matrix row. No bounds checking on subscript.
450  // @{
451  T *operator()(unsigned row)
452  {
453  UT_ASSERT_P(row < 2);
454  return matx[row];
455  }
456  const T *operator()(unsigned row) const
457  {
458  UT_ASSERT_P(row < 2);
459  return matx[row];
460  }
461  inline
462  const UT_Vector2T<T> &operator[](unsigned row) const;
463  inline
464  UT_Vector2T<T> &operator[](unsigned row);
465  // @}
466 
467  /// Dot product with another matrix
468  /// Does dot(a,b) = sum_ij a_ij * b_ij
469  T dot(const UT_Matrix2T<T> &m) const;
470 
471  /// Euclidean or Frobenius norm of a matrix.
472  /// Does sqrt(sum(a_ij ^2))
474  { return SYSsqrt(getEuclideanNorm2()); }
475  /// Euclidean norm squared.
476  T getEuclideanNorm2() const;
477 
478  /// Get the 1-norm of this matrix, assuming a row vector convention.
479  /// Returns the maximum absolute row sum. ie. max_i(sum_j(abs(a_ij)))
480  T getNorm1() const;
481 
482  /// Get the inf-norm of this matrix, assuming a row vector convention.
483  /// Returns the maximum absolute column sum. ie. max_j(sum_i(abs(a_ij)))
484  T getNormInf() const;
485 
486  /// Get the max-norm of this matrix
487  /// Returns the maximum absolute entry. ie. max_j(max_i(abs(a_ij)))
488  T getNormMax() const;
489 
490  /// Get the spectral norm of this matrix
491  /// Returns the maximum singular value.
492  T getNormSpectral() const;
493 
494  // I/O methods. Return 0 if read/write successful, -1 if unsuccessful.
495  int save(std::ostream &os, int binary) const;
496  bool load(UT_IStream &is);
497 
498  void outAsciiNoName(std::ostream &os) const;
499 
500  /// @{
501  /// Methods to serialize to a JSON stream. The matrix is stored as an
502  /// array of 4 reals.
503  bool save(UT_JSONWriter &w) const;
504  bool save(UT_JSONValue &v) const;
505  bool load(UT_JSONParser &p);
506  /// @}
507 
508  // I/O friends:
509  friend std::ostream &operator<<(std::ostream &os, const UT_Matrix2T<T> &v)
510  {
511  // v.className(os);
512  v.outAsciiNoName(os);
513  return os;
514  }
515 
516  /// Returns the vector size
517  static int entries() { return tuple_size; }
518 
519 private:
520  void writeClassName(std::ostream &os) const;
521  static const char *className();
522 
523  union {
524  T matx[2][2];
525  T myFloats[tuple_size];
526  };
527 };
528 
529 #include "UT_Vector2.h"
530 
531 template <>
532 inline
534 {
535  return 1e-5f;
536 }
537 
538 template <>
539 inline
541 {
542  return 1e-11;
543 }
544 
545 // Special instantiations to handle the fact that we have UT_Vector2T<int64>::getBary()
546 template <>
547 inline
549 {
550  return 0;
551 }
552 
553 template <>
554 inline
556 {
557  return 0;
558 }
559 
560 template <typename T>
561 template <typename S>
562 inline
564 {
565  matx[0][0] = matx[0][1] = vec.x();
566  matx[1][0] = matx[1][1] = vec.y();
567  return *this;
568 }
569 
570 template <typename T>
571 template <typename S>
572 inline
574 {
575  matx[0][0]+=vec.x(); matx[0][1]+=vec.x();
576  matx[1][0]+=vec.y(); matx[1][1]+=vec.y();
577  return *this;
578 }
579 
580 template <typename T>
581 template <typename S>
582 inline
584 {
585  matx[0][0]-=vec.x(); matx[0][1]-=vec.x();
586  matx[1][0]-=vec.y(); matx[1][1]-=vec.y();
587  return *this;
588 }
589 
590 template <typename T>
591 inline
593 {
594  UT_ASSERT_P(row < 2);
595  return *(const UT_Vector2T<T>*)(matx[row]);
596 }
597 
598 template <typename T>
599 inline
601 {
602  UT_ASSERT_P(row < 2);
603  return *(UT_Vector2T<T>*)(matx[row]);
604 }
605 
606 
607 // Free floating functions:
608 template <typename T, typename S>
609 static inline
611 {
612  return mat+vec;
613 }
614 
615 template <typename T>
616 static inline
617 UT_Matrix2T<T> operator+(T sc, const UT_Matrix2T<T> &m1)
618 {
619  return m1+sc;
620 }
621 
622 template <typename T>
623 static inline
624 UT_Matrix2T<T> operator-(const UT_Matrix2T<T> &m1, T sc)
625 {
626  return m1+(-sc);
627 }
628 
629 template <typename T,typename S>
630 static inline
631 UT_Matrix2T<T> operator*(S sc, const UT_Matrix2T<T> &m1)
632 {
633  return m1*sc;
634 }
635 
636 template <typename T>
637 static inline
638 UT_Matrix2T<T> operator/(const UT_Matrix2T<T> &m1, T scalar)
639 {
640  return m1 * (T(1)/scalar);
641 }
642 
643 template <typename T>
644 static inline
645 T dot(const UT_Matrix2T<T> &m1, const UT_Matrix2T<T> &m2){
646  return m1.dot(m2);
647 }
648 
649 template <typename T>
650 inline
652 {
653  return UT_Matrix2T<T>(
654  SYSmin(v1(0,0), v2(0,0)),
655  SYSmin(v1(0,1), v2(0,1)),
656  SYSmin(v1(1,0), v2(1,0)),
657  SYSmin(v1(1,1), v2(1,1))
658  );
659 }
660 
661 template <typename T>
662 inline
664 {
665  return UT_Matrix2T<T>(
666  SYSmax(v1(0,0), v2(0,0)),
667  SYSmax(v1(0,1), v2(0,1)),
668  SYSmax(v1(1,0), v2(1,0)),
669  SYSmax(v1(1,1), v2(1,1))
670  );
671 }
672 
673 template <typename T,typename S>
674 inline
676 {
677  return UT_Matrix2T<T>(
678  SYSlerp(v1(0,0), v2(0,0), t),
679  SYSlerp(v1(0,1), v2(0,1), t),
680  SYSlerp(v1(1,0), v2(1,0), t),
681  SYSlerp(v1(1,1), v2(1,1), t)
682  );
683 }
684 
685 #ifndef UT_DISABLE_VECTORIZE_MATRIX
686 template <>
687 inline
689 {
690  const v4uf l(v1.data());
691  const v4uf r(v2.data());
692 
693  UT_Matrix2T<float> result_mat;
694  vm_store(result_mat.data(), SYSlerp(l, r, t).vector);
695  return result_mat;
696 }
697 #endif
698 
699 template< typename T, exint D >
700 class UT_FixedVector;
701 
702 template<typename T>
704 {
706  typedef T DataType;
707  static const exint TupleSize = 4;
708  static const bool isVectorType = true;
709 };
710 
711 // Overload for custom formatting of UT_Matrix2T<T> with UTformat.
712 template<typename T>
713 UT_API size_t format(char *buffer, size_t buffer_size, const UT_Matrix2T<T> &v);
714 
715 // UT_Matrix2TFromFixed<T> is a function object that
716 // creates a UT_Matrix2T<T> from a fixed array-like type TS,
717 // examples of which include T[4], UT_FixedVector<T,4> and UT_FixedArray<T,4> (AKA std::array<T,4>)
718 template <typename T>
720 {
721  template< typename TS >
722  constexpr SYS_FORCE_INLINE UT_Matrix2T<T> operator()(const TS& as) const noexcept
723  {
724  SYS_STATIC_ASSERT( SYS_IsFixedArrayOf_v< TS, T, 2 * 2 > );
725 
726  return UT_Matrix2T<T>{as[0], as[1], as[2], as[3]};
727  }
728 };
729 
730 // Convert a fixed array-like type TS into a UT_Matrix2T< T >.
731 // This allows conversion to UT_Matrix2T without fixing T.
732 // Instead, the element type of TS determines the type T.
733 template< typename TS >
735 UTmakeMatrix2T( const TS& as ) noexcept
736 {
738 
739  return UT_Matrix2TFromFixed< T >{}( as );
740 }
741 
742 // UT_FromFixed<V> creates a V from a flat, fixed array-like representation
743 
744 // Primary
745 template <typename V >
746 struct UT_FromFixed;
747 
748 // Partial specialization for UT_Matrix2T
749 template <typename T>
751 
752 #endif
void identity()
Set the matrix to identity.
Definition: UT_Matrix2.h:378
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:561
constexpr SYS_FORCE_INLINE UT_Matrix2T< T > operator()(const TS &as) const noexcept
Definition: UT_Matrix2.h:722
void rotate(T theta)
Rotate by theta radians.
Definition: UT_Matrix2.h:405
#define SYS_STATIC_ASSERT(expr)
void initialize()
Initialize this matrix to zero.
Definition: UT_Matrix2.h:420
constexpr UT_Matrix2T(const fpreal32 m[2][2]) noexcept
Definition: UT_Matrix2.h:113
int int32
Definition: SYS_Types.h:39
constexpr T determinant() const noexcept
Definition: UT_Matrix2.h:220
T tolerance() const
Returns the tolerance of our class.
const T * operator()(unsigned row) const
Return a matrix row. No bounds checking on subscript.
Definition: UT_Matrix2.h:456
constexpr bool operator!=(const UT_Matrix2T< T > &m) const noexcept
Definition: UT_Matrix2.h:177
int solve(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
Definition: UT_Matrix2.h:273
constexpr UT_Matrix2T< SYS_FixedArrayElement_t< TS > > UTmakeMatrix2T(const TS &as) noexcept
Definition: UT_Matrix2.h:735
GLboolean invert
Definition: glcorearb.h:549
SYS_FORCE_INLINE T & operator()(unsigned row, unsigned col) noexcept
Return a matrix entry. No bounds checking on subscripts.
Definition: UT_Matrix2.h:428
GLboolean * data
Definition: glcorearb.h:131
const GLdouble * v
Definition: glcorearb.h:837
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:577
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
typename SYS_FixedArrayElement< T >::type SYS_FixedArrayElement_t
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Matrix2T< T > &v)
SYS_FORCE_INLINE T operator()(unsigned row, unsigned col) const noexcept
Return a matrix entry. No bounds checking on subscripts.
Definition: UT_Matrix2.h:433
int64 exint
Definition: SYS_Types.h:125
GLdouble s
Definition: glad.h:3009
UT_Matrix2T< T > & operator=(T val)
Definition: UT_Matrix2.h:182
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define UT_API
Definition: UT_API.h:14
UT_Matrix2T< T > SYSbilerp(const UT_Matrix2T< T > &u0v0, const UT_Matrix2T< T > &u1v0, const UT_Matrix2T< T > &u0v1, const UT_Matrix2T< T > &u1v1, S u, S v)
Bilinear interpolation.
Definition: UT_Matrix2.h:72
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
static const exint TupleSize
UT_Matrix2T< T > & operator/=(T scalar)
Definition: UT_Matrix2.h:204
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
UT_Matrix2T< T > SYSlerp(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S t)
Definition: UT_Matrix2.h:675
void scale(T sx, T sy)
Definition: UT_Matrix2.h:410
UT_Matrix2T< T > SYSbarycentric(const UT_Matrix2T< T > &v0, const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S u, S v)
Barycentric interpolation.
Definition: UT_Matrix2.h:79
float fpreal32
Definition: SYS_Types.h:200
static int entries()
Returns the vector size.
Definition: UT_Matrix2.h:517
void scale(const UT_Vector2T< T > &s)
Definition: UT_Matrix2.h:415
unsigned hash() const
Compute a hash.
Definition: UT_Matrix2.h:447
constexpr UT_Matrix2T(T val) noexcept
Construct identity matrix, multipled by scalar.
Definition: UT_Matrix2.h:106
T * operator()(unsigned row)
Return a matrix row. No bounds checking on subscript.
Definition: UT_Matrix2.h:451
double fpreal64
Definition: SYS_Types.h:201
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector2.h:423
GLsizei GLboolean transpose
Definition: glcorearb.h:832
GA_API const UT_StringHolder scale
GLfloat f
Definition: glcorearb.h:1926
T getEuclideanNorm() const
Definition: UT_Matrix2.h:473
Definition: core.h:760
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:587
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:130
static const bool isVectorType
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Definition: VM_SIMD.h:188
T matx[2][2]
Definition: UT_Matrix2.h:524
long long int64
Definition: SYS_Types.h:116
bool isZero() const
Definition: UT_Matrix2.h:393
UT_Matrix2T< T > & operator=(UT_Matrix2T< T > &&m)=default
Default move assignment operator.
T dot(const UT_Matrix2T< T > &m) const
void transpose()
Definition: UT_Matrix2.h:344
UT_Matrix2T< T > & operator+=(const UT_Matrix2T< T > &m)
Definition: UT_Matrix2.h:157
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
Definition: ImathMatrix.h:4660
int invert(UT_Matrix2T< T > &m) const
Definition: UT_Matrix2.h:243
GLdouble t
Definition: glad.h:2397
GLfloat v0
Definition: glcorearb.h:816
bool isIdentity() const
Definition: UT_Matrix2.h:386
bool SYSequalZero(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1069
class UT_API UT_Matrix2T
UT_Matrix2T< T > & operator-=(const UT_Matrix2T< T > &m)
Definition: UT_Matrix2.h:163
const UT_Vector2T< T > & operator[](unsigned row) const
Return a matrix row. No bounds checking on subscript.
Definition: UT_Matrix2.h:592
void zero()
Set the matrix to zero.
Definition: UT_Matrix2.h:384
T * data()
Return the raw matrix data.
Definition: UT_Matrix2.h:443
UT_Matrix2T< T > operator-() const
Definition: UT_Matrix2.h:150
GLfloat GLfloat v1
Definition: glcorearb.h:817
GLuint GLfloat * val
Definition: glcorearb.h:1608
void outerproductUpdate(T b, const UT_Vector2T< S > &v1, const UT_Vector2T< S > &v2)
Definition: UT_Matrix2.h:365
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
bool isEqual(const UT_Matrix2T< T > &m, T tolerance=T(SYS_FTOLERANCE)) const
Definition: UT_Matrix2.h:352
UT_Matrix2T< T > SYSmin(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
Definition: UT_Matrix2.h:651
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
#define SYS_FTOLERANCE
Definition: SYS_Types.h:208
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLenum GLenum GLsizei void * row
Definition: glad.h:5135
UT_Matrix2T< T > & operator-=(T scalar)
Definition: UT_Matrix2.h:194
int invert()
Definition: UT_Matrix2.h:233
int solveTranspose(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
Definition: UT_Matrix2.h:298
GLboolean r
Definition: glcorearb.h:1222
#define const
Definition: zconf.h:214
const T * data() const
Return the raw matrix data.
Definition: UT_Matrix2.h:442
bool isSymmetric(T tolerance=T(SYS_FTOLERANCE)) const
Check if symmetric up to a tolerance level to 0.
Definition: UT_Matrix2.h:338
UT_API UT_Matrix2T< T > operator/(T sc, const UT_Matrix2T< T > &mat)
bool SYSisEqual(const UT_Vector2T< T > &a, const UT_Vector2T< T > &b, S tol=SYS_FTOLERANCE)
Componentwise equality.
Definition: UT_Vector2.h:674
UT_Matrix2T< T > & operator+=(T scalar)
Definition: UT_Matrix2.h:188
UT_Matrix2T< T > & operator*=(T scalar)
Definition: UT_Matrix2.h:198
UT_Matrix2T< T > SYSmax(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
Definition: UT_Matrix2.h:663
constexpr bool operator==(const UT_Matrix2T< T > &m) const noexcept
Definition: UT_Matrix2.h:171
constexpr T trace() const noexcept
Definition: UT_Matrix2.h:224
UT_FixedVector< T, 4 > FixedVectorType
Definition: UT_Matrix2.h:705
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector2.h:425