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