Loading...
Searching...
No Matches
matrix2d.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// matrix2.template.h file to make changes.
27
28#ifndef PXR_BASE_GF_MATRIX2D_H
29#define PXR_BASE_GF_MATRIX2D_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/vec2d.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 GfMatrix2d> { static const bool value = true; };
49
50class GfMatrix2d;
51class GfMatrix2f;
52
62{
63public:
64 typedef double ScalarType;
65
66 static const size_t numRows = 2;
67 static const size_t numColumns = 2;
68
70 GfMatrix2d() = default;
71
75 GfMatrix2d(double m00, double m01,
76 double m10, double m11) {
77 Set(m00, m01,
78 m10, m11);
79 }
80
83 GfMatrix2d(const double m[2][2]) {
84 Set(m);
85 }
86
89 explicit GfMatrix2d(double s) {
90 SetDiagonal(s);
91 }
92
95 explicit GfMatrix2d(int s) {
96 SetDiagonal(s);
97 }
98
101 explicit GfMatrix2d(const GfVec2d& v) {
102 SetDiagonal(v);
103 }
104
111 GF_API
112 explicit GfMatrix2d(const std::vector< std::vector<double> >& v);
113
120 GF_API
121 explicit GfMatrix2d(const std::vector< std::vector<float> >& v);
122
124 GF_API
125 explicit GfMatrix2d(const class GfMatrix2f& m);
126
128 void SetRow(int i, const GfVec2d & v) {
129 _mtx[i][0] = v[0];
130 _mtx[i][1] = v[1];
131 }
132
134 void SetColumn(int i, const GfVec2d & v) {
135 _mtx[0][i] = v[0];
136 _mtx[1][i] = v[1];
137 }
138
140 GfVec2d GetRow(int i) const {
141 return GfVec2d(_mtx[i][0], _mtx[i][1]);
142 }
143
145 GfVec2d GetColumn(int i) const {
146 return GfVec2d(_mtx[0][i], _mtx[1][i]);
147 }
148
152 GfMatrix2d& Set(double m00, double m01,
153 double m10, double m11) {
154 _mtx[0][0] = m00; _mtx[0][1] = m01;
155 _mtx[1][0] = m10; _mtx[1][1] = m11;
156 return *this;
157 }
158
161 GfMatrix2d& Set(const double m[2][2]) {
162 _mtx[0][0] = m[0][0];
163 _mtx[0][1] = m[0][1];
164 _mtx[1][0] = m[1][0];
165 _mtx[1][1] = m[1][1];
166 return *this;
167 }
168
171 return SetDiagonal(1);
172 }
173
176 return SetDiagonal(0);
177 }
178
180 GF_API
182
184 GF_API
186
189 GF_API
190 double* Get(double m[2][2]) const;
191
194 double* data() {
195 return _mtx.GetData();
196 }
197
200 const double* data() const {
201 return _mtx.GetData();
202 }
203
205 double* GetArray() {
206 return _mtx.GetData();
207 }
208
210 const double* GetArray() const {
211 return _mtx.GetData();
212 }
213
217 double* operator [](int i) { return _mtx[i]; }
218
222 const double* operator [](int i) const { return _mtx[i]; }
223
225 friend inline size_t hash_value(GfMatrix2d const &m) {
226 return TfHash::Combine(
227 m._mtx[0][0],
228 m._mtx[0][1],
229 m._mtx[1][0],
230 m._mtx[1][1]
231 );
232 }
233
236 GF_API
237 bool operator ==(const GfMatrix2d& m) const;
238
241 GF_API
242 bool operator ==(const GfMatrix2f& m) const;
243
246 bool operator !=(const GfMatrix2d& m) const {
247 return !(*this == m);
248 }
249
252 bool operator !=(const GfMatrix2f& m) const {
253 return !(*this == m);
254 }
255
257 GF_API
259
265 GF_API
266 GfMatrix2d GetInverse(double* det = NULL, double eps = 0) const;
267
269 GF_API
270 double GetDeterminant() const;
271
272
274 GF_API
276
278 GF_API
280
282 friend GfMatrix2d operator *(const GfMatrix2d& m1, double d)
283 {
284 GfMatrix2d m = m1;
285 return m *= d;
286 }
287
289 // Returns the product of a matrix and a double.
290 friend GfMatrix2d operator *(double d, const GfMatrix2d& m)
291 {
292 return m * d;
293 }
294
296 GF_API
298
300 GF_API
302
304 GF_API
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 GfMatrix2d tmp(m1);
319 tmp -= m2;
320 return tmp;
321 }
322
324 friend GfMatrix2d operator *(const GfMatrix2d& m1, const GfMatrix2d& m2)
325 {
326 GfMatrix2d tmp(m1);
327 tmp *= m2;
328 return tmp;
329 }
330
332 friend GfMatrix2d operator /(const GfMatrix2d& m1, const GfMatrix2d& m2)
333 {
334 return(m1 * m2.GetInverse());
335 }
336
338 friend inline GfVec2d operator *(const GfMatrix2d& m, const GfVec2d& vec) {
339 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
340 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
341 }
342
344 friend inline GfVec2d operator *(const GfVec2d &vec, const GfMatrix2d& m) {
345 return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
346 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
347 }
348
351 GF_API
352 friend GfVec2f operator *(const GfMatrix2d& m, const GfVec2f& vec);
353
356 GF_API
357 friend GfVec2f operator *(const GfVec2f &vec, const GfMatrix2d& m);
358
359
360private:
363
364 // Friend declarations
365 friend class GfMatrix2f;
366};
367
368
372GF_API
373bool GfIsClose(GfMatrix2d const &m1, GfMatrix2d const &m2, double tolerance);
374
377GF_API std::ostream& operator<<(std::ostream &, GfMatrix2d const &);
378
379PXR_NAMESPACE_CLOSE_SCOPE
380
381#endif // PXR_BASE_GF_MATRIX2D_H
Declares Gf types.
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:62
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:89
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:161
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix2d.h:200
bool operator!=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2d.h:246
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:140
GF_API GfMatrix2d & operator*=(const GfMatrix2d &m)
Post-multiplies matrix m into this matrix.
GfMatrix2d(const GfVec2d &v)
Constructor.
Definition: matrix2d.h:101
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:282
GF_API GfMatrix2d(const std::vector< std::vector< double > > &v)
Constructor.
GfMatrix2d(const double m[2][2])
Constructor.
Definition: matrix2d.h:83
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:217
friend size_t hash_value(GfMatrix2d const &m)
Hash.
Definition: matrix2d.h:225
friend GfMatrix2d operator+(const GfMatrix2d &m1, const GfMatrix2d &m2)
Adds matrix m2 to m1.
Definition: matrix2d.h:308
GF_API GfMatrix2d GetTranspose() const
Returns the transpose of the matrix.
GfMatrix2d(double m00, double m01, double m10, double m11)
Constructor.
Definition: matrix2d.h:75
friend GfMatrix2d operator/(const GfMatrix2d &m1, const GfMatrix2d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2d.h:332
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:205
GfMatrix2d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2d.h:95
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix2d.h:194
GfMatrix2d & SetZero()
Sets the matrix to zero.
Definition: matrix2d.h:175
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:152
void SetRow(int i, const GfVec2d &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2d.h:128
GfMatrix2d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2d.h:170
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:145
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix2d.h:210
void SetColumn(int i, const GfVec2d &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2d.h:134
Stores a 2x2 matrix of float elements.
Definition: matrix2f.h:62
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 for a vector of 2 double components.
Definition: vec2d.h:63
Basic type for a vector of 2 float components.
Definition: vec2f.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(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:42