HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range3d.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_RANGE3D_H
29 #define PXR_BASE_GF_RANGE3D_H
30 
31 /// \file gf/range3d.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 GfRange3d> { static const bool value = true; };
53 
54 /// \class GfRange3d
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 GfRange3d
64 {
65 public:
66 
67  /// Helper typedef.
69 
70  static const size_t dimension = GfVec3d::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  GfRange3d(const GfVec3d &min, const GfVec3d &max)
87  : _min(min), _max(max)
88  {
89  }
90 
91 
92  /// Implicitly convert from GfRange3f.
93  GF_API
94  GfRange3d(class GfRange3f const &other);
95 
96  /// Returns the minimum value of the range.
97  const GfVec3d &GetMin() const { return _min; }
98 
99  /// Returns the maximum value of the range.
100  const GfVec3d &GetMax() const { return _max; }
101 
102  /// Returns the size of the range.
103  GfVec3d 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 GfVec3d &min) { _min = min; }
115 
116  /// Sets the maximum value of the range.
117  void SetMax(const GfVec3d &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 GfVec3d &point) { UnionWith(point); }
127 
128  /// Modifies the range if necessary to surround the given range.
129  /// \deprecated Use UnionWith() instead.
130  void ExtendBy(const GfRange3d &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 GfVec3d &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 GfRange3d &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 GfVec3d &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 GfRange3d &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 GfRange3d &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 GfRange3d which contains both \p a and \p b.
172  static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b) {
173  GfRange3d 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 GfRange3d &UnionWith(const GfRange3d &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 GfRange3d &UnionWith(const GfVec3d &b) {
188  _FindMin(_min,b);
189  _FindMax(_max,b);
190  return *this;
191  }
192 
193  /// Returns the smallest \c GfRange3d which contains both \p a and \p b
194  /// \deprecated Use GetUnion() instead.
195  static GfRange3d Union(const GfRange3d &a, const GfRange3d &b) {
196  return GetUnion(a, b);
197  }
198 
199  /// Extend \p this to include \p b.
200  /// \deprecated Use UnionWith() instead.
201  const GfRange3d &Union(const GfRange3d &b) {
202  return UnionWith(b);
203  }
204 
205  /// Extend \p this to include \p b.
206  /// \deprecated Use UnionWith() instead.
207  const GfRange3d &Union(const GfVec3d &b) {
208  return UnionWith(b);
209  }
210 
211  /// Returns a \c GfRange3d that describes the intersection of \p a and \p b.
212  static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b) {
213  GfRange3d res = a;
214  _FindMax(res._min,b._min);
215  _FindMin(res._max,b._max);
216  return res;
217  }
218 
219  /// Returns a \c GfRange3d that describes the intersection of \p a and \p b.
220  /// \deprecated Use GetIntersection() instead.
221  static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &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  GfRange3d &operator *=(double m) {
256  if (m > 0) {
257  _min *= m;
258  _max *= m;
259  } else {
260  GfVec3d tmp = _min;
261  _min = _max * m;
262  _max = tmp * m;
263  }
264  return *this;
265  }
266 
267  /// unary division.
268  GfRange3d &operator /=(double m) {
269  return *this *= (1.0 / m);
270  }
271 
272  /// binary sum.
273  GfRange3d operator +(const GfRange3d &b) const {
274  return GfRange3d(_min + b._min, _max + b._max);
275  }
276 
277 
278  /// binary difference.
279  GfRange3d operator -(const GfRange3d &b) const {
280  return GfRange3d(_min - b._max, _max - b._min);
281  }
282 
283  /// scalar multiply.
284  friend GfRange3d operator *(double m, const GfRange3d &r) {
285  return (m > 0 ?
286  GfRange3d(r._min*m, r._max*m) :
287  GfRange3d(r._max*m, r._min*m));
288  }
289 
290  /// scalar multiply.
291  friend GfRange3d operator *(const GfRange3d &r, double m) {
292  return (m > 0 ?
293  GfRange3d(r._min*m, r._max*m) :
294  GfRange3d(r._max*m, r._min*m));
295  }
296 
297  /// scalar divide.
298  friend GfRange3d operator /(const GfRange3d &r, double m) {
299  return r * (1.0 / m);
300  }
301 
302  /// hash.
303  friend inline size_t hash_value(const GfRange3d &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 GfRange3d &b) const {
309  return (_min == b._min && _max == b._max);
310  }
311 
312  bool operator !=(const GfRange3d &b) const {
313  return !(*this == b);
314  }
315 
316  /// Compare this range to a GfRange3f.
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 GfRange3f& other) const;
321  GF_API inline bool operator !=(const GfRange3f& other) const;
322 
323  /// Compute the squared distance from a point to the range.
324  GF_API
325  double GetDistanceSquared(const GfVec3d &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  GfVec3d 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  GfRange3d GetOctant(size_t i) const;
338 
339  /// The unit cube.
340  GF_API
341  static const GfRange3d UnitCube;
342 
343  private:
344  /// Minimum and maximum points.
345  GfVec3d _min, _max;
346 
347  /// Extends minimum point if necessary to contain given point.
348  static void _FindMin(GfVec3d &dest, const GfVec3d &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(GfVec3d &dest, const GfVec3d &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 GfRange3d.
363 /// \ingroup group_gf_DebuggingOutput
364 GF_API std::ostream& operator<<(std::ostream &, GfRange3d const &);
365 
367 #include "pxr/base/gf/range3f.h"
369 
370 inline bool
371 GfRange3d::operator ==(const GfRange3f& other) const {
372  return _min == GfVec3d(other.GetMin()) &&
373  _max == GfVec3d(other.GetMax());
374 }
375 
376 inline bool
377 GfRange3d::operator !=(const GfRange3f& other) const {
378  return !(*this == other);
379 }
380 
381 
383 
384 #endif // PXR_BASE_GF_RANGE3D_H
GF_API GfRange3d GetOctant(size_t i) const
static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:172
GLenum GLint * range
Definition: glcorearb.h:1925
*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
GfRange3d(const GfVec3d &min, const GfVec3d &max)
This constructor initializes the minimum and maximum points.
Definition: range3d.h:86
void SetMin(const GfVec3d &min)
Sets the minimum value of the range.
Definition: range3d.h:114
static GF_API const GfRange3d UnitCube
The unit cube.
Definition: range3d.h:341
double ScalarType
Scalar element type and dimension.
Definition: vec3d.h:66
bool IsOutside(const GfRange3d &range) const
Definition: range3d.h:165
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:97
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GfVec3d GetSize() const
Returns the size of the range.
Definition: range3d.h:103
static const size_t dimension
Definition: range3d.h:70
GfRange3d operator+(const GfRange3d &b) const
binary sum.
Definition: range3d.h:273
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void ExtendBy(const GfVec3d &point)
Definition: range3d.h:126
GfRange3d & operator+=(const GfRange3d &b)
unary sum.
Definition: range3d.h:241
GF_API GfVec3d GetCorner(size_t i) const
GF_API double GetDistanceSquared(const GfVec3d &p) const
Compute the squared distance from a point to the range.
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:97
const GfRange3d & UnionWith(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:187
friend GfRange3d operator/(const GfRange3d &r, double m)
scalar divide.
Definition: range3d.h:298
GfRange3d & operator-=(const GfRange3d &b)
unary difference.
Definition: range3d.h:248
bool IsInside(const GfVec3d &point) const
Definition: range3d.h:150
bool Contains(const GfRange3d &range) const
Definition: range3d.h:143
void SetEmpty()
Sets the range to an empty interval.
Definition: range3d.h:75
const GfRange3d & Union(const GfVec3d &b)
Definition: range3d.h:207
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3d.h:120
const GfRange3d & Union(const GfRange3d &b)
Definition: range3d.h:201
GF_API std::ostream & operator<<(std::ostream &, GfRange3d const &)
GfRange3d & operator/=(double m)
unary division.
Definition: range3d.h:268
static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b)
Definition: range3d.h:221
bool operator==(const GfRange3d &b) const
The min and max points must match exactly for equality.
Definition: range3d.h:308
static GfRange3d Union(const GfRange3d &a, const GfRange3d &b)
Definition: range3d.h:195
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GfRange3d()
The default constructor creates an empty range.
Definition: range3d.h:81
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:100
static const size_t dimension
Definition: vec3d.h:67
const GfRange3d & IntersectWith(const GfRange3d &b)
Definition: range3d.h:227
static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:212
bool IsInside(const GfRange3d &range) const
Definition: range3d.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
void ExtendBy(const GfRange3d &range)
Definition: range3d.h:130
const GfRange3d & UnionWith(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:180
void SetMax(const GfVec3d &max)
Sets the maximum value of the range.
Definition: range3d.h:117
bool Contains(const GfVec3d &point) const
Definition: range3d.h:134
Definition: vec3d.h:62
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
friend size_t hash_value(const GfRange3d &r)
hash.
Definition: range3d.h:303
GfVec3d::ScalarType ScalarType
Definition: range3d.h:71
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:100
friend GfRange3d operator*(double m, const GfRange3d &r)
scalar multiply.
Definition: range3d.h:284
Definition: core.h:1131
GfRange3d & operator*=(double m)
unary multiply.
Definition: range3d.h:255
GLboolean r
Definition: glcorearb.h:1222
const GfRange3d & Intersection(const GfRange3d &b)
Definition: range3d.h:236
GfVec3d MinMaxType
Helper typedef.
Definition: range3d.h:68
GfVec3d GetMidpoint() const
Definition: range3d.h:108
#define GF_API
Definition: api.h:40
bool operator!=(const GfRange3d &b) const
Definition: range3d.h:312
GfRange3d operator-(const GfRange3d &b) const
binary difference.
Definition: range3d.h:279