Loading...
Searching...
No Matches
matrix2d.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// matrix2.template.h file to make changes.
10
11#ifndef PXR_BASE_GF_MATRIX2D_H
12#define PXR_BASE_GF_MATRIX2D_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/vec2d.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 GfMatrix2d> { static const bool value = true; };
32
33class GfMatrix2d;
34class GfMatrix2f;
35
45{
46public:
47 typedef double ScalarType;
48
49 static const size_t numRows = 2;
50 static const size_t numColumns = 2;
51
54 GfMatrix2d() = default;
55
59 GfMatrix2d(double m00, double m01,
60 double m10, double m11) {
61 Set(m00, m01,
62 m10, m11);
63 }
64
67 GfMatrix2d(const double m[2][2]) {
68 Set(m);
69 }
70
73 explicit GfMatrix2d(double s) {
74 SetDiagonal(s);
75 }
76
79 explicit GfMatrix2d(int s) {
80 SetDiagonal(s);
81 }
82
85 explicit GfMatrix2d(const GfVec2d& v) {
86 SetDiagonal(v);
87 }
88
95 GF_API
96 explicit GfMatrix2d(const std::vector< std::vector<double> >& v);
97
104 GF_API
105 explicit GfMatrix2d(const std::vector< std::vector<float> >& v);
106
108 GF_API
109 explicit GfMatrix2d(const class GfMatrix2f& m);
110
112 void SetRow(int i, const GfVec2d & v) {
113 _mtx[i][0] = v[0];
114 _mtx[i][1] = v[1];
115 }
116
118 void SetColumn(int i, const GfVec2d & v) {
119 _mtx[0][i] = v[0];
120 _mtx[1][i] = v[1];
121 }
122
124 GfVec2d GetRow(int i) const {
125 return GfVec2d(_mtx[i][0], _mtx[i][1]);
126 }
127
129 GfVec2d GetColumn(int i) const {
130 return GfVec2d(_mtx[0][i], _mtx[1][i]);
131 }
132
136 GfMatrix2d& Set(double m00, double m01,
137 double m10, double m11) {
138 _mtx[0][0] = m00; _mtx[0][1] = m01;
139 _mtx[1][0] = m10; _mtx[1][1] = m11;
140 return *this;
141 }
142
145 GfMatrix2d& Set(const double m[2][2]) {
146 _mtx[0][0] = m[0][0];
147 _mtx[0][1] = m[0][1];
148 _mtx[1][0] = m[1][0];
149 _mtx[1][1] = m[1][1];
150 return *this;
151 }
152
155 return SetDiagonal(1);
156 }
157
160 return SetDiagonal(0);
161 }
162
164 GF_API
166
168 GF_API
170
173 GF_API
174 double* Get(double m[2][2]) const;
175
178 double* data() {
179 return _mtx.GetData();
180 }
181
184 const double* data() const {
185 return _mtx.GetData();
186 }
187
189 double* GetArray() {
190 return _mtx.GetData();
191 }
192
194 const double* GetArray() const {
195 return _mtx.GetData();
196 }
197
201 double* operator [](int i) { return _mtx[i]; }
202
206 const double* operator [](int i) const { return _mtx[i]; }
207
209 friend inline size_t hash_value(GfMatrix2d const &m) {
210 return TfHash::Combine(
211 m._mtx[0][0],
212 m._mtx[0][1],
213 m._mtx[1][0],
214 m._mtx[1][1]
215 );
216 }
217
220 GF_API
221 bool operator ==(const GfMatrix2d& m) const;
222
225 GF_API
226 bool operator ==(const GfMatrix2f& m) const;
227
230 bool operator !=(const GfMatrix2d& m) const {
231 return !(*this == m);
232 }
233
236 bool operator !=(const GfMatrix2f& m) const {
237 return !(*this == m);
238 }
239
241 GF_API
243
249 GF_API
250 GfMatrix2d GetInverse(double* det = NULL, double eps = 0) const;
251
253 GF_API
254 double GetDeterminant() const;
255
256
258 GF_API
260
262 GF_API
264
266 friend GfMatrix2d operator *(const GfMatrix2d& m1, double d)
267 {
268 GfMatrix2d m = m1;
269 return m *= d;
270 }
271
273 // Returns the product of a matrix and a double.
274 friend GfMatrix2d operator *(double d, const GfMatrix2d& m)
275 {
276 return m * d;
277 }
278
280 GF_API
282
284 GF_API
286
288 GF_API
290
292 friend GfMatrix2d operator +(const GfMatrix2d& m1, const GfMatrix2d& m2)
293 {
294 GfMatrix2d tmp(m1);
295 tmp += m2;
296 return tmp;
297 }
298
300 friend GfMatrix2d operator -(const GfMatrix2d& m1, const GfMatrix2d& m2)
301 {
302 GfMatrix2d tmp(m1);
303 tmp -= m2;
304 return tmp;
305 }
306
308 friend GfMatrix2d operator *(const GfMatrix2d& m1, const GfMatrix2d& m2)
309 {
310 GfMatrix2d tmp(m1);
311 tmp *= m2;
312 return tmp;
313 }
314
316 friend GfMatrix2d operator /(const GfMatrix2d& m1, const GfMatrix2d& m2)
317 {
318 return(m1 * m2.GetInverse());
319 }
320
322 friend inline GfVec2d operator *(const GfMatrix2d& m, const GfVec2d& vec) {
323 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
324 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
325 }
326
328 friend inline GfVec2d operator *(const GfVec2d &vec, const GfMatrix2d& m) {
329 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
330 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
331 }
332
333
334private:
337
338 // Friend declarations
339 friend class GfMatrix2f;
340};
341
342
346GF_API
347bool GfIsClose(GfMatrix2d const &m1, GfMatrix2d const &m2, double tolerance);
348
351GF_API std::ostream& operator<<(std::ostream &, GfMatrix2d const &);
352
353PXR_NAMESPACE_CLOSE_SCOPE
354
355#endif // PXR_BASE_GF_MATRIX2D_H
Declares Gf types.
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:45
GF_API GfMatrix2d(const class GfMatrix2f &m)
This explicit constructor converts a "float" matrix to a "double" matrix.
GF_API double * Get(double m[2][2]) const
Fills a 2x2 array of double values with the values in the matrix, specified in row-major order.
GfMatrix2d(double s)
Constructor.
Definition: matrix2d.h:73
GF_API GfMatrix2d & operator+=(const GfMatrix2d &m)
Adds matrix m to this matrix.
GfMatrix2d & Set(const double m[2][2])
Sets the matrix from a 2x2 array of double values, specified in row-major order.
Definition: matrix2d.h:145
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix2d.h:184
bool operator!=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2d.h:230
GF_API GfMatrix2d & SetDiagonal(const GfVec2d &)
Sets the matrix to have diagonal (v[0], v[1]).
GfVec2d GetRow(int i) const
Gets a row of the matrix as a Vec2.
Definition: matrix2d.h:124
GF_API GfMatrix2d & operator*=(const GfMatrix2d &m)
Post-multiplies matrix m into this matrix.
GfMatrix2d(const GfVec2d &v)
Constructor.
Definition: matrix2d.h:85
GF_API GfMatrix2d & operator-=(const GfMatrix2d &m)
Subtracts matrix m from this matrix.
friend GfMatrix2d operator*(const GfMatrix2d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix2d.h:266
GF_API GfMatrix2d(const std::vector< std::vector< double > > &v)
Constructor.
GfMatrix2d(const double m[2][2])
Constructor.
Definition: matrix2d.h:67
GF_API GfMatrix2d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
GF_API GfMatrix2d 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 2 double values so that standard indexing (suc...
Definition: matrix2d.h:201
friend size_t hash_value(GfMatrix2d const &m)
Hash.
Definition: matrix2d.h:209
friend GfMatrix2d operator+(const GfMatrix2d &m1, const GfMatrix2d &m2)
Adds matrix m2 to m1.
Definition: matrix2d.h:292
GF_API GfMatrix2d GetTranspose() const
Returns the transpose of the matrix.
GfMatrix2d(double m00, double m01, double m10, double m11)
Constructor.
Definition: matrix2d.h:59
friend GfMatrix2d operator/(const GfMatrix2d &m1, const GfMatrix2d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2d.h:316
GF_API GfMatrix2d(const std::vector< std::vector< float > > &v)
Constructor.
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix2d.h:189
GfMatrix2d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2d.h:79
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix2d.h:178
GfMatrix2d & SetZero()
Sets the matrix to zero.
Definition: matrix2d.h:159
GF_API bool operator==(const GfMatrix2d &m) const
Tests for element-wise matrix equality.
GfMatrix2d()=default
GfMatrix2d value-initializes to zero and performs no default initialization, like float or double.
GfMatrix2d & Set(double m00, double m01, double m10, double m11)
Sets the matrix from 4 independent double values, specified in row-major order.
Definition: matrix2d.h:136
void SetRow(int i, const GfVec2d &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2d.h:112
GfMatrix2d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2d.h:154
GF_API friend GfMatrix2d operator-(const GfMatrix2d &m)
Returns the unary negation of matrix m.
GfVec2d GetColumn(int i) const
Gets a column of the matrix as a Vec2.
Definition: matrix2d.h:129
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix2d.h:194
void SetColumn(int i, const GfVec2d &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2d.h:118
Stores a 2x2 matrix of float elements.
Definition: matrix2f.h:45
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 for a vector of 2 double components.
Definition: vec2d.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(GfMatrix2d const &m1, GfMatrix2d 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