10 #ifndef __UT_Matrix2_h__
11 #define __UT_Matrix2_h__
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
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
51 template <
typename T>
UT_API
53 template <
typename T,
typename S>
UT_API
55 template <
typename T,
typename S>
static inline
58 template <
typename T>
static inline
60 template <
typename T>
UT_API
67 template <
typename T,
typename S>
71 template <
typename T,
typename S>
78 template <
typename T,
typename S>
81 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
94 static constexpr
int tuple_size = 4;
114 : matx{{
T(m[0][0]),
T(m[0][1])},{
T(m[1][0]),
T(m[1][1])}}
117 : matx{{
T(m[0][0]),
T(m[0][1])},{
T(m[1][0]),
T(m[1][1])}}
123 : matx{{val00,val01},{val10,val11}}
127 template <
typename S>
129 : matx{{
T(m(0,0)),
T(m(0,1))},{
T(m(1,0)),
T(m(1,1))}}
134 template <
typename S>
136 : matx{{
T(m(0,0)),
T(m(0,1))},{
T(m(1,0)),
T(m(1,1))}}
147 template <
typename S>
153 -matx[0][0], -matx[0][1],
154 -matx[1][0], -matx[1][1]);
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];
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];
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) );
179 return !(*
this == m);
184 matx[0][0] =
val; matx[0][1] = 0;
185 matx[1][0] = 0; matx[1][1] =
val;
190 matx[0][0]+=scalar; matx[0][1]+=scalar;
191 matx[1][0]+=scalar; matx[1][1]+=scalar;
200 matx[0][0]*=scalar; matx[0][1]*=scalar;
201 matx[1][0]*=scalar; matx[1][1]*=scalar;
210 template <
typename S>
213 template <
typename S>
216 template <
typename S>
222 return matx[0][0]*matx[1][1] - matx[0][1]*matx[1][0];
225 {
return matx[0][0] + matx[1][1]; }
228 template <
typename S>
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();
258 -matx[1][0], matx[0][0]);
272 template <
typename S>
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();
285 T recipdet =
T(1)/det;
287 recipdet * (matx[1][1]*b.
x() - matx[0][1]*b.
y()),
288 recipdet * (matx[0][0]*b.
y() - matx[1][0]*b.
x()));
297 template <
typename S>
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();
310 T recipdet =
T(1)/det;
312 recipdet * (matx[1][1]*b.
x() - matx[1][0]*b.
y()),
313 recipdet * (matx[0][0]*b.
y() - matx[0][1]*b.
x()));
340 return SYSisEqual( matx[0][1], matx[1][0], tolerance );
347 tmp=matx[0][1]; matx[0][1]=matx[1][0]; matx[1][0]=tmp;
355 return (&m ==
this) || (
364 template <
typename S>
370 matx[0][0]+=bv1*v2.
x();
371 matx[0][1]+=bv1*v2.
y();
373 matx[1][0]+=bv1*v2.
x();
374 matx[1][1]+=bv1*v2.
y();
380 matx[0][0]=(
T)1;matx[0][1]=(
T)0;
381 matx[1][0]=(
T)0;matx[1][1]=(
T)1;
390 matx[0][0]==1 && matx[0][1]==0 &&
391 matx[1][0]==0 && matx[1][1]==1);
397 matx[0][0]==0 && matx[0][1]==0 &&
398 matx[1][0]==0 && matx[1][1]==0);
406 { (*this) *= rotationMat(theta); }
412 matx[0][0] *= sx; matx[0][1] *= sy;
413 matx[1][0] *= sx; matx[1][1] *= sy;
422 matx[0][0]=matx[0][1]= (
T)0;
423 matx[1][0]=matx[1][1]= (
T)0;
431 return matx[
row][col];
436 return matx[
row][col];
442 const T *
data()
const {
return myFloats; }
447 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
474 {
return SYSsqrt(getEuclideanNorm2()); }
476 T getEuclideanNorm2()
const;
484 T getNormInf()
const;
488 T getNormMax()
const;
492 T getNormSpectral()
const;
495 int save(std::ostream &os,
int binary)
const;
498 void outAsciiNoName(std::ostream &os)
const;
509 friend std::ostream &operator<<(std::ostream &os, const UT_Matrix2T<T> &
v)
512 v.outAsciiNoName(os);
520 void writeClassName(std::ostream &os)
const;
521 static const char *className();
525 T myFloats[tuple_size];
560 template <
typename T>
561 template <
typename S>
565 matx[0][0] = matx[0][1] = vec.
x();
566 matx[1][0] = matx[1][1] = vec.
y();
570 template <
typename T>
571 template <
typename S>
575 matx[0][0]+=vec.
x(); matx[0][1]+=vec.
x();
576 matx[1][0]+=vec.
y(); matx[1][1]+=vec.
y();
580 template <
typename T>
581 template <
typename S>
585 matx[0][0]-=vec.
x(); matx[0][1]-=vec.
x();
586 matx[1][0]-=vec.
y(); matx[1][1]-=vec.
y();
590 template <
typename T>
598 template <
typename T>
608 template <
typename T,
typename S>
615 template <
typename T>
622 template <
typename T>
629 template <
typename T,
typename S>
636 template <
typename T>
640 return m1 * (
T(1)/scalar);
643 template <
typename T>
649 template <
typename T>
661 template <
typename T>
673 template <
typename T,
typename S>
685 #ifndef UT_DISABLE_VECTORIZE_MATRIX
694 vm_store(result_mat.data(),
SYSlerp(l,
r, t).vector);
699 template<
typename T, ex
int D >
718 template <
typename T>
721 template<
typename TS >
733 template<
typename TS >
745 template <
typename V >
749 template <
typename T>
void identity()
Set the matrix to identity.
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.
constexpr SYS_FORCE_INLINE UT_Matrix2T< T > operator()(const TS &as) const noexcept
void rotate(T theta)
Rotate by theta radians.
#define SYS_STATIC_ASSERT(expr)
void initialize()
Initialize this matrix to zero.
constexpr UT_Matrix2T(const fpreal32 m[2][2]) noexcept
constexpr T determinant() const noexcept
T tolerance() const
Returns the tolerance of our class.
const T * operator()(unsigned row) const
Return a matrix row. No bounds checking on subscript.
constexpr bool operator!=(const UT_Matrix2T< T > &m) const noexcept
int solve(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
constexpr UT_Matrix2T< SYS_FixedArrayElement_t< TS > > UTmakeMatrix2T(const TS &as) noexcept
SYS_FORCE_INLINE T & operator()(unsigned row, unsigned col) noexcept
Return a matrix entry. No bounds checking on subscripts.
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.
const GLuint GLenum const void * binary
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.
UT_Matrix2T< T > & operator=(T val)
JSON reader class which handles parsing of JSON or bJSON files.
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.
Class which writes ASCII or binary JSON streams.
static const exint TupleSize
UT_Matrix2T< T > & operator/=(T scalar)
GLfloat GLfloat GLfloat v2
UT_Matrix2T< T > SYSlerp(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S t)
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.
static int entries()
Returns the vector size.
void scale(const UT_Vector2T< T > &s)
unsigned hash() const
Compute a hash.
constexpr UT_Matrix2T(T val) noexcept
Construct identity matrix, multipled by scalar.
T * operator()(unsigned row)
Return a matrix row. No bounds checking on subscript.
constexpr SYS_FORCE_INLINE T & x() noexcept
GLsizei GLboolean transpose
GA_API const UT_StringHolder scale
T getEuclideanNorm() const
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.
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
static const bool isVectorType
UT_Matrix2T< T > & operator=(UT_Matrix2T< T > &&m)=default
Default move assignment operator.
T dot(const UT_Matrix2T< T > &m) const
UT_Matrix2T< T > & operator+=(const UT_Matrix2T< T > &m)
GLboolean GLboolean GLboolean b
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
int invert(UT_Matrix2T< T > &m) const
bool SYSequalZero(const UT_Vector3T< T > &v)
UT_Matrix2T< T > & operator-=(const UT_Matrix2T< T > &m)
const UT_Vector2T< T > & operator[](unsigned row) const
Return a matrix row. No bounds checking on subscript.
void zero()
Set the matrix to zero.
T * data()
Return the raw matrix data.
LeafData & operator=(const LeafData &)=delete
UT_Matrix2T< T > operator-() const
void outerproductUpdate(T b, const UT_Vector2T< S > &v1, const UT_Vector2T< S > &v2)
Class to store JSON objects as C++ objects.
bool isEqual(const UT_Matrix2T< T > &m, T tolerance=T(SYS_FTOLERANCE)) const
UT_Matrix2T< T > SYSmin(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
GLubyte GLubyte GLubyte GLubyte w
GLenum GLenum GLsizei void * row
UT_Matrix2T< T > & operator-=(T scalar)
int solveTranspose(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
const T * data() const
Return the raw matrix data.
bool isSymmetric(T tolerance=T(SYS_FTOLERANCE)) const
Check if symmetric up to a tolerance level to 0.
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.
UT_Matrix2T< T > & operator+=(T scalar)
UT_Matrix2T< T > & operator*=(T scalar)
UT_Matrix2T< T > SYSmax(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
constexpr bool operator==(const UT_Matrix2T< T > &m) const noexcept
constexpr T trace() const noexcept
UT_FixedVector< T, 4 > FixedVectorType
constexpr SYS_FORCE_INLINE T & y() noexcept