This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
matrix3d.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
8// This file is generated by a script. Do not edit directly. Edit the
9// matrix3.template.h file to make changes.
10
11#ifndef PXR_BASE_GF_MATRIX3D_H
12#define PXR_BASE_GF_MATRIX3D_H
13
16
17#include "pxr/pxr.h"
18#include "pxr/base/gf/api.h"
19#include "pxr/base/gf/declare.h"
20#include "pxr/base/gf/matrixData.h"
21#include "pxr/base/gf/vec3d.h"
22#include "pxr/base/gf/traits.h"
23#include "pxr/base/tf/hash.h"
24
25#include <iosfwd>
26#include <vector>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
30template <>
31struct GfIsGfMatrix<class GfMatrix3d> { static const bool value = true; };
32
33class GfMatrix3d;
34class GfMatrix3f;
35class GfRotation;
36class GfQuaternion;
37class GfQuatd;
38
65{
66public:
67 typedef double ScalarType;
68
69 static const size_t numRows = 3;
70 static const size_t numColumns = 3;
71
73 GfMatrix3d() = default;
74
78 GfMatrix3d(double m00, double m01, double m02,
79 double m10, double m11, double m12,
80 double m20, double m21, double m22) {
81 Set(m00, m01, m02,
82 m10, m11, m12,
83 m20, m21, m22);
84 }
85
88 GfMatrix3d(const double m[3][3]) {
89 Set(m);
90 }
91
94 explicit GfMatrix3d(double s) {
95 SetDiagonal(s);
96 }
97
100 explicit GfMatrix3d(int s) {
101 SetDiagonal(s);
102 }
103
106 explicit GfMatrix3d(const GfVec3d& v) {
107 SetDiagonal(v);
108 }
109
116 GF_API
117 explicit GfMatrix3d(const std::vector< std::vector<double> >& v);
118
125 GF_API
126 explicit GfMatrix3d(const std::vector< std::vector<float> >& v);
127
129 GF_API
131
133 GF_API
134 explicit GfMatrix3d(const GfQuatd& rot);
135
137 GF_API
138 explicit GfMatrix3d(const class GfMatrix3f& m);
139
141 void SetRow(int i, const GfVec3d & v) {
142 _mtx[i][0] = v[0];
143 _mtx[i][1] = v[1];
144 _mtx[i][2] = v[2];
145 }
146
148 void SetColumn(int i, const GfVec3d & v) {
149 _mtx[0][i] = v[0];
150 _mtx[1][i] = v[1];
151 _mtx[2][i] = v[2];
152 }
153
155 GfVec3d GetRow(int i) const {
156 return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
157 }
158
160 GfVec3d GetColumn(int i) const {
161 return GfVec3d(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
162 }
163
167 GfMatrix3d& Set(double m00, double m01, double m02,
168 double m10, double m11, double m12,
169 double m20, double m21, double m22) {
170 _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
171 _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
172 _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
173 return *this;
174 }
175
178 GfMatrix3d& Set(const double m[3][3]) {
179 _mtx[0][0] = m[0][0];
180 _mtx[0][1] = m[0][1];
181 _mtx[0][2] = m[0][2];
182 _mtx[1][0] = m[1][0];
183 _mtx[1][1] = m[1][1];
184 _mtx[1][2] = m[1][2];
185 _mtx[2][0] = m[2][0];
186 _mtx[2][1] = m[2][1];
187 _mtx[2][2] = m[2][2];
188 return *this;
189 }
190
193 return SetDiagonal(1);
194 }
195
198 return SetDiagonal(0);
199 }
200
202 GF_API
204
206 GF_API
208
211 GF_API
212 double* Get(double m[3][3]) const;
213
216 double* data() {
217 return _mtx.GetData();
218 }
219
222 const double* data() const {
223 return _mtx.GetData();
224 }
225
227 double* GetArray() {
228 return _mtx.GetData();
229 }
230
232 const double* GetArray() const {
233 return _mtx.GetData();
234 }
235
239 double* operator [](int i) { return _mtx[i]; }
240
244 const double* operator [](int i) const { return _mtx[i]; }
245
247 friend inline size_t hash_value(GfMatrix3d const &m) {
248 return TfHash::Combine(
249 m._mtx[0][0],
250 m._mtx[0][1],
251 m._mtx[0][2],
252 m._mtx[1][0],
253 m._mtx[1][1],
254 m._mtx[1][2],
255 m._mtx[2][0],
256 m._mtx[2][1],
257 m._mtx[2][2]
258 );
259 }
260
263 GF_API
264 bool operator ==(const GfMatrix3d& m) const;
265
268 GF_API
269 bool operator ==(const GfMatrix3f& m) const;
270
273 bool operator !=(const GfMatrix3d& m) const {
274 return !(*this == m);
275 }
276
279 bool operator !=(const GfMatrix3f& m) const {
280 return !(*this == m);
281 }
282
284 GF_API
286
292 GF_API
293 GfMatrix3d GetInverse(double* det = NULL, double eps = 0) const;
294
296 GF_API
297 double GetDeterminant() const;
298
307 GF_API
308 bool Orthonormalize(bool issueWarning=true);
309
311 GF_API
312 GfMatrix3d GetOrthonormalized(bool issueWarning=true) const;
313
317 GF_API
318 double GetHandedness() const;
319
322 bool IsRightHanded() const {
323 return GetHandedness() == 1.0;
324 }
325
328 bool IsLeftHanded() const {
329 return GetHandedness() == -1.0;
330 }
331
333 GF_API
335
337 GF_API
339
341 friend GfMatrix3d operator *(const GfMatrix3d& m1, double d)
342 {
343 GfMatrix3d m = m1;
344 return m *= d;
345 }
346
348 // Returns the product of a matrix and a double.
349 friend GfMatrix3d operator *(double d, const GfMatrix3d& m)
350 {
351 return m * d;
352 }
353
355 GF_API
357
359 GF_API
361
363 GF_API
365
367 friend GfMatrix3d operator +(const GfMatrix3d& m1, const GfMatrix3d& m2)
368 {
369 GfMatrix3d tmp(m1);
370 tmp += m2;
371 return tmp;
372 }
373
375 friend GfMatrix3d operator -(const GfMatrix3d& m1, const GfMatrix3d& m2)
376 {
377 GfMatrix3d tmp(m1);
378 tmp -= m2;
379 return tmp;
380 }
381
383 friend GfMatrix3d operator *(const GfMatrix3d& m1, const GfMatrix3d& m2)
384 {
385 GfMatrix3d tmp(m1);
386 tmp *= m2;
387 return tmp;
388 }
389
391 friend GfMatrix3d operator /(const GfMatrix3d& m1, const GfMatrix3d& m2)
392 {
393 return(m1 * m2.GetInverse());
394 }
395
397 friend inline GfVec3d operator *(const GfMatrix3d& m, const GfVec3d& vec) {
398 return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
399 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
400 vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
401 }
402
404 friend inline GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d& m) {
405 return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
406 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
407 vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
408 }
409
411 GF_API
412 GfMatrix3d& SetScale(double scaleFactor);
413
416
418 GF_API
420
422 GF_API
424
427 GF_API
428 GfMatrix3d& SetScale(const GfVec3d &scaleFactors);
429
435 GF_API
437
444 GF_API
446 const GfVec3d &axis1,
447 const GfVec3d &axis2 ) const;
448
454 GF_API
456
458
459private:
462 void _SetRotateFromQuat(double r, const GfVec3d& i);
463
464
465private:
468
469 // Friend declarations
470 friend class GfMatrix3f;
471};
472
473
477GF_API
478bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance);
479
482GF_API std::ostream& operator<<(std::ostream &, GfMatrix3d const &);
483
484PXR_NAMESPACE_CLOSE_SCOPE
485
486#endif // PXR_BASE_GF_MATRIX3D_H
Declares Gf types.
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:65
GF_API GfMatrix3d GetTranspose() const
Returns the transpose of the matrix.
friend GfMatrix3d operator+(const GfMatrix3d &m1, const GfMatrix3d &m2)
Adds matrix m2 to m1.
Definition: matrix3d.h:367
friend GfMatrix3d operator*(const GfMatrix3d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix3d.h:341
GF_API GfMatrix3d(const GfRotation &rot)
Constructor. Initialize matrix from rotation.
GF_API GfMatrix3d & SetDiagonal(const GfVec3d &)
Sets the matrix to have diagonal (v[0], v[1], v[2]).
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix3d.h:222
GF_API GfMatrix3d & SetScale(double scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
GF_API GfMatrix3d & SetRotate(const GfQuatd &rot)
Sets the matrix to specify a rotation equivalent to rot.
GF_API GfQuaternion ExtractRotationQuaternion() const
Returns the quaternion corresponding to this matrix.
GfVec3d GetRow(int i) const
Gets a row of the matrix as a Vec3.
Definition: matrix3d.h:155
GF_API friend GfMatrix3d operator-(const GfMatrix3d &m)
Returns the unary negation of matrix m.
GF_API GfMatrix3d(const std::vector< std::vector< double > > &v)
Constructor.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
GF_API GfMatrix3d & operator+=(const GfMatrix3d &m)
Adds matrix m to this matrix.
GfVec3d GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3d.h:160
double * operator[](int i)
Accesses an indexed row i of the matrix as an array of 3 double values so that standard indexing (suc...
Definition: matrix3d.h:239
friend GfMatrix3d operator/(const GfMatrix3d &m1, const GfMatrix3d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3d.h:391
GF_API GfMatrix3d & SetScale(const GfVec3d &scaleFactors)
Sets the matrix to specify a nonuniform scaling in x, y, and z by the factors in vector scaleFactors.
GF_API bool operator==(const GfMatrix3d &m) const
Tests for element-wise matrix equality.
GfMatrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Constructor.
Definition: matrix3d.h:78
void SetRow(int i, const GfVec3d &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3d.h:141
GfMatrix3d & SetZero()
Sets the matrix to zero.
Definition: matrix3d.h:197
GF_API double GetHandedness() const
Returns the sign of the determinant of the matrix, i.e.
GfMatrix3d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3d.h:192
GF_API GfMatrix3d(const class GfMatrix3f &m)
This explicit constructor converts a "float" matrix to a "double" matrix.
GF_API GfMatrix3d & operator*=(const GfMatrix3d &m)
Post-multiplies matrix m into this matrix.
friend size_t hash_value(GfMatrix3d const &m)
Hash.
Definition: matrix3d.h:247
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix3d.h:227
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix3d.h:216
GfMatrix3d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3d.h:100
GF_API double * Get(double m[3][3]) const
Fills a 3x3 array of double values with the values in the matrix, specified in row-major order.
GfMatrix3d(const GfVec3d &v)
Constructor.
Definition: matrix3d.h:106
GF_API GfMatrix3d GetInverse(double *det=NULL, double eps=0) const
Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the matrix is singular.
GfMatrix3d(double s)
Constructor.
Definition: matrix3d.h:94
GfMatrix3d(const double m[3][3])
Constructor.
Definition: matrix3d.h:88
GfMatrix3d & Set(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Sets the matrix from 9 independent double values, specified in row-major order.
Definition: matrix3d.h:167
GfMatrix3d & Set(const double m[3][3])
Sets the matrix from a 3x3 array of double values, specified in row-major order.
Definition: matrix3d.h:178
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3d.h:273
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
GF_API GfMatrix3d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
bool IsLeftHanded() const
Returns true if the vectors in matrix form a left-handed coordinate system.
Definition: matrix3d.h:328
GF_API GfMatrix3d(const GfQuatd &rot)
Constructor. Initialize matrix from a quaternion.
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.
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3d.h:322
void SetColumn(int i, const GfVec3d &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3d.h:148
GfMatrix3d()=default
Default constructor. Leaves the matrix component values undefined.
GF_API GfMatrix3d(const std::vector< std::vector< float > > &v)
Constructor.
GF_API GfMatrix3d & operator-=(const GfMatrix3d &m)
Subtracts matrix m from this matrix.
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix3d.h:232
GF_API GfMatrix3d GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
GF_API GfMatrix3d & SetRotate(const GfRotation &rot)
Sets the matrix to specify a rotation equivalent to rot.
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:65
A class template used by GfMatrixXX to store values.
Definition: matrixData.h:19
T * GetData()
Return a pointer to the start of all the data.
Definition: matrixData.h:33
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:43
Basic type: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:33
Basic type: 3-space rotation specification.
Definition: rotation.h:37
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GF_API bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance)
Tests for equality within a given tolerance, returning true if the difference between each component ...
A metafunction with a static const bool member 'value' that is true for GfMatrix types,...
Definition: traits.h:25