28 #ifndef PXR_BASE_GF_MATRIX4D_H
29 #define PXR_BASE_GF_MATRIX4D_H
35 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/matrixData.h"
39 #include "pxr/base/gf/traits.h"
45 #include <boost/functional/hash.hpp>
50 PXR_NAMESPACE_OPEN_SCOPE
91 typedef double ScalarType;
93 static const size_t numRows = 4;
94 static const size_t numColumns = 4;
103 double m10,
double m11,
double m12,
double m13,
104 double m20,
double m21,
double m22,
double m23,
105 double m30,
double m31,
double m32,
double m33) {
106 Set(m00, m01, m02, m03,
137 explicit GfMatrix4d(
const std::vector< std::vector<double> >& v);
146 explicit GfMatrix4d(
const std::vector< std::vector<float> >& v);
155 explicit GfMatrix4d(
const std::vector<double>& r0,
156 const std::vector<double>& r1,
157 const std::vector<double>& r2,
158 const std::vector<double>& r3);
167 explicit GfMatrix4d(
const std::vector<float>& r0,
168 const std::vector<float>& r1,
169 const std::vector<float>& r2,
170 const std::vector<float>& r3);
205 return GfVec4d(_mtx[i][0], _mtx[i][1], _mtx[i][2], _mtx[i][3]);
210 return GfVec4d(_mtx[0][i], _mtx[1][i], _mtx[2][i], _mtx[3][i]);
217 double m10,
double m11,
double m12,
double m13,
218 double m20,
double m21,
double m22,
double m23,
219 double m30,
double m31,
double m32,
double m33) {
220 _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02; _mtx[0][3] = m03;
221 _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12; _mtx[1][3] = m13;
222 _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22; _mtx[2][3] = m23;
223 _mtx[3][0] = m30; _mtx[3][1] = m31; _mtx[3][2] = m32; _mtx[3][3] = m33;
230 _mtx[0][0] = m[0][0];
231 _mtx[0][1] = m[0][1];
232 _mtx[0][2] = m[0][2];
233 _mtx[0][3] = m[0][3];
234 _mtx[1][0] = m[1][0];
235 _mtx[1][1] = m[1][1];
236 _mtx[1][2] = m[1][2];
237 _mtx[1][3] = m[1][3];
238 _mtx[2][0] = m[2][0];
239 _mtx[2][1] = m[2][1];
240 _mtx[2][2] = m[2][2];
241 _mtx[2][3] = m[2][3];
242 _mtx[3][0] = m[3][0];
243 _mtx[3][1] = m[3][1];
244 _mtx[3][2] = m[3][2];
245 _mtx[3][3] = m[3][3];
270 double*
Get(
double m[4][4])
const;
310 boost::hash_combine(h, *p++);
327 return !(*
this == m);
333 return !(*
this == m);
362 return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
369 return _GetDeterminant3(0, 1, 2, 0, 1, 2);
483 return GfVec4d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2] + vec[3] * m._mtx[0][3],
484 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2] + vec[3] * m._mtx[1][3],
485 vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[2][3],
486 vec[0] * m._mtx[3][0] + vec[1] * m._mtx[3][1] + vec[2] * m._mtx[3][2] + vec[3] * m._mtx[3][3]);
491 return GfVec4d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0] + vec[3] * m._mtx[3][0],
492 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1] + vec[3] * m._mtx[3][1],
493 vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[3][2],
494 vec[0] * m._mtx[0][3] + vec[1] * m._mtx[1][3] + vec[2] * m._mtx[2][3] + vec[3] * m._mtx[3][3]);
613 double eps = 1e-10)
const;
618 return GfVec3d(_mtx[3][0], _mtx[3][1], _mtx[3][2]);
660 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
661 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
662 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
663 vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3]));
672 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
673 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
674 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
675 vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3])));
684 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
685 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
686 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
697 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
698 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
699 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
708 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
709 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
710 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
719 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
720 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
721 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
729 double _GetDeterminant3(
size_t row1,
size_t row2,
size_t row3,
730 size_t col1,
size_t col2,
size_t col3)
const;
733 void _Jacobi3(
GfVec3d *eigenvalues,
GfVec3d eigenvectors[3])
const;
737 void _SetRotateFromQuat(
double r,
const GfVec3d& i);
759 PXR_NAMESPACE_CLOSE_SCOPE
761 #endif // PXR_BASE_GF_MATRIX4D_H
GfVec3f GfProject(const GfVec4f &v)
Projects homogeneous v into Euclidean space and returns the result as a Vec3f.
friend GfMatrix4d operator*(const GfMatrix4d &m1, double d)
Returns the product of a matrix and a double.
GfVec4d GetRow(int i) const
Gets a row of the matrix as a Vec4.
GfVec3d TransformAffine(const GfVec3d &vec) const
Transforms the row vector vec by the matrix, returning the result.
Stores a 4x4 matrix of float elements.
GfVec3d ExtractTranslation() const
Returns the translation part of the matrix, defined as the first three elements of the last row...
bool IsRightHanded() const
Returns true if the vectors in the upper 3x3 matrix form a right-handed coordinate system...
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
GF_API GfQuatd ExtractRotationQuat() const
Return the rotation corresponding to this matrix as a quaternion.
GfMatrix4d & Set(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
Sets the matrix from 16 independent double values, specified in row-major order.
GF_API GfMatrix4d & SetTranslateOnly(const GfVec3d &t)
Sets matrix to specify a translation by the vector trans, without clearing the rotation.
GF_API GfMatrix4d & SetScale(double scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
friend GfMatrix4d operator+(const GfMatrix4d &m1, const GfMatrix4d &m2)
Adds matrix m2 to m1.
Assorted mathematical utility functions.
GfMatrix4d & Set(const double m[4][4])
Sets the matrix from a 4x4 array of double values, specified in row-major order.
double * operator[](int i)
Accesses an indexed row i of the matrix as an array of 4 double values so that standard indexing (suc...
void SetColumn(int i, const GfVec4d &v)
Sets a column of the matrix from a Vec4.
Basic type for a vector of 3 float components.
GfVec3d GetRow3(int i) const
Gets a row of the matrix as a Vec3.
GF_API GfMatrix4d & SetRotate(const GfQuatd &rot)
Sets the matrix to specify a rotation equivalent to rot, and clears the translation.
Basic type for a vector of 4 double components.
const double * GetArray() const
Returns vector components as a const array of double values.
GF_API GfMatrix4d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
GF_API GfMatrix4d & SetTransform(const GfRotation &rotate, const GfVec3d &translate)
Sets matrix to specify a rotation by rotate and a translation by translate.
void SetRow(int i, const GfVec4d &v)
Sets a row of the matrix from a Vec4.
GF_API GfMatrix4d RemoveScaleShear() const
Returns the matrix with any scaling or shearing removed, leaving only the rotation and translation...
void SetRow3(int i, const GfVec3d &v)
Sets a row of the matrix from a Vec3.
double GfAbs(double f)
Return abs(f).
friend GfMatrix4d operator/(const GfMatrix4d &m1, const GfMatrix4d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
double * data()
Returns raw access to components of matrix as an array of double values.
GfMatrix4d(double s)
Constructor.
bool HasOrthogonalRows3() const
Returns true, if the row vectors of the upper 3x3 matrix form an orthogonal basis.
GF_API GfMatrix4d GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
GF_API GfMatrix4d & operator+=(const GfMatrix4d &m)
Adds matrix m to this matrix.
GF_API double GetHandedness() const
Returns the sign of the determinant of the upper 3x3 matrix, i.e.
GF_API GfMatrix4d & SetLookAt(const GfVec3d &eyePoint, const GfVec3d ¢erPoint, const GfVec3d &upDirection)
Sets the matrix to specify a viewing matrix from parameters similar to those used by gluLookAt(3G)...
GF_API GfVec3d DecomposeRotation(const GfVec3d &axis0, const GfVec3d &axis1, const GfVec3d &axis2) const
Decompose the rotation corresponding to this matrix about 3 orthogonal axes.
GfMatrix4d()=default
Default constructor. Leaves the matrix component values undefined.
GfVec4d GetColumn(int i) const
Gets a column of the matrix as a Vec4.
GF_API double * Get(double m[4][4]) const
Fills a 4x4 array of double values with the values in the matrix, specified in row-major order...
GfVec3f Transform(const GfVec3f &vec) const
Transforms the row vector vec by the matrix, returning the result.
T * GetData()
Return a pointer to the start of all the data.
GfMatrix4d(const double m[4][4])
Constructor.
Stores a 4x4 matrix of double elements.
A metafunction with a static const bool member 'value' that is true for GfMatrix types, like GfMatrix3d, GfMatrix4f, etc and false for all other types.
GfMatrix4d & SetZero()
Sets the matrix to zero.
GF_API GfMatrix4d GetInverse(double *det=NULL, double eps=0) const
Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the matrix is singular.
GF_API bool Factor(GfMatrix4d *r, GfVec3d *s, GfMatrix4d *u, GfVec3d *t, GfMatrix4d *p, double eps=1e-10) const
Factors the matrix into 5 components:
GfVec3d TransformDir(const GfVec3d &vec) const
Transforms row vector vec by the matrix, returning the result.
GF_API friend GfMatrix4d operator-(const GfMatrix4d &m)
Returns the unary negation of matrix m.
decltype(std::declval< Left >()*std::declval< Right >()) GfDot(Left left, Right right)
Returns the dot (inner) product of two vectors.
Utility functions for GfVec4f and GfVec4d as homogeneous vectors.
GfMatrix4d & SetIdentity()
Sets the matrix to the identity matrix.
GF_API GfMatrix4d & SetRotateOnly(const GfQuatd &rot)
Sets the matrix to specify a rotation equivalent to rot, without clearing the translation.
bool IsLeftHanded() const
Returns true if the vectors in the upper 3x3 matrix form a left-handed coordinate system...
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
GF_API GfMatrix4d & operator-=(const GfMatrix4d &m)
Subtracts matrix m from this matrix.
GfMatrix4d(const GfVec4d &v)
Constructor.
const double * data() const
Returns const raw access to components of matrix as an array of double values.
GfVec3d Transform(const GfVec3d &vec) const
Transforms the row vector vec by the matrix, returning the result.
GF_API GfMatrix4d GetTranspose() const
Returns the transpose of the matrix.
friend size_t hash_value(GfMatrix4d const &m)
Hash.
GfMatrix4d(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
Constructor.
double * GetArray()
Returns vector components as an array of double values.
GfVec3f TransformAffine(const GfVec3f &vec) const
Transforms the row vector vec by the matrix, returning the result.
Basic type for a vector of 4 float components.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
bool operator!=(const GfMatrix4d &m) const
Tests for element-wise matrix inequality.
GF_API GfMatrix3d ExtractRotationMatrix() const
Returns the rotation corresponding to this matrix.
Basic type for a vector of 3 double components.
Defines useful mathematical limits.
GF_API GfMatrix4d & operator*=(const GfMatrix4d &m)
Post-multiplies matrix m into this matrix.
GF_API GfMatrix4d & SetTranslate(const GfVec3d &trans)
Sets matrix to specify a translation by the vector trans, and clears the rotation.
GfVec3f TransformDir(const GfVec3f &vec) const
Transforms row vector vec by the matrix, returning the result.
Stores a 3x3 matrix of double elements.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
GF_API bool operator==(const GfMatrix4d &m) const
Tests for element-wise matrix equality.
Basic type: 3-space rotation specification.
double GetDeterminant3() const
Returns the determinant of the upper 3x3 matrix.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.