Loading...
Searching...
No Matches
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#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 GfRange3f> { static const bool value = true; };
53
64{
65public:
66
69
70 static const size_t dimension = GfVec3f::dimension;
71 typedef GfVec3f::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 GfRange3f(const GfVec3f &min, const GfVec3f &max)
87 : _min(min), _max(max)
88 {
89 }
90
91
93 GF_API
94 explicit GfRange3f(class GfRange3d const &other);
95
97 const GfVec3f &GetMin() const { return _min; }
98
100 const GfVec3f &GetMax() const { return _max; }
101
103 GfVec3f 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 GfVec3f &min) { _min = min; }
115
117 void SetMax(const GfVec3f &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 GfVec3f &point) { UnionWith(point); }
127
130 void ExtendBy(const GfRange3f &range) { UnionWith(range); }
131
134 bool Contains(const GfVec3f &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 GfRange3f &range) const {
144 return Contains(range._min) && Contains(range._max);
145 }
146
150 bool IsInside(const GfVec3f &point) const {
151 return Contains(point);
152 }
153
158 bool IsInside(const GfRange3f &range) const {
159 return Contains(range);
160 }
161
165 bool IsOutside(const GfRange3f &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 GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b) {
173 GfRange3f res = a;
174 _FindMin(res._min,b._min);
175 _FindMax(res._max,b._max);
176 return res;
177 }
178
180 const GfRange3f &UnionWith(const GfRange3f &b) {
181 _FindMin(_min,b._min);
182 _FindMax(_max,b._max);
183 return *this;
184 }
185
187 const GfRange3f &UnionWith(const GfVec3f &b) {
188 _FindMin(_min,b);
189 _FindMax(_max,b);
190 return *this;
191 }
192
195 static GfRange3f Union(const GfRange3f &a, const GfRange3f &b) {
196 return GetUnion(a, b);
197 }
198
201 const GfRange3f &Union(const GfRange3f &b) {
202 return UnionWith(b);
203 }
204
207 const GfRange3f &Union(const GfVec3f &b) {
208 return UnionWith(b);
209 }
210
212 static GfRange3f GetIntersection(const GfRange3f &a, const GfRange3f &b) {
213 GfRange3f res = a;
214 _FindMax(res._min,b._min);
215 _FindMin(res._max,b._max);
216 return res;
217 }
218
221 static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &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 GfVec3f 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 GfRange3f(_min + b._min, _max + b._max);
275 }
276
277
280 return GfRange3f(_min - b._max, _max - b._min);
281 }
282
284 friend GfRange3f operator *(double m, const GfRange3f &r) {
285 return (m > 0 ?
286 GfRange3f(r._min*m, r._max*m) :
287 GfRange3f(r._max*m, r._min*m));
288 }
289
291 friend GfRange3f operator *(const GfRange3f &r, double m) {
292 return (m > 0 ?
293 GfRange3f(r._min*m, r._max*m) :
294 GfRange3f(r._max*m, r._min*m));
295 }
296
298 friend GfRange3f operator /(const GfRange3f &r, double m) {
299 return r * (1.0 / m);
300 }
301
303 friend inline size_t hash_value(const GfRange3f &r) {
304 return TfHash::Combine(r._min, r._max);
305 }
306
308 bool operator ==(const GfRange3f &b) const {
309 return (_min == b._min && _max == b._max);
310 }
311
312 bool operator !=(const GfRange3f &b) const {
313 return !(*this == b);
314 }
315
320 GF_API inline bool operator ==(const GfRange3d& other) const;
321 GF_API inline bool operator !=(const GfRange3d& other) const;
322
324 GF_API
325 double GetDistanceSquared(const GfVec3f &p) const;
326
330 GF_API
331 GfVec3f GetCorner(size_t i) const;
332
336 GF_API
337 GfRange3f GetOctant(size_t i) const;
338
340 GF_API
341 static const GfRange3f UnitCube;
342
343 private:
345 GfVec3f _min, _max;
346
348 static void _FindMin(GfVec3f &dest, const GfVec3f &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(GfVec3f &dest, const GfVec3f &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 &, GfRange3f const &);
365
366PXR_NAMESPACE_CLOSE_SCOPE
367#include "pxr/base/gf/range3d.h"
368PXR_NAMESPACE_OPEN_SCOPE
369
370inline bool
372 return _min == GfVec3f(other.GetMin()) &&
373 _max == GfVec3f(other.GetMax());
374}
375
376inline bool
377GfRange3f::operator !=(const GfRange3d& other) const {
378 return !(*this == other);
379}
380
381
382PXR_NAMESPACE_CLOSE_SCOPE
383
384#endif // PXR_BASE_GF_RANGE3F_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
const GfVec3d & GetMin() const
Returns the minimum value of the range.
Definition: range3d.h:97
const GfVec3d & GetMax() const
Returns the maximum value of the range.
Definition: range3d.h:100
Basic type: 3-dimensional floating point range.
Definition: range3f.h:64
const GfRange3f & Union(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:207
GfVec3f GetSize() const
Returns the size of the range.
Definition: range3f.h:103
friend size_t hash_value(const GfRange3f &r)
hash.
Definition: range3f.h:303
void ExtendBy(const GfRange3f &range)
Modifies the range if necessary to surround the given range.
Definition: range3f.h:130
void SetMin(const GfVec3f &min)
Sets the minimum value of the range.
Definition: range3f.h:114
static GfRange3f GetUnion(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:172
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:212
static GF_API const GfRange3f UnitCube
The unit cube.
Definition: range3f.h:341
static GfRange3f Union(const GfRange3f &a, const GfRange3f &b)
Returns the smallest GfRange3f which contains both a and b.
Definition: range3f.h:195
GfRange3f operator-(const GfRange3f &b) const
binary difference.
Definition: range3f.h:279
friend GfRange3f operator/(const GfRange3f &r, double m)
scalar divide.
Definition: range3f.h:298
const GfRange3f & IntersectWith(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:227
const GfRange3f & Intersection(const GfRange3f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range3f.h:236
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:86
static GfRange3f Intersection(const GfRange3f &a, const GfRange3f &b)
Returns a GfRange3f that describes the intersection of a and b.
Definition: range3f.h:221
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:117
bool Contains(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:134
GfRange3f()
The default constructor creates an empty range.
Definition: range3f.h:81
GfRange3f & operator*=(double m)
unary multiply.
Definition: range3f.h:255
const GfVec3f & GetMin() const
Returns the minimum value of the range.
Definition: range3f.h:97
void ExtendBy(const GfVec3f &point)
Modifies the range if necessary to surround the given value.
Definition: range3f.h:126
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range3f.h:120
const GfRange3f & UnionWith(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:180
const GfRange3f & Union(const GfRange3f &b)
Extend this to include b.
Definition: range3f.h:201
GfVec3f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range3f.h:108
GfRange3f & operator+=(const GfRange3f &b)
unary sum.
Definition: range3f.h:241
bool Contains(const GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:143
void SetEmpty()
Sets the range to an empty interval.
Definition: range3f.h:75
bool IsInside(const GfVec3f &point) const
Returns true if the point is located inside the range.
Definition: range3f.h:150
GfVec3f MinMaxType
Helper typedef.
Definition: range3f.h:68
bool IsOutside(const GfRange3f &range) const
Returns true if the range is located entirely outside the range.
Definition: range3f.h:165
bool IsInside(const GfRange3f &range) const
Returns true if the range is located entirely inside the range.
Definition: range3f.h:158
const GfVec3f & GetMax() const
Returns the maximum value of the range.
Definition: range3f.h:100
const GfRange3f & UnionWith(const GfVec3f &b)
Extend this to include b.
Definition: range3f.h:187
GfRange3f & operator-=(const GfRange3f &b)
unary difference.
Definition: range3f.h:248
bool operator==(const GfRange3f &b) const
The min and max points must match exactly for equality.
Definition: range3f.h:308
friend GfRange3f operator*(double m, const GfRange3f &r)
scalar multiply.
Definition: range3f.h:284
GfRange3f & operator/=(double m)
unary division.
Definition: range3f.h:268
GfRange3f operator+(const GfRange3f &b) const
binary sum.
Definition: range3f.h:273
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
float ScalarType
Scalar element type and dimension.
Definition: vec3f.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