HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range3f.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 // range.template.h file to make changes.
27 
28 #ifndef PXR_BASE_GF_RANGE3F_H
29 #define PXR_BASE_GF_RANGE3F_H
30 
31 /// \file gf/range3f.h
32 /// \ingroup group_gf_BasicGeometry
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/vec3d.h"
38 #include "pxr/base/gf/vec3f.h"
39 #include "pxr/base/gf/traits.h"
40 #include "pxr/base/tf/hash.h"
41 
42 #include <cfloat>
43 #include <cstddef>
44 #include <iosfwd>
45 
47 
48 class GfRange3d;
49 class GfRange3f;
50 
51 template <>
52 struct GfIsGfRange<class GfRange3f> { static const bool value = true; };
53 
54 /// \class GfRange3f
55 /// \ingroup group_gf_BasicGeometry
56 ///
57 /// Basic type: 3-dimensional floating point range.
58 ///
59 /// This class represents a 3-dimensional range (or interval) All
60 /// operations are component-wise and conform to interval mathematics. An
61 /// empty range is one where max < min.
62 /// The default empty is [FLT_MAX,-FLT_MAX]
63 class GfRange3f
64 {
65 public:
66 
67  /// Helper typedef.
69 
70  static const size_t dimension = GfVec3f::dimension;
72 
73  /// Sets the range to an empty interval
74  // TODO check whether this can be deprecated.
75  void inline SetEmpty() {
76  _min[0] = _min[1] = _min[2] = FLT_MAX;
77  _max[0] = _max[1] = _max[2] = -FLT_MAX;
78  }
79 
80  /// The default constructor creates an empty range.
82  SetEmpty();
83  }
84 
85  /// This constructor initializes the minimum and maximum points.
86  GfRange3f(const GfVec3f &min, const GfVec3f &max)
87  : _min(min), _max(max)
88  {
89  }
90 
91 
92  /// Construct from GfRange3d.
93  GF_API
94  explicit GfRange3f(class GfRange3d const &other);
95 
96  /// Returns the minimum value of the range.
97  const GfVec3f &GetMin() const { return _min; }
98 
99  /// Returns the maximum value of the range.
100  const GfVec3f &GetMax() const { return _max; }
101 
102  /// Returns the size of the range.
103  GfVec3f GetSize() const { return _max - _min; }
104 
105  /// Returns the midpoint of the range, that is, 0.5*(min+max).
106  /// Note: this returns zero in the case of default-constructed ranges,
107  /// or ranges set via SetEmpty().
109  return static_cast<ScalarType>(0.5) * _min
110  + static_cast<ScalarType>(0.5) * _max;
111  }
112 
113  /// Sets the minimum value of the range.
114  void SetMin(const GfVec3f &min) { _min = min; }
115 
116  /// Sets the maximum value of the range.
117  void SetMax(const GfVec3f &max) { _max = max; }
118 
119  /// Returns whether the range is empty (max < min).
120  bool IsEmpty() const {
121  return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
122  }
123 
124  /// Modifies the range if necessary to surround the given value.
125  /// \deprecated Use UnionWith() instead.
126  void ExtendBy(const GfVec3f &point) { UnionWith(point); }
127 
128  /// Modifies the range if necessary to surround the given range.
129  /// \deprecated Use UnionWith() instead.
130  void ExtendBy(const GfRange3f &range) { UnionWith(range); }
131 
132  /// Returns true if the \p point is located inside the range. As with all
133  /// operations of this type, the range is assumed to include its extrema.
134  bool Contains(const GfVec3f &point) const {
135  return (point[0] >= _min[0] && point[0] <= _max[0]
136  && point[1] >= _min[1] && point[1] <= _max[1]
137  && point[2] >= _min[2] && point[2] <= _max[2]);
138  }
139 
140  /// Returns true if the \p range is located entirely inside the range. As
141  /// with all operations of this type, the ranges are assumed to include
142  /// their extrema.
143  bool Contains(const GfRange3f &range) const {
144  return Contains(range._min) && Contains(range._max);
145  }
146 
147  /// Returns true if the \p point is located inside the range. As with all
148  /// operations of this type, the range is assumed to include its extrema.
149  /// \deprecated Use Contains() instead.
150  bool IsInside(const GfVec3f &point) const {
151  return Contains(point);
152  }
153 
154  /// Returns true if the \p range is located entirely inside the range. As
155  /// with all operations of this type, the ranges are assumed to include
156  /// their extrema.
157  /// \deprecated Use Contains() instead.
158  bool IsInside(const GfRange3f &range) const {
159  return Contains(range);
160  }
161 
162  /// Returns true if the \p range is located entirely outside the range. As
163  /// with all operations of this type, the ranges are assumed to include
164  /// their extrema.
165  bool IsOutside(const GfRange3f &range) const {
166  return ((range._max[0] < _min[0] || range._min[0] > _max[0])
167  || (range._max[1] < _min[1] || range._min[1] > _max[1])
168  || (range._max[2] < _min[2] || range._min[2] > _max[2]));
169  }
170 
171  /// Returns the smallest \c GfRange3f which contains both \p a and \p b.
172  static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b) {
173  GfRange3f res = a;
174  _FindMin(res._min,b._min);
175  _FindMax(res._max,b._max);
176  return res;
177  }
178 
179  /// Extend \p this to include \p b.
180  const GfRange3f &UnionWith(const GfRange3f &b) {
181  _FindMin(_min,b._min);
182  _FindMax(_max,b._max);
183  return *this;
184  }
185 
186  /// Extend \p this to include \p b.
187  const GfRange3f &UnionWith(const GfVec3f &b) {
188  _FindMin(_min,b);
189  _FindMax(_max,b);
190  return *this;
191  }
192 
193  /// Returns the smallest \c GfRange3f which contains both \p a and \p b
194  /// \deprecated Use GetUnion() instead.
195  static GfRange3f Union(const GfRange3f &a, const GfRange3f &b) {
196  return GetUnion(a, b);
197  }
198 
199  /// Extend \p this to include \p b.
200  /// \deprecated Use UnionWith() instead.
201  const GfRange3f &Union(const GfRange3f &b) {
202  return UnionWith(b);
203  }
204 
205  /// Extend \p this to include \p b.
206  /// \deprecated Use UnionWith() instead.
207  const GfRange3f &Union(const GfVec3f &b) {
208  return UnionWith(b);
209  }
210 
211  /// Returns a \c GfRange3f that describes the intersection of \p a and \p b.
212  static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b) {
213  GfRange3f res = a;
214  _FindMax(res._min,b._min);
215  _FindMin(res._max,b._max);
216  return res;
217  }
218 
219  /// Returns a \c GfRange3f that describes the intersection of \p a and \p b.
220  /// \deprecated Use GetIntersection() instead.
221  static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b) {
222  return GetIntersection(a, b);
223  }
224 
225  /// Modifies this range to hold its intersection with \p b and returns the
226  /// result
228  _FindMax(_min,b._min);
229  _FindMin(_max,b._max);
230  return *this;
231  }
232 
233  /// Modifies this range to hold its intersection with \p b and returns the
234  /// result.
235  /// \deprecated Use IntersectWith() instead.
237  return IntersectWith(b);
238  }
239 
240  /// unary sum.
242  _min += b._min;
243  _max += b._max;
244  return *this;
245  }
246 
247  /// unary difference.
249  _min -= b._max;
250  _max -= b._min;
251  return *this;
252  }
253 
254  /// unary multiply.
255  GfRange3f &operator *=(double m) {
256  if (m > 0) {
257  _min *= m;
258  _max *= m;
259  } else {
260  GfVec3f tmp = _min;
261  _min = _max * m;
262  _max = tmp * m;
263  }
264  return *this;
265  }
266 
267  /// unary division.
268  GfRange3f &operator /=(double m) {
269  return *this *= (1.0 / m);
270  }
271 
272  /// binary sum.
273  GfRange3f operator +(const GfRange3f &b) const {
274  return GfRange3f(_min + b._min, _max + b._max);
275  }
276 
277 
278  /// binary difference.
279  GfRange3f operator -(const GfRange3f &b) const {
280  return GfRange3f(_min - b._max, _max - b._min);
281  }
282 
283  /// scalar multiply.
284  friend GfRange3f operator *(double m, const GfRange3f &r) {
285  return (m > 0 ?
286  GfRange3f(r._min*m, r._max*m) :
287  GfRange3f(r._max*m, r._min*m));
288  }
289 
290  /// scalar multiply.
291  friend GfRange3f operator *(const GfRange3f &r, double m) {
292  return (m > 0 ?
293  GfRange3f(r._min*m, r._max*m) :
294  GfRange3f(r._max*m, r._min*m));
295  }
296 
297  /// scalar divide.
298  friend GfRange3f operator /(const GfRange3f &r, double m) {
299  return r * (1.0 / m);
300  }
301 
302  /// hash.
303  friend inline size_t hash_value(const GfRange3f &r) {
304  return TfHash::Combine(r._min, r._max);
305  }
306 
307  /// The min and max points must match exactly for equality.
308  bool operator ==(const GfRange3f &b) const {
309  return (_min == b._min && _max == b._max);
310  }
311 
312  bool operator !=(const GfRange3f &b) const {
313  return !(*this == b);
314  }
315 
316  /// Compare this range to a GfRange3d.
317  ///
318  /// The values must match exactly and it does exactly what you might
319  /// expect when comparing float and double values.
320  GF_API inline bool operator ==(const GfRange3d& other) const;
321  GF_API inline bool operator !=(const GfRange3d& other) const;
322 
323  /// Compute the squared distance from a point to the range.
324  GF_API
325  double GetDistanceSquared(const GfVec3f &p) const;
326 
327  /// Returns the ith corner of the range, in the following order:
328  /// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
329  /// D/U is down/up, and B/F is back/front.
330  GF_API
331  GfVec3f GetCorner(size_t i) const;
332 
333  /// Returns the ith octant of the range, in the following order:
334  /// LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF. Where L/R is left/right,
335  /// D/U is down/up, and B/F is back/front.
336  GF_API
337  GfRange3f GetOctant(size_t i) const;
338 
339  /// The unit cube.
340  GF_API
341  static const GfRange3f UnitCube;
342 
343  private:
344  /// Minimum and maximum points.
345  GfVec3f _min, _max;
346 
347  /// Extends minimum point if necessary to contain given point.
348  static void _FindMin(GfVec3f &dest, const GfVec3f &point) {
349  if (point[0] < dest[0]) dest[0] = point[0];
350  if (point[1] < dest[1]) dest[1] = point[1];
351  if (point[2] < dest[2]) dest[2] = point[2];
352  }
353 
354  /// Extends maximum point if necessary to contain given point.
355  static void _FindMax(GfVec3f &dest, const GfVec3f &point) {
356  if (point[0] > dest[0]) dest[0] = point[0];
357  if (point[1] > dest[1]) dest[1] = point[1];
358  if (point[2] > dest[2]) dest[2] = point[2];
359  }
360 };
361 
362 /// Output a GfRange3f.
363 /// \ingroup group_gf_DebuggingOutput
364 GF_API std::ostream& operator<<(std::ostream &, GfRange3f const &);
365 
367 #include "pxr/base/gf/range3d.h"
369 
370 inline bool
371 GfRange3f::operator ==(const GfRange3d& other) const {
372  return _min == GfVec3f(other.GetMin()) &&
373  _max == GfVec3f(other.GetMax());
374 }
375 
376 inline bool
377 GfRange3f::operator !=(const GfRange3d& other) const {
378  return !(*this == other);
379 }
380 
381 
383 
384 #endif // PXR_BASE_GF_RANGE3F_H
const GfRange3f & Intersection(const GfRange3f &b)
Definition: range3f.h:236
GfRange3f & operator/=(double m)
unary division.
Definition: range3f.h:268
GLenum GLint * range
Definition: glcorearb.h:1925
static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:172
*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 GfRange3f & UnionWith(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:180
GfVec3f MinMaxType
Helper typedef.
Definition: range3f.h:68
static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b)
Definition: range3f.h:221
GfRange3f & operator+=(const GfRange3f &b)
unary sum.
Definition: range3f.h:241
static const size_t dimension
Definition: vec3f.h:67
bool operator!=(const GfRange3f &b) const
Definition: range3f.h:312
const GfRange3f & Union(const GfVec3f &b)
Definition: range3f.h:207
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:97
Definition: vec3f.h:62
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3f.h:120
const GfRange3f & Union(const GfRange3f &b)
Definition: range3f.h:201
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:97
bool IsInside(const GfVec3f &point) const
Definition: range3f.h:150
friend GfRange3f operator*(double m, const GfRange3f &r)
scalar multiply.
Definition: range3f.h:284
GfRange3f(const GfVec3f &min, const GfVec3f &max)
This constructor initializes the minimum and maximum points.
Definition: range3f.h:86
bool Contains(const GfVec3f &point) const
Definition: range3f.h:134
GfRange3f operator+(const GfRange3f &b) const
binary sum.
Definition: range3f.h:273
void SetMax(const GfVec3f &max)
Sets the maximum value of the range.
Definition: range3f.h:117
void ExtendBy(const GfRange3f &range)
Definition: range3f.h:130
GfRange3f & operator-=(const GfRange3f &b)
unary difference.
Definition: range3f.h:248
GF_API std::ostream & operator<<(std::ostream &, GfRange3f const &)
bool IsInside(const GfRange3f &range) const
Definition: range3f.h:158
static GF_API const GfRange3f UnitCube
The unit cube.
Definition: range3f.h:341
void SetMin(const GfVec3f &min)
Sets the minimum value of the range.
Definition: range3f.h:114
GF_API GfVec3f GetCorner(size_t i) const
const GfRange3f & IntersectWith(const GfRange3f &b)
Definition: range3f.h:227
static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:212
float ScalarType
Scalar element type and dimension.
Definition: vec3f.h:66
static GfRange3f Union(const GfRange3f &a, const GfRange3f &b)
Definition: range3f.h:195
GfRange3f & operator*=(double m)
unary multiply.
Definition: range3f.h:255
friend size_t hash_value(const GfRange3f &r)
hash.
Definition: range3f.h:303
void ExtendBy(const GfVec3f &point)
Definition: range3f.h:126
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool Contains(const GfRange3f &range) const
Definition: range3f.h:143
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:100
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
GfVec3f GetMidpoint() const
Definition: range3f.h:108
bool IsOutside(const GfRange3f &range) const
Definition: range3f.h:165
bool operator==(const GfRange3f &b) const
The min and max points must match exactly for equality.
Definition: range3f.h:308
GF_API GfRange3f GetOctant(size_t i) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GfVec3f::ScalarType ScalarType
Definition: range3f.h:71
GfRange3f()
The default constructor creates an empty range.
Definition: range3f.h:81
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:100
void SetEmpty()
Sets the range to an empty interval.
Definition: range3f.h:75
Definition: core.h:1131
GF_API double GetDistanceSquared(const GfVec3f &p) const
Compute the squared distance from a point to the range.
GLboolean r
Definition: glcorearb.h:1222
GfRange3f operator-(const GfRange3f &b) const
binary difference.
Definition: range3f.h:279
GfVec3f GetSize() const
Returns the size of the range.
Definition: range3f.h:103
friend GfRange3f operator/(const GfRange3f &r, double m)
scalar divide.
Definition: range3f.h:298
#define GF_API
Definition: api.h:40
static const size_t dimension
Definition: range3f.h:70
const GfRange3f & UnionWith(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:187