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