HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
size3.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 #ifndef PXR_BASE_GF_SIZE3_H
8 #define PXR_BASE_GF_SIZE3_H
9 
10 /// \file gf/size3.h
11 /// \ingroup group_gf_LinearAlgebra
12 
13 #include "pxr/pxr.h"
14 #include "pxr/base/arch/inttypes.h"
15 #include "pxr/base/gf/vec3i.h"
16 #include "pxr/base/gf/api.h"
17 
18 #include <iosfwd>
19 
21 
22 /// \class GfSize3
23 /// \ingroup group_gf_LinearAlgebra
24 ///
25 /// Three-dimensional array of sizes
26 ///
27 /// GfSize3 is used to represent triples of counts. It is based on the
28 /// datatype size_t, and thus can only represent non-negative values in each
29 /// dimension. If you need to represent negative numbers as well, use GfVeci.
30 ///
31 /// Usage of GfSize3 is similar to that of GfVec3i, except that all
32 /// mathematical operations are componentwise (including multiplication).
33 ///
34 class GfSize3 {
35 public:
36  /// Default constructor initializes components to zero
37  GfSize3() {
38  Set(0, 0, 0);
39  }
40 
41  /// Copy constructor.
42  GfSize3(const GfSize3& o) {
43  *this = o;
44  }
45 
46  /// Conversion from GfVec3i
47  explicit GfSize3(const GfVec3i&o) {
48  Set(o[0], o[1], o[2]);
49  }
50 
51  /// Construct from an array
52  GfSize3(const size_t v[3]) {
53  Set(v);
54  }
55 
56  /// Construct from three values
57  GfSize3(size_t v0, size_t v1, size_t v2) {
58  Set(v0, v1, v2);
59  }
60 
61  /// Set to the values in \p v.
62  GfSize3 & Set(const size_t v[3]) {
63  _vec[0] = v[0];
64  _vec[1] = v[1];
65  _vec[2] = v[2];
66  return *this;
67  }
68 
69  /// Set to values passed directly
70  GfSize3 & Set(size_t v0, size_t v1, size_t v2) {
71  _vec[0] = v0;
72  _vec[1] = v1;
73  _vec[2] = v2;
74  return *this;
75  }
76 
77  /// Array operator
78  size_t & operator [](size_t i) {
79  return _vec[i];
80  }
81 
82  /// Const array operator
83  const size_t & operator [](size_t i) const {
84  return _vec[i];
85  }
86 
87  /// Component-wise equality
88  bool operator ==(const GfSize3 &v) const {
89  return _vec[0] == v._vec[0] && _vec[1] == v._vec[1] &&
90  _vec[2] == v._vec[2];
91  }
92 
93  /// Component-wise inequality
94  bool operator !=(const GfSize3 &v) const {
95  return ! (*this == v);
96  }
97 
98  /// Component-wise in-place addition
100  _vec[0] += v._vec[0];
101  _vec[1] += v._vec[1];
102  _vec[2] += v._vec[2];
103  return *this;
104  }
105 
106  /// Component-wise in-place subtraction
108  _vec[0] -= v._vec[0];
109  _vec[1] -= v._vec[1];
110  _vec[2] -= v._vec[2];
111  return *this;
112  }
113 
114  /// Component-wise in-place multiplication.
116  _vec[0] *= v._vec[0];
117  _vec[1] *= v._vec[1];
118  _vec[2] *= v._vec[2];
119  return *this;
120  }
121 
122  /// Component-wise in-place multiplication by a scalar
123  GfSize3 & operator *=(size_t d) {
124  _vec[0] = _vec[0] * d;
125  _vec[1] = _vec[1] * d;
126  _vec[2] = _vec[2] * d;
127  return *this;
128  }
129 
130  /// Component-wise in-place division by a scalar
131  GfSize3 & operator /=(size_t d) {
132  _vec[0] = _vec[0] / d;
133  _vec[1] = _vec[1] / d;
134  _vec[2] = _vec[2] / d;
135  return *this;
136  }
137 
138  /// Component-wise addition
139  friend GfSize3 operator +(const GfSize3 &v1, const GfSize3 &v3) {
140  return GfSize3(v1._vec[0]+v3._vec[0],
141  v1._vec[1]+v3._vec[1],
142  v1._vec[2]+v3._vec[2]);
143  }
144 
145  /// Component-wise subtraction
146  friend GfSize3 operator -(const GfSize3 &v1, const GfSize3 &v3) {
147  return GfSize3(v1._vec[0]-v3._vec[0],
148  v1._vec[1]-v3._vec[1],
149  v1._vec[2]-v3._vec[2]);
150  }
151 
152  /// Component-wise multiplication
153  friend GfSize3 operator *(const GfSize3 &v1, const GfSize3 &v3) {
154  return GfSize3(v1._vec[0]*v3._vec[0],
155  v1._vec[1]*v3._vec[1],
156  v1._vec[2]*v3._vec[2]);
157  }
158 
159  /// Component-wise multiplication by a scalar
160  friend GfSize3 operator *(const GfSize3 &v1, size_t s) {
161  return GfSize3(v1._vec[0]*s,
162  v1._vec[1]*s,
163  v1._vec[2]*s);
164  }
165 
166  /// Component-wise multiplication by a scalar
167  friend GfSize3 operator *(size_t s, const GfSize3 &v1) {
168  return GfSize3(v1._vec[0]*s,
169  v1._vec[1]*s,
170  v1._vec[2]*s);
171  }
172 
173  /// Component-wise division by a scalar
174  friend GfSize3 operator /(const GfSize3 &v1, size_t s) {
175  return GfSize3(v1._vec[0]/s,
176  v1._vec[1]/s,
177  v1._vec[2]/s);
178  }
179 
180  /// Output operator
181  friend GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
182 
183  /// Conversion to GfVec3i
184  operator GfVec3i() const {
185  return GfVec3i(_vec[0],_vec[1],_vec[2]);
186  }
187 private:
188  size_t _vec[3];
189 };
190 
191 // Friend functions must be declared
192 GF_API std::ostream &operator<<(std::ostream &o, GfSize3 const &v);
193 
195 
196 #endif // PXR_BASE_GF_SIZE3_H
friend GfSize3 operator*(const GfSize3 &v1, const GfSize3 &v3)
Component-wise multiplication.
Definition: size3.h:153
const GLdouble * v
Definition: glcorearb.h:837
Definition: size3.h:34
GfSize3 & operator/=(size_t d)
Component-wise in-place division by a scalar.
Definition: size3.h:131
GfSize3 & Set(size_t v0, size_t v1, size_t v2)
Set to values passed directly.
Definition: size3.h:70
GLdouble s
Definition: glad.h:3009
GfSize3(const size_t v[3])
Construct from an array.
Definition: size3.h:52
GF_API std::ostream & operator<<(std::ostream &o, GfSize3 const &v)
GfSize3 & operator*=(GfSize3 const &v)
Component-wise in-place multiplication.
Definition: size3.h:115
GLfloat GLfloat GLfloat v2
Definition: glcorearb.h:818
GLfloat GLfloat GLfloat GLfloat v3
Definition: glcorearb.h:819
size_t & operator[](size_t i)
Array operator.
Definition: size3.h:78
bool operator==(const GfSize3 &v) const
Component-wise equality.
Definition: size3.h:88
GfSize3 & Set(const size_t v[3])
Set to the values in v.
Definition: size3.h:62
friend GF_API std::ostream & operator<<(std::ostream &o, GfSize3 const &v)
Output operator.
friend GfSize3 operator/(const GfSize3 &v1, size_t s)
Component-wise division by a scalar.
Definition: size3.h:174
Definition: vec3i.h:43
GfSize3(size_t v0, size_t v1, size_t v2)
Construct from three values.
Definition: size3.h:57
bool operator!=(const GfSize3 &v) const
Component-wise inequality.
Definition: size3.h:94
GfSize3(const GfVec3i &o)
Conversion from GfVec3i.
Definition: size3.h:47
GLfloat v0
Definition: glcorearb.h:816
GfSize3 & operator+=(const GfSize3 &v)
Component-wise in-place addition.
Definition: size3.h:99
GfSize3 & operator-=(const GfSize3 &v)
Component-wise in-place subtraction.
Definition: size3.h:107
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
friend GfSize3 operator-(const GfSize3 &v1, const GfSize3 &v3)
Component-wise subtraction.
Definition: size3.h:146
GfSize3()
Default constructor initializes components to zero.
Definition: size3.h:37
GLfloat GLfloat v1
Definition: glcorearb.h:817
GfSize3(const GfSize3 &o)
Copy constructor.
Definition: size3.h:42
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
friend GfSize3 operator+(const GfSize3 &v1, const GfSize3 &v3)
Component-wise addition.
Definition: size3.h:139
#define GF_API
Definition: api.h:23