All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GF_MATRIX3D_H
29 #define 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 
41 #include <boost/functional/hash.hpp>
42 
43 #include <iosfwd>
44 #include <vector>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 template <>
49 struct GfIsGfMatrix<class GfMatrix3d> { static const bool value = true; };
50 
51 class GfMatrix3d;
52 class GfMatrix3f;
53 class GfRotation;
54 class GfQuaternion;
55 class GfQuatd;
56 
83 {
84 public:
85  typedef double ScalarType;
86 
87  static const size_t numRows = 3;
88  static const size_t numColumns = 3;
89 
91  GfMatrix3d() = default;
92 
96  GfMatrix3d(double m00, double m01, double m02,
97  double m10, double m11, double m12,
98  double m20, double m21, double m22) {
99  Set(m00, m01, m02,
100  m10, m11, m12,
101  m20, m21, m22);
102  }
103 
106  GfMatrix3d(const double m[3][3]) {
107  Set(m);
108  }
109 
112  explicit GfMatrix3d(double s) {
113  SetDiagonal(s);
114  }
115 
118  explicit GfMatrix3d(int s) {
119  SetDiagonal(s);
120  }
121 
124  explicit GfMatrix3d(const GfVec3d& v) {
125  SetDiagonal(v);
126  }
127 
134  GF_API
135  explicit GfMatrix3d(const std::vector< std::vector<double> >& v);
136 
143  GF_API
144  explicit GfMatrix3d(const std::vector< std::vector<float> >& v);
145 
147  GF_API
148  GfMatrix3d(const GfRotation& rot);
149 
151  GF_API
152  explicit GfMatrix3d(const GfQuatd& rot);
153 
155  GF_API
156  explicit GfMatrix3d(const class GfMatrix3f& m);
157 
159  void SetRow(int i, const GfVec3d & v) {
160  _mtx[i][0] = v[0];
161  _mtx[i][1] = v[1];
162  _mtx[i][2] = v[2];
163  }
164 
166  void SetColumn(int i, const GfVec3d & v) {
167  _mtx[0][i] = v[0];
168  _mtx[1][i] = v[1];
169  _mtx[2][i] = v[2];
170  }
171 
173  GfVec3d GetRow(int i) const {
174  return GfVec3d(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
175  }
176 
178  GfVec3d GetColumn(int i) const {
179  return GfVec3d(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
180  }
181 
185  GfMatrix3d& Set(double m00, double m01, double m02,
186  double m10, double m11, double m12,
187  double m20, double m21, double m22) {
188  _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02;
189  _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12;
190  _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22;
191  return *this;
192  }
193 
196  GfMatrix3d& Set(const double m[3][3]) {
197  _mtx[0][0] = m[0][0];
198  _mtx[0][1] = m[0][1];
199  _mtx[0][2] = m[0][2];
200  _mtx[1][0] = m[1][0];
201  _mtx[1][1] = m[1][1];
202  _mtx[1][2] = m[1][2];
203  _mtx[2][0] = m[2][0];
204  _mtx[2][1] = m[2][1];
205  _mtx[2][2] = m[2][2];
206  return *this;
207  }
208 
211  return SetDiagonal(1);
212  }
213 
216  return SetDiagonal(0);
217  }
218 
220  GF_API
221  GfMatrix3d& SetDiagonal(double s);
222 
224  GF_API
225  GfMatrix3d& SetDiagonal(const GfVec3d&);
226 
229  GF_API
230  double* Get(double m[3][3]) const;
231 
234  double* data() {
235  return _mtx.GetData();
236  }
237 
240  const double* data() const {
241  return _mtx.GetData();
242  }
243 
245  double* GetArray() {
246  return _mtx.GetData();
247  }
248 
250  const double* GetArray() const {
251  return _mtx.GetData();
252  }
253 
257  double* operator [](int i) { return _mtx[i]; }
258 
262  const double* operator [](int i) const { return _mtx[i]; }
263 
265  friend inline size_t hash_value(GfMatrix3d const &m) {
266  int nElems = 3 * 3;
267  size_t h = 0;
268  const double *p = m.GetArray();
269  while (nElems--)
270  boost::hash_combine(h, *p++);
271  return h;
272  }
273 
276  GF_API
277  bool operator ==(const GfMatrix3d& m) const;
278 
281  GF_API
282  bool operator ==(const GfMatrix3f& m) const;
283 
286  bool operator !=(const GfMatrix3d& m) const {
287  return !(*this == m);
288  }
289 
292  bool operator !=(const GfMatrix3f& m) const {
293  return !(*this == m);
294  }
295 
297  GF_API
298  GfMatrix3d GetTranspose() const;
299 
305  GF_API
306  GfMatrix3d GetInverse(double* det = NULL, double eps = 0) const;
307 
309  GF_API
310  double GetDeterminant() const;
311 
320  GF_API
321  bool Orthonormalize(bool issueWarning=true);
322 
324  GF_API
325  GfMatrix3d GetOrthonormalized(bool issueWarning=true) const;
326 
330  GF_API
331  double GetHandedness() const;
332 
335  bool IsRightHanded() const {
336  return GetHandedness() == 1.0;
337  }
338 
341  bool IsLeftHanded() const {
342  return GetHandedness() == -1.0;
343  }
344 
346  GF_API
347  GfMatrix3d& operator *=(const GfMatrix3d& m);
348 
350  GF_API
351  GfMatrix3d& operator *=(double);
352 
354  friend GfMatrix3d operator *(const GfMatrix3d& m1, double d)
355  {
356  GfMatrix3d m = m1;
357  return m *= d;
358  }
359 
361  // Returns the product of a matrix and a double.
362  friend GfMatrix3d operator *(double d, const GfMatrix3d& m)
363  {
364  return m * d;
365  }
366 
368  GF_API
369  GfMatrix3d& operator +=(const GfMatrix3d& m);
370 
372  GF_API
373  GfMatrix3d& operator -=(const GfMatrix3d& m);
374 
376  GF_API
377  friend GfMatrix3d operator -(const GfMatrix3d& m);
378 
380  friend GfMatrix3d operator +(const GfMatrix3d& m1, const GfMatrix3d& m2)
381  {
382  GfMatrix3d tmp(m1);
383  tmp += m2;
384  return tmp;
385  }
386 
388  friend GfMatrix3d operator -(const GfMatrix3d& m1, const GfMatrix3d& m2)
389  {
390  GfMatrix3d tmp(m1);
391  tmp -= m2;
392  return tmp;
393  }
394 
396  friend GfMatrix3d operator *(const GfMatrix3d& m1, const GfMatrix3d& m2)
397  {
398  GfMatrix3d tmp(m1);
399  tmp *= m2;
400  return tmp;
401  }
402 
404  friend GfMatrix3d operator /(const GfMatrix3d& m1, const GfMatrix3d& m2)
405  {
406  return(m1 * m2.GetInverse());
407  }
408 
410  friend inline GfVec3d operator *(const GfMatrix3d& m, const GfVec3d& vec) {
411  return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2],
412  vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2],
413  vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2]);
414  }
415 
417  friend inline GfVec3d operator *(const GfVec3d &vec, const GfMatrix3d& m) {
418  return GfVec3d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0],
419  vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1],
420  vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2]);
421  }
422 
425  GF_API
426  friend GfVec3f operator *(const GfMatrix3d& m, const GfVec3f& vec);
427 
430  GF_API
431  friend GfVec3f operator *(const GfVec3f &vec, const GfMatrix3d& m);
432 
434  GF_API
435  GfMatrix3d& SetScale(double scaleFactor);
436 
439 
441  GF_API
442  GfMatrix3d& SetRotate(const GfQuatd &rot);
443 
445  GF_API
446  GfMatrix3d& SetRotate(const GfRotation &rot);
447 
450  GF_API
451  GfMatrix3d& SetScale(const GfVec3d &scaleFactors);
452 
458  GF_API
459  GfRotation ExtractRotation() const;
460 
467  GF_API
468  GfVec3d DecomposeRotation(const GfVec3d &axis0,
469  const GfVec3d &axis1,
470  const GfVec3d &axis2 ) const;
471 
477  GF_API
479 
481 
482 private:
485  void _SetRotateFromQuat(double r, const GfVec3d& i);
486 
487 
488 private:
490  GfMatrixData<double, 3, 3> _mtx;
491 
492  // Friend declarations
493  friend class GfMatrix3f;
494 };
495 
496 
500 GF_API
501 bool GfIsClose(GfMatrix3d const &m1, GfMatrix3d const &m2, double tolerance);
502 
505 GF_API std::ostream& operator<<(std::ostream &, GfMatrix3d const &);
506 
507 PXR_NAMESPACE_CLOSE_SCOPE
508 
509 #endif // 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:166
GfMatrix3d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3d.h:118
GF_API GfMatrix3d GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix3d.h:240
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix3d.h:245
GfMatrix3d(double s)
Constructor.
Definition: matrix3d.h:112
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
Definition: math.h:39
bool IsLeftHanded() const
Returns true if the vectors in matrix form a left-handed coordinate system.
Definition: matrix3d.h:341
GF_API GfMatrix3d & operator+=(const GfMatrix3d &m)
Adds matrix m to this matrix.
GfMatrix3d()=default
Default constructor. Leaves the matrix component values undefined.
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:185
GfMatrix3d(const double m[3][3])
Constructor.
Definition: matrix3d.h:106
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:196
GfMatrix3d & SetZero()
Sets the matrix to zero.
Definition: matrix3d.h:215
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Basic type: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:50
GfVec3d GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3d.h:178
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(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
Constructor.
Definition: matrix3d.h:96
GF_API GfMatrix3d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
GF_API bool operator==(const GfMatrix3d &m) const
Tests for element-wise matrix equality.
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:82
GfMatrix3d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3d.h:210
friend GfMatrix3d operator*(const GfMatrix3d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix3d.h:354
GF_API GfMatrix3d GetTranspose() const
Returns the transpose of the matrix.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
A metafunction with a static const bool member &#39;value&#39; that is true for GfMatrix types, like GfMatrix3d, GfMatrix4f, etc and false for all other types.
Definition: traits.h:40
friend GfMatrix3d operator+(const GfMatrix3d &m1, const GfMatrix3d &m2)
Adds matrix m2 to m1.
Definition: matrix3d.h:380
GF_API friend GfMatrix3d operator-(const GfMatrix3d &m)
Returns the unary negation of matrix m.
GF_API GfMatrix3d & operator-=(const GfMatrix3d &m)
Subtracts matrix m from this matrix.
GF_API GfMatrix3d & SetRotate(const GfQuatd &rot)
Sets the matrix to specify a rotation equivalent to rot.
GF_API GfMatrix3d & operator*=(const GfMatrix3d &m)
Post-multiplies matrix m into this matrix.
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.
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:257
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3d.h:335
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix3d.h:250
GfMatrix3d(const GfVec3d &v)
Constructor.
Definition: matrix3d.h:124
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix3d.h:234
GF_API GfQuaternion ExtractRotationQuaternion() const
Returns the quaternion corresponding to this matrix.
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3d.h:286
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:82
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.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quatd.h:60
Basic type: 3-space rotation specification.
Definition: rotation.h:55
GF_API double GetHandedness() const
Returns the sign of the determinant of the matrix, i.e.
GfVec3d GetRow(int i) const
Gets a row of the matrix as a Vec3.
Definition: matrix3d.h:173
void SetRow(int i, const GfVec3d &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3d.h:159
friend GfMatrix3d operator/(const GfMatrix3d &m1, const GfMatrix3d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3d.h:404
friend size_t hash_value(GfMatrix3d const &m)
Hash.
Definition: matrix3d.h:265