4 #ifndef OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
5 #define OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
13 #include <type_traits>
22 template<
typename Vec3T>
35 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax);
40 BBox(
const Vec3T& xyzMin,
const Vec3T& xyzMax,
bool sorted);
62 const Vec3T&
min()
const {
return mMin; }
64 const Vec3T&
max()
const {
return mMax; }
66 Vec3T&
min() {
return mMin; }
68 Vec3T&
max() {
return mMax; }
80 operator bool()
const {
return !this->
empty(); }
103 bool isInside(
const Vec3T& xyz)
const;
114 void expand(
const Vec3T& xyz);
127 template<
typename MapType>
130 template<
typename MapType>
134 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
136 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
146 template<
typename Vec3T>
154 template<
typename Vec3T>
157 mMin(xyzMin), mMax(xyzMax)
161 template<
typename Vec3T>
164 mMin(xyzMin), mMax(xyzMax)
166 if (!sorted) this->
sort();
169 template<
typename Vec3T>
172 mMin(xyzMin), mMax(xyzMin)
181 template<
typename Vec3T>
184 mMin(xyz[0], xyz[1], xyz[2]),
185 mMax(xyz[3], xyz[4], xyz[5])
187 if (!sorted) this->
sort();
194 template<
typename Vec3T>
200 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
202 return mMin[0] >= mMax[0] || mMin[1] >= mMax[1] || mMin[2] >= mMax[2];
206 template<
typename Vec3T>
211 return mMin == rhs.
min() && mMax == rhs.
max();
218 template<
typename Vec3T>
222 Vec3T tMin(mMin), tMax(mMax);
223 for (
int i = 0; i < 3; ++i) {
224 mMin[i] =
std::min(tMin[i], tMax[i]);
225 mMax[i] =
std::max(tMin[i], tMax[i]);
230 template<
typename Vec3T>
235 return (mMin[0] <= mMax[0] && mMin[1] <= mMax[1] && mMin[2] <= mMax[2]);
238 return (mMin[0] < (mMax[0] + t) && mMin[1] < (mMax[1] + t) && mMin[2] < (mMax[2] + t));
243 template<
typename Vec3T>
247 return (
Vec3d(mMin.asPointer()) +
Vec3d(mMax.asPointer())) * 0.5;
251 template<
typename Vec3T>
256 return (mMax - mMin) + Vec3T(1, 1, 1);
258 return (mMax - mMin);
265 template<
typename Vec3T>
270 return xyz[0] >= mMin[0] && xyz[0] <= mMax[0] &&
271 xyz[1] >= mMin[1] && xyz[1] <= mMax[1] &&
272 xyz[2] >= mMin[2] && xyz[2] <= mMax[2];
275 return xyz[0] > (mMin[0]-
t) && xyz[0] < (mMax[0]+t) &&
276 xyz[1] > (mMin[1]-
t) && xyz[1] < (mMax[1]+t) &&
277 xyz[2] > (mMin[2]-
t) && xyz[2] < (mMax[2]+t);
282 template<
typename Vec3T>
287 return b.
min()[0] >= mMin[0] && b.
max()[0] <= mMax[0] &&
288 b.
min()[1] >= mMin[1] && b.
max()[1] <= mMax[1] &&
289 b.
min()[2] >= mMin[2] && b.
max()[2] <= mMax[2];
292 return (b.
min()[0]-
t) > mMin[0] && (b.
max()[0]+
t) < mMax[0] &&
293 (b.
min()[1]-
t) > mMin[1] && (b.
max()[1]+
t) < mMax[1] &&
294 (b.
min()[2]-
t) > mMin[2] && (b.
max()[2]+
t) < mMax[2];
299 template<
typename Vec3T>
304 return mMax[0] >= b.
min()[0] && mMin[0] <= b.
max()[0] &&
305 mMax[1] >= b.
min()[1] && mMin[1] <= b.
max()[1] &&
306 mMax[2] >= b.
min()[2] && mMin[2] <= b.
max()[2];
309 return mMax[0] > (b.
min()[0]-
t) && mMin[0] < (b.
max()[0]+
t) &&
310 mMax[1] > (b.
min()[1]-
t) && mMin[1] < (b.
max()[1]+
t) &&
311 mMax[2] > (b.
min()[2]-
t) && mMin[2] < (b.
max()[2]+
t);
319 template<
typename Vec3T>
324 for (
int i = 0; i < 3; ++i) {
331 template<
typename Vec3T>
335 for (
int i = 0; i < 3; ++i) {
336 mMin[i] =
std::min(mMin[i], xyz[i]);
337 mMax[i] =
std::max(mMax[i], xyz[i]);
342 template<
typename Vec3T>
346 for (
int i = 0; i < 3; ++i) {
352 template<
typename Vec3T>
357 for (
int i = 0; i < 3; ++i) {
358 mMin[i] =
std::min(mMin[i], xyzMin[i]);
359 mMax[i] =
std::max(mMax[i], xyzMin[i] + size);
364 template<
typename Vec3T>
372 template<
typename Vec3T>
373 template<
typename MapType>
379 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
380 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
381 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
382 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
383 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
384 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
385 bbox.
expand(map.applyMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
386 bbox.
expand(map.applyMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
390 template<
typename Vec3T>
391 template<
typename MapType>
397 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMin[2])));
398 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMin[1], mMax[2])));
399 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMin[2])));
400 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMin[2])));
401 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMin[2])));
402 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMin[1], mMax[2])));
403 bbox.
expand(map.applyInverseMap(
Vec3R(mMin[0], mMax[1], mMax[2])));
404 bbox.
expand(map.applyInverseMap(
Vec3R(mMax[0], mMax[1], mMax[2])));
411 template<
typename Vec3T>
413 operator<<(std::ostream& os, const BBox<Vec3T>&
b)
415 os <<
b.min() <<
" -> " <<
b.max();
423 #endif // OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
GLsizei const GLfloat * value
void translate(const Vec3T &t)
Translate this bounding box by (tx, ty, tz).
Vec3T & max()
Return a non-const reference to the maximum point of this bounding box.
GLuint GLsizei GLsizei * length
#define OPENVDB_USE_VERSION_NAMESPACE
void expand(ElementType padding)
Pad this bounding box.
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
void read(std::istream &is)
Unserialize this bounding box from the given stream.
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
BBox applyMap(const MapType &map) const
Apply a map to this bounding box.
BBox applyInverseMap(const MapType &map) const
Apply the inverse of a map to this bounding box.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
bool operator!=(const BBox &rhs) const
Return true if this bounding box differs from the given bounding box.
bool empty() const
Return true if this bounding box is empty, i.e., it has no (positive) volume.
typename Vec3Type::ValueType ElementType
GLboolean GLboolean GLboolean b
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
Vec3T extents() const
Return the extents of this bounding box, i.e., the length along each axis.
Axis-aligned bounding box.
BBox()
The default constructor creates an invalid bounding box.
BBox & operator=(const BBox &)=default
bool intersects(const BBox &other) const
Return true if the given bounding box overlaps with this bounding box.
bool operator==(const BBox &rhs) const
Return true if this bounding box is identical to the given bounding box.
ElementType volume() const
Return the volume enclosed by this bounding box.
Vec3d getCenter() const
Return the center point of this bounding box.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec3T & min()
Return a non-const reference to the minimum point of this bounding box.
bool hasOverlap(const BBox &) const
Return true if the given bounding box overlaps with this bounding box.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE constexpr T abs(T a) IMATH_NOEXCEPT
bool isSorted() const
Return true if all components of the minimum point are less than or equal to the corresponding compon...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
void sort()
Sort the mininum and maximum points of this bounding box by their x, y and z components.
bool hasVolume() const
Return true if this bounding box has (positive) volume.
bool isInside(const Vec3T &xyz) const
Return true if the given point is inside this bounding box.