13 #ifndef INCLUDED_IMATHMATRIXALGO_H
14 #define INCLUDED_IMATHMATRIXALGO_H
24 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
470 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
return mat;
490 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
return false;
560 row[0] =
Vec3<T> (mat[0][0], mat[0][1], mat[0][2]);
561 row[1] =
Vec3<T> (mat[1][0], mat[1][1], mat[1][2]);
562 row[2] =
Vec3<T> (mat[2][0], mat[2][1], mat[2][2]);
565 for (
int i = 0; i < 3; i++)
566 for (
int j = 0;
j < 3;
j++)
580 for (
int i = 0; i < 3; i++)
605 shr[0] = row[0].
dot (row[1]);
606 row[1] -= shr[0] * row[0];
609 scl.
y = row[1].length ();
617 shr[1] = row[0].
dot (row[2]);
618 row[2] -= shr[1] * row[0];
619 shr[2] = row[1].
dot (row[2]);
620 row[2] -= shr[2] * row[1];
623 scl.
z = row[2].length ();
634 if (row[0].
dot (row[1].
cross (row[2])) < 0)
635 for (
int i = 0; i < 3; i++)
643 for (
int i = 0; i < 3; i++)
645 mat[i][0] = row[i][0];
646 mat[i][1] = row[i][1];
647 mat[i][2] = row[i][2];
666 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
667 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
668 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
696 rot.
x = std::atan2 (M[1][2], M[2][2]);
712 T cy =
std::sqrt (N[0][0] * N[0][0] + N[0][1] * N[0][1]);
713 rot.
y = std::atan2 (-N[0][2], cy);
714 rot.
z = std::atan2 (-N[1][0], N[1][1]);
725 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
726 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
727 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
755 rot.
x = -std::atan2 (M[1][0], M[0][0]);
771 T cy =
std::sqrt (N[2][2] * N[2][2] + N[2][1] * N[2][1]);
772 rot.
y = -std::atan2 (-N[2][0], cy);
773 rot.
z = -std::atan2 (-N[1][2], N[1][1]);
785 int nxt[3] = {1, 2, 0};
786 tr = mat[0][0] + mat[1][1] + mat[2][2];
792 quat.
r = s /
T (2.0);
795 quat.
v.x = (mat[1][2] - mat[2][1]) * s;
796 quat.
v.y = (mat[2][0] - mat[0][2]) * s;
797 quat.
v.z = (mat[0][1] - mat[1][0]) * s;
803 if (mat[1][1] > mat[0][0]) i = 1;
804 if (mat[2][2] > mat[i][i]) i = 2;
808 s =
std::sqrt ((mat[i][i] - (mat[j][j] + mat[k][k])) +
T (1.0));
811 if (s != T (0.0)) s = T (0.5) /
s;
813 q[3] = (mat[
j][k] - mat[k][
j]) * s;
814 q[
j] = (mat[i][
j] + mat[
j][i]) * s;
815 q[k] = (mat[i][k] + mat[k][i]) * s;
888 for (
int i = 0; i < 3; i++)
890 if ((
abs (scl) < 1 &&
894 throw std::domain_error (
"Cannot remove zero scaling "
950 if (fromDir.
length () == 0)
963 return fromDir2zAxis * zAxis2ToDir;
1013 result.
x[0][0] = row[0][0];
1014 result.
x[0][1] = row[0][1];
1015 result.
x[0][2] = row[0][2];
1016 result.
x[0][3] = (
T) 0;
1018 result.
x[1][0] = row[1][0];
1019 result.
x[1][1] = row[1][1];
1020 result.
x[1][2] = row[1][2];
1021 result.
x[1][3] = (
T) 0;
1023 result.
x[2][0] = row[2][0];
1024 result.
x[2][1] = row[2][1];
1025 result.
x[2][2] = row[2][2];
1026 result.
x[2][3] = (
T) 0;
1028 result.
x[3][0] = (
T) 0;
1029 result.
x[3][1] = (
T) 0;
1030 result.
x[3][2] = (
T) 0;
1031 result.
x[3][3] = (
T) 1;
1095 _rOffset *=
T(
M_PI / 180.0);
1098 O[3][0] = tOffset[0];
1099 O[3][1] = tOffset[1];
1100 O[3][2] = tOffset[2];
1127 throw std::domain_error (
"degenerate A matrix in computeRSMatrix");
1131 throw std::domain_error (
"degenerate B matrix in computeRSMatrix");
1133 if (!keepRotateA) ar = br;
1135 if (!keepScaleA) as = bs;
1171 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
return mat;
1191 if (!
extractSHRT (mat, scl, shr, rot, tran, exc))
return false;
1244 row[0] =
Vec2<T> (mat[0][0], mat[0][1]);
1245 row[1] =
Vec2<T> (mat[1][0], mat[1][1]);
1248 for (
int i = 0; i < 2; i++)
1249 for (
int j = 0;
j < 2;
j++)
1263 for (
int i = 0; i < 2; i++)
1287 shr = row[0].
dot (row[1]);
1288 row[1] -= shr * row[0];
1291 scl.
y = row[1].length ();
1302 if (row[0].
x * row[1].
y - row[0].
y * row[1].
x < 0)
1312 for (
int i = 0; i < 2; i++)
1314 mat[i][0] = row[i].
x;
1315 mat[i][1] = row[i].
y;
1331 Vec2<T> i (mat[0][0], mat[0][1]);
1341 rot = -std::atan2 (j[0], i[0]);
1352 Vec2<T> i (mat[0][0], mat[0][1]);
1362 rot = -std::atan2 (j[0], i[0]);
1388 for (
int i = 0; i < 2; i++)
1390 if ((
abs (scl) < 1 &&
1394 throw std::domain_error (
1395 "Cannot remove zero scaling from matrix.");
1436 template <
typename T>
1441 const size_t numPoints,
1442 const bool doScaling =
false);
1458 template <
typename T>
1462 const size_t numPoints,
1463 const bool doScaling =
false);
1480 template <
typename T>
1486 const T tol = std::numeric_limits<T>::epsilon (),
1487 const bool forcePositiveDeterminant =
false);
1504 template <
typename T>
1510 const T tol = std::numeric_limits<T>::epsilon (),
1511 const bool forcePositiveDeterminant =
false);
1522 template <
typename T>
1534 template <
typename T>
1550 template <
typename T>
1562 template <
typename T>
1571 template <
typename TM,
typename TV>
void maxEigenVector (TM& A, TV& S);
1575 template <
typename TM,
typename TV>
void minEigenVector (TM& A, TV& S);
1577 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
1579 #endif // INCLUDED_IMATHMATRIXALGO_H
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)
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)
IMATH_EXPORT_CONST M44d identity44d
M44d identity matrix.
IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT
Return the Euclidean norm.
GA_API const UT_StringHolder rot
vfloat4 sqrt(const vfloat4 &a)
GLdouble GLdouble GLdouble z
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
M44f identity matrix.
GLboolean GLboolean GLboolean GLboolean a
IMATH_HOSTDEVICE Vec3< T > normalized() const IMATH_NOEXCEPT
Return a normalized vector. Does not modify *this.
IMATH_HOSTDEVICE constexpr T dot(const Vec3 &v) const IMATH_NOEXCEPT
Dot product.
Vec3< T > v
The imaginary vector.
T x[4][4]
Matrix elements.
**But if you need a result
GLdouble GLdouble GLdouble q
IMATH_EXPORT_CONST M22d identity22d
M22d identity matrix.
bool extractAndRemoveScalingAndShear(Matrix44< T > &mat, Vec3< T > &scl, Vec3< T > &shr, bool exc=true)
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix33 & shear(const S &xy) IMATH_NOEXCEPT
bool checkForZeroScaleInRow(const T &scl, const Vec3< T > &row, bool exc=true)
Matrix44< T > rotationMatrix(const Vec3< T > &fromDirection, const Vec3< T > &toDirection)
Matrix44< T > sansScaling(const Matrix44< T > &mat, bool exc=true)
IMATH_HOSTDEVICE constexpr T dot(const Vec2 &v) const IMATH_NOEXCEPT
Dot product.
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix44 & shear(const Vec3< S > &h) IMATH_NOEXCEPT
void extractEulerZYX(const Matrix44< T > &mat, Vec3< T > &rot)
IMATH_HOSTDEVICE Vec3< T > toXYZVector() const IMATH_NOEXCEPT
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
IMATH_HOSTDEVICE constexpr Matrix44< T > toMatrix44() const IMATH_NOEXCEPT
Return a 4x4 rotation matrix.
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Quat< T > & setRotation(const Vec3< T > &fromDirection, const Vec3< T > &toDirection) IMATH_NOEXCEPT
#define IMATH_EXPORT_CONST
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix33 & translate(const Vec2< S > &t) IMATH_NOEXCEPT
IMATH_EXPORT_CONST M33d identity33d
M33d identity matrix.
Matrix44< T > outerProduct(const Vec4< T > &a, const Vec4< T > &b)
Return the 4x4 outer product two 4-vectors.
void jacobiSVD(const Matrix33< T > &A, Matrix33< T > &U, Vec3< T > &S, Matrix33< T > &V, const T tol=std::numeric_limits< T >::epsilon(), const bool forcePositiveDeterminant=false)
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 Order order() const IMATH_NOEXCEPT
Return the order.
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix44 & translate(const Vec3< S > &t) IMATH_NOEXCEPT
GLboolean GLboolean GLboolean b
bool removeScalingAndShear(Matrix44< T > &mat, bool exc=true)
Remove scaling and shear from the given 4x4 matrix in place.
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix44 & scale(const Vec3< S > &s) IMATH_NOEXCEPT
IMATH_HOSTDEVICE void makeIdentity() IMATH_NOEXCEPT
Set to the identity matrix.
Quat< T > extractQuat(const Matrix44< T > &mat)
GLfloat GLfloat GLfloat GLfloat h
IMATH_HOSTDEVICE constexpr Matrix44 transposed() const IMATH_NOEXCEPT
Return the transpose.
void jacobiEigenSolver(Matrix33< T > &A, Vec3< T > &S, Matrix33< T > &V, const T tol)
IMATH_HOSTDEVICE const Matrix44 & rotate(const Vec3< S > &r) IMATH_NOEXCEPT
Matrix44< T > sansScalingAndShear(const Matrix44< T > &mat, bool exc=true)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder N
Matrix44< T > computeLocalFrame(const Vec3< T > &p, const Vec3< T > &xDir, const Vec3< T > &normal)
IMATH_HOSTDEVICE IMATH_CONSTEXPR14 const Matrix33 & rotate(S r) IMATH_NOEXCEPT
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_EXPORT_CONST M22f identity22f
M22f identity matrix.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
GLenum GLenum GLsizei void * row
IMATH_EXPORT_CONST M33f identity33f
M33f identity matrix.
void extractEuler(const Matrix22< T > &mat, T &rot)
IMATH_HOSTDEVICE constexpr Vec3 cross(const Vec3 &v) const IMATH_NOEXCEPT
Right-handed cross product.
IMATH_HOSTDEVICE const Vec3 & normalize() IMATH_NOEXCEPT
Normalize in place. If length()==0, return a null vector.
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)
M44d procrustesRotationAndTranslation(const Vec3< T > *A, const Vec3< T > *B, const T *weights, const size_t numPoints, const bool doScaling=false)
bool removeScaling(Matrix44< T > &mat, bool exc=true)
IMATH_HOSTDEVICE void makeIdentity() IMATH_NOEXCEPT
Set to the identity matrix.
IMATH_HOSTDEVICE T length() const IMATH_NOEXCEPT
Return the Euclidean norm.
IMATH_HOSTDEVICE const Vec2 & normalize() IMATH_NOEXCEPT
Normalize in place. If length()==0, return a null vector.