All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
41 #include <boost/functional/hash.hpp>
42 
43 #include <iosfwd>
44 #include <vector>
45 
46 PXR_NAMESPACE_OPEN_SCOPE
47 
48 template <>
49 struct GfIsGfMatrix<class GfMatrix2d> { static const bool value = true; };
50 
51 class GfMatrix2d;
52 class GfMatrix2f;
53 
63 {
64 public:
65  typedef double ScalarType;
66 
67  static const size_t numRows = 2;
68  static const size_t numColumns = 2;
69 
71  GfMatrix2d() = default;
72 
76  GfMatrix2d(double m00, double m01,
77  double m10, double m11) {
78  Set(m00, m01,
79  m10, m11);
80  }
81 
84  GfMatrix2d(const double m[2][2]) {
85  Set(m);
86  }
87 
90  explicit GfMatrix2d(double s) {
91  SetDiagonal(s);
92  }
93 
96  explicit GfMatrix2d(int s) {
97  SetDiagonal(s);
98  }
99 
102  explicit GfMatrix2d(const GfVec2d& v) {
103  SetDiagonal(v);
104  }
105 
112  GF_API
113  explicit GfMatrix2d(const std::vector< std::vector<double> >& v);
114 
121  GF_API
122  explicit GfMatrix2d(const std::vector< std::vector<float> >& v);
123 
125  GF_API
126  explicit GfMatrix2d(const class GfMatrix2f& m);
127 
129  void SetRow(int i, const GfVec2d & v) {
130  _mtx[i][0] = v[0];
131  _mtx[i][1] = v[1];
132  }
133 
135  void SetColumn(int i, const GfVec2d & v) {
136  _mtx[0][i] = v[0];
137  _mtx[1][i] = v[1];
138  }
139 
141  GfVec2d GetRow(int i) const {
142  return GfVec2d(_mtx[i][0], _mtx[i][1]);
143  }
144 
146  GfVec2d GetColumn(int i) const {
147  return GfVec2d(_mtx[0][i], _mtx[1][i]);
148  }
149 
153  GfMatrix2d& Set(double m00, double m01,
154  double m10, double m11) {
155  _mtx[0][0] = m00; _mtx[0][1] = m01;
156  _mtx[1][0] = m10; _mtx[1][1] = m11;
157  return *this;
158  }
159 
162  GfMatrix2d& Set(const double m[2][2]) {
163  _mtx[0][0] = m[0][0];
164  _mtx[0][1] = m[0][1];
165  _mtx[1][0] = m[1][0];
166  _mtx[1][1] = m[1][1];
167  return *this;
168  }
169 
172  return SetDiagonal(1);
173  }
174 
177  return SetDiagonal(0);
178  }
179 
181  GF_API
182  GfMatrix2d& SetDiagonal(double s);
183 
185  GF_API
186  GfMatrix2d& SetDiagonal(const GfVec2d&);
187 
190  GF_API
191  double* Get(double m[2][2]) const;
192 
195  double* data() {
196  return _mtx.GetData();
197  }
198 
201  const double* data() const {
202  return _mtx.GetData();
203  }
204 
206  double* GetArray() {
207  return _mtx.GetData();
208  }
209 
211  const double* GetArray() const {
212  return _mtx.GetData();
213  }
214 
218  double* operator [](int i) { return _mtx[i]; }
219 
223  const double* operator [](int i) const { return _mtx[i]; }
224 
226  friend inline size_t hash_value(GfMatrix2d const &m) {
227  int nElems = 2 * 2;
228  size_t h = 0;
229  const double *p = m.GetArray();
230  while (nElems--)
231  boost::hash_combine(h, *p++);
232  return h;
233  }
234 
237  GF_API
238  bool operator ==(const GfMatrix2d& m) const;
239 
242  GF_API
243  bool operator ==(const GfMatrix2f& m) const;
244 
247  bool operator !=(const GfMatrix2d& m) const {
248  return !(*this == m);
249  }
250 
253  bool operator !=(const GfMatrix2f& m) const {
254  return !(*this == m);
255  }
256 
258  GF_API
259  GfMatrix2d GetTranspose() const;
260 
266  GF_API
267  GfMatrix2d GetInverse(double* det = NULL, double eps = 0) const;
268 
270  GF_API
271  double GetDeterminant() const;
272 
273 
275  GF_API
276  GfMatrix2d& operator *=(const GfMatrix2d& m);
277 
279  GF_API
280  GfMatrix2d& operator *=(double);
281 
283  friend GfMatrix2d operator *(const GfMatrix2d& m1, double d)
284  {
285  GfMatrix2d m = m1;
286  return m *= d;
287  }
288 
290  // Returns the product of a matrix and a double.
291  friend GfMatrix2d operator *(double d, const GfMatrix2d& m)
292  {
293  return m * d;
294  }
295 
297  GF_API
298  GfMatrix2d& operator +=(const GfMatrix2d& m);
299 
301  GF_API
302  GfMatrix2d& operator -=(const GfMatrix2d& m);
303 
305  GF_API
306  friend GfMatrix2d operator -(const GfMatrix2d& m);
307 
309  friend GfMatrix2d operator +(const GfMatrix2d& m1, const GfMatrix2d& m2)
310  {
311  GfMatrix2d tmp(m1);
312  tmp += m2;
313  return tmp;
314  }
315 
317  friend GfMatrix2d operator -(const GfMatrix2d& m1, const GfMatrix2d& m2)
318  {
319  GfMatrix2d tmp(m1);
320  tmp -= m2;
321  return tmp;
322  }
323 
325  friend GfMatrix2d operator *(const GfMatrix2d& m1, const GfMatrix2d& m2)
326  {
327  GfMatrix2d tmp(m1);
328  tmp *= m2;
329  return tmp;
330  }
331 
333  friend GfMatrix2d operator /(const GfMatrix2d& m1, const GfMatrix2d& m2)
334  {
335  return(m1 * m2.GetInverse());
336  }
337 
339  friend inline GfVec2d operator *(const GfMatrix2d& m, const GfVec2d& vec) {
340  return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1],
341  vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1]);
342  }
343 
345  friend inline GfVec2d operator *(const GfVec2d &vec, const GfMatrix2d& m) {
346  return GfVec2d(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0],
347  vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1]);
348  }
349 
352  GF_API
353  friend GfVec2f operator *(const GfMatrix2d& m, const GfVec2f& vec);
354 
357  GF_API
358  friend GfVec2f operator *(const GfVec2f &vec, const GfMatrix2d& m);
359 
360 
361 private:
364 
365  // Friend declarations
366  friend class GfMatrix2f;
367 };
368 
369 
373 GF_API
374 bool GfIsClose(GfMatrix2d const &m1, GfMatrix2d const &m2, double tolerance);
375 
378 GF_API std::ostream& operator<<(std::ostream &, GfMatrix2d const &);
379 
380 PXR_NAMESPACE_CLOSE_SCOPE
381 
382 #endif // PXR_BASE_GF_MATRIX2D_H
GF_API GfMatrix2d & SetDiagonal(double s)
Sets the matrix to s times the identity matrix.
GfMatrix2d & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2d.h:171
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:218
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
Definition: math.h:42
void SetColumn(int i, const GfVec2d &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2d.h:135
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
bool operator!=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2d.h:247
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:153
const double * GetArray() const
Returns vector components as a const array of double values.
Definition: matrix2d.h:211
double * data()
Returns raw access to components of matrix as an array of double values.
Definition: matrix2d.h:195
GF_API GfMatrix2d GetTranspose() const
Returns the transpose of the matrix.
GfMatrix2d(double s)
Constructor.
Definition: matrix2d.h:90
GfVec2d GetColumn(int i) const
Gets a column of the matrix as a Vec2.
Definition: matrix2d.h:146
Declares Gf types.
GfMatrix2d()=default
Default constructor. Leaves the matrix component values undefined.
friend size_t hash_value(GfMatrix2d const &m)
Hash.
Definition: matrix2d.h:226
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
GfMatrix2d(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2d.h:96
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:62
GF_API bool operator==(const GfMatrix2d &m) const
Tests for element-wise matrix equality.
GfMatrix2d(double m00, double m01, double m10, double m11)
Constructor.
Definition: matrix2d.h:76
void SetRow(int i, const GfVec2d &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2d.h:129
T * GetData()
Return a pointer to the start of all the data.
Definition: matrixData.h:50
A metafunction with a static const bool member &#39;value&#39; that is true for GfMatrix types, like GfMatrix3d, GfMatrix4f, etc and false for all other types.
Definition: traits.h:42
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...
friend GfMatrix2d operator*(const GfMatrix2d &m1, double d)
Returns the product of a matrix and a double.
Definition: matrix2d.h:283
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.
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:162
GF_API GfMatrix2d & operator+=(const GfMatrix2d &m)
Adds matrix m to this matrix.
GfMatrix2d(const GfVec2d &v)
Constructor.
Definition: matrix2d.h:102
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
const double * data() const
Returns const raw access to components of matrix as an array of double values.
Definition: matrix2d.h:201
GF_API GfMatrix2d & operator-=(const GfMatrix2d &m)
Subtracts matrix m from this matrix.
double * GetArray()
Returns vector components as an array of double values.
Definition: matrix2d.h:206
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
GF_API GfMatrix2d & operator*=(const GfMatrix2d &m)
Post-multiplies matrix m into this matrix.
friend GfMatrix2d operator/(const GfMatrix2d &m1, const GfMatrix2d &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2d.h:333
friend GfMatrix2d operator+(const GfMatrix2d &m1, const GfMatrix2d &m2)
Adds matrix m2 to m1.
Definition: matrix2d.h:309
GfVec2d GetRow(int i) const
Gets a row of the matrix as a Vec2.
Definition: matrix2d.h:141
GfMatrix2d(const double m[2][2])
Constructor.
Definition: matrix2d.h:84
GfMatrix2d & SetZero()
Sets the matrix to zero.
Definition: matrix2d.h:176
Stores a 2x2 matrix of float elements.
Definition: matrix2f.h:62
GF_API friend GfMatrix2d operator-(const GfMatrix2d &m)
Returns the unary negation of matrix m.