Loading...
Searching...
No Matches
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 PXR_BASE_GF_RANGE3D_H
29#define PXR_BASE_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#include "pxr/base/tf/hash.h"
41
42#include <cfloat>
43#include <cstddef>
44#include <iosfwd>
45
46PXR_NAMESPACE_OPEN_SCOPE
47
48class GfRange3d;
49class GfRange3f;
50
51template <>
52struct GfIsGfRange<class GfRange3d> { static const bool value = true; };
53
64{
65public:
66
69
70 static const size_t dimension = GfVec3d::dimension;
71 typedef GfVec3d::ScalarType ScalarType;
72
74 // TODO check whether this can be deprecated.
75 void inline SetEmpty() {
76 _min[0] = _min[1] = _min[2] = FLT_MAX;
77 _max[0] = _max[1] = _max[2] = -FLT_MAX;
78 }
79
82 SetEmpty();
83 }
84
86 GfRange3d(const GfVec3d &min, const GfVec3d &max)
87 : _min(min), _max(max)
88 {
89 }
90
91
93 GF_API
94 GfRange3d(class GfRange3f const &other);
95
97 const GfVec3d &GetMin() const { return _min; }
98
100 const GfVec3d &GetMax() const { return _max; }
101
103 GfVec3d GetSize() const { return _max - _min; }
104
109 return static_cast<ScalarType>(0.5) * _min
110 + static_cast<ScalarType>(0.5) * _max;
111 }
112
114 void SetMin(const GfVec3d &min) { _min = min; }
115
117 void SetMax(const GfVec3d &max) { _max = max; }
118
120 bool IsEmpty() const {
121 return _min[0] > _max[0] || _min[1] > _max[1] || _min[2] > _max[2];
122 }
123
126 void ExtendBy(const GfVec3d &point) { UnionWith(point); }
127
130 void ExtendBy(const GfRange3d &range) { UnionWith(range); }
131
134 bool Contains(const GfVec3d &point) const {
135 return (point[0] >= _min[0] && point[0] <= _max[0]
136 && point[1] >= _min[1] && point[1] <= _max[1]
137 && point[2] >= _min[2] && point[2] <= _max[2]);
138 }
139
143 bool Contains(const GfRange3d &range) const {
144 return Contains(range._min) && Contains(range._max);
145 }
146
150 bool IsInside(const GfVec3d &point) const {
151 return Contains(point);
152 }
153
158 bool IsInside(const GfRange3d &range) const {
159 return Contains(range);
160 }
161
165 bool IsOutside(const GfRange3d &range) const {
166 return ((range._max[0] < _min[0] || range._min[0] > _max[0])
167 || (range._max[1] < _min[1] || range._min[1] > _max[1])
168 || (range._max[2] < _min[2] || range._min[2] > _max[2]));
169 }
170
172 static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b) {
173 GfRange3d res = a;
174 _FindMin(res._min,b._min);
175 _FindMax(res._max,b._max);
176 return res;
177 }
178
180 const GfRange3d &UnionWith(const GfRange3d &b) {
181 _FindMin(_min,b._min);
182 _FindMax(_max,b._max);
183 return *this;
184 }
185
187 const GfRange3d &UnionWith(const GfVec3d &b) {
188 _FindMin(_min,b);
189 _FindMax(_max,b);
190 return *this;
191 }
192
195 static GfRange3d Union(const GfRange3d &a, const GfRange3d &b) {
196 return GetUnion(a, b);
197 }
198
201 const GfRange3d &Union(const GfRange3d &b) {
202 return UnionWith(b);
203 }
204
207 const GfRange3d &Union(const GfVec3d &b) {
208 return UnionWith(b);
209 }
210
212 static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b) {
213 GfRange3d res = a;
214 _FindMax(res._min,b._min);
215 _FindMin(res._max,b._max);
216 return res;
217 }
218
221 static GfRange3d Intersection(const GfRange3d &a, const GfRange3d &b) {
222 return GetIntersection(a, b);
223 }
224
228 _FindMax(_min,b._min);
229 _FindMin(_max,b._max);
230 return *this;
231 }
232
237 return IntersectWith(b);
238 }
239
242 _min += b._min;
243 _max += b._max;
244 return *this;
245 }
246
249 _min -= b._max;
250 _max -= b._min;
251 return *this;
252 }
253
256 if (m > 0) {
257 _min *= m;
258 _max *= m;
259 } else {
260 GfVec3d tmp = _min;
261 _min = _max * m;
262 _max = tmp * m;
263 }
264 return *this;
265 }
266
269 return *this *= (1.0 / m);
270 }
271
274 return GfRange3d(_min + b._min, _max + b._max);
275 }
276
277
280 return GfRange3d(_min - b._max, _max - b._min);
281 }
282
284 friend GfRange3d operator *(double m, const GfRange3d &r) {
285 return (m > 0 ?
286 GfRange3d(r._min*m, r._max*m) :
287 GfRange3d(r._max*m, r._min*m));
288 }
289
291 friend GfRange3d operator *(const GfRange3d &r, double m) {
292 return (m > 0 ?
293 GfRange3d(r._min*m, r._max*m) :
294 GfRange3d(r._max*m, r._min*m));
295 }
296
298 friend GfRange3d operator /(const GfRange3d &r, double m) {
299 return r * (1.0 / m);
300 }
301
303 friend inline size_t hash_value(const GfRange3d &r) {
304 return TfHash::Combine(r._min, r._max);
305 }
306
308 bool operator ==(const GfRange3d &b) const {
309 return (_min == b._min && _max == b._max);
310 }
311
312 bool operator !=(const GfRange3d &b) const {
313 return !(*this == b);
314 }
315
320 GF_API inline bool operator ==(const GfRange3f& other) const;
321 GF_API inline bool operator !=(const GfRange3f& other) const;
322
324 GF_API
325 double GetDistanceSquared(const GfVec3d &p) const;
326
330 GF_API
331 GfVec3d GetCorner(size_t i) const;
332
336 GF_API
337 GfRange3d GetOctant(size_t i) const;
338
340 GF_API
341 static const GfRange3d UnitCube;
342
343 private:
345 GfVec3d _min, _max;
346
348 static void _FindMin(GfVec3d &dest, const GfVec3d &point) {
349 if (point[0] < dest[0]) dest[0] = point[0];
350 if (point[1] < dest[1]) dest[1] = point[1];
351 if (point[2] < dest[2]) dest[2] = point[2];
352 }
353
355 static void _FindMax(GfVec3d &dest, const GfVec3d &point) {
356 if (point[0] > dest[0]) dest[0] = point[0];
357 if (point[1] > dest[1]) dest[1] = point[1];
358 if (point[2] > dest[2]) dest[2] = point[2];
359 }
360};
361
364GF_API std::ostream& operator<<(std::ostream &, GfRange3d const &);
365
366PXR_NAMESPACE_CLOSE_SCOPE
367#include "pxr/base/gf/range3f.h"
368PXR_NAMESPACE_OPEN_SCOPE
369
370inline bool
372 return _min == GfVec3d(other.GetMin()) &&
373 _max == GfVec3d(other.GetMax());
374}
375
376inline bool
377GfRange3d::operator !=(const GfRange3f& other) const {
378 return !(*this == other);
379}
380
381
382PXR_NAMESPACE_CLOSE_SCOPE
383
384#endif // PXR_BASE_GF_RANGE3D_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
const GfRange3d & IntersectWith(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:227
const GfRange3d & UnionWith(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:180
static GfRange3d GetIntersection(const GfRange3d &a, const GfRange3d &b)
Returns a GfRange3d that describes the intersection of a and b.
Definition: range3d.h:212
GfRange3d & operator-=(const GfRange3d &b)
unary difference.
Definition: range3d.h:248
const GfRange3d & Intersection(const GfRange3d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3d.h:236
void ExtendBy(const GfRange3d &range)
Modifies the range if necessary to surround the given range.
Definition: range3d.h:130
static GfRange3d GetUnion(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:172
static GfRange3d Union(const GfRange3d &a, const GfRange3d &b)
Returns the smallest GfRange3d which contains both a and b.
Definition: range3d.h:195
GfRange3d(const GfVec3d &min, const GfVec3d &max)
This constructor initializes the minimum and maximum points.
Definition: range3d.h:86
bool IsInside(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:150
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:97
const GfRange3d & Union(const GfRange3d &b)
Extend this to include b.
Definition: range3d.h:201
bool IsOutside(const GfRange3d &range) const
Returns true if the range is located entirely outside the range.
Definition: range3d.h:165
GfVec3d MinMaxType
Helper typedef.
Definition: range3d.h:68
bool Contains(const GfVec3d &point) const
Returns true if the point is located inside the range.
Definition: range3d.h:134
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:284
GfRange3d & operator/=(double m)
unary division.
Definition: range3d.h:268
const GfRange3d & UnionWith(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:187
static GF_API const GfRange3d UnitCube
The unit cube.
Definition: range3d.h:341
GfVec3d GetSize() const
Returns the size of the range.
Definition: range3d.h:103
friend GfRange3d operator/(const GfRange3d &r, double m)
scalar divide.
Definition: range3d.h:298
GfRange3d & operator*=(double m)
unary multiply.
Definition: range3d.h:255
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3d.h:120
void SetMax(const GfVec3d &max)
Sets the maximum value of the range.
Definition: range3d.h:117
GfRange3d operator-(const GfRange3d &b) const
binary difference.
Definition: range3d.h:279
const GfRange3d & Union(const GfVec3d &b)
Extend this to include b.
Definition: range3d.h:207
bool Contains(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:143
void ExtendBy(const GfVec3d &point)
Modifies the range if necessary to surround the given value.
Definition: range3d.h:126
void SetMin(const GfVec3d &min)
Sets the minimum value of the range.
Definition: range3d.h:114
GfRange3d & operator+=(const GfRange3d &b)
unary sum.
Definition: range3d.h:241
void SetEmpty()
Sets the range to an empty interval.
Definition: range3d.h:75
GfVec3d GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3d.h:108
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:100
friend size_t hash_value(const GfRange3d &r)
hash.
Definition: range3d.h:303
bool operator==(const GfRange3d &b) const
The min and max points must match exactly for equality.
Definition: range3d.h:308
GfRange3d operator+(const GfRange3d &b) const
binary sum.
Definition: range3d.h:273
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:221
bool IsInside(const GfRange3d &range) const
Returns true if the range is located entirely inside the range.
Definition: range3d.h:158
GfRange3d()
The default constructor creates an empty range.
Definition: range3d.h:81
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:64
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:97
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:100
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
double ScalarType
Scalar element type and dimension.
Definition: vec3d.h:66
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
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:57