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 //
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 
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 GfRange3f> { static const bool value = true; };
54 
64 class GfRange3f
65 {
66 public:
67 
70 
71  static const size_t dimension = GfVec3f::dimension;
72  typedef GfVec3f::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  GfRange3f(const GfVec3f &min, const GfVec3f &max)
88  : _min(min), _max(max)
89  {
90  }
91 
93  const GfVec3f &GetMin() const { return _min; }
94 
96  const GfVec3f &GetMax() const { return _max; }
97 
99  GfVec3f 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 GfVec3f &min) { _min = min; }
111 
113  void SetMax(const GfVec3f &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 GfVec3f &point) { UnionWith(point); }
123 
126  void ExtendBy(const GfRange3f &range) { UnionWith(range); }
127 
130  bool Contains(const GfVec3f &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 GfRange3f &range) const {
140  return Contains(range._min) && Contains(range._max);
141  }
142 
146  bool IsInside(const GfVec3f &point) const {
147  return Contains(point);
148  }
149 
154  bool IsInside(const GfRange3f &range) const {
155  return Contains(range);
156  }
157 
161  bool IsOutside(const GfRange3f &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 GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b) {
169  GfRange3f res = a;
170  _FindMin(res._min,b._min);
171  _FindMax(res._max,b._max);
172  return res;
173  }
174 
176  const GfRange3f &UnionWith(const GfRange3f &b) {
177  _FindMin(_min,b._min);
178  _FindMax(_max,b._max);
179  return *this;
180  }
181 
183  const GfRange3f &UnionWith(const GfVec3f &b) {
184  _FindMin(_min,b);
185  _FindMax(_max,b);
186  return *this;
187  }
188 
191  static GfRange3f Union(const GfRange3f &a, const GfRange3f &b) {
192  return GetUnion(a, b);
193  }
194 
197  const GfRange3f &Union(const GfRange3f &b) {
198  return UnionWith(b);
199  }
200 
203  const GfRange3f &Union(const GfVec3f &b) {
204  return UnionWith(b);
205  }
206 
208  static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b) {
209  GfRange3f res = a;
210  _FindMax(res._min,b._min);
211  _FindMin(res._max,b._max);
212  return res;
213  }
214 
217  static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b) {
218  return GetIntersection(a, b);
219  }
220 
223  const GfRange3f &IntersectWith(const GfRange3f &b) {
224  _FindMax(_min,b._min);
225  _FindMin(_max,b._max);
226  return *this;
227  }
228 
232  const GfRange3f &Intersection(const GfRange3f &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  GfRange3f operator *=(double m) {
252  if (m > 0) {
253  _min *= m;
254  _max *= m;
255  } else {
256  GfVec3f tmp = _min;
257  _min = _max * m;
258  _max = tmp * m;
259  }
260  return *this;
261  }
262 
264  GfRange3f operator /=(double m) {
265  return *this *= (1.0 / m);
266  }
267 
269  GfRange3f operator +(const GfRange3f &b) const {
270  return GfRange3f(_min + b._min, _max + b._max);
271  }
272 
273 
275  GfRange3f operator -(const GfRange3f &b) const {
276  return GfRange3f(_min - b._max, _max - b._min);
277  }
278 
280  friend GfRange3f operator *(double m, const GfRange3f &r) {
281  return (m > 0 ?
282  GfRange3f(r._min*m, r._max*m) :
283  GfRange3f(r._max*m, r._min*m));
284  }
285 
287  friend GfRange3f operator *(const GfRange3f &r, double m) {
288  return (m > 0 ?
289  GfRange3f(r._min*m, r._max*m) :
290  GfRange3f(r._max*m, r._min*m));
291  }
292 
294  friend GfRange3f operator /(const GfRange3f &r, double m) {
295  return r * (1.0 / m);
296  }
297 
299  friend inline size_t hash_value(const GfRange3f &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 GfRange3f &b) const {
308  return (_min == b._min && _max == b._max);
309  }
310 
311  bool operator !=(const GfRange3f &b) const {
312  return !(*this == b);
313  }
314 
319  GF_API inline bool operator ==(const GfRange3d& other) const;
320  GF_API inline bool operator !=(const GfRange3d& other) const;
321 
323  GF_API
324  double GetDistanceSquared(const GfVec3f &p) const;
325 
329  GF_API
330  GfVec3f GetCorner(size_t i) const;
331 
335  GF_API
336  GfRange3f GetOctant(size_t i) const;
337 
339  GF_API
340  static const GfRange3f UnitCube;
341 
342  private:
344  GfVec3f _min, _max;
345 
347  static void _FindMin(GfVec3f &dest, const GfVec3f &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(GfVec3f &dest, const GfVec3f &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 &, GfRange3f const &);
364 
365 PXR_NAMESPACE_CLOSE_SCOPE
366 #include "pxr/base/gf/range3d.h"
367 PXR_NAMESPACE_OPEN_SCOPE
368 
369 inline bool
370 GfRange3f::operator ==(const GfRange3d& other) const {
371  return _min == GfVec3f(other.GetMin()) &&
372  _max == GfVec3f(other.GetMax());
373 }
374 
375 inline bool
376 GfRange3f::operator !=(const GfRange3d& other) const {
377  return !(*this == other);
378 }
379 
380 
381 PXR_NAMESPACE_CLOSE_SCOPE
382 
383 #endif // PXR_BASE_GF_RANGE3F_H
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 GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:154
const GfRange3f & Intersection(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:232
static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:168
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
void ExtendBy(const GfVec3f &point)
Modifies the range if necessary to surround the given value.
Definition: range3f.h:122
static GfRange3f Union(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:191
A metafunction with a static const bool member &#39;value&#39; that is true for GfRange types and false for a...
Definition: traits.h:52
bool IsInside(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:146
GfRange3f operator/=(double m)
unary division.
Definition: range3f.h:264
static GF_API const GfRange3f UnitCube
The unit cube.
Definition: range3f.h:340
bool IsOutside(const GfRange3f &range) const
Returns true if the range is located entirely outside the range.
Definition: range3f.h:161
static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:208
GfRange3f operator+(const GfRange3f &b) const
binary sum.
Definition: range3f.h:269
bool Contains(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:130
friend GfRange3f operator*(double m, const GfRange3f &r)
scalar multiply.
Definition: range3f.h:280
GfRange3f operator*=(double m)
unary multiply.
Definition: range3f.h:251
GF_API GfVec3f GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF.
GfRange3f operator-=(const GfRange3f &b)
unary difference.
Definition: range3f.h:244
void SetMin(const GfVec3f &min)
Sets the minimum value of the range.
Definition: range3f.h:110
GfVec3f GetSize() const
Returns the size of the range.
Definition: range3f.h:99
const GfRange3f & Union(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:197
static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:217
Basic type: 3-dimensional floating point range.
Definition: range3f.h:64
void SetMax(const GfVec3f &max)
Sets the maximum value of the range.
Definition: range3f.h:113
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:93
GF_API GfRange3f GetOctant(size_t i) const
Returns the ith octant of the range, in the following order: LDB, RDB, LUB, RUB, LDF, RDF, LUF, RUF.
GfRange3f operator-(const GfRange3f &b) const
binary difference.
Definition: range3f.h:275
friend size_t hash_value(const GfRange3f &r)
hash.
Definition: range3f.h:299
const GfRange3f & Union(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:203
GF_API double GetDistanceSquared(const GfVec3f &p) const
Compute the squared distance from a point to the range.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfRange3f(const GfVec3f &min, const GfVec3f &max)
This constructor initializes the minimum and maximum points.
Definition: range3f.h:87
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:96
const GfRange3f & UnionWith(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:183
void SetEmpty()
Sets the range to an empty interval.
Definition: range3f.h:76
GfRange3f operator+=(const GfRange3f &b)
unary sum.
Definition: range3f.h:237
bool IsEmpty() const
Returns whether the range is empty (max &lt; min).
Definition: range3f.h:116
const GfRange3f & IntersectWith(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:223
void ExtendBy(const GfRange3f &range)
Modifies the range if necessary to surround the given range.
Definition: range3f.h:126
float ScalarType
Scalar element type and dimension.
Definition: vec3f.h:67
friend GfRange3f operator/(const GfRange3f &r, double m)
scalar divide.
Definition: range3f.h:294
GfVec3f MinMaxType
Helper typedef.
Definition: range3f.h:69
const GfRange3f & UnionWith(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:176
bool operator==(const GfRange3f &b) const
The min and max points must match exactly for equality.
Definition: range3f.h:307
bool Contains(const GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:139
GfVec3f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3f.h:104
GfRange3f()
The default constructor creates an empty range.
Definition: range3f.h:82