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