HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vec4i.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 //
24 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script. Do not edit directly. Edit the
26 // vec.template.h file to make changes.
27 
28 #ifndef GF_VEC4I_H
29 #define GF_VEC4I_H
30 
31 /// \file gf/vec4i.h
32 /// \ingroup group_gf_LinearAlgebra
33 
34 #include "pxr/pxr.h"
35 #include "pxr/base/tf/diagnostic.h"
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/limits.h"
38 #include "pxr/base/gf/traits.h"
39 
40 #include <hboost/functional/hash.hpp>
41 
42 #include <cstddef>
43 
44 #include <iosfwd>
45 
47 
48 class GfVec4i;
49 
50 template <>
51 struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
52 
53 /// \class GfVec4i
54 /// \ingroup group_gf_LinearAlgebra
55 ///
56 /// Basic type for a vector of 4 int components.
57 ///
58 /// Represents a vector of 4 components of type \c int.
59 /// It is intended to be fast and simple.
60 ///
61 class GfVec4i
62 {
63 public:
64  /// Scalar element type and dimension.
65  typedef int ScalarType;
66  static const size_t dimension = 4;
67 
68  /// Default constructor does no initialization.
69  GfVec4i() = default;
70 
71  /// Initialize all elements to a single value.
72  constexpr explicit GfVec4i(int value)
73  : _data{ value, value, value, value }
74  {
75  }
76 
77  /// Initialize all elements with explicit arguments.
78  constexpr GfVec4i(int s0, int s1, int s2, int s3)
79  : _data{ s0, s1, s2, s3 }
80  {
81  }
82 
83  /// Construct with pointer to values.
84  template <class Scl>
85  constexpr explicit GfVec4i(Scl const *p)
86  : _data{ p[0], p[1], p[2], p[3] }
87  {
88  }
89 
90  /// Create a unit vector along the X-axis.
91  static GfVec4i XAxis() {
92  GfVec4i result(0);
93  result[0] = 1;
94  return result;
95  }
96  /// Create a unit vector along the Y-axis.
97  static GfVec4i YAxis() {
98  GfVec4i result(0);
99  result[1] = 1;
100  return result;
101  }
102  /// Create a unit vector along the Z-axis.
103  static GfVec4i ZAxis() {
104  GfVec4i result(0);
105  result[2] = 1;
106  return result;
107  }
108  /// Create a unit vector along the W-axis.
109  static GfVec4i WAxis() {
110  GfVec4i result(0);
111  result[3] = 1;
112  return result;
113  }
114 
115  /// Create a unit vector along the i-th axis, zero-based. Return the zero
116  /// vector if \p i is greater than or equal to 4.
117  static GfVec4i Axis(size_t i) {
118  GfVec4i result(0);
119  if (i < 4)
120  result[i] = 1;
121  return result;
122  }
123 
124  /// Set all elements with passed arguments.
125  GfVec4i &Set(int s0, int s1, int s2, int s3) {
126  _data[0] = s0;
127  _data[1] = s1;
128  _data[2] = s2;
129  _data[3] = s3;
130  return *this;
131  }
132 
133  /// Set all elements with a pointer to data.
134  GfVec4i &Set(int const *a) {
135  return Set(a[0], a[1], a[2], a[3]);
136  }
137 
138  /// Direct data access.
139  int const *data() const { return _data; }
140  int *data() { return _data; }
141  int const *GetArray() const { return data(); }
142 
143  /// Indexing.
144  int const &operator[](size_t i) const { return _data[i]; }
145  int &operator[](size_t i) { return _data[i]; }
146 
147  /// Hash.
148  friend inline size_t hash_value(GfVec4i const &vec) {
149  size_t h = 0;
150  hboost::hash_combine(h, vec[0]);
151  hboost::hash_combine(h, vec[1]);
152  hboost::hash_combine(h, vec[2]);
153  hboost::hash_combine(h, vec[3]);
154  return h;
155  }
156 
157  /// Equality comparison.
158  bool operator==(GfVec4i const &other) const {
159  return _data[0] == other[0] &&
160  _data[1] == other[1] &&
161  _data[2] == other[2] &&
162  _data[3] == other[3];
163  }
164  bool operator!=(GfVec4i const &other) const {
165  return !(*this == other);
166  }
167 
168  // TODO Add inequality for other vec types...
169  /// Equality comparison.
170  GF_API
171  bool operator==(class GfVec4d const &other) const;
172  /// Equality comparison.
173  GF_API
174  bool operator==(class GfVec4f const &other) const;
175  /// Equality comparison.
176  GF_API
177  bool operator==(class GfVec4h const &other) const;
178 
179  /// Create a vec with negated elements.
180  GfVec4i operator-() const {
181  return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
182  }
183 
184  /// Addition.
185  GfVec4i &operator+=(GfVec4i const &other) {
186  _data[0] += other[0];
187  _data[1] += other[1];
188  _data[2] += other[2];
189  _data[3] += other[3];
190  return *this;
191  }
192  friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
193  return GfVec4i(l) += r;
194  }
195 
196  /// Subtraction.
197  GfVec4i &operator-=(GfVec4i const &other) {
198  _data[0] -= other[0];
199  _data[1] -= other[1];
200  _data[2] -= other[2];
201  _data[3] -= other[3];
202  return *this;
203  }
204  friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
205  return GfVec4i(l) -= r;
206  }
207 
208  /// Multiplication by scalar.
209  GfVec4i &operator*=(double s) {
210  _data[0] *= s;
211  _data[1] *= s;
212  _data[2] *= s;
213  _data[3] *= s;
214  return *this;
215  }
216  GfVec4i operator*(double s) const {
217  return GfVec4i(*this) *= s;
218  }
219  friend GfVec4i operator*(double s, GfVec4i const &v) {
220  return v * s;
221  }
222 
223  /// Division by scalar.
225  _data[0] /= s;
226  _data[1] /= s;
227  _data[2] /= s;
228  _data[3] /= s;
229  return *this;
230  }
231  GfVec4i operator/(int s) const {
232  return GfVec4i(*this) /= s;
233  }
234 
235  /// See GfDot().
236  int operator*(GfVec4i const &v) const {
237  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
238  }
239 
240  /// Returns the projection of \p this onto \p v. That is:
241  /// \code
242  /// v * (*this * v)
243  /// \endcode
244  GfVec4i GetProjection(GfVec4i const &v) const {
245  return v * (*this * v);
246  }
247 
248  /// Returns the orthogonal complement of \p this->GetProjection(b).
249  /// That is:
250  /// \code
251  /// *this - this->GetProjection(b)
252  /// \endcode
253  GfVec4i GetComplement(GfVec4i const &b) const {
254  return *this - this->GetProjection(b);
255  }
256 
257  /// Squared length.
258  int GetLengthSq() const {
259  return *this * *this;
260  }
261 
262 
263 private:
264  int _data[4];
265 };
266 
267 /// Output a GfVec4i.
268 /// \ingroup group_gf_DebuggingOutput
269 GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
270 
271 
272 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
273 inline GfVec4i
274 GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
275  return GfVec4i(
276  v1[0] * v2[0],
277  v1[1] * v2[1],
278  v1[2] * v2[2],
279  v1[3] * v2[3]
280  );
281 }
282 
283 /// Returns component-wise quotient of vectors \p v1 and \p v2.
284 inline GfVec4i
285 GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
286  return GfVec4i(
287  v1[0] / v2[0],
288  v1[1] / v2[1],
289  v1[2] / v2[2],
290  v1[3] / v2[3]
291  );
292 }
293 
294 /// Returns the dot (inner) product of two vectors.
295 inline int
296 GfDot(GfVec4i const &v1, GfVec4i const &v2) {
297  return v1 * v2;
298 }
299 
300 
302 
303 #endif // GF_VEC4I_H
GLdouble s
Definition: glew.h:1390
Definition: vec4i.h:61
static GfVec4i Axis(size_t i)
Definition: vec4i.h:117
friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:192
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:144
GfVec4i GfCompMult(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec4i.h:274
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:180
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:209
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:148
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:197
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:72
int const * GetArray() const
Definition: vec4i.h:141
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:97
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:285
Definition: vec4d.h:63
int const * data() const
Direct data access.
Definition: vec4i.h:139
GLdouble l
Definition: glew.h:9122
const GLdouble * v
Definition: glew.h:1391
GfVec4i()=default
Default constructor does no initialization.
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:224
GfVec4i GetComplement(GfVec4i const &b) const
Definition: vec4i.h:253
Definition: vec4h.h:64
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:185
GLfloat GLfloat GLfloat v2
Definition: glew.h:1856
int & operator[](size_t i)
Definition: vec4i.h:145
GfVec4i operator*(double s) const
Definition: vec4i.h:216
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:103
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:158
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
GF_API std::ostream & operator<<(std::ostream &, GfVec4i const &)
GfVec4i GetProjection(GfVec4i const &v) const
Definition: vec4i.h:244
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:85
Definition: vec4f.h:63
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:296
GLfloat GLfloat p
Definition: glew.h:16321
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:125
bool operator!=(GfVec4i const &other) const
Definition: vec4i.h:164
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
friend GfVec4i operator*(double s, GfVec4i const &v)
Definition: vec4i.h:219
int * data()
Definition: vec4i.h:140
GfVec4i operator/(int s) const
Definition: vec4i.h:231
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
Definition: glew.h:12681
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
GfVec4i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec4i.h:134
friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:204
GLuint64EXT * result
Definition: glew.h:14007
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:91
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s0
Definition: glew.h:12681
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:65
static const size_t dimension
Definition: vec4i.h:66
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:236
GLsizei const GLfloat * value
Definition: glew.h:1849
GLfloat GLfloat v1
Definition: glew.h:1852
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:78
#define GF_API
Definition: api.h:40
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:109
int GetLengthSq() const
Squared length.
Definition: vec4i.h:258