Loading...
Searching...
No Matches
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
74 GfMatrix3d() = default;
75
79 GfMatrix3d(double m00, double m01, double m02,
80 double m10, double m11, double m12,
81 double m20, double m21, double m22) {
82 Set(m00, m01, m02,
83 m10, m11, m12,
84 m20, m21, m22);
85 }
86
89 GfMatrix3d(const double m[3][3]) {
90 Set(m);
91 }
92
95 explicit GfMatrix3d(double s) {
96 SetDiagonal(s);
97 }
98
101 explicit GfMatrix3d(int s) {
102 SetDiagonal(s);
103 }
104
107 explicit GfMatrix3d(const GfVec3d& v) {
108 SetDiagonal(v);
109 }
110
117 GF_API
118 explicit GfMatrix3d(const std::vector< std::vector<double> >& v);
119
126 GF_API
127 explicit GfMatrix3d(const std::vector< std::vector<float> >& v);
128
130 GF_API
132
134 GF_API
135 explicit GfMatrix3d(const GfQuatd& rot);
136
138 GF_API
139 explicit GfMatrix3d(const class GfMatrix3f& m);
140
142 void SetRow(int i, const GfVec3d & v) {
143 _mtx[i][0] = v[0];
144 _mtx[i][1] = v[1];
145 _mtx[i][2] = v[2];
146 }
147
149 void SetColumn(int i, const GfVec3d & v) {
150 _mtx[0][i] = v[0];
151 _mtx[1][i] = v[1];
152 _mtx[2][i] = v[2];
153 }
154
156 GfVec3d GetRow(int i) const {
157 return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
158 }
159
161 GfVec3d GetColumn(int i) const {
162 return GfVec3d(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
163 }
164
168 GfMatrix3d& Set(double m00, double m01, double m02,
169 double m10, double m11, double m12,
170 double m20, double m21, double m22) {
171 _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
172 _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
173 _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
174 return *this;
175 }
176
179 GfMatrix3d& Set(const double m[3][3]) {
180 _mtx[0][0] = m[0][0];
181 _mtx[0][1] = m[0][1];
182 _mtx[0][2] = m[0][2];
183 _mtx[1][0] = m[1][0];
184 _mtx[1][1] = m[1][1];
185 _mtx[1][2] = m[1][2];
186 _mtx[2][0] = m[2][0];
187 _mtx[2][1] = m[2][1];
188 _mtx[2][2] = m[2][2];
189 return *this;
190 }
191
194 return SetDiagonal(1);
195 }
196
199 return SetDiagonal(0);
200 }
201
203 GF_API
205
207 GF_API
209
212 GF_API
213 double* Get(double m[3][3]) const;
214
217 double* data() {
218 return _mtx.GetData();
219 }
220
223 const double* data() const {
224 return _mtx.GetData();
225 }
226
228 double* GetArray() {
229 return _mtx.GetData();
230 }
231
233 const double* GetArray() const {
234 return _mtx.GetData();
235 }
236
240 double* operator [](int i) { return _mtx[i]; }
241
245 const double* operator [](int i) const { return _mtx[i]; }
246
248 friend inline size_t hash_value(GfMatrix3d const &m) {
249 return TfHash::Combine(
250 m._mtx[0][0],
251 m._mtx[0][1],
252 m._mtx[0][2],
253 m._mtx[1][0],
254 m._mtx[1][1],
255 m._mtx[1][2],
256 m._mtx[2][0],
257 m._mtx[2][1],
258 m._mtx[2][2]
259 );
260 }
261
264 GF_API
265 bool operator ==(const GfMatrix3d& m) const;
266
269 GF_API
270 bool operator ==(const GfMatrix3f& m) const;
271
274 bool operator !=(const GfMatrix3d& m) const {
275 return !(*this == m);
276 }
277
280 bool operator !=(const GfMatrix3f& m) const {
281 return !(*this == m);
282 }
283
285 GF_API
287
293 GF_API
294 GfMatrix3d GetInverse(double* det = NULL, double eps = 0) const;
295
297 GF_API
298 double GetDeterminant() const;
299
308 GF_API
309 bool Orthonormalize(bool issueWarning=true);
310
312 GF_API
313 GfMatrix3d GetOrthonormalized(bool issueWarning=true) const;
314
318 GF_API
319 double GetHandedness() const;
320
323 bool IsRightHanded() const {
324 return GetHandedness() == 1.0;
325 }
326
329 bool IsLeftHanded() const {
330 return GetHandedness() == -1.0;
331 }
332
334 GF_API
336
338 GF_API
340
342 friend GfMatrix3d operator *(const GfMatrix3d& m1, double d)
343 {
344 GfMatrix3d m = m1;
345 return m *= d;
346 }
347
349 // Returns the product of a matrix and a double.
350 friend GfMatrix3d operator *(double d, const GfMatrix3d& m)
351 {
352 return m * d;
353 }
354
356 GF_API
358
360 GF_API
362
364 GF_API
366
368 friend GfMatrix3d operator +(const GfMatrix3d& m1, const GfMatrix3d& m2)
369 {
370 GfMatrix3d tmp(m1);
371 tmp += m2;
372 return tmp;
373 }
374
376 friend GfMatrix3d operator -(const GfMatrix3d& m1, const GfMatrix3d& m2)
377 {
378 GfMatrix3d tmp(m1);
379 tmp -= m2;
380 return tmp;
381 }
382
384 friend GfMatrix3d operator *(const GfMatrix3d& m1, const GfMatrix3d& m2)
385 {
386 GfMatrix3d tmp(m1);
387 tmp *= m2;
388 return tmp;
389 }
390
392 friend GfMatrix3d operator /(const GfMatrix3d& m1, const GfMatrix3d& m2)
393 {
394 return(m1 * m2.GetInverse());
395 }
396
398 friend inline GfVec3d operator *(const GfMatrix3d& m, const GfVec3d& vec) {
399 return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
400 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
401 vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
402 }
403
405 friend inline GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d& m) {
406 return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
407 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
408 vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
409 }
410
412 GF_API
413 GfMatrix3d& SetScale(double scaleFactor);
414
417
419 GF_API
421
423 GF_API
425
428 GF_API
429 GfMatrix3d& SetScale(const GfVec3d &scaleFactors);
430
436 GF_API
438
445 GF_API
447 const GfVec3d &axis1,
448 const GfVec3d &axis2 ) const;
449
455 GF_API
457
459
460private:
463 void _SetRotateFromQuat(double r, const GfVec3d& i);
464
465
466private:
469
470 // Friend declarations
471 friend class GfMatrix3f;
472};
473
474
478GF_API
479bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance);
480
483GF_API std::ostream& operator<<(std::ostream &, GfMatrix3d const &);
484
485PXR_NAMESPACE_CLOSE_SCOPE
486
487#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:368
friend GfMatrix3d operator*(const GfMatrix3d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix3d.h:342
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:223
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:156
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:161
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:240
friend GfMatrix3d operator/(const GfMatrix3d &m1, const GfMatrix3d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3d.h:392
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:79
void SetRow(int i, const GfVec3d &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3d.h:142
GfMatrix3d & SetZero()
Sets the matrix to zero.
Definition: matrix3d.h:198
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:193
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:248
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix3d.h:228
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix3d.h:217
GfMatrix3d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3d.h:101
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:107
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:95
GfMatrix3d(const double m[3][3])
Constructor.
Definition: matrix3d.h:89
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:168
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:179
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3d.h:274
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:329
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:323
void SetColumn(int i, const GfVec3d &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3d.h:149
GfMatrix3d()=default
GfMatrix3d value-initializes to zero and performs no default initialization, like float or double.
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:233
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:487
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