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);
81 const Vec3T&
min()
const {
return mMin; }
84 const Vec3T&
max()
const {
return mMax; }
87 Vec3T&
min() {
return mMin; }
90 Vec3T&
max() {
return mMax; }
106 operator bool()
const {
return !this->empty(); }
111 bool isSorted()
const;
114 Vec3d getCenter()
const;
120 Vec3T extents()
const;
132 bool isInside(
const Vec3T& xyz)
const;
135 bool isInside(
const BBox&)
const;
138 bool hasOverlap(
const BBox&)
const;
141 void expand(ElementType padding);
144 void expand(
const Vec3T& xyz);
147 void expand(
const BBox&);
151 void expand(
const Vec3T& xyzMin,
const ElementType& length);
154 void translate(
const Vec3T& t);
157 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
160 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
170 template<
typename Vec3T>
178 template<
typename Vec3T>
181 mMin(xyzMin), mMax(xyzMax)
185 template<
typename Vec3T>
188 mMin(xyzMin), mMax(xyzMax)
190 if (!sorted) this->
sort();
193 template<
typename Vec3T>
196 mMin(xyzMin), mMax(xyzMin)
199 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
205 template<
typename Vec3T>
208 mMin(xyz[0], xyz[1], xyz[2]),
209 mMax(xyz[3], xyz[4], xyz[5])
211 if (!sorted) this->
sort();
215 template<
typename Vec3T>
218 mMin(other.mMin), mMax(other.mMax)
226 template<
typename Vec3T>
230 if (boost::is_integral<ElementType>::value) {
232 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
234 return mMin[0] >= mMax[0] || mMin[1] >= mMax[1] || mMin[2] >= mMax[2];
238 template<
typename Vec3T>
242 if (boost::is_integral<ElementType>::value) {
243 return mMin == rhs.
min() && mMax == rhs.
max();
250 template<
typename Vec3T>
254 Vec3T tMin(mMin), tMax(mMax);
255 for (
size_t i = 0; i < 3; ++i) {
256 mMin[i] =
std::min(tMin[i], tMax[i]);
257 mMax[i] =
std::max(tMin[i], tMax[i]);
262 template<
typename Vec3T>
266 if (boost::is_integral<ElementType>::value) {
267 return (mMin[0] <= mMax[0] && mMin[1] <= mMax[1] && mMin[2] <= mMax[2]);
270 return (mMin[0] < (mMax[0] + t) && mMin[1] < (mMax[1] + t) && mMin[2] < (mMax[2] + t));
275 template<
typename Vec3T>
279 return (
Vec3d(mMin.asPointer()) +
Vec3d(mMax.asPointer())) * 0.5;
283 template<
typename Vec3T>
287 if (boost::is_integral<ElementType>::value) {
288 return (mMax - mMin) + Vec3T(1, 1, 1);
290 return (mMax - mMin);
297 template<
typename Vec3T>
301 if (boost::is_integral<ElementType>::value) {
302 return xyz[0] >= mMin[0] && xyz[0] <= mMax[0] &&
303 xyz[1] >= mMin[1] && xyz[1] <= mMax[1] &&
304 xyz[2] >= mMin[2] && xyz[2] <= mMax[2];
307 return xyz[0] > (mMin[0]-t) && xyz[0] < (mMax[0]+t) &&
308 xyz[1] > (mMin[1]-t) && xyz[1] < (mMax[1]+t) &&
309 xyz[2] > (mMin[2]-t) && xyz[2] < (mMax[2]+t);
314 template<
typename Vec3T>
318 if (boost::is_integral<ElementType>::value) {
319 return b.
min()[0] >= mMin[0] && b.
max()[0] <= mMax[0] &&
320 b.
min()[1] >= mMin[1] && b.
max()[1] <= mMax[1] &&
321 b.
min()[2] >= mMin[2] && b.
max()[2] <= mMax[2];
324 return (b.
min()[0]-t) > mMin[0] && (b.
max()[0]+t) < mMax[0] &&
325 (b.
min()[1]-t) > mMin[1] && (b.
max()[1]+t) < mMax[1] &&
326 (b.
min()[2]-t) > mMin[2] && (b.
max()[2]+t) < mMax[2];
331 template<
typename Vec3T>
335 if (boost::is_integral<ElementType>::value) {
336 return mMax[0] >= b.
min()[0] && mMin[0] <= b.
max()[0] &&
337 mMax[1] >= b.
min()[1] && mMin[1] <= b.
max()[1] &&
338 mMax[2] >= b.
min()[2] && mMin[2] <= b.
max()[2];
341 return mMax[0] > (b.
min()[0]-t) && mMin[0] < (b.
max()[0]+t) &&
342 mMax[1] > (b.
min()[1]-t) && mMin[1] < (b.
max()[1]+t) &&
343 mMax[2] > (b.
min()[2]-t) && mMin[2] < (b.
max()[2]+t);
351 template<
typename Vec3T>
356 for (
size_t i = 0; i < 3; ++i) {
363 template<
typename Vec3T>
367 for (
size_t i = 0; i < 3; ++i) {
368 mMin[i] =
std::min(mMin[i], xyz[i]);
369 mMax[i] =
std::max(mMax[i], xyz[i]);
374 template<
typename Vec3T>
378 for (
size_t i = 0; i < 3; ++i) {
384 template<
typename Vec3T>
388 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
389 for (
size_t i = 0; i < 3; ++i) {
390 mMin[i] =
std::min(mMin[i], xyzMin[i]);
391 mMax[i] =
std::max(mMax[i], xyzMin[i] + size);
396 template<
typename Vec3T>
408 template<
typename Vec3T>
410 operator<<(std::ostream& os, const BBox<Vec3T>& b)
412 os << b.min() <<
" -> " << b.max();
420 #endif // OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
Vec3T & min()
Return a non-const reference to the minimum point of the BBox.
Definition: BBox.h:87
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
BBox()
Default constructor creates an invalid BBox.
Definition: BBox.h:172
Vec3T extents() const
Returns the extents of the BBox, i.e. the length per axis for floating points values or number of gri...
Definition: BBox.h:285
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool isSorted() const
Return true if the all components of mMin <= mMax, i.e. the volume is not negative.
Definition: BBox.h:264
Vec3T & max()
Return a non-const reference to the maximum point of the BBox.
Definition: BBox.h:90
ElementType volume() const
Return the volume spanned by this BBox.
Definition: BBox.h:123
Vec3d getCenter() const
Return the center point of the BBox.
Definition: BBox.h:277
bool hasOverlap(const BBox &) const
Return true if the given bounding box overlaps with this bounding box.
Definition: BBox.h:333
Axis-aligned bounding box.
Definition: BBox.h:47
bool isInside(const Vec3T &xyz) const
Return true if point (x, y, z) is inside this bounding box.
Definition: BBox.h:299
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:430
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition: BBox.h:126
Vec3Type::ValueType ElementType
Definition: BBox.h:53
bool hasVolume() const
Return true if the BBox has a (positive) volume.
Definition: BBox.h:103
void translate(const Vec3T &t)
Translate this bounding box by .
Definition: BBox.h:398
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition: BBox.h:160
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition: Math.h:814
double ValueType
Definition: Vec3.h:51
#define OPENVDB_VERSION_NAME
Definition: version.h:45
static T value()
Definition: Math.h:116
Vec3T ValueType
Definition: BBox.h:51
void expand(ElementType padding)
Pad this bounding box.
Definition: BBox.h:353
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition: BBox.h:129
void sort()
Sort the min/max by x,y,z component.
Definition: BBox.h:252
Vec3< double > Vec3d
Definition: Vec3.h:605
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:796
bool operator!=(const BBox &rhs) const
Return true if the two BBox'es are not identical.
Definition: BBox.h:96
const Vec3T & min() const
Return a const reference to the minimum point of the BBox.
Definition: BBox.h:81
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition: BBox.h:157
bool empty() const
Return true if the BBox is empty, i.e. has no (positive) volume.
Definition: BBox.h:228
Vec3T Vec3Type
Definition: BBox.h:50
Vec3T VectorType
Definition: BBox.h:52
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
bool isApproxEqual(const Hermite &lhs, const Hermite &rhs)
Definition: Hermite.h:470
const Vec3T & max() const
Return a const reference to the maximum point of the BBox.
Definition: BBox.h:84
bool operator==(const BBox &rhs) const
Return true if the two BBox'es are identical.
Definition: BBox.h:240