Loading...
Searching...
No Matches
matrix3f.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_MATRIX3F_H
12#define PXR_BASE_GF_MATRIX3F_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/vec3f.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 GfMatrix3f> { static const bool value = true; };
32
33class GfMatrix3d;
34class GfMatrix3f;
35class GfRotation;
36class GfQuaternion;
37class GfQuatf;
38
65{
66public:
67 typedef float ScalarType;
68
69 static const size_t numRows = 3;
70 static const size_t numColumns = 3;
71
74 GfMatrix3f() = default;
75
79 GfMatrix3f(float m00, float m01, float m02,
80 float m10, float m11, float m12,
81 float m20, float m21, float m22) {
82 Set(m00, m01, m02,
83 m10, m11, m12,
84 m20, m21, m22);
85 }
86
89 GfMatrix3f(const float m[3][3]) {
90 Set(m);
91 }
92
95 explicit GfMatrix3f(float s) {
96 SetDiagonal(s);
97 }
98
101 explicit GfMatrix3f(int s) {
102 SetDiagonal(s);
103 }
104
107 explicit GfMatrix3f(const GfVec3f& v) {
108 SetDiagonal(v);
109 }
110
117 GF_API
118 explicit GfMatrix3f(const std::vector< std::vector<double> >& v);
119
126 GF_API
127 explicit GfMatrix3f(const std::vector< std::vector<float> >& v);
128
130 GF_API
132
134 GF_API
135 explicit GfMatrix3f(const GfQuatf& rot);
136
138 GF_API
139 explicit GfMatrix3f(const class GfMatrix3d& m);
140
142 void SetRow(int i, const GfVec3f & 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 GfVec3f & v) {
150 _mtx[0][i] = v[0];
151 _mtx[1][i] = v[1];
152 _mtx[2][i] = v[2];
153 }
154
156 GfVec3f GetRow(int i) const {
157 return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
158 }
159
161 GfVec3f GetColumn(int i) const {
162 return GfVec3f(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
163 }
164
168 GfMatrix3f& Set(float m00, float m01, float m02,
169 float m10, float m11, float m12,
170 float m20, float m21, float 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 GfMatrix3f& Set(const float 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 float* Get(float m[3][3]) const;
214
217 float* data() {
218 return _mtx.GetData();
219 }
220
223 const float* data() const {
224 return _mtx.GetData();
225 }
226
228 float* GetArray() {
229 return _mtx.GetData();
230 }
231
233 const float* GetArray() const {
234 return _mtx.GetData();
235 }
236
240 float* operator [](int i) { return _mtx[i]; }
241
245 const float* operator [](int i) const { return _mtx[i]; }
246
248 friend inline size_t hash_value(GfMatrix3f 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 GfMatrix3f 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 GfMatrix3f 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 GfMatrix3f operator *(const GfMatrix3f& m1, double d)
343 {
344 GfMatrix3f m = m1;
345 return m *= d;
346 }
347
349 // Returns the product of a matrix and a float.
350 friend GfMatrix3f operator *(double d, const GfMatrix3f& m)
351 {
352 return m * d;
353 }
354
356 GF_API
358
360 GF_API
362
364 GF_API
366
368 friend GfMatrix3f operator +(const GfMatrix3f& m1, const GfMatrix3f& m2)
369 {
370 GfMatrix3f tmp(m1);
371 tmp += m2;
372 return tmp;
373 }
374
376 friend GfMatrix3f operator -(const GfMatrix3f& m1, const GfMatrix3f& m2)
377 {
378 GfMatrix3f tmp(m1);
379 tmp -= m2;
380 return tmp;
381 }
382
384 friend GfMatrix3f operator *(const GfMatrix3f& m1, const GfMatrix3f& m2)
385 {
386 GfMatrix3f tmp(m1);
387 tmp *= m2;
388 return tmp;
389 }
390
392 friend GfMatrix3f operator /(const GfMatrix3f& m1, const GfMatrix3f& m2)
393 {
394 return(m1 * m2.GetInverse());
395 }
396
398 friend inline GfVec3f operator *(const GfMatrix3f& m, const GfVec3f& vec) {
399 return GfVec3f(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 GfVec3f operator *(const GfVec3f &vec, const GfMatrix3f& m) {
406 return GfVec3f(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 GfMatrix3f& SetScale(float scaleFactor);
414
417
419 GF_API
421
423 GF_API
425
428 GF_API
429 GfMatrix3f& SetScale(const GfVec3f &scaleFactors);
430
436 GF_API
438
445 GF_API
447 const GfVec3f &axis1,
448 const GfVec3f &axis2 ) const;
449
455 GF_API
457
459
460private:
463 void _SetRotateFromQuat(float r, const GfVec3f& i);
464
465
466private:
469
470 // Friend declarations
471 friend class GfMatrix3d;
472};
473
474
478GF_API
479bool GfIsClose(GfMatrix3f const &m1, GfMatrix3f const &m2, double tolerance);
480
483GF_API std::ostream& operator<<(std::ostream &, GfMatrix3f const &);
484
485PXR_NAMESPACE_CLOSE_SCOPE
486
487#endif // PXR_BASE_GF_MATRIX3F_H
Declares Gf types.
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:65
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:65
GF_API GfMatrix3f(const GfQuatf &rot)
Constructor. Initialize matrix from a quaternion.
const float * GetArray() const
Returns vector components as a const array of float values.
Definition: matrix3f.h:233
float * data()
Returns raw access to components of matrix as an array of float values.
Definition: matrix3f.h:217
GF_API GfMatrix3f & operator+=(const GfMatrix3f &m)
Adds matrix m to this matrix.
friend size_t hash_value(GfMatrix3f const &m)
Hash.
Definition: matrix3f.h:248
GfVec3f GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3f.h:161
GfMatrix3f & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3f.h:193
GfMatrix3f & SetZero()
Sets the matrix to zero.
Definition: matrix3f.h:198
GF_API GfMatrix3f & SetRotate(const GfRotation &rot)
Sets the matrix to specify a rotation equivalent to rot.
GfMatrix3f()=default
GfMatrix3f value-initializes to zero and performs no default initialization, like float or double.
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.
GF_API GfMatrix3f & SetDiagonal(float s)
Sets the matrix to s times the identity matrix.
GfMatrix3f(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Constructor.
Definition: matrix3f.h:79
GF_API GfMatrix3f & operator-=(const GfMatrix3f &m)
Subtracts matrix m from this matrix.
GF_API GfQuaternion ExtractRotationQuaternion() const
Returns the quaternion corresponding to this matrix.
GfVec3f GetRow(int i) const
Gets a row of the matrix as a Vec3.
Definition: matrix3f.h:156
const float * data() const
Returns const raw access to components of matrix as an array of float values.
Definition: matrix3f.h:223
GF_API GfMatrix3f & SetDiagonal(const GfVec3f &)
Sets the matrix to have diagonal (v[0], v[1], v[2]).
GF_API GfMatrix3f(const std::vector< std::vector< float > > &v)
Constructor.
GF_API GfMatrix3f & SetRotate(const GfQuatf &rot)
Sets the matrix to specify a rotation equivalent to rot.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
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:107
GF_API GfMatrix3f & SetScale(float scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
GF_API friend GfMatrix3f operator-(const GfMatrix3f &m)
Returns the unary negation of matrix m.
friend GfMatrix3f operator*(const GfMatrix3f &m1, double d)
Returns the product of a matrix and a float.
Definition: matrix3f.h:342
GF_API bool operator==(const GfMatrix3d &m) const
Tests for element-wise matrix equality.
GF_API GfMatrix3f GetTranspose() const
Returns the transpose of the matrix.
friend GfMatrix3f operator/(const GfMatrix3f &m1, const GfMatrix3f &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix3f.h:392
GF_API GfMatrix3f(const GfRotation &rot)
Constructor. Initialize matrix from rotation.
friend GfMatrix3f operator+(const GfMatrix3f &m1, const GfMatrix3f &m2)
Adds matrix m2 to m1.
Definition: matrix3f.h:368
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:240
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:168
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:179
GF_API double GetHandedness() const
Returns the sign of the determinant of the matrix, i.e.
GF_API GfMatrix3f & SetScale(const GfVec3f &scaleFactors)
Sets the matrix to specify a nonuniform scaling in x, y, and z by the factors in vector scaleFactors.
float * GetArray()
Returns vector components as an array of float values.
Definition: matrix3f.h:228
GF_API GfMatrix3f(const std::vector< std::vector< double > > &v)
Constructor.
GfMatrix3f(const float m[3][3])
Constructor.
Definition: matrix3f.h:89
void SetColumn(int i, const GfVec3f &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3f.h:149
GF_API GfMatrix3f GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
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.
GfMatrix3f(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix3f.h:101
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3f.h:274
GF_API GfMatrix3f(const class GfMatrix3d &m)
This explicit constructor converts a "double" matrix to a "float" matrix.
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
bool IsLeftHanded() const
Returns true if the vectors in matrix form a left-handed coordinate system.
Definition: matrix3f.h:329
void SetRow(int i, const GfVec3f &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3f.h:142
GfMatrix3f(float s)
Constructor.
Definition: matrix3f.h:95
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3f.h:323
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
GF_API GfMatrix3f & operator*=(const GfMatrix3f &m)
Post-multiplies matrix m into this matrix.
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: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:33
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:43
Basic type: 3-space rotation specification.
Definition: rotation.h:37
Basic type for a vector of 3 float components.
Definition: vec3f.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(GfMatrix3f const &m1, GfMatrix3f 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