matrix2f.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_MATRIX2F_H
29 #define PXR_BASE_GF_MATRIX2F_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/vec2f.h"
39 #include "pxr/base/gf/traits.h"
40 #include "pxr/base/tf/hash.h"
41 
42 #include <iosfwd>
43 #include <vector>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 template <>
48 struct GfIsGfMatrix<class GfMatrix2f> { static const bool value = true; };
49 
50 class GfMatrix2d;
51 class GfMatrix2f;
52 
62 {
63 public:
64  typedef float ScalarType;
65 
66  static const size_t numRows = 2;
67  static const size_t numColumns = 2;
68 
70  GfMatrix2f() = default;
71 
75  GfMatrix2f(float m00, float m01,
76  float m10, float m11) {
77  Set(m00, m01,
78  m10, m11);
79  }
80 
83  GfMatrix2f(const float m[2][2]) {
84  Set(m);
85  }
86 
89  explicit GfMatrix2f(float s) {
90  SetDiagonal(s);
91  }
92 
95  explicit GfMatrix2f(int s) {
96  SetDiagonal(s);
97  }
98 
101  explicit GfMatrix2f(const GfVec2f& v) {
102  SetDiagonal(v);
103  }
104 
111  GF_API
112  explicit GfMatrix2f(const std::vector< std::vector<double> >& v);
113 
120  GF_API
121  explicit GfMatrix2f(const std::vector< std::vector<float> >& v);
122 
124  GF_API
125  explicit GfMatrix2f(const class GfMatrix2d& m);
126 
128  void SetRow(int i, const GfVec2f & v) {
129  _mtx[i][0] = v[0];
130  _mtx[i][1] = v[1];
131  }
132 
134  void SetColumn(int i, const GfVec2f & v) {
135  _mtx[0][i] = v[0];
136  _mtx[1][i] = v[1];
137  }
138 
140  GfVec2f GetRow(int i) const {
141  return GfVec2f(_mtx[i][0], _mtx[i][1]);
142  }
143 
145  GfVec2f GetColumn(int i) const {
146  return GfVec2f(_mtx[0][i], _mtx[1][i]);
147  }
148 
152  GfMatrix2f& Set(float m00, float m01,
153  float m10, float 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  GfMatrix2f& Set(const float 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
181  GfMatrix2f& SetDiagonal(float s);
182 
184  GF_API
185  GfMatrix2f& SetDiagonal(const GfVec2f&);
186 
189  GF_API
190  float* Get(float m[2][2]) const;
191 
194  float* data() {
195  return _mtx.GetData();
196  }
197 
200  const float* data() const {
201  return _mtx.GetData();
202  }
203 
205  float* GetArray() {
206  return _mtx.GetData();
207  }
208 
210  const float* GetArray() const {
211  return _mtx.GetData();
212  }
213 
217  float* operator [](int i) { return _mtx[i]; }
218 
222  const float* operator [](int i) const { return _mtx[i]; }
223 
225  friend inline size_t hash_value(GfMatrix2f 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
258  GfMatrix2f GetTranspose() const;
259 
265  GF_API
266  GfMatrix2f GetInverse(double* det = NULL, double eps = 0) const;
267 
269  GF_API
270  double GetDeterminant() const;
271 
272 
274  GF_API
275  GfMatrix2f& operator *=(const GfMatrix2f& m);
276 
278  GF_API
279  GfMatrix2f& operator *=(double);
280 
282  friend GfMatrix2f operator *(const GfMatrix2f& m1, double d)
283  {
284  GfMatrix2f m = m1;
285  return m *= d;
286  }
287 
289  // Returns the product of a matrix and a float.
290  friend GfMatrix2f operator *(double d, const GfMatrix2f& m)
291  {
292  return m * d;
293  }
294 
296  GF_API
297  GfMatrix2f& operator +=(const GfMatrix2f& m);
298 
300  GF_API
301  GfMatrix2f& operator -=(const GfMatrix2f& m);
302 
304  GF_API
305  friend GfMatrix2f operator -(const GfMatrix2f& m);
306 
308  friend GfMatrix2f operator +(const GfMatrix2f& m1, const GfMatrix2f& m2)
309  {
310  GfMatrix2f tmp(m1);
311  tmp += m2;
312  return tmp;
313  }
314 
316  friend GfMatrix2f operator -(const GfMatrix2f& m1, const GfMatrix2f& m2)
317  {
318  GfMatrix2f tmp(m1);
319  tmp -= m2;
320  return tmp;
321  }
322 
324  friend GfMatrix2f operator *(const GfMatrix2f& m1, const GfMatrix2f& m2)
325  {
326  GfMatrix2f tmp(m1);
327  tmp *= m2;
328  return tmp;
329  }
330 
332  friend GfMatrix2f operator /(const GfMatrix2f& m1, const GfMatrix2f& m2)
333  {
334  return(m1 * m2.GetInverse());
335  }
336 
338  friend inline GfVec2f operator *(const GfMatrix2f& m, const GfVec2f& vec) {
339  return GfVec2f(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 GfVec2f operator *(const GfVec2f &vec, const GfMatrix2f& m) {
345  return GfVec2f(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 
349 
350 private:
353 
354  // Friend declarations
355  friend class GfMatrix2d;
356 };
357 
358 
362 GF_API
363 bool GfIsClose(GfMatrix2f const &m1, GfMatrix2f const &m2, double tolerance);
364 
367 GF_API std::ostream& operator<<(std::ostream &, GfMatrix2f const &);
368 
369 PXR_NAMESPACE_CLOSE_SCOPE
370 
371 #endif // PXR_BASE_GF_MATRIX2F_H
GF_API float * Get(float m[2][2]) const
Fills a 2x2 array of float values with the values in the matrix, specified in row-major order.
GF_API bool GfIsClose(GfMatrix2f const &m1, GfMatrix2f const &m2, double tolerance)
Tests for equality within a given tolerance, returning true if the difference between each component ...
GfMatrix2f(const GfVec2f &v)
Constructor.
Definition: matrix2f.h:101
GfVec2f GetColumn(int i) const
Gets a column of the matrix as a Vec2.
Definition: matrix2f.h:145
GF_API GfMatrix2f & operator+=(const GfMatrix2f &m)
Adds matrix m to this matrix.
const float * operator [](int i) const
Accesses an indexed row i of the matrix as an array of 2 float values so that standard indexing (such...
Definition: matrix2f.h:222
float * data()
Returns raw access to components of matrix as an array of float values.
Definition: matrix2f.h:194
GfMatrix2f & Set(float m00, float m01, float m10, float m11)
Sets the matrix from 4 independent float values, specified in row-major order.
Definition: matrix2f.h:152
float * operator [](int i)
Accesses an indexed row i of the matrix as an array of 2 float values so that standard indexing (such...
Definition: matrix2f.h:217
const float * GetArray() const
Returns vector components as a const array of float values.
Definition: matrix2f.h:210
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
GF_API GfMatrix2f & SetDiagonal(float s)
Sets the matrix to s times the identity matrix.
GF_API GfMatrix2f & operator -=(const GfMatrix2f &m)
Subtracts matrix m from this matrix.
Declares Gf types.
GF_API std::ostream & operator<<(std::ostream &, GfMatrix2f const &)
Output a GfMatrix2f.
void SetRow(int i, const GfVec2f &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2f.h:128
GF_API bool operator==(const GfMatrix2d &m) const
Tests for element-wise matrix equality.
GfMatrix2f(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2f.h:95
GfMatrix2f & Set(const float m[2][2])
Sets the matrix from a 2x2 array of float values, specified in row-major order.
Definition: matrix2f.h:161
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:61
GfMatrix2f(const float m[2][2])
Constructor.
Definition: matrix2f.h:83
bool operator !=(const GfMatrix2f &m) const
Tests for element-wise matrix inequality.
Definition: matrix2f.h:252
GfMatrix2f(float s)
Constructor.
Definition: matrix2f.h:89
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:519
GF_API GfMatrix2f & operator *=(const GfMatrix2f &m)
Post-multiplies matrix m into this matrix.
T * GetData()
Return a pointer to the start of all the data.
Definition: matrixData.h:50
A metafunction with a static const bool member 'value' that is true for GfMatrix types,...
Definition: traits.h:42
GF_API friend GfMatrix2f operator -(const GfMatrix2f &m)
Returns the unary negation of matrix m.
friend GfMatrix2f operator/(const GfMatrix2f &m1, const GfMatrix2f &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2f.h:332
GF_API GfMatrix2f GetTranspose() const
Returns the transpose of the matrix.
GfVec2f GetRow(int i) const
Gets a row of the matrix as a Vec2.
Definition: matrix2f.h:140
float * GetArray()
Returns vector components as an array of float values.
Definition: matrix2f.h:205
friend size_t hash_value(GfMatrix2f const &m)
Hash.
Definition: matrix2f.h:225
friend GfMatrix2f operator *(const GfMatrix2f &m1, double d)
Returns the product of a matrix and a float.
Definition: matrix2f.h:282
GfMatrix2f & SetZero()
Sets the matrix to zero.
Definition: matrix2f.h:175
friend GfVec2f operator *(const GfVec2f &vec, const GfMatrix2f &m)
Returns the product of row vector vec and a matrix m.
Definition: matrix2f.h:344
bool operator !=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2f.h:246
friend GfMatrix2f operator *(const GfMatrix2f &m1, const GfMatrix2f &m2)
Multiplies matrix m1 by m2.
Definition: matrix2f.h:324
GfMatrix2f()=default
Default constructor. Leaves the matrix component values undefined.
Basic type for a vector of 2 float components.
Definition: vec2f.h:62
const float * data() const
Returns const raw access to components of matrix as an array of float values.
Definition: matrix2f.h:200
friend GfMatrix2f operator+(const GfMatrix2f &m1, const GfMatrix2f &m2)
Adds matrix m2 to m1.
Definition: matrix2f.h:308
void SetColumn(int i, const GfVec2f &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2f.h:134
friend GfMatrix2f operator -(const GfMatrix2f &m1, const GfMatrix2f &m2)
Subtracts matrix m2 from m1.
Definition: matrix2f.h:316
friend GfVec2f operator *(const GfMatrix2f &m, const GfVec2f &vec)
Returns the product of a matrix m and a column vector vec.
Definition: matrix2f.h:338
GfMatrix2f(float m00, float m01, float m10, float m11)
Constructor.
Definition: matrix2f.h:75
Stores a 2x2 matrix of float elements.
Definition: matrix2f.h:61
GF_API GfMatrix2f GetInverse(double *det=NULL, double eps=0) const
Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the matrix is singular.
GfMatrix2f & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2f.h:170