matrix3d.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
25 // This file is generated by a script. Do not edit directly. Edit the
26 // matrix3.template.h file to make changes.
27 
28 #ifndef PXR_BASE_GF_MATRIX3D_H
29 #define PXR_BASE_GF_MATRIX3D_H
30 
33 
34 #include "pxr/pxr.h"
35 #include "pxr/base/gf/api.h"
36 #include "pxr/base/gf/declare.h"
37 #include "pxr/base/gf/matrixData.h"
38 #include "pxr/base/gf/vec3d.h"
39 #include "pxr/base/gf/traits.h"
40 #include "pxr/base/tf/hash.h"
41 
42 #include <iosfwd>
43 #include <vector>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 template <>
48 struct GfIsGfMatrix<class GfMatrix3d> { static const bool value = true; };
49 
50 class GfMatrix3d;
51 class GfMatrix3f;
52 class GfRotation;
53 class GfQuaternion;
54 class GfQuatd;
55 
82 {
83 public:
84  typedef double ScalarType;
85 
86  static const size_t numRows = 3;
87  static const size_t numColumns = 3;
88 
90  GfMatrix3d() = default;
91 
95  GfMatrix3d(double m00, double m01, double m02,
96  double m10, double m11, double m12,
97  double m20, double m21, double m22) {
98  Set(m00, m01, m02,
99  m10, m11, m12,
100  m20, m21, m22);
101  }
102 
105  GfMatrix3d(const double m[3][3]) {
106  Set(m);
107  }
108 
111  explicit GfMatrix3d(double s) {
112  SetDiagonal(s);
113  }
114 
117  explicit GfMatrix3d(int s) {
118  SetDiagonal(s);
119  }
120 
123  explicit GfMatrix3d(const GfVec3d& v) {
124  SetDiagonal(v);
125  }
126 
133  GF_API
134  explicit GfMatrix3d(const std::vector< std::vector<double> >& v);
135 
142  GF_API
143  explicit GfMatrix3d(const std::vector< std::vector<float> >& v);
144 
146  GF_API
147  GfMatrix3d(const GfRotation& rot);
148 
150  GF_API
151  explicit GfMatrix3d(const GfQuatd& rot);
152 
154  GF_API
155  explicit GfMatrix3d(const class GfMatrix3f& m);
156 
158  void SetRow(int i, const GfVec3d & v) {
159  _mtx[i][0] = v[0];
160  _mtx[i][1] = v[1];
161  _mtx[i][2] = v[2];
162  }
163 
165  void SetColumn(int i, const GfVec3d & v) {
166  _mtx[0][i] = v[0];
167  _mtx[1][i] = v[1];
168  _mtx[2][i] = v[2];
169  }
170 
172  GfVec3d GetRow(int i) const {
173  return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
174  }
175 
177  GfVec3d GetColumn(int i) const {
178  return GfVec3d(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
179  }
180 
184  GfMatrix3d& Set(double m00, double m01, double m02,
185  double m10, double m11, double m12,
186  double m20, double m21, double m22) {
187  _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
188  _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
189  _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
190  return *this;
191  }
192 
195  GfMatrix3d& Set(const double m[3][3]) {
196  _mtx[0][0] = m[0][0];
197  _mtx[0][1] = m[0][1];
198  _mtx[0][2] = m[0][2];
199  _mtx[1][0] = m[1][0];
200  _mtx[1][1] = m[1][1];
201  _mtx[1][2] = m[1][2];
202  _mtx[2][0] = m[2][0];
203  _mtx[2][1] = m[2][1];
204  _mtx[2][2] = m[2][2];
205  return *this;
206  }
207 
210  return SetDiagonal(1);
211  }
212 
215  return SetDiagonal(0);
216  }
217 
219  GF_API
220  GfMatrix3d& SetDiagonal(double s);
221 
223  GF_API
224  GfMatrix3d& SetDiagonal(const GfVec3d&);
225 
228  GF_API
229  double* Get(double m[3][3]) const;
230 
233  double* data() {
234  return _mtx.GetData();
235  }
236 
239  const double* data() const {
240  return _mtx.GetData();
241  }
242 
244  double* GetArray() {
245  return _mtx.GetData();
246  }
247 
249  const double* GetArray() const {
250  return _mtx.GetData();
251  }
252 
256  double* operator [](int i) { return _mtx[i]; }
257 
261  const double* operator [](int i) const { return _mtx[i]; }
262 
264  friend inline size_t hash_value(GfMatrix3d const &m) {
265  return TfHash::Combine(
266  m._mtx[0][0],
267  m._mtx[0][1],
268  m._mtx[0][2],
269  m._mtx[1][0],
270  m._mtx[1][1],
271  m._mtx[1][2],
272  m._mtx[2][0],
273  m._mtx[2][1],
274  m._mtx[2][2]
275  );
276  }
277 
280  GF_API
281  bool operator ==(const GfMatrix3d& m) const;
282 
285  GF_API
286  bool operator ==(const GfMatrix3f& m) const;
287 
290  bool operator !=(const GfMatrix3d& m) const {
291  return !(*this == m);
292  }
293 
296  bool operator !=(const GfMatrix3f& m) const {
297  return !(*this == m);
298  }
299 
301  GF_API
302  GfMatrix3d GetTranspose() const;
303 
309  GF_API
310  GfMatrix3d GetInverse(double* det = NULL, double eps = 0) const;
311 
313  GF_API
314  double GetDeterminant() const;
315 
324  GF_API
325  bool Orthonormalize(bool issueWarning=true);
326 
328  GF_API
329  GfMatrix3d GetOrthonormalized(bool issueWarning=true) const;
330 
334  GF_API
335  double GetHandedness() const;
336 
339  bool IsRightHanded() const {
340  return GetHandedness() == 1.0;
341  }
342 
345  bool IsLeftHanded() const {
346  return GetHandedness() == -1.0;
347  }
348 
350  GF_API
351  GfMatrix3d& operator *=(const GfMatrix3d& m);
352 
354  GF_API
355  GfMatrix3d& operator *=(double);
356 
358  friend GfMatrix3d operator *(const GfMatrix3d& m1, double d)
359  {
360  GfMatrix3d m = m1;
361  return m *= d;
362  }
363 
365  // Returns the product of a matrix and a double.
366  friend GfMatrix3d operator *(double d, const GfMatrix3d& m)
367  {
368  return m * d;
369  }
370 
372  GF_API
373  GfMatrix3d& operator +=(const GfMatrix3d& m);
374 
376  GF_API
377  GfMatrix3d& operator -=(const GfMatrix3d& m);
378 
380  GF_API
381  friend GfMatrix3d operator -(const GfMatrix3d& m);
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  GfMatrix3d tmp(m1);
395  tmp -= m2;
396  return tmp;
397  }
398 
400  friend GfMatrix3d operator *(const GfMatrix3d& m1, const GfMatrix3d& m2)
401  {
402  GfMatrix3d tmp(m1);
403  tmp *= m2;
404  return tmp;
405  }
406 
408  friend GfMatrix3d operator /(const GfMatrix3d& m1, const GfMatrix3d& m2)
409  {
410  return(m1 * m2.GetInverse());
411  }
412 
414  friend inline GfVec3d operator *(const GfMatrix3d& m, const GfVec3d& vec) {
415  return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
416  vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
417  vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
418  }
419 
421  friend inline GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d& m) {
422  return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
423  vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
424  vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
425  }
426 
429  GF_API
430  friend GfVec3f operator *(const GfMatrix3d& m, const GfVec3f& vec);
431 
434  GF_API
435  friend GfVec3f operator *(const GfVec3f &vec, const GfMatrix3d& m);
436 
438  GF_API
439  GfMatrix3d& SetScale(double scaleFactor);
440 
443 
445  GF_API
446  GfMatrix3d& SetRotate(const GfQuatd &rot);
447 
449  GF_API
450  GfMatrix3d& SetRotate(const GfRotation &rot);
451 
454  GF_API
455  GfMatrix3d& SetScale(const GfVec3d &scaleFactors);
456 
462  GF_API
463  GfRotation ExtractRotation() const;
464 
471  GF_API
472  GfVec3d DecomposeRotation(const GfVec3d &axis0,
473  const GfVec3d &axis1,
474  const GfVec3d &axis2 ) const;
475 
481  GF_API
483 
485 
486 private:
489  void _SetRotateFromQuat(double r, const GfVec3d& i);
490 
491 
492 private:
495 
496  // Friend declarations
497  friend class GfMatrix3f;
498 };
499 
500 
504 GF_API
505 bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance);
506 
509 GF_API std::ostream& operator<<(std::ostream &, GfMatrix3d const &);
510 
511 PXR_NAMESPACE_CLOSE_SCOPE
512 
513 #endif // PXR_BASE_GF_MATRIX3D_H
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
void SetColumn(int i, const GfVec3d &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3d.h:165
GfMatrix3d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3d.h:117
bool operator !=(const GfMatrix3f &m) const
Tests for element-wise matrix inequality.
Definition: matrix3d.h:296
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3d.h:339
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix3d.h:244
friend GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d &m)
Returns the product of row vector vec and a matrix m.
Definition: matrix3d.h:421
GfMatrix3d(double s)
Constructor.
Definition: matrix3d.h:111
bool operator !=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3d.h:290
GF_API GfMatrix3d & operator+=(const GfMatrix3d &m)
Adds matrix m to this matrix.
GfMatrix3d()=default
Default constructor. Leaves the matrix component values undefined.
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
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.
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:184
GfMatrix3d(const double m[3][3])
Constructor.
Definition: matrix3d.h:105
const double * operator [](int i) const
Accesses an indexed row i of the matrix as an array of 3 double values so that standard indexing (suc...
Definition: matrix3d.h:261
friend GfVec3d operator *(const GfMatrix3d &m, const GfVec3d &vec)
Returns the product of a matrix m and a column vector vec.
Definition: matrix3d.h:414
GF_API GfMatrix3d & SetScale(double scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
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:195
GfMatrix3d & SetZero()
Sets the matrix to zero.
Definition: matrix3d.h:214
GfVec3d GetRow(int i) const
Gets a row of the matrix as a Vec3.
Definition: matrix3d.h:172
Basic type for a vector of 3 float components.
Definition: vec3f.h:62
GF_API GfMatrix3d GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
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.
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix3d.h:249
Declares Gf types.
Basic type: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:49
GF_API std::ostream & operator<<(std::ostream &, GfMatrix3d const &)
Output a GfMatrix3d.
GfMatrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Constructor.
Definition: matrix3d.h:95
GF_API GfMatrix3d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
GF_API double GetHandedness() const
Returns the sign of the determinant of the matrix, i.e.
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:81
GfMatrix3d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3d.h:209
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:519
T * GetData()
Return a pointer to the start of all the data.
Definition: matrixData.h:50
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:256
A metafunction with a static const bool member 'value' that is true for GfMatrix types,...
Definition: traits.h:42
GF_API bool operator==(const GfMatrix3d &m) const
Tests for element-wise matrix equality.
friend GfMatrix3d operator *(const GfMatrix3d &m1, const GfMatrix3d &m2)
Multiplies matrix m1 by m2.
Definition: matrix3d.h:400
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix3d.h:239
friend GfMatrix3d operator -(const GfMatrix3d &m1, const GfMatrix3d &m2)
Subtracts matrix m2 from m1.
Definition: matrix3d.h:392
friend GfMatrix3d operator *(const GfMatrix3d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix3d.h:358
GfVec3d GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3d.h:177
friend GfMatrix3d operator+(const GfMatrix3d &m1, const GfMatrix3d &m2)
Adds matrix m2 to m1.
Definition: matrix3d.h:384
GF_API GfMatrix3d & SetRotate(const GfQuatd &rot)
Sets the matrix to specify a rotation equivalent to rot.
GF_API friend GfMatrix3d operator -(const GfMatrix3d &m)
Returns the unary negation of matrix m.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
GfMatrix3d(const GfVec3d &v)
Constructor.
Definition: matrix3d.h:123
bool IsLeftHanded() const
Returns true if the vectors in matrix form a left-handed coordinate system.
Definition: matrix3d.h:345
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix3d.h:233
Basic type for a vector of 3 double components.
Definition: vec3d.h:62
GF_API GfQuaternion ExtractRotationQuaternion() const
Returns the quaternion corresponding to this matrix.
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:81
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 ...
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatd.h:59
GF_API GfMatrix3d & operator -=(const GfMatrix3d &m)
Subtracts matrix m from this matrix.
GF_API GfMatrix3d & operator *=(const GfMatrix3d &m)
Post-multiplies matrix m into this matrix.
Basic type: 3-space rotation specification.
Definition: rotation.h:54
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.
void SetRow(int i, const GfVec3d &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3d.h:158
friend GfMatrix3d operator/(const GfMatrix3d &m1, const GfMatrix3d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3d.h:408
friend size_t hash_value(GfMatrix3d const &m)
Hash.
Definition: matrix3d.h:264
GF_API GfMatrix3d GetTranspose() const
Returns the transpose of the matrix.