Go to the documentation of this file.
31 #ifndef OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
32 #define OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
40 #include <type_traits>
49 template<
typename Vec3T>
62 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax);
67 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax,
bool sorted);
89 const Vec3T&
min()
const {
return mMin; }
91 const Vec3T&
max()
const {
return mMax; }
93 Vec3T&
min() {
return mMin; }
95 Vec3T&
max() {
return mMax; }
107 operator bool()
const {
return !this->empty(); }
154 template<
typename MapType>
157 template<
typename MapType>
161 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
163 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
173 template<
typename Vec3T>
181 template<
typename Vec3T>
184 mMin(xyzMin), mMax(xyzMax)
188 template<
typename Vec3T>
191 mMin(xyzMin), mMax(xyzMax)
193 if (!sorted) this->
sort();
196 template<
typename Vec3T>
199 mMin(xyzMin), mMax(xyzMin)
202 const ElementType size = std::is_integral<ElementType>::value ? length-1 : length;
208 template<
typename Vec3T>
211 mMin(xyz[0], xyz[1], xyz[2]),
212 mMax(xyz[3], xyz[4], xyz[5])
214 if (!sorted) this->
sort();
221 template<
typename Vec3T>
225 if (std::is_integral<ElementType>::value) {
227 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
229 return mMin[0] >= mMax[0] || mMin[1] >= mMax[1] || mMin[2] >= mMax[2];
233 template<
typename Vec3T>
237 if (std::is_integral<ElementType>::value) {
238 return mMin == rhs.
min() && mMax == rhs.
max();
245 template<
typename Vec3T>
249 Vec3T tMin(mMin), tMax(mMax);
250 for (
int i = 0; i < 3; ++i) {
251 mMin[i] =
std::min(tMin[i], tMax[i]);
252 mMax[i] =
std::max(tMin[i], tMax[i]);
257 template<
typename Vec3T>
261 if (std::is_integral<ElementType>::value) {
262 return (mMin[0] <= mMax[0] && mMin[1] <= mMax[1] && mMin[2] <= mMax[2]);
265 return (mMin[0] < (mMax[0] + t) && mMin[1] < (mMax[1] + t) && mMin[2] < (mMax[2] + t));
270 template<
typename Vec3T>
274 return (
Vec3d(mMin.asPointer()) +
Vec3d(mMax.asPointer())) * 0.5;
278 template<
typename Vec3T>
282 if (std::is_integral<ElementType>::value) {
283 return (mMax - mMin) + Vec3T(1, 1, 1);
285 return (mMax - mMin);
292 template<
typename Vec3T>
296 if (std::is_integral<ElementType>::value) {
297 return xyz[0] >= mMin[0] && xyz[0] <= mMax[0] &&
298 xyz[1] >= mMin[1] && xyz[1] <= mMax[1] &&
299 xyz[2] >= mMin[2] && xyz[2] <= mMax[2];
302 return xyz[0] > (mMin[0]-t) && xyz[0] < (mMax[0]+t) &&
303 xyz[1] > (mMin[1]-t) && xyz[1] < (mMax[1]+t) &&
304 xyz[2] > (mMin[2]-t) && xyz[2] < (mMax[2]+t);
309 template<
typename Vec3T>
313 if (std::is_integral<ElementType>::value) {
314 return b.
min()[0] >= mMin[0] && b.
max()[0] <= mMax[0] &&
315 b.
min()[1] >= mMin[1] && b.
max()[1] <= mMax[1] &&
316 b.
min()[2] >= mMin[2] && b.
max()[2] <= mMax[2];
319 return (b.
min()[0]-t) > mMin[0] && (b.
max()[0]+t) < mMax[0] &&
320 (b.
min()[1]-t) > mMin[1] && (b.
max()[1]+t) < mMax[1] &&
321 (b.
min()[2]-t) > mMin[2] && (b.
max()[2]+t) < mMax[2];
326 template<
typename Vec3T>
330 if (std::is_integral<ElementType>::value) {
331 return mMax[0] >= b.
min()[0] && mMin[0] <= b.
max()[0] &&
332 mMax[1] >= b.
min()[1] && mMin[1] <= b.
max()[1] &&
333 mMax[2] >= b.
min()[2] && mMin[2] <= b.
max()[2];
336 return mMax[0] > (b.
min()[0]-t) && mMin[0] < (b.
max()[0]+t) &&
337 mMax[1] > (b.
min()[1]-t) && mMin[1] < (b.
max()[1]+t) &&
338 mMax[2] > (b.
min()[2]-t) && mMin[2] < (b.
max()[2]+t);
346 template<
typename Vec3T>
351 for (
int i = 0; i < 3; ++i) {
358 template<
typename Vec3T>
362 for (
int i = 0; i < 3; ++i) {
363 mMin[i] =
std::min(mMin[i], xyz[i]);
364 mMax[i] =
std::max(mMax[i], xyz[i]);
369 template<
typename Vec3T>
373 for (
int i = 0; i < 3; ++i) {
379 template<
typename Vec3T>
383 const ElementType size = std::is_integral<ElementType>::value ? length-1 : length;
384 for (
int i = 0; i < 3; ++i) {
385 mMin[i] =
std::min(mMin[i], xyzMin[i]);
386 mMax[i] =
std::max(mMax[i], xyzMin[i] + size);
391 template<
typename Vec3T>
399 template<
typename Vec3T>
400 template<
typename MapType>
406 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
407 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
408 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
409 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
410 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
411 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
412 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
413 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
417 template<
typename Vec3T>
418 template<
typename MapType>
424 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
425 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
426 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
427 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
428 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
429 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
430 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
431 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
438 template<
typename Vec3T>
442 os << b.
min() <<
" -> " << b.
max();
450 #endif // OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
ElementType volume() const
Return the volume enclosed by this bounding box.
Definition: BBox.h:127
bool empty() const
Return true if this bounding box is empty, i.e., it has no (positive) volume.
Definition: BBox.h:223
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: BBox.h:163
BBox(const Vec3T &xyzMin, const Vec3T &xyzMax, bool sorted)
Construct a bounding box that exactly encloses the given minimum and maximum points.
Definition: BBox.h:190
BBox applyMap(const MapType &map) const
Apply a map to this bounding box.
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:358
bool isSorted() const
Return true if all components of the minimum point are less than or equal to the corresponding compon...
Definition: BBox.h:259
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
Definition: BBox.h:91
void translate(const Vec3T &t)
Translate this bounding box by (tx, ty, tz).
Definition: BBox.h:393
Vec3T & min()
Return a non-const reference to the minimum point of this bounding box.
Definition: BBox.h:93
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
Definition: BBox.h:89
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:890
bool intersects(const BBox &other) const
Return true if the given bounding box overlaps with this bounding box.
Definition: BBox.h:136
void expand(const Vec3T &xyzMin, const ElementType &length)
Union this bounding box with the cubical bounding box with minimum point xyzMin and the given edge le...
Definition: BBox.h:381
BBox()
The default constructor creates an invalid bounding box.
Definition: BBox.h:175
Vec3d getCenter() const
Return the center point of this bounding box.
Definition: BBox.h:272
void expand(ElementType padding)
Pad this bounding box.
Definition: BBox.h:348
bool isInside(const BBox &) const
Return true if the given bounding box is inside this bounding box.
Definition: BBox.h:311
static T value()
Definition: Math.h:117
BBox(const ElementType *xyz, bool sorted=true)
Construct a bounding box that exactly encloses two points, whose coordinates are given by an array of...
Definition: BBox.h:210
bool isInside(const Vec3T &xyz) const
Return true if the given point is inside this bounding box.
Definition: BBox.h:294
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool hasVolume() const
Return true if this bounding box has (positive) volume.
Definition: BBox.h:105
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
Definition: BBox.h:440
BBox(const Vec3T &xyzMin, const ElementType &length)
Contruct a cubical bounding box from a minimum coordinate and an edge length.
Definition: BBox.h:198
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:911
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: BBox.h:161
Vec3T extents() const
Return the extents of this bounding box, i.e., the length along each axis.
Definition: BBox.h:280
BBox & operator=(const BBox &)=default
Vec3< double > Vec3d
Definition: Vec3.h:679
bool operator!=(const BBox &rhs) const
Return true if this bounding box differs from the given bounding box.
Definition: BBox.h:100
BBox applyInverseMap(const MapType &map) const
Apply the inverse of a map to this bounding box.
double ValueType
Definition: Vec3.h:54
bool hasOverlap(const BBox &) const
Return true if the given bounding box overlaps with this bounding box.
Definition: BBox.h:328
Axis-aligned bounding box.
Definition: BBox.h:51
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
typename Vec3Type::ValueType ElementType
Definition: BBox.h:56
void expand(const Vec3T &xyz)
Expand this bounding box to enclose the given point.
Definition: BBox.h:360
BBox(const Vec3T &xyzMin, const Vec3T &xyzMax)
Construct a bounding box that exactly encloses the given minimum and maximum points.
Definition: BBox.h:183
Definition: Exceptions.h:40
void sort()
Sort the mininum and maximum points of this bounding box by their x, y and z components.
Definition: BBox.h:247
void expand(const BBox &)
Union this bounding box with the given bounding box.
Definition: BBox.h:371
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: BBox.h:124
Vec3T & max()
Return a non-const reference to the maximum point of this bounding box.
Definition: BBox.h:95
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: BBox.h:122
BBox(const BBox &)=default
bool operator==(const BBox &rhs) const
Return true if this bounding box is identical to the given bounding box.
Definition: BBox.h:235