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