This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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//
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
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
29PXR_NAMESPACE_OPEN_SCOPE
30
31class GfRange3d;
32class GfRange3f;
33
34template <>
35struct GfIsGfRange<class GfRange3f> { static const bool value = true; };
36
47{
48public:
49
52
53 static const size_t dimension = GfVec3f::dimension;
54 typedef GfVec3f::ScalarType ScalarType;
55
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
65 SetEmpty();
66 }
67
69 GfRange3f(const GfVec3f &min, const GfVec3f &max)
70 : _min(min), _max(max)
71 {
72 }
73
74
76 GF_API
77 explicit GfRange3f(class GfRange3d const &other);
78
80 const GfVec3f &GetMin() const { return _min; }
81
83 const GfVec3f &GetMax() const { return _max; }
84
86 GfVec3f GetSize() const { return _max - _min; }
87
92 return static_cast<ScalarType>(0.5) * _min
93 + static_cast<ScalarType>(0.5) * _max;
94 }
95
97 void SetMin(const GfVec3f &min) { _min = min; }
98
100 void SetMax(const GfVec3f &max) { _max = max; }
101
103 bool IsEmpty() const {
104 return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
105 }
106
109 void ExtendBy(const GfVec3f &point) { UnionWith(point); }
110
113 void ExtendBy(const GfRange3f &range) { UnionWith(range); }
114
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
126 bool Contains(const GfRange3f &range) const {
127 return Contains(range._min) && Contains(range._max);
128 }
129
133 bool IsInside(const GfVec3f &point) const {
134 return Contains(point);
135 }
136
141 bool IsInside(const GfRange3f &range) const {
142 return Contains(range);
143 }
144
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
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
163 const GfRange3f &UnionWith(const GfRange3f &b) {
164 _FindMin(_min,b._min);
165 _FindMax(_max,b._max);
166 return *this;
167 }
168
170 const GfRange3f &UnionWith(const GfVec3f &b) {
171 _FindMin(_min,b);
172 _FindMax(_max,b);
173 return *this;
174 }
175
178 static GfRange3f Union(const GfRange3f &a, const GfRange3f &b) {
179 return GetUnion(a, b);
180 }
181
184 const GfRange3f &Union(const GfRange3f &b) {
185 return UnionWith(b);
186 }
187
190 const GfRange3f &Union(const GfVec3f &b) {
191 return UnionWith(b);
192 }
193
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
204 static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b) {
205 return GetIntersection(a, b);
206 }
207
211 _FindMax(_min,b._min);
212 _FindMin(_max,b._max);
213 return *this;
214 }
215
220 return IntersectWith(b);
221 }
222
225 _min += b._min;
226 _max += b._max;
227 return *this;
228 }
229
232 _min -= b._max;
233 _max -= b._min;
234 return *this;
235 }
236
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
252 return *this *= (1.0 / m);
253 }
254
257 return GfRange3f(_min + b._min, _max + b._max);
258 }
259
260
263 return GfRange3f(_min - b._max, _max - b._min);
264 }
265
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
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
281 friend GfRange3f operator /(const GfRange3f &r, double m) {
282 return r * (1.0 / m);
283 }
284
286 friend inline size_t hash_value(const GfRange3f &r) {
287 return TfHash::Combine(r._min, r._max);
288 }
289
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
303 GF_API inline bool operator ==(const GfRange3d& other) const;
304 GF_API inline bool operator !=(const GfRange3d& other) const;
305
307 GF_API
308 double GetDistanceSquared(const GfVec3f &p) const;
309
313 GF_API
314 GfVec3f GetCorner(size_t i) const;
315
319 GF_API
320 GfRange3f GetOctant(size_t i) const;
321
323 GF_API
324 static const GfRange3f UnitCube;
325
326 private:
328 GfVec3f _min, _max;
329
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
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
347GF_API std::ostream& operator<<(std::ostream &, GfRange3f const &);
348
349PXR_NAMESPACE_CLOSE_SCOPE
350#include "pxr/base/gf/range3d.h"
351PXR_NAMESPACE_OPEN_SCOPE
352
353inline bool
355 return _min == GfVec3f(other.GetMin()) &&
356 _max == GfVec3f(other.GetMax());
357}
358
359inline bool
360GfRange3f::operator !=(const GfRange3d& other) const {
361 return !(*this == other);
362}
363
364
365PXR_NAMESPACE_CLOSE_SCOPE
366
367#endif // PXR_BASE_GF_RANGE3F_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:80
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:83
Basic type: 3-dimensional floating point range.
Definition: range3f.h:47
const GfRange3f & Union(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:190
GfVec3f GetSize() const
Returns the size of the range.
Definition: range3f.h:86
friend size_t hash_value(const GfRange3f &r)
hash.
Definition: range3f.h:286
void ExtendBy(const GfRange3f &range)
Modifies the range if necessary to surround the given range.
Definition: range3f.h:113
void SetMin(const GfVec3f &min)
Sets the minimum value of the range.
Definition: range3f.h:97
static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:155
GF_API GfVec3f GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: LDB, RDB, LUB, RUB, LDF,...
static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:195
static GF_API const GfRange3f UnitCube
The unit cube.
Definition: range3f.h:324
static GfRange3f Union(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:178
GfRange3f operator-(const GfRange3f &b) const
binary difference.
Definition: range3f.h:262
friend GfRange3f operator/(const GfRange3f &r, double m)
scalar divide.
Definition: range3f.h:281
const GfRange3f & IntersectWith(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:210
const GfRange3f & Intersection(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:219
GF_API GfRange3f(class GfRange3d const &other)
Construct from GfRange3d.
GfRange3f(const GfVec3f &min, const GfVec3f &max)
This constructor initializes the minimum and maximum points.
Definition: range3f.h:69
static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:204
GF_API double GetDistanceSquared(const GfVec3f &p) const
Compute the squared distance from a point to the range.
GF_API GfRange3f GetOctant(size_t i) const
Returns the ith octant of the range, in the following order: LDB, RDB, LUB, RUB, LDF,...
void SetMax(const GfVec3f &max)
Sets the maximum value of the range.
Definition: range3f.h:100
bool Contains(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:117
GfRange3f()
The default constructor creates an empty range.
Definition: range3f.h:64
GfRange3f & operator*=(double m)
unary multiply.
Definition: range3f.h:238
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:80
void ExtendBy(const GfVec3f &point)
Modifies the range if necessary to surround the given value.
Definition: range3f.h:109
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3f.h:103
const GfRange3f & UnionWith(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:163
const GfRange3f & Union(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:184
GfVec3f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3f.h:91
GfRange3f & operator+=(const GfRange3f &b)
unary sum.
Definition: range3f.h:224
bool Contains(const GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:126
void SetEmpty()
Sets the range to an empty interval.
Definition: range3f.h:58
bool IsInside(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:133
GfVec3f MinMaxType
Helper typedef.
Definition: range3f.h:51
bool IsOutside(const GfRange3f &range) const
Returns true if the range is located entirely outside the range.
Definition: range3f.h:148
bool IsInside(const GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:141
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:83
const GfRange3f & UnionWith(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:170
GfRange3f & operator-=(const GfRange3f &b)
unary difference.
Definition: range3f.h:231
bool operator==(const GfRange3f &b) const
The min and max points must match exactly for equality.
Definition: range3f.h:291
friend GfRange3f operator*(double m, const GfRange3f &r)
scalar multiply.
Definition: range3f.h:267
GfRange3f & operator/=(double m)
unary division.
Definition: range3f.h:251
GfRange3f operator+(const GfRange3f &b) const
binary sum.
Definition: range3f.h:256
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
float ScalarType
Scalar element type and dimension.
Definition: vec3f.h:49
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:475
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
A metafunction with a static const bool member 'value' that is true for GfRange types and false for a...
Definition: traits.h:40