All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 GF_MATRIX2F_H
29 #define 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 
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 GfMatrix2f> { static const bool value = true; };
50 
51 class GfMatrix2d;
52 class GfMatrix2f;
53 
63 {
64 public:
65  typedef float ScalarType;
66 
67  static const size_t numRows = 2;
68  static const size_t numColumns = 2;
69 
71  GfMatrix2f() = default;
72 
76  GfMatrix2f(float m00, float m01,
77  float m10, float m11) {
78  Set(m00, m01,
79  m10, m11);
80  }
81 
84  GfMatrix2f(const float m[2][2]) {
85  Set(m);
86  }
87 
90  explicit GfMatrix2f(float s) {
91  SetDiagonal(s);
92  }
93 
96  explicit GfMatrix2f(int s) {
97  SetDiagonal(s);
98  }
99 
102  explicit GfMatrix2f(const GfVec2f& v) {
103  SetDiagonal(v);
104  }
105 
112  GF_API
113  explicit GfMatrix2f(const std::vector< std::vector<double> >& v);
114 
121  GF_API
122  explicit GfMatrix2f(const std::vector< std::vector<float> >& v);
123 
125  GF_API
126  explicit GfMatrix2f(const class GfMatrix2d& m);
127 
129  void SetRow(int i, const GfVec2f & v) {
130  _mtx[i][0] = v[0];
131  _mtx[i][1] = v[1];
132  }
133 
135  void SetColumn(int i, const GfVec2f & v) {
136  _mtx[0][i] = v[0];
137  _mtx[1][i] = v[1];
138  }
139 
141  GfVec2f GetRow(int i) const {
142  return GfVec2f(_mtx[i][0], _mtx[i][1]);
143  }
144 
146  GfVec2f GetColumn(int i) const {
147  return GfVec2f(_mtx[0][i], _mtx[1][i]);
148  }
149 
153  GfMatrix2f& Set(float m00, float m01,
154  float m10, float 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  GfMatrix2f& Set(const float 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  GfMatrix2f& SetDiagonal(float s);
183 
185  GF_API
186  GfMatrix2f& SetDiagonal(const GfVec2f&);
187 
190  GF_API
191  float* Get(float m[2][2]) const;
192 
195  float* data() {
196  return _mtx.GetData();
197  }
198 
201  const float* data() const {
202  return _mtx.GetData();
203  }
204 
206  float* GetArray() {
207  return _mtx.GetData();
208  }
209 
211  const float* GetArray() const {
212  return _mtx.GetData();
213  }
214 
218  float* operator [](int i) { return _mtx[i]; }
219 
223  const float* operator [](int i) const { return _mtx[i]; }
224 
226  friend inline size_t hash_value(GfMatrix2f const &m) {
227  int nElems = 2 * 2;
228  size_t h = 0;
229  const float *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  GfMatrix2f GetTranspose() const;
260 
266  GF_API
267  GfMatrix2f GetInverse(double* det = NULL, double eps = 0) const;
268 
270  GF_API
271  double GetDeterminant() const;
272 
273 
275  GF_API
276  GfMatrix2f& operator *=(const GfMatrix2f& m);
277 
279  GF_API
280  GfMatrix2f& operator *=(double);
281 
283  friend GfMatrix2f operator *(const GfMatrix2f& m1, double d)
284  {
285  GfMatrix2f m = m1;
286  return m *= d;
287  }
288 
290  // Returns the product of a matrix and a float.
291  friend GfMatrix2f operator *(double d, const GfMatrix2f& m)
292  {
293  return m * d;
294  }
295 
297  GF_API
298  GfMatrix2f& operator +=(const GfMatrix2f& m);
299 
301  GF_API
302  GfMatrix2f& operator -=(const GfMatrix2f& m);
303 
305  GF_API
306  friend GfMatrix2f operator -(const GfMatrix2f& m);
307 
309  friend GfMatrix2f operator +(const GfMatrix2f& m1, const GfMatrix2f& m2)
310  {
311  GfMatrix2f tmp(m1);
312  tmp += m2;
313  return tmp;
314  }
315 
317  friend GfMatrix2f operator -(const GfMatrix2f& m1, const GfMatrix2f& m2)
318  {
319  GfMatrix2f tmp(m1);
320  tmp -= m2;
321  return tmp;
322  }
323 
325  friend GfMatrix2f operator *(const GfMatrix2f& m1, const GfMatrix2f& m2)
326  {
327  GfMatrix2f tmp(m1);
328  tmp *= m2;
329  return tmp;
330  }
331 
333  friend GfMatrix2f operator /(const GfMatrix2f& m1, const GfMatrix2f& m2)
334  {
335  return(m1 * m2.GetInverse());
336  }
337 
339  friend inline GfVec2f operator *(const GfMatrix2f& m, const GfVec2f& vec) {
340  return GfVec2f(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 GfVec2f operator *(const GfVec2f &vec, const GfMatrix2f& m) {
346  return GfVec2f(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 
350 
351 private:
353  GfMatrixData<float, 2, 2> _mtx;
354 
355  // Friend declarations
356  friend class GfMatrix2d;
357 };
358 
359 
363 GF_API
364 bool GfIsClose(GfMatrix2f const &m1, GfMatrix2f const &m2, double tolerance);
365 
368 GF_API std::ostream& operator<<(std::ostream &, GfMatrix2f const &);
369 
370 PXR_NAMESPACE_CLOSE_SCOPE
371 
372 #endif // 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...
GfMatrix2f(const GfVec2f &v)
Constructor.
Definition: matrix2f.h:102
GF_API GfMatrix2f & operator+=(const GfMatrix2f &m)
Adds matrix m to this matrix.
bool GfIsClose(double a, double b, double epsilon)
Returns true if a and b are with epsilon of each other.
Definition: math.h:39
float * data()
Returns raw access to components of matrix as an array of float values.
Definition: matrix2f.h:195
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:153
GfVec2f GetRow(int i) const
Gets a row of the matrix as a Vec2.
Definition: matrix2f.h:141
GF_API GfMatrix2f & SetDiagonal(float s)
Sets the matrix to s times the identity matrix.
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:218
GF_API bool operator==(const GfMatrix2d &m) const
Tests for element-wise matrix equality.
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
void SetRow(int i, const GfVec2f &v)
Sets a row of the matrix from a Vec2.
Definition: matrix2f.h:129
bool operator!=(const GfMatrix2d &m) const
Tests for element-wise matrix inequality.
Definition: matrix2f.h:247
GfMatrix2f(int s)
This explicit constructor initializes the matrix to s times the identity matrix.
Definition: matrix2f.h:96
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:162
Stores a 2x2 matrix of double elements.
Definition: matrix2d.h:62
GfMatrix2f(const float m[2][2])
Constructor.
Definition: matrix2f.h:84
const float * GetArray() const
Returns vector components as a const array of float values.
Definition: matrix2f.h:211
GfMatrix2f(float s)
Constructor.
Definition: matrix2f.h:90
GF_API GfMatrix2f GetTranspose() const
Returns the transpose of the matrix.
GF_API GfMatrix2f & operator*=(const GfMatrix2f &m)
Post-multiplies matrix m into this matrix.
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:40
friend GfMatrix2f operator/(const GfMatrix2f &m1, const GfMatrix2f &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
Definition: matrix2f.h:333
float * GetArray()
Returns vector components as an array of float values.
Definition: matrix2f.h:206
friend size_t hash_value(GfMatrix2f const &m)
Hash.
Definition: matrix2f.h:226
GF_API friend GfMatrix2f operator-(const GfMatrix2f &m)
Returns the unary negation of matrix m.
const float * data() const
Returns const raw access to components of matrix as an array of float values.
Definition: matrix2f.h:201
GfMatrix2f & SetZero()
Sets the matrix to zero.
Definition: matrix2f.h:176
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
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()=default
Default constructor. Leaves the matrix component values undefined.
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
friend GfMatrix2f operator+(const GfMatrix2f &m1, const GfMatrix2f &m2)
Adds matrix m2 to m1.
Definition: matrix2f.h:309
friend GfMatrix2f operator*(const GfMatrix2f &m1, double d)
Returns the product of a matrix and a float.
Definition: matrix2f.h:283
void SetColumn(int i, const GfVec2f &v)
Sets a column of the matrix from a Vec2.
Definition: matrix2f.h:135
GF_API GfMatrix2f & operator-=(const GfMatrix2f &m)
Subtracts matrix m from this matrix.
GfVec2f GetColumn(int i) const
Gets a column of the matrix as a Vec2.
Definition: matrix2f.h:146
GfMatrix2f(float m00, float m01, float m10, float m11)
Constructor.
Definition: matrix2f.h:76
Stores a 2x2 matrix of float elements.
Definition: matrix2f.h:62
GfMatrix2f & SetIdentity()
Sets the matrix to the identity matrix.
Definition: matrix2f.h:171