All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
matrix3f.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_MATRIX3F_H
29 #define GF_MATRIX3F_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/vec3f.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 GfMatrix3f> { static const bool value = true; };
50 
51 class GfMatrix3d;
52 class GfMatrix3f;
53 class GfRotation;
54 class GfQuaternion;
55 class GfQuatf;
56 
83 {
84 public:
85  typedef float ScalarType;
86 
87  static const size_t numRows = 3;
88  static const size_t numColumns = 3;
89 
91  GfMatrix3f() = default;
92 
96  GfMatrix3f(float m00, float m01, float m02,
97  float m10, float m11, float m12,
98  float m20, float m21, float m22) {
99  Set(m00, m01, m02,
100  m10, m11, m12,
101  m20, m21, m22);
102  }
103 
106  GfMatrix3f(const float m[3][3]) {
107  Set(m);
108  }
109 
112  explicit GfMatrix3f(float s) {
113  SetDiagonal(s);
114  }
115 
118  explicit GfMatrix3f(int s) {
119  SetDiagonal(s);
120  }
121 
124  explicit GfMatrix3f(const GfVec3f& v) {
125  SetDiagonal(v);
126  }
127 
134  GF_API
135  explicit GfMatrix3f(const std::vector< std::vector<double> >& v);
136 
143  GF_API
144  explicit GfMatrix3f(const std::vector< std::vector<float> >& v);
145 
147  GF_API
148  GfMatrix3f(const GfRotation& rot);
149 
151  GF_API
152  explicit GfMatrix3f(const GfQuatf& rot);
153 
155  GF_API
156  explicit GfMatrix3f(const class GfMatrix3d& m);
157 
159  void SetRow(int i, const GfVec3f & 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 GfVec3f & v) {
167  _mtx[0][i] = v[0];
168  _mtx[1][i] = v[1];
169  _mtx[2][i] = v[2];
170  }
171 
173  GfVec3f GetRow(int i) const {
174  return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
175  }
176 
178  GfVec3f GetColumn(int i) const {
179  return GfVec3f(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
180  }
181 
185  GfMatrix3f& Set(float m00, float m01, float m02,
186  float m10, float m11, float m12,
187  float m20, float m21, float 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  GfMatrix3f& Set(const float 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  GfMatrix3f& SetDiagonal(float s);
222 
224  GF_API
225  GfMatrix3f& SetDiagonal(const GfVec3f&);
226 
229  GF_API
230  float* Get(float m[3][3]) const;
231 
234  float* data() {
235  return _mtx.GetData();
236  }
237 
240  const float* data() const {
241  return _mtx.GetData();
242  }
243 
245  float* GetArray() {
246  return _mtx.GetData();
247  }
248 
250  const float* GetArray() const {
251  return _mtx.GetData();
252  }
253 
257  float* operator [](int i) { return _mtx[i]; }
258 
262  const float* operator [](int i) const { return _mtx[i]; }
263 
265  friend inline size_t hash_value(GfMatrix3f const &m) {
266  int nElems = 3 * 3;
267  size_t h = 0;
268  const float *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  GfMatrix3f GetTranspose() const;
299 
305  GF_API
306  GfMatrix3f 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  GfMatrix3f 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  GfMatrix3f& operator *=(const GfMatrix3f& m);
348 
350  GF_API
351  GfMatrix3f& operator *=(double);
352 
354  friend GfMatrix3f operator *(const GfMatrix3f& m1, double d)
355  {
356  GfMatrix3f m = m1;
357  return m *= d;
358  }
359 
361  // Returns the product of a matrix and a float.
362  friend GfMatrix3f operator *(double d, const GfMatrix3f& m)
363  {
364  return m * d;
365  }
366 
368  GF_API
369  GfMatrix3f& operator +=(const GfMatrix3f& m);
370 
372  GF_API
373  GfMatrix3f& operator -=(const GfMatrix3f& m);
374 
376  GF_API
377  friend GfMatrix3f operator -(const GfMatrix3f& m);
378 
380  friend GfMatrix3f operator +(const GfMatrix3f& m1, const GfMatrix3f& m2)
381  {
382  GfMatrix3f tmp(m1);
383  tmp += m2;
384  return tmp;
385  }
386 
388  friend GfMatrix3f operator -(const GfMatrix3f& m1, const GfMatrix3f& m2)
389  {
390  GfMatrix3f tmp(m1);
391  tmp -= m2;
392  return tmp;
393  }
394 
396  friend GfMatrix3f operator *(const GfMatrix3f& m1, const GfMatrix3f& m2)
397  {
398  GfMatrix3f tmp(m1);
399  tmp *= m2;
400  return tmp;
401  }
402 
404  friend GfMatrix3f operator /(const GfMatrix3f& m1, const GfMatrix3f& m2)
405  {
406  return(m1 * m2.GetInverse());
407  }
408 
410  friend inline GfVec3f operator *(const GfMatrix3f& m, const GfVec3f& vec) {
411  return GfVec3f(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 GfVec3f operator *(const GfVec3f &vec, const GfMatrix3f& m) {
418  return GfVec3f(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 
424  GF_API
425  GfMatrix3f& SetScale(float scaleFactor);
426 
429 
431  GF_API
432  GfMatrix3f& SetRotate(const GfQuatf &rot);
433 
435  GF_API
436  GfMatrix3f& SetRotate(const GfRotation &rot);
437 
440  GF_API
441  GfMatrix3f& SetScale(const GfVec3f &scaleFactors);
442 
448  GF_API
449  GfRotation ExtractRotation() const;
450 
457  GF_API
458  GfVec3f DecomposeRotation(const GfVec3f &axis0,
459  const GfVec3f &axis1,
460  const GfVec3f &axis2 ) const;
461 
467  GF_API
469 
471 
472 private:
475  void _SetRotateFromQuat(float r, const GfVec3f& i);
476 
477 
478 private:
480  GfMatrixData<float, 3, 3> _mtx;
481 
482  // Friend declarations
483  friend class GfMatrix3d;
484 };
485 
486 
490 GF_API
491 bool GfIsClose(GfMatrix3f const &m1, GfMatrix3f const &m2, double tolerance);
492 
495 GF_API std::ostream& operator<<(std::ostream &, GfMatrix3f const &);
496 
497 PXR_NAMESPACE_CLOSE_SCOPE
498 
499 #endif // GF_MATRIX3F_H
const float * data() const
Returns const raw access to components of matrix as an array of float values.
Definition: matrix3f.h:240
const float * GetArray() const
Returns vector components as a const array of float values.
Definition: matrix3f.h:250
friend GfMatrix3f operator/(const GfMatrix3f &m1, const GfMatrix3f &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3f.h:404
friend GfMatrix3f operator*(const GfMatrix3f &m1, double d)
Returns the product of a matrix and a float.
Definition: matrix3f.h:354
GfMatrix3f(float s)
Constructor.
Definition: matrix3f.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
GF_API float * Get(float m[3][3]) const
Fills a 3x3 array of float values with the values in the matrix, specified in row-major order...
float * GetArray()
Returns vector components as an array of float values.
Definition: matrix3f.h:245
GF_API GfVec3f DecomposeRotation(const GfVec3f &axis0, const GfVec3f &axis1, const GfVec3f &axis2) const
Decompose the rotation corresponding to this matrix about 3 orthogonal axes.
GfMatrix3f(const GfVec3f &v)
Constructor.
Definition: matrix3f.h:124
GF_API GfMatrix3f & SetRotate(const GfQuatf &rot)
Sets the matrix to specify a rotation equivalent to rot.
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
GF_API GfMatrix3f & operator-=(const GfMatrix3f &m)
Subtracts matrix m from this matrix.
GF_API GfMatrix3f & operator*=(const GfMatrix3f &m)
Post-multiplies matrix m into this matrix.
Basic type: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:50
bool IsLeftHanded() const
Returns true if the vectors in matrix form a left-handed coordinate system.
Definition: matrix3f.h:341
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients...
Definition: quatf.h:60
GfMatrix3f & Set(const float m[3][3])
Sets the matrix from a 3x3 array of float values, specified in row-major order.
Definition: matrix3f.h:196
void SetRow(int i, const GfVec3f &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3f.h:159
GfVec3f GetRow(int i) const
Gets a row of the matrix as a Vec3.
Definition: matrix3f.h:173
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:82
GfMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Constructor.
Definition: matrix3f.h:96
GF_API GfMatrix3f & operator+=(const GfMatrix3f &m)
Adds matrix m to this matrix.
GF_API GfMatrix3f GetInverse(double *det=NULL, double eps=0) const
Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the matrix is singular.
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3f.h:335
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
void SetColumn(int i, const GfVec3f &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3f.h:166
GF_API bool operator==(const GfMatrix3d &m) const
Tests for element-wise matrix equality.
GF_API GfMatrix3f GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
GfMatrix3f(const float m[3][3])
Constructor.
Definition: matrix3f.h:106
GF_API friend GfMatrix3f operator-(const GfMatrix3f &m)
Returns the unary negation of matrix m.
GfVec3f GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3f.h:178
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3f.h:286
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfMatrix3f()=default
Default constructor. Leaves the matrix component values undefined.
GfMatrix3f & Set(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Sets the matrix from 9 independent float values, specified in row-major order.
Definition: matrix3f.h:185
GF_API double GetHandedness() const
Returns the sign of the determinant of the matrix, i.e.
float * data()
Returns raw access to components of matrix as an array of float values.
Definition: matrix3f.h:234
GfMatrix3f & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3f.h:210
GfMatrix3f(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3f.h:118
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:82
GF_API GfMatrix3f & SetDiagonal(float s)
Sets the matrix to s times the identity matrix.
friend size_t hash_value(GfMatrix3f const &m)
Hash.
Definition: matrix3f.h:265
float * operator[](int i)
Accesses an indexed row i of the matrix as an array of 3 float values so that standard indexing (such...
Definition: matrix3f.h:257
GF_API GfMatrix3f & SetScale(float scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
Basic type: 3-space rotation specification.
Definition: rotation.h:55
GF_API GfMatrix3f GetTranspose() const
Returns the transpose of the matrix.
GF_API GfQuaternion ExtractRotationQuaternion() const
Returns the quaternion corresponding to this matrix.
GfMatrix3f & SetZero()
Sets the matrix to zero.
Definition: matrix3f.h:215
friend GfMatrix3f operator+(const GfMatrix3f &m1, const GfMatrix3f &m2)
Adds matrix m2 to m1.
Definition: matrix3f.h:380