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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // vec.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_VEC4I_H
12 #define PXR_BASE_GF_VEC4I_H
13 
14 /// \file gf/vec4i.h
15 /// \ingroup group_gf_LinearAlgebra
16 
17 #include "pxr/pxr.h"
18 #include "pxr/base/tf/diagnostic.h"
19 #include "pxr/base/gf/api.h"
20 #include "pxr/base/gf/limits.h"
21 #include "pxr/base/gf/traits.h"
22 #include "pxr/base/tf/hash.h"
23 
24 #include <cstddef>
25 
26 #include <iosfwd>
27 
29 
30 class GfVec4i;
31 
32 template <>
33 struct GfIsGfVec<class GfVec4i> { static const bool value = true; };
34 
35 /// \class GfVec4i
36 /// \ingroup group_gf_LinearAlgebra
37 ///
38 /// Basic type for a vector of 4 int components.
39 ///
40 /// Represents a vector of 4 components of type \c int.
41 /// It is intended to be fast and simple.
42 ///
43 class GfVec4i
44 {
45 public:
46  /// Scalar element type and dimension.
47  typedef int ScalarType;
48  static const size_t dimension = 4;
49 
50  /// Default constructor does no initialization.
51  GfVec4i() = default;
52 
53  /// Initialize all elements to a single value.
54  constexpr explicit GfVec4i(int value)
55  : _data{ value, value, value, value }
56  {
57  }
58 
59  /// Initialize all elements with explicit arguments.
60  constexpr GfVec4i(int s0, int s1, int s2, int s3)
61  : _data{ s0, s1, s2, s3 }
62  {
63  }
64 
65  /// Construct with pointer to values.
66  template <class Scl>
67  constexpr explicit GfVec4i(Scl const *p)
68  : _data{ p[0], p[1], p[2], p[3] }
69  {
70  }
71 
72  /// Create a unit vector along the X-axis.
73  static GfVec4i XAxis() {
74  GfVec4i result(0);
75  result[0] = 1;
76  return result;
77  }
78  /// Create a unit vector along the Y-axis.
79  static GfVec4i YAxis() {
80  GfVec4i result(0);
81  result[1] = 1;
82  return result;
83  }
84  /// Create a unit vector along the Z-axis.
85  static GfVec4i ZAxis() {
86  GfVec4i result(0);
87  result[2] = 1;
88  return result;
89  }
90  /// Create a unit vector along the W-axis.
91  static GfVec4i WAxis() {
92  GfVec4i result(0);
93  result[3] = 1;
94  return result;
95  }
96 
97  /// Create a unit vector along the i-th axis, zero-based. Return the zero
98  /// vector if \p i is greater than or equal to 4.
99  static GfVec4i Axis(size_t i) {
100  GfVec4i result(0);
101  if (i < 4)
102  result[i] = 1;
103  return result;
104  }
105 
106  /// Set all elements with passed arguments.
107  GfVec4i &Set(int s0, int s1, int s2, int s3) {
108  _data[0] = s0;
109  _data[1] = s1;
110  _data[2] = s2;
111  _data[3] = s3;
112  return *this;
113  }
114 
115  /// Set all elements with a pointer to data.
116  GfVec4i &Set(int const *a) {
117  return Set(a[0], a[1], a[2], a[3]);
118  }
119 
120  /// Direct data access.
121  int const *data() const { return _data; }
122  int *data() { return _data; }
123  int const *GetArray() const { return data(); }
124 
125  /// Indexing.
126  int const &operator[](size_t i) const { return _data[i]; }
127  int &operator[](size_t i) { return _data[i]; }
128 
129  /// Hash.
130  friend inline size_t hash_value(GfVec4i const &vec) {
131  return TfHash::Combine(vec[0], vec[1], vec[2], vec[3]);
132  }
133 
134  /// Equality comparison.
135  bool operator==(GfVec4i const &other) const {
136  return _data[0] == other[0] &&
137  _data[1] == other[1] &&
138  _data[2] == other[2] &&
139  _data[3] == other[3];
140  }
141  bool operator!=(GfVec4i const &other) const {
142  return !(*this == other);
143  }
144 
145  // TODO Add inequality for other vec types...
146  /// Equality comparison.
147  GF_API
148  bool operator==(class GfVec4d const &other) const;
149  /// Equality comparison.
150  GF_API
151  bool operator==(class GfVec4f const &other) const;
152  /// Equality comparison.
153  GF_API
154  bool operator==(class GfVec4h const &other) const;
155 
156  /// Create a vec with negated elements.
157  GfVec4i operator-() const {
158  return GfVec4i(-_data[0], -_data[1], -_data[2], -_data[3]);
159  }
160 
161  /// Addition.
162  GfVec4i &operator+=(GfVec4i const &other) {
163  _data[0] += other[0];
164  _data[1] += other[1];
165  _data[2] += other[2];
166  _data[3] += other[3];
167  return *this;
168  }
169  friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r) {
170  return GfVec4i(l) += r;
171  }
172 
173  /// Subtraction.
174  GfVec4i &operator-=(GfVec4i const &other) {
175  _data[0] -= other[0];
176  _data[1] -= other[1];
177  _data[2] -= other[2];
178  _data[3] -= other[3];
179  return *this;
180  }
181  friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r) {
182  return GfVec4i(l) -= r;
183  }
184 
185  /// Multiplication by scalar.
186  GfVec4i &operator*=(double s) {
187  _data[0] *= s;
188  _data[1] *= s;
189  _data[2] *= s;
190  _data[3] *= s;
191  return *this;
192  }
193  GfVec4i operator*(double s) const {
194  return GfVec4i(*this) *= s;
195  }
196  friend GfVec4i operator*(double s, GfVec4i const &v) {
197  return v * s;
198  }
199 
200  /// Division by scalar.
202  _data[0] /= s;
203  _data[1] /= s;
204  _data[2] /= s;
205  _data[3] /= s;
206  return *this;
207  }
208  GfVec4i operator/(int s) const {
209  return GfVec4i(*this) /= s;
210  }
211 
212  /// See GfDot().
213  int operator*(GfVec4i const &v) const {
214  return _data[0] * v[0] + _data[1] * v[1] + _data[2] * v[2] + _data[3] * v[3];
215  }
216 
217  /// Returns the projection of \p this onto \p v. That is:
218  /// \code
219  /// v * (*this * v)
220  /// \endcode
221  GfVec4i GetProjection(GfVec4i const &v) const {
222  return v * (*this * v);
223  }
224 
225  /// Returns the orthogonal complement of \p this->GetProjection(b).
226  /// That is:
227  /// \code
228  /// *this - this->GetProjection(b)
229  /// \endcode
230  GfVec4i GetComplement(GfVec4i const &b) const {
231  return *this - this->GetProjection(b);
232  }
233 
234  /// Squared length.
235  int GetLengthSq() const {
236  return *this * *this;
237  }
238 
239 
240 private:
241  int _data[4];
242 };
243 
244 /// Output a GfVec4i.
245 /// \ingroup group_gf_DebuggingOutput
246 GF_API std::ostream& operator<<(std::ostream &, GfVec4i const &);
247 
248 
249 /// Returns component-wise multiplication of vectors \p v1 and \p v2.
250 inline GfVec4i
251 GfCompMult(GfVec4i const &v1, GfVec4i const &v2) {
252  return GfVec4i(
253  v1[0] * v2[0],
254  v1[1] * v2[1],
255  v1[2] * v2[2],
256  v1[3] * v2[3]
257  );
258 }
259 
260 /// Returns component-wise quotient of vectors \p v1 and \p v2.
261 inline GfVec4i
262 GfCompDiv(GfVec4i const &v1, GfVec4i const &v2) {
263  return GfVec4i(
264  v1[0] / v2[0],
265  v1[1] / v2[1],
266  v1[2] / v2[2],
267  v1[3] / v2[3]
268  );
269 }
270 
271 /// Returns the dot (inner) product of two vectors.
272 inline int
273 GfDot(GfVec4i const &v1, GfVec4i const &v2) {
274  return v1 * v2;
275 }
276 
277 
279 
280 #endif // PXR_BASE_GF_VEC4I_H
Definition: vec4i.h:43
static GfVec4i Axis(size_t i)
Definition: vec4i.h:99
friend GfVec4i operator+(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:169
int const & operator[](size_t i) const
Indexing.
Definition: vec4i.h:126
GfVec4i GfCompMult(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise multiplication of vectors v1 and v2.
Definition: vec4i.h:251
GfVec4i operator-() const
Create a vec with negated elements.
Definition: vec4i.h:157
GfVec4i & operator*=(double s)
Multiplication by scalar.
Definition: vec4i.h:186
friend size_t hash_value(GfVec4i const &vec)
Hash.
Definition: vec4i.h:130
GfVec4i & operator-=(GfVec4i const &other)
Subtraction.
Definition: vec4i.h:174
*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:632
const GLdouble * v
Definition: glcorearb.h:837
constexpr GfVec4i(int value)
Initialize all elements to a single value.
Definition: vec4i.h:54
GLsizei const GLfloat * value
Definition: glcorearb.h:824
int const * GetArray() const
Definition: vec4i.h:123
static GfVec4i YAxis()
Create a unit vector along the Y-axis.
Definition: vec4i.h:79
GfVec4i GfCompDiv(GfVec4i const &v1, GfVec4i const &v2)
Returns component-wise quotient of vectors v1 and v2.
Definition: vec4i.h:262
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
Definition: vec4d.h:45
int const * data() const
Direct data access.
Definition: vec4i.h:121
**But if you need a result
Definition: thread.h:622
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GfVec4i()=default
Default constructor does no initialization.
GfVec4i & operator/=(int s)
Division by scalar.
Definition: vec4i.h:201
GfVec4i GetComplement(GfVec4i const &b) const
Definition: vec4i.h:230
Definition: vec4h.h:46
GfVec4i & operator+=(GfVec4i const &other)
Addition.
Definition: vec4i.h:162
int & operator[](size_t i)
Definition: vec4i.h:127
GfVec4i operator*(double s) const
Definition: vec4i.h:193
static GfVec4i ZAxis()
Create a unit vector along the Z-axis.
Definition: vec4i.h:85
bool operator==(GfVec4i const &other) const
Equality comparison.
Definition: vec4i.h:135
GF_API std::ostream & operator<<(std::ostream &, GfVec4i const &)
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GfVec4i GetProjection(GfVec4i const &v) const
Definition: vec4i.h:221
constexpr GfVec4i(Scl const *p)
Construct with pointer to values.
Definition: vec4i.h:67
Definition: vec4f.h:45
int GfDot(GfVec4i const &v1, GfVec4i const &v2)
Returns the dot (inner) product of two vectors.
Definition: vec4i.h:273
GfVec4i & Set(int s0, int s1, int s2, int s3)
Set all elements with passed arguments.
Definition: vec4i.h:107
bool operator!=(GfVec4i const &other) const
Definition: vec4i.h:141
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
friend GfVec4i operator*(double s, GfVec4i const &v)
Definition: vec4i.h:196
int * data()
Definition: vec4i.h:122
GfVec4i operator/(int s) const
Definition: vec4i.h:208
GLfloat GLfloat v1
Definition: glcorearb.h:817
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GfVec4i & Set(int const *a)
Set all elements with a pointer to data.
Definition: vec4i.h:116
friend GfVec4i operator-(GfVec4i const &l, GfVec4i const &r)
Definition: vec4i.h:181
static GfVec4i XAxis()
Create a unit vector along the X-axis.
Definition: vec4i.h:73
GLboolean r
Definition: glcorearb.h:1222
int ScalarType
Scalar element type and dimension.
Definition: vec4i.h:47
static const size_t dimension
Definition: vec4i.h:48
int operator*(GfVec4i const &v) const
See GfDot().
Definition: vec4i.h:213
constexpr GfVec4i(int s0, int s1, int s2, int s3)
Initialize all elements with explicit arguments.
Definition: vec4i.h:60
#define GF_API
Definition: api.h:23
static GfVec4i WAxis()
Create a unit vector along the W-axis.
Definition: vec4i.h:91
int GetLengthSq() const
Squared length.
Definition: vec4i.h:235