31 #ifndef OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED 32 #define OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED 38 #include <boost/type_traits/is_integral.hpp> 46 template<
typename Vec3T>
59 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax);
63 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax,
bool sorted);
78 BBox& operator=(
const BBox&) =
default;
84 const Vec3T&
min()
const {
return mMin; }
87 const Vec3T&
max()
const {
return mMax; }
90 Vec3T&
min() {
return mMin; }
93 Vec3T&
max() {
return mMax; }
109 operator bool()
const {
return !this->empty(); }
114 bool isSorted()
const;
117 Vec3d getCenter()
const;
123 Vec3T extents()
const;
135 bool isInside(
const Vec3T& xyz)
const;
138 bool isInside(
const BBox&)
const;
141 bool hasOverlap(
const BBox&)
const;
144 void expand(ElementType padding);
147 void expand(
const Vec3T& xyz);
150 void expand(
const BBox&);
154 void expand(
const Vec3T& xyzMin,
const ElementType& length);
157 void translate(
const Vec3T& t);
160 template<
typename MapType>
161 BBox applyMap(
const MapType& map)
const;
164 template<
typename MapType>
165 BBox applyInverseMap(
const MapType& map)
const;
168 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
171 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
181 template<
typename Vec3T>
189 template<
typename Vec3T>
192 mMin(xyzMin), mMax(xyzMax)
196 template<
typename Vec3T>
199 mMin(xyzMin), mMax(xyzMax)
201 if (!sorted) this->sort();
204 template<
typename Vec3T>
207 mMin(xyzMin), mMax(xyzMin)
210 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
216 template<
typename Vec3T>
219 mMin(xyz[0], xyz[1], xyz[2]),
220 mMax(xyz[3], xyz[4], xyz[5])
222 if (!sorted) this->sort();
229 template<
typename Vec3T>
233 if (boost::is_integral<ElementType>::value) {
235 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
237 return mMin[0] >= mMax[0] || mMin[1] >= mMax[1] || mMin[2] >= mMax[2];
241 template<
typename Vec3T>
245 if (boost::is_integral<ElementType>::value) {
246 return mMin == rhs.
min() && mMax == rhs.
max();
253 template<
typename Vec3T>
257 Vec3T tMin(mMin), tMax(mMax);
258 for (
int i = 0;
i < 3; ++
i) {
265 template<
typename Vec3T>
269 if (boost::is_integral<ElementType>::value) {
270 return (mMin[0] <= mMax[0] && mMin[1] <= mMax[1] && mMin[2] <= mMax[2]);
273 return (mMin[0] < (mMax[0] + t) && mMin[1] < (mMax[1] + t) && mMin[2] < (mMax[2] + t));
278 template<
typename Vec3T>
282 return (
Vec3d(mMin.asPointer()) +
Vec3d(mMax.asPointer())) * 0.5;
286 template<
typename Vec3T>
290 if (boost::is_integral<ElementType>::value) {
291 return (mMax - mMin) + Vec3T(1, 1, 1);
293 return (mMax - mMin);
300 template<
typename Vec3T>
304 if (boost::is_integral<ElementType>::value) {
305 return xyz[0] >= mMin[0] && xyz[0] <= mMax[0] &&
306 xyz[1] >= mMin[1] && xyz[1] <= mMax[1] &&
307 xyz[2] >= mMin[2] && xyz[2] <= mMax[2];
310 return xyz[0] > (mMin[0]-t) && xyz[0] < (mMax[0]+t) &&
311 xyz[1] > (mMin[1]-t) && xyz[1] < (mMax[1]+t) &&
312 xyz[2] > (mMin[2]-t) && xyz[2] < (mMax[2]+t);
317 template<
typename Vec3T>
321 if (boost::is_integral<ElementType>::value) {
322 return b.
min()[0] >= mMin[0] && b.
max()[0] <= mMax[0] &&
323 b.
min()[1] >= mMin[1] && b.
max()[1] <= mMax[1] &&
324 b.
min()[2] >= mMin[2] && b.
max()[2] <= mMax[2];
327 return (b.
min()[0]-t) > mMin[0] && (b.
max()[0]+t) < mMax[0] &&
328 (b.
min()[1]-t) > mMin[1] && (b.
max()[1]+t) < mMax[1] &&
329 (b.
min()[2]-t) > mMin[2] && (b.
max()[2]+t) < mMax[2];
334 template<
typename Vec3T>
338 if (boost::is_integral<ElementType>::value) {
339 return mMax[0] >= b.
min()[0] && mMin[0] <= b.
max()[0] &&
340 mMax[1] >= b.
min()[1] && mMin[1] <= b.
max()[1] &&
341 mMax[2] >= b.
min()[2] && mMin[2] <= b.
max()[2];
344 return mMax[0] > (b.
min()[0]-t) && mMin[0] < (b.
max()[0]+t) &&
345 mMax[1] > (b.
min()[1]-t) && mMin[1] < (b.
max()[1]+t) &&
346 mMax[2] > (b.
min()[2]-t) && mMin[2] < (b.
max()[2]+t);
354 template<
typename Vec3T>
359 for (
int i = 0;
i < 3; ++
i) {
366 template<
typename Vec3T>
370 for (
int i = 0;
i < 3; ++
i) {
377 template<
typename Vec3T>
381 for (
int i = 0;
i < 3; ++
i) {
387 template<
typename Vec3T>
391 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
392 for (
int i = 0;
i < 3; ++
i) {
399 template<
typename Vec3T>
407 template<
typename Vec3T>
408 template<
typename MapType>
414 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
415 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
416 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
417 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
418 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
419 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
420 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
421 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
425 template<
typename Vec3T>
426 template<
typename MapType>
432 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
433 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
434 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
435 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
436 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
437 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
438 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
439 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
446 template<
typename Vec3T>
448 operator<<(std::ostream& os, const BBox<Vec3T>& b)
450 os << b.
min() <<
" -> " << b.max();
458 #endif // OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: BBox.h:171
bool hasVolume() const
Return true if the BBox has a (positive) volume.
Definition: BBox.h:106
Tolerance for floating-point comparison.
Definition: Math.h:117
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Vec3T & max()
Return a non-const reference to the maximum point of the BBox.
Definition: BBox.h:93
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:886
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
bool isApproxEqual(const Type &a, const Type &b)
Return true if a is equal to b to within the default floating-point comparison tolerance.
Definition: Math.h:354
ElementType volume() const
Return the volume spanned by this BBox.
Definition: BBox.h:126
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: BBox.h:132
Vec3Type::ValueType ElementType
Definition: BBox.h:53
double ValueType
Definition: Vec3.h:53
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Vec3T ValueType
Definition: BBox.h:51
const Vec3T & min() const
Return a const reference to the minimum point of the BBox.
Definition: BBox.h:84
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: BBox.h:129
const Vec3T & max() const
Return a const reference to the maximum point of the BBox.
Definition: BBox.h:87
Definition: Exceptions.h:39
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:487
Vec3< double > Vec3d
Definition: Vec3.h:678
void expand(ElementType padding)
Pad this bounding box.
Definition: BBox.h:356
bool operator!=(const BBox &rhs) const
Return true if the two BBox'es are not identical.
Definition: BBox.h:99
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: BBox.h:168
Vec3T Vec3Type
Definition: BBox.h:50
Vec3T VectorType
Definition: BBox.h:52
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
static constexpr size_t size
The size of a LeafBuffer when LeafBuffer::mOutOfCore is atomic.
Definition: LeafBuffer.h:85
math::Vec3< Real > Vec3R
Definition: Types.h:75
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:907
Axis-aligned bounding box.
Definition: BBox.h:47
Vec3T & min()
Return a non-const reference to the minimum point of the BBox.
Definition: BBox.h:90