4 #ifndef OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
21 template<
typename T>
class Vec3;
22 template<
typename T>
class Mat4;
23 template<
typename T>
class Quat;
37 #if OPENVDB_ABI_VERSION_NUMBER >= 8
47 for (
int i=0; i<3; ++i) {
48 for (
int j=0; j<3; ++j) {
67 template<
typename Source>
69 Source d, Source e, Source
f,
70 Source
g, Source
h, Source i)
85 template<
typename Source>
99 template<
typename Source>
114 template<
typename Source>
117 for (
int i=0; i<3; ++i) {
118 for (
int j=0; j<3; ++j) {
127 for (
int i=0; i<3; ++i) {
128 for (
int j=0; j<3; ++j) {
169 return Vec3<T>((*this)(i,0), (*
this)(i,1), (*
this)(i,2));
185 return Vec3<T>((*this)(0,j), (*
this)(1,j), (*
this)(2,j));
254 vdiag[0], vtri[0], vtri[1],
255 vtri[0], vdiag[1], vtri[2],
256 vtri[1], vtri[2], vdiag[2]
268 {*
this = rotation<Mat3<T> >(
q);}
273 {*
this = rotation<Mat3<T> >(axis,
angle);}
304 template<
typename Source>
332 -
MyBase::mm[0], -MyBase::mm[1], -MyBase::mm[2],
333 -MyBase::mm[3], -MyBase::mm[4], -MyBase::mm[5],
334 -MyBase::mm[6], -MyBase::mm[7], -MyBase::mm[8]
344 template <
typename S>
360 template <
typename S>
378 template <
typename S>
396 template <
typename S>
441 MyBase::mm[5] * MyBase::mm[6] - MyBase::mm[3] * MyBase::mm[8],
442 MyBase::mm[3] * MyBase::mm[7] - MyBase::mm[4] * MyBase::mm[6],
443 MyBase::mm[2] * MyBase::mm[7] - MyBase::mm[1] * MyBase::mm[8],
444 MyBase::mm[0] * MyBase::mm[8] - MyBase::mm[2] * MyBase::mm[6],
445 MyBase::mm[1] * MyBase::mm[6] - MyBase::mm[0] * MyBase::mm[7],
446 MyBase::mm[1] * MyBase::mm[5] - MyBase::mm[2] * MyBase::mm[4],
447 MyBase::mm[2] * MyBase::mm[3] - MyBase::mm[0] * MyBase::mm[5],
448 MyBase::mm[0] * MyBase::mm[4] - MyBase::mm[1] * MyBase::mm[3]);
456 MyBase::mm[2] * MyBase::mm[7] - MyBase::mm[1] * MyBase::mm[8],
457 MyBase::mm[1] * MyBase::mm[5] - MyBase::mm[2] * MyBase::mm[4],
458 MyBase::mm[5] * MyBase::mm[6] - MyBase::mm[3] * MyBase::mm[8],
459 MyBase::mm[0] * MyBase::mm[8] - MyBase::mm[2] * MyBase::mm[6],
460 MyBase::mm[2] * MyBase::mm[3] - MyBase::mm[0] * MyBase::mm[5],
461 MyBase::mm[3] * MyBase::mm[7] - MyBase::mm[4] * MyBase::mm[6],
462 MyBase::mm[1] * MyBase::mm[6] - MyBase::mm[0] * MyBase::mm[7],
463 MyBase::mm[0] * MyBase::mm[4] - MyBase::mm[1] * MyBase::mm[3]);
472 MyBase::mm[1], MyBase::mm[4], MyBase::mm[7],
473 MyBase::mm[2], MyBase::mm[5], MyBase::mm[8]);
487 OPENVDB_THROW(ArithmeticError,
"Inversion of singular 3x3 matrix");
489 return inv * (
T(1)/
det);
496 const T co10 = MyBase::mm[5]*MyBase::mm[6] - MyBase::mm[3]*MyBase::mm[8];
497 const T co20 = MyBase::mm[3]*MyBase::mm[7] - MyBase::mm[4]*MyBase::mm[6];
498 return MyBase::mm[0]*co00 + MyBase::mm[1]*co10 + MyBase::mm[2]*co20;
518 template<
typename T0>
521 return static_cast< Vec3<T0> >(v * *
this);
526 template<
typename T0>
529 return static_cast< Vec3<T0> >(*
this *
v);
539 ret.
mm[0] *= diag(0);
540 ret.
mm[1] *= diag(1);
541 ret.
mm[2] *= diag(2);
542 ret.
mm[3] *= diag(0);
543 ret.
mm[4] *= diag(1);
544 ret.
mm[5] *= diag(2);
545 ret.
mm[6] *= diag(0);
546 ret.
mm[7] *= diag(1);
547 ret.
mm[8] *= diag(2);
555 template <
typename T0,
typename T1>
561 for (
int i=0; i<9; ++i) {
569 template <
typename T0,
typename T1>
574 template <
typename S,
typename T>
580 template <
typename S,
typename T>
590 template <
typename T0,
typename T1>
600 template <
typename T0,
typename T1>
610 template <
typename T0,
typename T1>
620 template<
typename T,
typename MT>
626 _v[0]*m[0] + _v[1]*m[1] + _v[2]*m[2],
627 _v[0]*m[3] + _v[1]*m[4] + _v[2]*m[5],
628 _v[0]*m[6] + _v[1]*m[7] + _v[2]*m[8]);
633 template<
typename T,
typename MT>
639 _v[0]*m[0] + _v[1]*m[3] + _v[2]*m[6],
640 _v[0]*m[1] + _v[1]*m[4] + _v[2]*m[7],
641 _v[0]*m[2] + _v[1]*m[5] + _v[2]*m[8]);
646 template<
typename T,
typename MT>
656 template <
typename T>
659 return Mat3<T>(v1[0]*v2[0], v1[0]*v2[1], v1[0]*v2[2],
660 v1[1]*v2[0], v1[1]*v2[1], v1[1]*v2[2],
661 v1[2]*v2[0], v1[2]*v2[1], v1[2]*v2[2]);
668 template<
typename T,
typename T0>
678 namespace mat3_internal {
687 double cotan_of_2_theta;
689 double cosin_of_theta;
695 double Sjj_minus_Sii = D[j] - D[i];
698 tan_of_theta = Sij / Sjj_minus_Sii;
701 cotan_of_2_theta = 0.5*Sjj_minus_Sii / Sij ;
703 if (cotan_of_2_theta < 0.) {
705 -1./(
sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) - cotan_of_2_theta);
708 1./(
sqrt(1. + cotan_of_2_theta*cotan_of_2_theta) + cotan_of_2_theta);
712 cosin_of_theta = 1./
sqrt( 1. + tan_of_theta * tan_of_theta);
713 sin_of_theta = cosin_of_theta * tan_of_theta;
714 z = tan_of_theta * Sij;
718 for (
int k = 0; k < i; ++k) {
720 S(k,i) = cosin_of_theta * temp - sin_of_theta * S(k,j);
721 S(k,j)= sin_of_theta * temp + cosin_of_theta * S(k,j);
723 for (
int k = i+1; k < j; ++k) {
725 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(k,j);
726 S(k,j) = sin_of_theta * temp + cosin_of_theta * S(k,j);
728 for (
int k = j+1; k <
n; ++k) {
730 S(i,k) = cosin_of_theta * temp - sin_of_theta * S(j,k);
731 S(j,k) = sin_of_theta * temp + cosin_of_theta * S(j,k);
733 for (
int k = 0; k <
n; ++k)
736 Q(k,i) = cosin_of_theta * temp - sin_of_theta*Q(k,j);
737 Q(k,j) = sin_of_theta * temp + cosin_of_theta*Q(k,j);
752 unsigned int MAX_ITERATIONS=250)
762 for (
int i = 0; i <
n; ++i) {
766 unsigned int iterations(0);
773 for (
int i = 0; i <
n; ++i) {
774 for (
int j = i+1; j <
n; ++j) {
787 for (
int i = 0; i <
n; ++i) {
788 for (
int j = i+1; j <
n; ++j){
794 if (fabs(S(i,j)) > max_element) {
795 max_element = fabs(S(i,j));
802 }
while (iterations < MAX_ITERATIONS);
814 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) *op =
math::Abs(*ip);
818 template<
typename Type1,
typename Type2>
825 for (
unsigned i = 0; i < 9; ++i, ++op, ++ip) {
837 return cwiseLessThan<3, T>(m0, m1);
844 return cwiseGreaterThan<3, T>(m0, m1);
851 #if OPENVDB_ABI_VERSION_NUMBER >= 8
865 #endif // OPENVDB_MATH_MAT3_H_HAS_BEEN_INCLUDED
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.
GLboolean GLboolean GLboolean b
void setToRotation(const Quat< T > &q)
Set this matrix to the rotation matrix specified by the quaternion.
bool cwiseGreaterThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
void pivot(int i, int j, Mat3< T > &S, Vec3< T > &D, Mat3< T > &Q)
Mat3< T > outerProduct(const Vec3< T > &v1, const Vec3< T > &v2)
Vec3< typename promote< T, MT >::type > operator*(const Vec3< T > &_v, const Mat3< MT > &_m)
Multiply _v by _m and return the resulting vector.
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Mat3(Source a, Source b, Source c, Source d, Source e, Source f, Source g, Source h, Source i)
Constructor given array of elements, the ordering is in row major form:
Mat3(const Mat4< T > &m)
Conversion from Mat4 (copies top left)
Mat3 snapBasis(Axis axis, const Vec3< T > &direction)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
void setToRotation(const Vec3< T > &axis, T angle)
Set this matrix to the rotation specified by axis and angle.
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.
Vec3< T > col(int j) const
Get jth column, e.g. Vec3d v = m.col(0);.
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
void setZero()
Set this matrix to zero.
GLenum GLenum GLenum input
vfloat4 sqrt(const vfloat4 &a)
Mat3< typename promote< T0, T1 >::type > operator*(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Multiply m0 by m1 and return the resulting matrix.
#define OPENVDB_USE_VERSION_NAMESPACE
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
Mat3< T > operator-() const
Negation operator, for e.g. m1 = -m2;.
Tolerance for floating-point comparison.
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
void setRows(const Vec3< T > &v1, const Vec3< T > &v2, const Vec3< T > &v3)
Set the rows of this matrix to the vectors v1, v2, v3.
Mat3()
Trivial constructor, the matrix is NOT initialized.
void setColumns(const Vec3< T > &v1, const Vec3< T > &v2, const Vec3< T > &v3)
Set the columns of this matrix to the vectors v1, v2, v3.
Mat3(const Vec3< Source > &v1, const Vec3< Source > &v2, const Vec3< Source > &v3, bool rows=true)
GLdouble GLdouble GLdouble GLdouble q
Vec3< T0 > transform(const Vec3< T0 > &v) const
Mat3 transpose() const
returns transpose of this
#define OPENVDB_IS_POD(Type)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
static const Mat3< T > & identity()
Predefined constant for identity matrix.
static Mat3 symmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Return a matrix with the prescribed diagonal and symmetric triangular components. ...
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
bool diagonalizeSymmetricMatrix(const Mat3< T > &input, Mat3< T > &Q, Vec3< T > &D, unsigned int MAX_ITERATIONS=250)
Use Jacobi iterations to decompose a symmetric 3x3 matrix (diagonalize and compute eigenvectors) ...
Coord Abs(const Coord &xyz)
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.
GLfloat GLfloat GLfloat v2
Mat3 inverse(T tolerance=0) const
Mat3< typename promote< S, T >::type > operator*(const Mat3< T > &m, S scalar)
Multiply each element of the given matrix by scalar and return the result.
void setCol(int j, const Vec3< T > &v)
Set jth column to vector v.
Vec3< T > row(int i) const
Get ith row, e.g. Vec3d v = m.row(1);.
GLboolean GLboolean GLboolean GLboolean a
bool eq(const Mat3 &m, T eps=1.0e-8) const
Return true if this matrix is equivalent to m within a tolerance of eps.
Mat3(const Mat3< Source > &m)
Conversion constructor.
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
GLdouble GLdouble GLdouble z
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
bool cwiseLessThan(const Mat< SIZE, T > &m0, const Mat< SIZE, T > &m1)
const Mat3< T > & operator+=(const Mat3< S > &m1)
Add each element of the given matrix to the corresponding element of this matrix. ...
T det() const
Determinant of matrix.
Mat3 adjoint() const
Return the adjoint of this matrix, i.e., the transpose of its cofactor.
GLfloat GLfloat GLfloat GLfloat v3
static const Mat3< T > & zero()
Predefined constant for zero matrix.
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
const Mat3< T > & operator*=(S scalar)
Multiplication operator, e.g. M = scalar * M;.
Mat3(const Mat< 3, T > &m)
Copy constructor.
void setSkew(const Vec3< T > &v)
Set the matrix as cross product of the given vector.
GLfloat GLfloat GLfloat GLfloat h
void setRow(int i, const Vec3< T > &v)
Set ith row to vector v.
void setSymmetric(const Vec3< T > &vdiag, const Vec3< T > &vtri)
Set diagonal and symmetric triangular components.
Mat3 timesDiagonal(const Vec3< T > &diag) const
Treat diag as a diagonal matrix and return the product of this matrix with diag (from the right)...
T * asPointer()
Direct access to the internal data.
T trace() const
Trace of matrix.
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
static unsigned numElements()
const Mat3 & operator=(const Mat3< Source > &m)
Assignment operator.
void setIdentity()
Set this matrix to identity.
T & operator()(int i, int j)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
Vec3< T0 > pretransform(const Vec3< T0 > &v) const
Mat3< T > powLerp(const Mat3< T0 > &m1, const Mat3< T0 > &m2, T t)
const Mat3< T > & operator*=(const Mat3< S > &m1)
Multiply this matrix by the given matrix.
MatType snapMatBasis(const MatType &source, Axis axis, const Vec3< typename MatType::value_type > &direction)
This function snaps a specific axis to a specific direction, preserving scaling.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Vec3< typename promote< T, MT >::type > operator*(const Mat3< MT > &_m, const Vec3< T > &_v)
Multiply _m by _v and return the resulting vector.
MatType skew(const Vec3< typename MatType::value_type > &skew)
Return a matrix as the cross product of the given vector.
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
T operator()(int i, int j) const
#define OPENVDB_THROW(exception, message)
Mat3 cofactor() const
Return the cofactor matrix of this matrix.
void powSolve(const MatType &aA, MatType &aB, double aPower, double aTol=0.01)
const Mat3< T > & operator-=(const Mat3< S > &m1)
Subtract each element of the given matrix from the corresponding element of this matrix.