36 #ifndef INCLUDED_IMATHMATRIXALGO_H
37 #define INCLUDED_IMATHMATRIXALGO_H
478 row[0] =
Vec3<T> (mat[0][0], mat[0][1], mat[0][2]);
479 row[1] =
Vec3<T> (mat[1][0], mat[1][1], mat[1][2]);
480 row[2] =
Vec3<T> (mat[2][0], mat[2][1], mat[2][2]);
483 for (
int i=0; i < 3; i++)
484 for (
int j=0; j < 3; j++)
498 for (
int i=0; i < 3; i++)
524 shr[0] = row[0].
dot (row[1]);
525 row[1] -= shr[0] * row[0];
528 scl.
y = row[1].length ();
537 shr[1] = row[0].
dot (row[2]);
538 row[2] -= shr[1] * row[0];
539 shr[2] = row[1].
dot (row[2]);
540 row[2] -= shr[2] * row[1];
543 scl.
z = row[2].length ();
555 if (row[0].
dot (row[1].
cross (row[2])) < 0)
556 for (
int i=0; i < 3; i++)
564 for (
int i=0; i < 3; i++)
566 mat[i][0] = row[i][0];
567 mat[i][1] = row[i][1];
568 mat[i][2] = row[i][2];
588 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
589 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
590 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
635 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
636 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
637 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
685 int nxt[3] = {1, 2, 0};
686 tr = mat[0][0] + mat[1][1] + mat[2][2];
694 quat.
v.x = (mat[1][2] - mat[2][1]) * s;
695 quat.
v.y = (mat[2][0] - mat[0][2]) * s;
696 quat.
v.z = (mat[0][1] - mat[1][0]) * s;
701 if (mat[1][1] > mat[0][0])
703 if (mat[2][2] > mat[i][i])
708 s =
Math<T>::sqrt ((mat[i][i] - (mat[j][j] + mat[k][k])) +
T(1.0));
714 q[3] = (mat[j][k] - mat[k][j]) * s;
715 q[j] = (mat[i][j] + mat[j][i]) * s;
716 q[k] = (mat[i][k] + mat[k][i]) * s;
751 IMATH_INTERNAL_NAMESPACE::Euler<T> eXYZ (r, IMATH_INTERNAL_NAMESPACE::Euler<T>::XYZ);
752 IMATH_INTERNAL_NAMESPACE::Euler<T> e (eXYZ, rOrder);
753 r = e.toXYZVector ();
768 return extractSHRT(mat, s, h, r, t, exc, IMATH_INTERNAL_NAMESPACE::Euler<T>::XYZ);
790 for (
int i = 0; i < 3; i++)
795 throw IMATH_INTERNAL_NAMESPACE::ZeroScaleExc (
"Cannot remove zero scaling "
812 a.
w*b.
x, a.
w*b.
y, a.
w*b.
z, a.
w*b.
w);
840 if (fromDir.
length () == 0)
853 return fromDir2zAxis * zAxis2ToDir;
866 if ( targetDir.
length () == 0 )
873 if ( upDir.
length () == 0 )
907 result.
x[0][0] = row[0][0];
908 result.
x[0][1] = row[0][1];
909 result.
x[0][2] = row[0][2];
910 result.
x[0][3] = (
T)0;
912 result.
x[1][0] = row[1][0];
913 result.
x[1][1] = row[1][1];
914 result.
x[1][2] = row[1][2];
915 result.
x[1][3] = (
T)0;
917 result.
x[2][0] = row[2][0];
918 result.
x[2][1] = row[2][1];
919 result.
x[2][2] = row[2][2];
920 result.
x[2][3] = (
T)0;
922 result.
x[3][0] = (
T)0;
923 result.
x[3][1] = (
T)0;
924 result.
x[3][2] = (
T)0;
925 result.
x[3][3] = (
T)1;
991 _rOffset *=
M_PI / 180.0;
994 O[3][0] = tOffset[0];
995 O[3][1] = tOffset[1];
996 O[3][2] = tOffset[2];
1071 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
1093 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
1149 Vec2<T> &scl, T &shr,
bool exc)
1153 row[0] =
Vec2<T> (mat[0][0], mat[0][1]);
1154 row[1] =
Vec2<T> (mat[1][0], mat[1][1]);
1157 for (
int i=0; i < 2; i++)
1158 for (
int j=0; j < 2; j++)
1172 for (
int i=0; i < 2; i++)
1197 shr = row[0].
dot (row[1]);
1198 row[1] -= shr * row[0];
1201 scl.
y = row[1].length ();
1213 if (row[0][0] * row[1][1] - row[0][1] * row[1][0] < 0)
1223 for (
int i=0; i < 2; i++)
1225 mat[i][0] = row[i][0];
1226 mat[i][1] = row[i][1];
1243 Vec2<T> i (mat[0][0], mat[0][1]);
1244 Vec2<T> j (mat[1][0], mat[1][1]);
1287 for (
int i = 0; i < 2; i++)
1292 throw IMATH_INTERNAL_NAMESPACE::ZeroScaleExc (
1293 "Cannot remove zero scaling from matrix.");
1308 a.
y*b.
x, a.
y*b.
y, a.
y*b.
z,
1309 a.
z*b.
x, a.
z*b.
y, a.
z*b.
z );
1322 template <
typename T>
1325 const IMATH_INTERNAL_NAMESPACE::Vec3<T>* B,
1327 const size_t numPoints,
1328 const bool doScaling =
false);
1331 template <
typename T>
1334 const IMATH_INTERNAL_NAMESPACE::Vec3<T>* B,
1335 const size_t numPoints,
1336 const bool doScaling =
false);
1353 template <
typename T>
1355 jacobiSVD (
const IMATH_INTERNAL_NAMESPACE::Matrix33<T>& A,
1356 IMATH_INTERNAL_NAMESPACE::Matrix33<T>& U,
1357 IMATH_INTERNAL_NAMESPACE::Vec3<T>& S,
1358 IMATH_INTERNAL_NAMESPACE::Matrix33<T>& V,
1359 const T tol = IMATH_INTERNAL_NAMESPACE::limits<T>::epsilon(),
1360 const bool forcePositiveDeterminant =
false);
1362 template <
typename T>
1364 jacobiSVD (
const IMATH_INTERNAL_NAMESPACE::Matrix44<T>& A,
1365 IMATH_INTERNAL_NAMESPACE::Matrix44<T>& U,
1366 IMATH_INTERNAL_NAMESPACE::Vec4<T>& S,
1367 IMATH_INTERNAL_NAMESPACE::Matrix44<T>& V,
1368 const T tol = IMATH_INTERNAL_NAMESPACE::limits<T>::epsilon(),
1369 const bool forcePositiveDeterminant =
false);
1380 template <
typename T>
1387 template <
typename T>
1397 template <
typename T>
1404 template <
typename T>
1416 template <
typename TM,
typename TV>
1419 template <
typename TM,
typename TV>
1425 #endif // INCLUDED_IMATHMATRIXALGO_H
#define IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
void extractEulerXYZ(const Matrix44< T > &mat, Vec3< T > &rot)
bool extractScalingAndShear(const Matrix44< T > &mat, Vec3< T > &scl, Vec3< T > &shr, bool exc=true)
Matrix44< T > rotationMatrixWithUpDir(const Vec3< T > &fromDir, const Vec3< T > &toDir, const Vec3< T > &upDir)
bool extractScaling(const Matrix44< T > &mat, Vec3< T > &scl, bool exc=true)
void maxEigenVector(TM &A, TV &S)
T dot(const Vec2 &v) const
bool extractSHRT(const Matrix44< T > &mat, Vec3< T > &s, Vec3< T > &h, Vec3< T > &r, Vec3< T > &t, bool exc, typename Euler< T >::Order rOrder)
Matrix44< T > computeRSMatrix(bool keepRotateA, bool keepScaleA, const Matrix44< T > &A, const Matrix44< T > &B)
void jacobiSVD(const IMATH_INTERNAL_NAMESPACE::Matrix33< T > &A, IMATH_INTERNAL_NAMESPACE::Matrix33< T > &U, IMATH_INTERNAL_NAMESPACE::Vec3< T > &S, IMATH_INTERNAL_NAMESPACE::Matrix33< T > &V, const T tol=IMATH_INTERNAL_NAMESPACE::limits< T >::epsilon(), const bool forcePositiveDeterminant=false)
IMATH_EXPORT_CONST M44d identity44d
#define IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
#define IMATH_EXPORT_CONST
Vec3 cross(const Vec3 &v) const
void extractEuler(const Matrix33< T > &mat, T &rot)
GLboolean GLboolean GLboolean GLboolean a
GA_API const UT_StringHolder rot
Matrix44< T > addOffset(const Matrix44< T > &inMat, const Vec3< T > &tOffset, const Vec3< T > &rOffset, const Vec3< T > &sOffset, const Vec3< T > &ref)
IMATH_EXPORT_CONST M44f identity44f
format_arg_store< context, Args...> as
bool extractAndRemoveScalingAndShear(Matrix44< T > &mat, Vec3< T > &scl, Vec3< T > &shr, bool exc=true)
bool checkForZeroScaleInRow(const T &scl, const Vec3< T > &row, bool exc=true)
GLdouble GLdouble GLdouble GLdouble q
Matrix44< T > rotationMatrix(const Vec3< T > &fromDirection, const Vec3< T > &toDirection)
const Matrix44 & translate(const Vec3< S > &t)
Matrix44< T > sansScaling(const Matrix44< T > &mat, bool exc=true)
Matrix44< T > toMatrix44() const
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T abs(T a)
GLint GLint GLint GLint GLint x
GLint GLint GLint GLint GLint GLint y
void extractEulerZYX(const Matrix44< T > &mat, Vec3< T > &rot)
Matrix44 transposed() const
T dot(const Vec3 &v) const
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Vec3< T > normalized() const
IMATH_EXPORT_CONST M33d identity33d
const Matrix44 & shear(const Vec3< S > &h)
Matrix44< T > outerProduct(const Vec4< T > &a, const Vec4< T > &b)
GLfloat GLfloat GLfloat GLfloat h
const Matrix33 & translate(const Vec2< S > &t)
bool removeScalingAndShear(Matrix44< T > &mat, bool exc=true)
Quat< T > extractQuat(const Matrix44< T > &mat)
GLdouble GLdouble GLdouble b
const Matrix33 & rotate(S r)
const Matrix44 & scale(const Vec3< S > &s)
const Matrix33 & shear(const S &xy)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_EXPORT_CONST M33f identity33f
void jacobiEigenSolver(Matrix33< T > &A, Vec3< T > &S, Matrix33< T > &V, const T tol)
Matrix44< T > sansScalingAndShear(const Matrix44< T > &mat, bool exc=true)
GLdouble GLdouble GLdouble r
Quat< T > & setRotation(const Vec3< T > &fromDirection, const Vec3< T > &toDirection)
GA_API const UT_StringHolder N
Matrix44< T > computeLocalFrame(const Vec3< T > &p, const Vec3< T > &xDir, const Vec3< T > &normal)
const Matrix44 & rotate(const Vec3< S > &r)
IMATH_INTERNAL_NAMESPACE::M44d procrustesRotationAndTranslation(const IMATH_INTERNAL_NAMESPACE::Vec3< T > *A, const IMATH_INTERNAL_NAMESPACE::Vec3< T > *B, const T *weights, const size_t numPoints, const bool doScaling=false)
void minEigenVector(TM &A, TV &S)
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
void alignZAxisWithTargetDir(Matrix44< T > &result, Vec3< T > targetDir, Vec3< T > upDir)
bool removeScaling(Matrix44< T > &mat, bool exc=true)