Loading...
Searching...
No Matches
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 PXR_BASE_GF_MATRIX3F_H
29#define PXR_BASE_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#include "pxr/base/tf/hash.h"
41
42#include <iosfwd>
43#include <vector>
44
45PXR_NAMESPACE_OPEN_SCOPE
46
47template <>
48struct GfIsGfMatrix<class GfMatrix3f> { static const bool value = true; };
49
50class GfMatrix3d;
51class GfMatrix3f;
52class GfRotation;
53class GfQuaternion;
54class GfQuatf;
55
82{
83public:
84 typedef float ScalarType;
85
86 static const size_t numRows = 3;
87 static const size_t numColumns = 3;
88
90 GfMatrix3f() = default;
91
95 GfMatrix3f(float m00, float m01, float m02,
96 float m10, float m11, float m12,
97 float m20, float m21, float m22) {
98 Set(m00, m01, m02,
99 m10, m11, m12,
100 m20, m21, m22);
101 }
102
105 GfMatrix3f(const float m[3][3]) {
106 Set(m);
107 }
108
111 explicit GfMatrix3f(float s) {
112 SetDiagonal(s);
113 }
114
117 explicit GfMatrix3f(int s) {
118 SetDiagonal(s);
119 }
120
123 explicit GfMatrix3f(const GfVec3f& v) {
124 SetDiagonal(v);
125 }
126
133 GF_API
134 explicit GfMatrix3f(const std::vector< std::vector<double> >& v);
135
142 GF_API
143 explicit GfMatrix3f(const std::vector< std::vector<float> >& v);
144
146 GF_API
148
150 GF_API
151 explicit GfMatrix3f(const GfQuatf& rot);
152
154 GF_API
155 explicit GfMatrix3f(const class GfMatrix3d& m);
156
158 void SetRow(int i, const GfVec3f & 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 GfVec3f & v) {
166 _mtx[0][i] = v[0];
167 _mtx[1][i] = v[1];
168 _mtx[2][i] = v[2];
169 }
170
172 GfVec3f GetRow(int i) const {
173 return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
174 }
175
177 GfVec3f GetColumn(int i) const {
178 return GfVec3f(_mtx[0][i], _mtx[1][i], _mtx[2][i]);
179 }
180
184 GfMatrix3f& Set(float m00, float m01, float m02,
185 float m10, float m11, float m12,
186 float m20, float m21, float 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 GfMatrix3f& Set(const float 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
221
223 GF_API
225
228 GF_API
229 float* Get(float m[3][3]) const;
230
233 float* data() {
234 return _mtx.GetData();
235 }
236
239 const float* data() const {
240 return _mtx.GetData();
241 }
242
244 float* GetArray() {
245 return _mtx.GetData();
246 }
247
249 const float* GetArray() const {
250 return _mtx.GetData();
251 }
252
256 float* operator [](int i) { return _mtx[i]; }
257
261 const float* operator [](int i) const { return _mtx[i]; }
262
264 friend inline size_t hash_value(GfMatrix3f 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
303
309 GF_API
310 GfMatrix3f 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 GfMatrix3f 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
352
354 GF_API
356
358 friend GfMatrix3f operator *(const GfMatrix3f& m1, double d)
359 {
360 GfMatrix3f m = m1;
361 return m *= d;
362 }
363
365 // Returns the product of a matrix and a float.
366 friend GfMatrix3f operator *(double d, const GfMatrix3f& m)
367 {
368 return m * d;
369 }
370
372 GF_API
374
376 GF_API
378
380 GF_API
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 GfMatrix3f tmp(m1);
395 tmp -= m2;
396 return tmp;
397 }
398
400 friend GfMatrix3f operator *(const GfMatrix3f& m1, const GfMatrix3f& m2)
401 {
402 GfMatrix3f tmp(m1);
403 tmp *= m2;
404 return tmp;
405 }
406
408 friend GfMatrix3f operator /(const GfMatrix3f& m1, const GfMatrix3f& m2)
409 {
410 return(m1 * m2.GetInverse());
411 }
412
414 friend inline GfVec3f operator *(const GfMatrix3f& m, const GfVec3f& vec) {
415 return GfVec3f(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 GfVec3f operator *(const GfVec3f &vec, const GfMatrix3f& m) {
422 return GfVec3f(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
428 GF_API
429 GfMatrix3f& SetScale(float scaleFactor);
430
433
435 GF_API
437
439 GF_API
441
444 GF_API
445 GfMatrix3f& SetScale(const GfVec3f &scaleFactors);
446
452 GF_API
454
461 GF_API
463 const GfVec3f &axis1,
464 const GfVec3f &axis2 ) const;
465
471 GF_API
473
475
476private:
479 void _SetRotateFromQuat(float r, const GfVec3f& i);
480
481
482private:
485
486 // Friend declarations
487 friend class GfMatrix3d;
488};
489
490
494GF_API
495bool GfIsClose(GfMatrix3f const &m1, GfMatrix3f const &m2, double tolerance);
496
499GF_API std::ostream& operator<<(std::ostream &, GfMatrix3f const &);
500
501PXR_NAMESPACE_CLOSE_SCOPE
502
503#endif // PXR_BASE_GF_MATRIX3F_H
Declares Gf types.
Stores a 3x3 matrix of double elements.
Definition: matrix3d.h:82
Stores a 3x3 matrix of float elements.
Definition: matrix3f.h:82
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:249
float * data()
Returns raw access to components of matrix as an array of float values.
Definition: matrix3f.h:233
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:264
GfVec3f GetColumn(int i) const
Gets a column of the matrix as a Vec3.
Definition: matrix3f.h:177
GfMatrix3f & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix3f.h:209
GfMatrix3f & SetZero()
Sets the matrix to zero.
Definition: matrix3f.h:214
GF_API GfMatrix3f & SetRotate(const GfRotation &rot)
Sets the matrix to specify a rotation equivalent to rot.
GfMatrix3f()=default
Default constructor. Leaves the matrix component values undefined.
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:95
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:172
const float * data() const
Returns const raw access to components of matrix as an array of float values.
Definition: matrix3f.h:239
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:123
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:358
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:408
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:384
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:256
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:184
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:195
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:244
GF_API GfMatrix3f(const std::vector< std::vector< double > > &v)
Constructor.
GfMatrix3f(const float m[3][3])
Constructor.
Definition: matrix3f.h:105
void SetColumn(int i, const GfVec3f &v)
Sets a column of the matrix from a Vec3.
Definition: matrix3f.h:165
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:117
bool operator!=(const GfMatrix3d &m) const
Tests for element-wise matrix inequality.
Definition: matrix3f.h:290
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:345
void SetRow(int i, const GfVec3f &v)
Sets a row of the matrix from a Vec3.
Definition: matrix3f.h:158
GfMatrix3f(float s)
Constructor.
Definition: matrix3f.h:111
bool IsRightHanded() const
Returns true if the vectors in the matrix form a right-handed coordinate system.
Definition: matrix3f.h:339
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:36
T * GetData()
Return a pointer to the start of all the data.
Definition: matrixData.h:50
Basic type: complex number with scalar real part and vector imaginary part.
Definition: quaternion.h:50
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quatf.h:60
Basic type: 3-space rotation specification.
Definition: rotation.h:54
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
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:42