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