Loading...
Searching...
No Matches
range3d.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_RANGE3D_H
12#define PXR_BASE_GF_RANGE3D_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 GfRange3d> { static const bool value = true; };
36
47{
48public:
49
52
53 static const size_t dimension = GfVec3d::dimension;
54 typedef GfVec3d::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 GfRange3d(const GfVec3d &min, const GfVec3d &max)
70 : _min(min), _max(max)
71 {
72 }
73
74
76 GF_API
77 GfRange3d(class GfRange3f const &other);
78
80 const GfVec3d &GetMin() const { return _min; }
81
83 const GfVec3d &GetMax() const { return _max; }
84
86 GfVec3d 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 GfVec3d &min) { _min = min; }
98
100 void SetMax(const GfVec3d &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 GfVec3d &point) { UnionWith(point); }
110
113 void ExtendBy(const GfRange3d &range) { UnionWith(range); }
114
117 bool Contains(const GfVec3d &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 GfRange3d &range) const {
127 return Contains(range._min) && Contains(range._max);
128 }
129
133 bool IsInside(const GfVec3d &point) const {
134 return Contains(point);
135 }
136
141 bool IsInside(const GfRange3d &range) const {
142 return Contains(range);
143 }
144
148 bool IsOutside(const GfRange3d &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 GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b) {
156 GfRange3d res = a;
157 _FindMin(res._min,b._min);
158 _FindMax(res._max,b._max);
159 return res;
160 }
161
163 const GfRange3d &UnionWith(const GfRange3d &b) {
164 _FindMin(_min,b._min);
165 _FindMax(_max,b._max);
166 return *this;
167 }
168
170 const GfRange3d &UnionWith(const GfVec3d &b) {
171 _FindMin(_min,b);
172 _FindMax(_max,b);
173 return *this;
174 }
175
178 static GfRange3d Union(const GfRange3d &a, const GfRange3d &b) {
179 return GetUnion(a, b);
180 }
181
184 const GfRange3d &Union(const GfRange3d &b) {
185 return UnionWith(b);
186 }
187
190 const GfRange3d &Union(const GfVec3d &b) {
191 return UnionWith(b);
192 }
193
195 static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b) {
196 GfRange3d res = a;
197 _FindMax(res._min,b._min);
198 _FindMin(res._max,b._max);
199 return res;
200 }
201
204 static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &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 GfVec3d 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 GfRange3d(_min + b._min, _max + b._max);
258 }
259
260
263 return GfRange3d(_min - b._max, _max - b._min);
264 }
265
267 friend GfRange3d operator *(double m, const GfRange3d &r) {
268 return (m > 0 ?
269 GfRange3d(r._min*m, r._max*m) :
270 GfRange3d(r._max*m, r._min*m));
271 }
272
274 friend GfRange3d operator *(const GfRange3d &r, double m) {
275 return (m > 0 ?
276 GfRange3d(r._min*m, r._max*m) :
277 GfRange3d(r._max*m, r._min*m));
278 }
279
281 friend GfRange3d operator /(const GfRange3d &r, double m) {
282 return r * (1.0 / m);
283 }
284
286 friend inline size_t hash_value(const GfRange3d &r) {
287 return TfHash::Combine(r._min, r._max);
288 }
289
291 bool operator ==(const GfRange3d &b) const {
292 return (_min == b._min && _max == b._max);
293 }
294
295 bool operator !=(const GfRange3d &b) const {
296 return !(*this == b);
297 }
298
303 GF_API inline bool operator ==(const GfRange3f& other) const;
304 GF_API inline bool operator !=(const GfRange3f& other) const;
305
307 GF_API
308 double GetDistanceSquared(const GfVec3d &p) const;
309
313 GF_API
314 GfVec3d GetCorner(size_t i) const;
315
319 GF_API
320 GfRange3d GetOctant(size_t i) const;
321
323 GF_API
324 static const GfRange3d UnitCube;
325
326 private:
328 GfVec3d _min, _max;
329
331 static void _FindMin(GfVec3d &dest, const GfVec3d &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(GfVec3d &dest, const GfVec3d &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 &, GfRange3d const &);
348
349PXR_NAMESPACE_CLOSE_SCOPE
350#include "pxr/base/gf/range3f.h"
351PXR_NAMESPACE_OPEN_SCOPE
352
353inline bool
355 return _min == GfVec3d(other.GetMin()) &&
356 _max == GfVec3d(other.GetMax());
357}
358
359inline bool
360GfRange3d::operator !=(const GfRange3f& other) const {
361 return !(*this == other);
362}
363
364
365PXR_NAMESPACE_CLOSE_SCOPE
366
367#endif // PXR_BASE_GF_RANGE3D_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
const GfRange3d & IntersectWith(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:210
const GfRange3d & UnionWith(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:163
static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:195
GfRange3d & operator-=(const GfRange3d &b)
unary difference.
Definition: range3d.h:231
const GfRange3d & Intersection(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:219
void ExtendBy(const GfRange3d &range)
Modifies the range if necessary to surround the given range.
Definition: range3d.h:113
static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:155
static GfRange3d Union(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:178
GfRange3d(const GfVec3d &min, const GfVec3d &max)
This constructor initializes the minimum and maximum points.
Definition: range3d.h:69
bool IsInside(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:133
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:80
const GfRange3d & Union(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:184
bool IsOutside(const GfRange3d &range) const
Returns true if the range is located entirely outside the range.
Definition: range3d.h:148
GfVec3d MinMaxType
Helper typedef.
Definition: range3d.h:51
bool Contains(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:117
GF_API GfRange3d GetOctant(size_t i) const
Returns the ith octant of the range, in the following order: LDB, RDB, LUB, RUB, LDF,...
friend GfRange3d operator*(double m, const GfRange3d &r)
scalar multiply.
Definition: range3d.h:267
GfRange3d & operator/=(double m)
unary division.
Definition: range3d.h:251
const GfRange3d & UnionWith(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:170
static GF_API const GfRange3d UnitCube
The unit cube.
Definition: range3d.h:324
GfVec3d GetSize() const
Returns the size of the range.
Definition: range3d.h:86
friend GfRange3d operator/(const GfRange3d &r, double m)
scalar divide.
Definition: range3d.h:281
GfRange3d & operator*=(double m)
unary multiply.
Definition: range3d.h:238
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3d.h:103
void SetMax(const GfVec3d &max)
Sets the maximum value of the range.
Definition: range3d.h:100
GfRange3d operator-(const GfRange3d &b) const
binary difference.
Definition: range3d.h:262
const GfRange3d & Union(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:190
bool Contains(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:126
void ExtendBy(const GfVec3d &point)
Modifies the range if necessary to surround the given value.
Definition: range3d.h:109
void SetMin(const GfVec3d &min)
Sets the minimum value of the range.
Definition: range3d.h:97
GfRange3d & operator+=(const GfRange3d &b)
unary sum.
Definition: range3d.h:224
void SetEmpty()
Sets the range to an empty interval.
Definition: range3d.h:58
GfVec3d GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3d.h:91
GF_API double GetDistanceSquared(const GfVec3d &p) const
Compute the squared distance from a point to the range.
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:83
friend size_t hash_value(const GfRange3d &r)
hash.
Definition: range3d.h:286
bool operator==(const GfRange3d &b) const
The min and max points must match exactly for equality.
Definition: range3d.h:291
GfRange3d operator+(const GfRange3d &b) const
binary sum.
Definition: range3d.h:256
GF_API GfRange3d(class GfRange3f const &other)
Implicitly convert from GfRange3f.
static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:204
bool IsInside(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:141
GfRange3d()
The default constructor creates an empty range.
Definition: range3d.h:64
GF_API GfVec3d GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: LDB, RDB, LUB, RUB, LDF,...
Basic type: 3-dimensional floating point range.
Definition: range3f.h:47
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:80
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:83
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
double ScalarType
Scalar element type and dimension.
Definition: vec3d.h:49
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
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