This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
53 GfMatrix2d() = default;
54
58 GfMatrix2d(double m00, double m01,
59 double m10, double m11) {
60 Set(m00, m01,
61 m10, m11);
62 }
63
66 GfMatrix2d(const double m[2][2]) {
67 Set(m);
68 }
69
72 explicit GfMatrix2d(double s) {
73 SetDiagonal(s);
74 }
75
78 explicit GfMatrix2d(int s) {
79 SetDiagonal(s);
80 }
81
84 explicit GfMatrix2d(const GfVec2d& v) {
85 SetDiagonal(v);
86 }
87
94 GF_API
95 explicit GfMatrix2d(const std::vector< std::vector<double> >& v);
96
103 GF_API
104 explicit GfMatrix2d(const std::vector< std::vector<float> >& v);
105
107 GF_API
108 explicit GfMatrix2d(const class GfMatrix2f& m);
109
111 void SetRow(int i, const GfVec2d & v) {
112 _mtx[i][0] = v[0];
113 _mtx[i][1] = v[1];
114 }
115
117 void SetColumn(int i, const GfVec2d & v) {
118 _mtx[0][i] = v[0];
119 _mtx[1][i] = v[1];
120 }
121
123 GfVec2d GetRow(int i) const {
124 return GfVec2d(_mtx[i][0], _mtx[i][1]);
125 }
126
128 GfVec2d GetColumn(int i) const {
129 return GfVec2d(_mtx[0][i], _mtx[1][i]);
130 }
131
135 GfMatrix2d& Set(double m00, double m01,
136 double m10, double m11) {
137 _mtx[0][0] = m00; _mtx[0][1] = m01;
138 _mtx[1][0] = m10; _mtx[1][1] = m11;
139 return *this;
140 }
141
144 GfMatrix2d& Set(const double m[2][2]) {
145 _mtx[0][0] = m[0][0];
146 _mtx[0][1] = m[0][1];
147 _mtx[1][0] = m[1][0];
148 _mtx[1][1] = m[1][1];
149 return *this;
150 }
151
154 return SetDiagonal(1);
155 }
156
159 return SetDiagonal(0);
160 }
161
163 GF_API
165
167 GF_API
169
172 GF_API
173 double* Get(double m[2][2]) const;
174
177 double* data() {
178 return _mtx.GetData();
179 }
180
183 const double* data() const {
184 return _mtx.GetData();
185 }
186
188 double* GetArray() {
189 return _mtx.GetData();
190 }
191
193 const double* GetArray() const {
194 return _mtx.GetData();
195 }
196
200 double* operator [](int i) { return _mtx[i]; }
201
205 const double* operator [](int i) const { return _mtx[i]; }
206
208 friend inline size_t hash_value(GfMatrix2d const &m) {
209 return TfHash::Combine(
210 m._mtx[0][0],
211 m._mtx[0][1],
212 m._mtx[1][0],
213 m._mtx[1][1]
214 );
215 }
216
219 GF_API
220 bool operator ==(const GfMatrix2d& m) const;
221
224 GF_API
225 bool operator ==(const GfMatrix2f& m) const;
226
229 bool operator !=(const GfMatrix2d& m) const {
230 return !(*this == m);
231 }
232
235 bool operator !=(const GfMatrix2f& m) const {
236 return !(*this == m);
237 }
238
240 GF_API
242
248 GF_API
249 GfMatrix2d GetInverse(double* det = NULL, double eps = 0) const;
250
252 GF_API
253 double GetDeterminant() const;
254
255
257 GF_API
259
261 GF_API
263
265 friend GfMatrix2d operator *(const GfMatrix2d& m1, double d)
266 {
267 GfMatrix2d m = m1;
268 return m *= d;
269 }
270
272 // Returns the product of a matrix and a double.
273 friend GfMatrix2d operator *(double d, const GfMatrix2d& m)
274 {
275 return m * d;
276 }
277
279 GF_API
281
283 GF_API
285
287 GF_API
289
291 friend GfMatrix2d operator +(const GfMatrix2d& m1, const GfMatrix2d& m2)
292 {
293 GfMatrix2d tmp(m1);
294 tmp += m2;
295 return tmp;
296 }
297
299 friend GfMatrix2d operator -(const GfMatrix2d& m1, const GfMatrix2d& m2)
300 {
301 GfMatrix2d tmp(m1);
302 tmp -= m2;
303 return tmp;
304 }
305
307 friend GfMatrix2d operator *(const GfMatrix2d& m1, const GfMatrix2d& m2)
308 {
309 GfMatrix2d tmp(m1);
310 tmp *= m2;
311 return tmp;
312 }
313
315 friend GfMatrix2d operator /(const GfMatrix2d& m1, const GfMatrix2d& m2)
316 {
317 return(m1 * m2.GetInverse());
318 }
319
321 friend inline GfVec2d operator *(const GfMatrix2d& m, const GfVec2d& vec) {
322 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
323 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
324 }
325
327 friend inline GfVec2d operator *(const GfVec2d &vec, const GfMatrix2d& m) {
328 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
329 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
330 }
331
332
333private:
336
337 // Friend declarations
338 friend class GfMatrix2f;
339};
340
341
345GF_API
346bool GfIsClose(GfMatrix2d const &m1, GfMatrix2d const &m2, double tolerance);
347
350GF_API std::ostream& operator<<(std::ostream &, GfMatrix2d const &);
351
352PXR_NAMESPACE_CLOSE_SCOPE
353
354#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:72
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:144
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix2d.h:183
bool operator!=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2d.h:229
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:123
GF_API GfMatrix2d & operator*=(const GfMatrix2d &m)
Post-multiplies matrix m into this matrix.
GfMatrix2d(const GfVec2d &v)
Constructor.
Definition: matrix2d.h:84
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:265
GF_API GfMatrix2d(const std::vector< std::vector< double > > &v)
Constructor.
GfMatrix2d(const double m[2][2])
Constructor.
Definition: matrix2d.h:66
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:200
friend size_t hash_value(GfMatrix2d const &m)
Hash.
Definition: matrix2d.h:208
friend GfMatrix2d operator+(const GfMatrix2d &m1, const GfMatrix2d &m2)
Adds matrix m2 to m1.
Definition: matrix2d.h:291
GF_API GfMatrix2d GetTranspose() const
Returns the transpose of the matrix.
GfMatrix2d(double m00, double m01, double m10, double m11)
Constructor.
Definition: matrix2d.h:58
friend GfMatrix2d operator/(const GfMatrix2d &m1, const GfMatrix2d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2d.h:315
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:188
GfMatrix2d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2d.h:78
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix2d.h:177
GfMatrix2d & SetZero()
Sets the matrix to zero.
Definition: matrix2d.h:158
GF_API bool operator==(const GfMatrix2d &m) const
Tests for element-wise matrix equality.
GfMatrix2d()=default
Default constructor. Leaves the matrix component values undefined.
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:135
void SetRow(int i, const GfVec2d &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2d.h:111
GfMatrix2d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2d.h:153
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:128
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix2d.h:193
void SetColumn(int i, const GfVec2d &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2d.h:117
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:475
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