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 //
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 
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 <boost/functional/hash.hpp>
42 
43 #include <cfloat>
44 #include <cstddef>
45 #include <iosfwd>
46 
47 PXR_NAMESPACE_OPEN_SCOPE
48 
49 class GfRange3d;
50 class GfRange3f;
51 
52 template <>
53 struct GfIsGfRange<class GfRange3d> { static const bool value = true; };
54 
64 class GfRange3d
65 {
66 public:
67 
70 
71  static const size_t dimension = GfVec3d::dimension;
72  typedef GfVec3d::ScalarType ScalarType;
73 
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 
83  SetEmpty();
84  }
85 
87  GfRange3d(const GfVec3d &min, const GfVec3d &max)
88  : _min(min), _max(max)
89  {
90  }
91 
93  const GfVec3d &GetMin() const { return _min; }
94 
96  const GfVec3d &GetMax() const { return _max; }
97 
99  GfVec3d GetSize() const { return _max - _min; }
100 
105  return static_cast<ScalarType>(0.5) * _min
106  + static_cast<ScalarType>(0.5) * _max;
107  }
108 
110  void SetMin(const GfVec3d &min) { _min = min; }
111 
113  void SetMax(const GfVec3d &max) { _max = max; }
114 
116  bool IsEmpty() const {
117  return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
118  }
119 
122  void ExtendBy(const GfVec3d &point) { UnionWith(point); }
123 
126  void ExtendBy(const GfRange3d &range) { UnionWith(range); }
127 
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 
139  bool Contains(const GfRange3d &range) const {
140  return Contains(range._min) && Contains(range._max);
141  }
142 
146  bool IsInside(const GfVec3d &point) const {
147  return Contains(point);
148  }
149 
154  bool IsInside(const GfRange3d &range) const {
155  return Contains(range);
156  }
157 
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 
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 
176  const GfRange3d &UnionWith(const GfRange3d &b) {
177  _FindMin(_min,b._min);
178  _FindMax(_max,b._max);
179  return *this;
180  }
181 
183  const GfRange3d &UnionWith(const GfVec3d &b) {
184  _FindMin(_min,b);
185  _FindMax(_max,b);
186  return *this;
187  }
188 
191  static GfRange3d Union(const GfRange3d &a, const GfRange3d &b) {
192  return GetUnion(a, b);
193  }
194 
197  const GfRange3d &Union(const GfRange3d &b) {
198  return UnionWith(b);
199  }
200 
203  const GfRange3d &Union(const GfVec3d &b) {
204  return UnionWith(b);
205  }
206 
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 
217  static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b) {
218  return GetIntersection(a, b);
219  }
220 
223  const GfRange3d &IntersectWith(const GfRange3d &b) {
224  _FindMax(_min,b._min);
225  _FindMin(_max,b._max);
226  return *this;
227  }
228 
232  const GfRange3d &Intersection(const GfRange3d &b) {
233  return IntersectWith(b);
234  }
235 
238  _min += b._min;
239  _max += b._max;
240  return *this;
241  }
242 
245  _min -= b._max;
246  _max -= b._min;
247  return *this;
248  }
249 
251  GfRange3d operator *=(double m) {
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 
264  GfRange3d operator /=(double m) {
265  return *this *= (1.0 / m);
266  }
267 
269  GfRange3d operator +(const GfRange3d &b) const {
270  return GfRange3d(_min + b._min, _max + b._max);
271  }
272 
273 
275  GfRange3d operator -(const GfRange3d &b) const {
276  return GfRange3d(_min - b._max, _max - b._min);
277  }
278 
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 
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 
294  friend GfRange3d operator /(const GfRange3d &r, double m) {
295  return r * (1.0 / m);
296  }
297 
299  friend inline size_t hash_value(const GfRange3d &r) {
300  size_t h = 0;
301  boost::hash_combine(h, r._min);
302  boost::hash_combine(h, r._max);
303  return h;
304  }
305 
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 
319  GF_API inline bool operator ==(const GfRange3f& other) const;
320  GF_API inline bool operator !=(const GfRange3f& other) const;
321 
323  GF_API
324  double GetDistanceSquared(const GfVec3d &p) const;
325 
329  GF_API
330  GfVec3d GetCorner(size_t i) const;
331 
335  GF_API
336  GfRange3d GetOctant(size_t i) const;
337 
339  GF_API
340  static const GfRange3d UnitCube;
341 
342  private:
344  GfVec3d _min, _max;
345 
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 
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 
363 GF_API std::ostream& operator<<(std::ostream &, GfRange3d const &);
364 
365 PXR_NAMESPACE_CLOSE_SCOPE
366 #include "pxr/base/gf/range3f.h"
367 PXR_NAMESPACE_OPEN_SCOPE
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 
381 PXR_NAMESPACE_CLOSE_SCOPE
382 
383 #endif // GF_RANGE3D_H
bool operator==(const GfRange3d &b) const
The min and max points must match exactly for equality.
Definition: range3d.h:307
const GfRange3d & Union(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:197
GfRange3d operator+(const GfRange3d &b) const
binary sum.
Definition: range3d.h:269
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:93
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:96
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
bool IsInside(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:146
double ScalarType
Scalar element type and dimension.
Definition: vec3d.h:67
static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:168
const GfRange3d & UnionWith(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:176
A metafunction with a static const bool member &#39;value&#39; that is true for GfRange types and false for a...
Definition: traits.h:50
GfRange3d(const GfVec3d &min, const GfVec3d &max)
This constructor initializes the minimum and maximum points.
Definition: range3d.h:87
GfRange3d operator/=(double m)
unary division.
Definition: range3d.h:264
static GfRange3d Union(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:191
GfRange3d operator-(const GfRange3d &b) const
binary difference.
Definition: range3d.h:275
void SetMin(const GfVec3d &min)
Sets the minimum value of the range.
Definition: range3d.h:110
void SetEmpty()
Sets the range to an empty interval.
Definition: range3d.h:76
GfVec3d MinMaxType
Helper typedef.
Definition: range3d.h:69
static GF_API const GfRange3d UnitCube
The unit cube.
Definition: range3d.h:340
bool Contains(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:130
friend GfRange3d operator/(const GfRange3d &r, double m)
scalar divide.
Definition: range3d.h:294
GfRange3d operator+=(const GfRange3d &b)
unary sum.
Definition: range3d.h:237
const GfRange3d & UnionWith(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:183
bool IsEmpty() const
Returns whether the range is empty (max &lt; min).
Definition: range3d.h:116
Basic type: 3-dimensional floating point range.
Definition: range3f.h:64
GfRange3d operator-=(const GfRange3d &b)
unary difference.
Definition: range3d.h:244
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:93
GF_API GfRange3d GetOctant(size_t i) const
Returns the ith octant of the range, in the following order: LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF.
const GfRange3d & Union(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:203
bool Contains(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:139
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfRange3d operator*=(double m)
unary multiply.
Definition: range3d.h:251
const GfRange3d & Intersection(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:232
void ExtendBy(const GfVec3d &point)
Modifies the range if necessary to surround the given value.
Definition: range3d.h:122
static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:217
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:96
GfVec3d GetSize() const
Returns the size of the range.
Definition: range3d.h:99
GfRange3d()
The default constructor creates an empty range.
Definition: range3d.h:82
friend size_t hash_value(const GfRange3d &r)
hash.
Definition: range3d.h:299
GfVec3d GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3d.h:104
bool IsInside(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:154
friend GfRange3d operator*(double m, const GfRange3d &r)
scalar multiply.
Definition: range3d.h:280
bool IsOutside(const GfRange3d &range) const
Returns true if the range is located entirely outside the range.
Definition: range3d.h:161
static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:208
void SetMax(const GfVec3d &max)
Sets the maximum value of the range.
Definition: range3d.h:113
GF_API double GetDistanceSquared(const GfVec3d &p) const
Compute the squared distance from a point to the range.
GF_API GfVec3d GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF.
const GfRange3d & IntersectWith(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:223
void ExtendBy(const GfRange3d &range)
Modifies the range if necessary to surround the given range.
Definition: range3d.h:126