4#ifndef OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED 
    5#define OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED 
   22template<
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(); }
 
  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); }
 
 
  146template<
typename Vec3T>
 
  154template<
typename Vec3T>
 
  157    mMin(xyzMin), mMax(xyzMax)
 
 
  161template<
typename Vec3T>
 
  164    mMin(xyzMin), mMax(xyzMax)
 
  166    if (!sorted) this->
sort();
 
 
  169template<
typename Vec3T>
 
  172    mMin(xyzMin), mMax(xyzMin)
 
  175    const ElementType size = std::is_integral<ElementType>::value ? length-1 : length;
 
 
  181template<
typename Vec3T>
 
  184    mMin(xyz[0], xyz[1], xyz[2]),
 
  185    mMax(xyz[3], xyz[4], xyz[5])
 
  187    if (!sorted) this->
sort();
 
 
  194template<
typename Vec3T>
 
  198    if (std::is_integral<ElementType>::value) {
 
  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];
 
 
  206template<
typename Vec3T>
 
  210    if (std::is_integral<ElementType>::value) {
 
  211        return mMin == rhs.
min() && mMax == rhs.
max();
 
 
  218template<
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]);
 
 
  230template<
typename Vec3T>
 
  234    if (std::is_integral<ElementType>::value) {
 
  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));
 
 
  243template<
typename Vec3T>
 
  247    return (
Vec3d(mMin.asPointer()) + 
Vec3d(mMax.asPointer())) * 0.5;
 
 
  251template<
typename Vec3T>
 
  255    if (std::is_integral<ElementType>::value) {
 
  256        return (mMax - mMin) + Vec3T(1, 1, 1);
 
  258        return (mMax - mMin);
 
 
  265template<
typename Vec3T>
 
  269    if (std::is_integral<ElementType>::value) {
 
  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);
 
 
  282template<
typename Vec3T>
 
  286    if (std::is_integral<ElementType>::value) {
 
  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];
 
 
  299template<
typename Vec3T>
 
  303    if (std::is_integral<ElementType>::value) {
 
  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);
 
 
  319template<
typename Vec3T>
 
  324    for (
int i = 0; i < 3; ++i) {
 
 
  331template<
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]);
 
 
  342template<
typename Vec3T>
 
  346    for (
int i = 0; i < 3; ++i) {
 
  347        mMin[i] = std::min(mMin[i], b.
min()[i]);
 
  348        mMax[i] = std::max(mMax[i], b.
max()[i]);
 
 
  352template<
typename Vec3T>
 
  356    const ElementType size = std::is_integral<ElementType>::value ? length-1 : length;
 
  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);
 
 
  364template<
typename Vec3T>
 
  372template<
typename Vec3T>
 
  373template<
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])));
 
 
  390template<
typename Vec3T>
 
  391template<
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])));
 
 
  411template<
typename Vec3T>
 
  415    os << b.
min() << 
" -> " << b.
max();
 
 
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Axis-aligned bounding box.
Definition BBox.h:24
BBox(const Vec3T &xyzMin, const ElementType &length)
Contruct a cubical bounding box from a minimum coordinate and an edge length.
Definition BBox.h:171
bool isInside(const Vec3T &xyz) const
Return true if the given point is inside this bounding box.
Definition BBox.h:267
BBox(const Vec3T &xyzMin, const Vec3T &xyzMax)
Construct a bounding box that exactly encloses the given minimum and maximum points.
Definition BBox.h:156
BBox()
The default constructor creates an invalid bounding box.
Definition BBox.h:148
size_t minExtent() const
Return the index (0, 1 or 2) of the shortest axis.
Definition BBox.h:97
const Vec3T & max() const
Return a const reference to the maximum point of this bounding box.
Definition BBox.h:64
void write(std::ostream &os) const
Serialize this bounding box to the given stream.
Definition BBox.h:136
bool hasOverlap(const BBox &) const
Return true if the given bounding box overlaps with this bounding box.
Definition BBox.h:301
void expand(const Vec3T &xyz)
Expand this bounding box to enclose the given point.
Definition BBox.h:333
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:354
void sort()
Sort the mininum and maximum points of this bounding box by their x, y and z components.
Definition BBox.h:220
ElementType volume() const
Return the volume enclosed by this bounding box.
Definition BBox.h:100
bool hasVolume() const
Return true if this bounding box has (positive) volume.
Definition BBox.h:78
Vec3d getCenter() const
Return the center point of this bounding box.
Definition BBox.h:245
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:163
bool isSorted() const
Return true if all components of the minimum point are less than or equal to the corresponding compon...
Definition BBox.h:232
bool empty() const
Return true if this bounding box is empty, i.e., it has no (positive) volume.
Definition BBox.h:196
void expand(ElementType padding)
Pad this bounding box.
Definition BBox.h:321
void translate(const Vec3T &t)
Translate this bounding box by (tx, ty, tz).
Definition BBox.h:366
void expand(const BBox &)
Union this bounding box with the given bounding box.
Definition BBox.h:344
size_t maxExtent() const
Return the index (0, 1 or 2) of the longest axis.
Definition BBox.h:95
bool operator==(const BBox &rhs) const
Return true if this bounding box is identical to the given bounding box.
Definition BBox.h:208
bool isInside(const BBox &) const
Return true if the given bounding box is inside this bounding box.
Definition BBox.h:284
bool operator!=(const BBox &rhs) const
Return true if this bounding box differs from the given bounding box.
Definition BBox.h:73
Vec3d ValueType
Definition BBox.h:27
Vec3T extents() const
Return the extents of this bounding box, i.e., the length along each axis.
Definition BBox.h:253
Vec3d Vec3Type
Definition BBox.h:26
const Vec3T & min() const
Return a const reference to the minimum point of this bounding box.
Definition BBox.h:62
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:183
Vec3T & min()
Return a non-const reference to the minimum point of this bounding box.
Definition BBox.h:66
BBox(const BBox &)=default
bool intersects(const BBox &other) const
Return true if the given bounding box overlaps with this bounding box.
Definition BBox.h:109
Vec3T & max()
Return a non-const reference to the maximum point of this bounding box.
Definition BBox.h:68
typename Vec3Type::ValueType ElementType
Definition BBox.h:29
Vec3d VectorType
Definition BBox.h:28
BBox & operator=(const BBox &)=default
BBox applyInverseMap(const MapType &map) const
Apply the inverse of a map to this bounding box.
BBox applyMap(const MapType &map) const
Apply a map to this bounding box.
void read(std::istream &is)
Unserialize this bounding box from the given stream.
Definition BBox.h:134
double ValueType
Definition Vec3.h:28
size_t MaxIndex(const Vec3T &v)
Return the index [0,1,2] of the largest value in a 3D vector.
Definition Math.h:946
std::ostream & operator<<(std::ostream &os, const BBox< Vec3T > &b)
Definition BBox.h:413
bool isApproxEqual(const Type &a, const Type &b, const Type &tolerance)
Return true if a is equal to b to within the given tolerance.
Definition Math.h:406
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition Math.h:930
Vec3< double > Vec3d
Definition Vec3.h:665
math::Vec3< Real > Vec3R
Definition Types.h:72
Definition Exceptions.h:13
static T value()
Definition Math.h:148
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218