13 #ifndef INCLUDED_IMATHMATRIXALGO_H
14 #define INCLUDED_IMATHMATRIXALGO_H
24 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
533 row[0] =
Vec3<T> (mat[0][0], mat[0][1], mat[0][2]);
534 row[1] =
Vec3<T> (mat[1][0], mat[1][1], mat[1][2]);
535 row[2] =
Vec3<T> (mat[2][0], mat[2][1], mat[2][2]);
538 for (
int i = 0; i < 3; i++)
539 for (
int j = 0;
j < 3;
j++)
553 for (
int i = 0; i < 3; i++)
579 shr[0] = row[0].
dot (row[1]);
580 row[1] -= shr[0] * row[0];
583 scl.
y = row[1].length();
592 shr[1] = row[0].
dot (row[2]);
593 row[2] -= shr[1] * row[0];
594 shr[2] = row[1].
dot (row[2]);
595 row[2] -= shr[2] * row[1];
598 scl.
z = row[2].length();
610 if (row[0].
dot (row[1].
cross (row[2])) < 0)
611 for (
int i = 0; i < 3; i++)
619 for (
int i = 0; i < 3; i++)
621 mat[i][0] = row[i][0];
622 mat[i][1] = row[i][1];
623 mat[i][2] = row[i][2];
642 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
643 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
644 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
650 Matrix44<T> M (i[0], i[1], i[2], 0, j[0], j[1], j[2], 0, k[0], k[1], k[2], 0, 0, 0, 0, 1);
672 T cy =
std::sqrt (N[0][0] * N[0][0] + N[0][1] * N[0][1]);
685 Vec3<T> i (mat[0][0], mat[0][1], mat[0][2]);
686 Vec3<T> j (mat[1][0], mat[1][1], mat[1][2]);
687 Vec3<T> k (mat[2][0], mat[2][1], mat[2][2]);
693 Matrix44<T> M (i[0], i[1], i[2], 0, j[0], j[1], j[2], 0, k[0], k[1], k[2], 0, 0, 0, 0, 1);
715 T cy =
std::sqrt (N[2][2] * N[2][2] + N[2][1] * N[2][1]);
731 int nxt[3] = { 1, 2, 0 };
732 tr = mat[0][0] + mat[1][1] + mat[2][2];
738 quat.
r = s /
T (2.0);
741 quat.
v.x = (mat[1][2] - mat[2][1]) * s;
742 quat.
v.y = (mat[2][0] - mat[0][2]) * s;
743 quat.
v.z = (mat[0][1] - mat[1][0]) * s;
749 if (mat[1][1] > mat[0][0])
751 if (mat[2][2] > mat[i][i])
756 s =
std::sqrt ((mat[i][i] - (mat[j][j] + mat[k][k])) +
T (1.0));
762 q[3] = (mat[
j][k] - mat[k][
j]) * s;
763 q[
j] = (mat[i][
j] + mat[
j][i]) * s;
764 q[k] = (mat[i][k] + mat[k][i]) * s;
830 for (
int i = 0; i < 3; i++)
835 throw std::domain_error (
"Cannot remove zero scaling "
889 if (fromDir.
length() == 0)
902 return fromDir2zAxis * zAxis2ToDir;
914 if (targetDir.
length() == 0)
955 result.
x[0][0] = row[0][0];
956 result.
x[0][1] = row[0][1];
957 result.
x[0][2] = row[0][2];
958 result.
x[0][3] = (
T) 0;
960 result.
x[1][0] = row[1][0];
961 result.
x[1][1] = row[1][1];
962 result.
x[1][2] = row[1][2];
963 result.
x[1][3] = (
T) 0;
965 result.
x[2][0] = row[2][0];
966 result.
x[2][1] = row[2][1];
967 result.
x[2][2] = row[2][2];
968 result.
x[2][3] = (
T) 0;
970 result.
x[3][0] = (
T) 0;
971 result.
x[3][1] = (
T) 0;
972 result.
x[3][2] = (
T) 0;
973 result.
x[3][3] = (
T) 1;
1036 _rOffset *=
M_PI / 180.0;
1039 O[3][0] = tOffset[0];
1040 O[3][1] = tOffset[1];
1041 O[3][2] = tOffset[2];
1186 row[0] =
Vec2<T> (mat[0][0], mat[0][1]);
1187 row[1] =
Vec2<T> (mat[1][0], mat[1][1]);
1190 for (
int i = 0; i < 2; i++)
1191 for (
int j = 0;
j < 2;
j++)
1205 for (
int i = 0; i < 2; i++)
1230 shr = row[0].
dot (row[1]);
1231 row[1] -= shr * row[0];
1234 scl.
y = row[1].length();
1246 if (row[0][0] * row[1][1] - row[0][1] * row[1][0] < 0)
1256 for (
int i = 0; i < 2; i++)
1258 mat[i][0] = row[i][0];
1259 mat[i][1] = row[i][1];
1275 Vec2<T> i (mat[0][0], mat[0][1]);
1296 Vec2<T> i (mat[0][0], mat[0][1]);
1332 for (
int i = 0; i < 2; i++)
1337 throw std::domain_error (
"Cannot remove zero scaling from matrix.");
1377 template <
typename T>
1382 const size_t numPoints,
1383 const bool doScaling =
false);
1399 template <
typename T>
1403 const size_t numPoints,
1404 const bool doScaling =
false);
1421 template <
typename T>
1426 const T tol = std::numeric_limits<T>::epsilon(),
1427 const bool forcePositiveDeterminant =
false);
1444 template <
typename T>
1449 const T tol = std::numeric_limits<T>::epsilon(),
1450 const bool forcePositiveDeterminant =
false);
1461 template <
typename T>
1472 template <
typename T>
1488 template <
typename T>
1499 template <
typename T>
1508 template <
typename TM,
typename TV>
void maxEigenVector (TM& A, TV& S);
1512 template <
typename TM,
typename TV>
void minEigenVector (TM& A, TV& S);
1514 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
1516 #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)
SYS_API double atan2(double y, double x)
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)
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
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.