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<
class _VectorType>
77 operator bool()
const {
return !empty(); }
79 bool isSorted()
const;
81 Vec3d getCenter()
const;
84 VectorType extents()
const;
89 size_t maxExtent()
const;
92 bool isInside(
const VectorType& xyz)
const;
95 bool isInside(
const BBox&)
const;
98 bool hasOverlap(
const BBox&)
const;
101 void expand(ElementType padding);
103 void expand(
const VectorType& xyz);
105 void expand(
const BBox&);
109 void expand(
const VectorType& xyzMin,
const ElementType& length);
111 void translate(
const VectorType& t);
114 void read(std::istream& is) { mMin.read(is); mMax.read(is); }
116 void write(std::ostream& os)
const { mMin.write(os); mMax.write(os); }
119 VectorType mMin, mMax;
126 template<
class VectorType>
134 template<
class VectorType>
137 mMin(xyzMin), mMax(xyzMax)
141 template<
class VectorType>
144 mMin(xyzMin), mMax(xyzMax)
146 if (!sorted) this->
sort();
149 template<
class VectorType>
152 mMin(xyzMin), mMax(xyzMin)
155 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
161 template<
class VectorType>
164 mMin(xyz[0], xyz[1], xyz[2]),
165 mMax(xyz[3], xyz[4], xyz[5])
167 if (!sorted) this->
sort();
171 template<
class VectorType>
174 mMin(other.mMin), mMax(other.mMax)
182 template<
class VectorType>
186 if (boost::is_integral<ElementType>::value) {
188 return (mMin[0] > mMax[0] || mMin[1] > mMax[1] || mMin[2] > mMax[2]);
190 return mMin[0] >= mMax[0] || mMin[1] >= mMax[1] || mMin[2] >= mMax[2];
194 template<
class VectorType>
198 if (boost::is_integral<ElementType>::value) {
199 return mMin == rhs.
min() && mMax == rhs.
max();
206 template<
class VectorType>
211 for (
size_t i = 0; i < 3; ++i) {
212 mMin[i] =
std::min(tMin[i], tMax[i]);
213 mMax[i] =
std::max(tMin[i], tMax[i]);
218 template<
class VectorType>
222 if (boost::is_integral<ElementType>::value) {
223 return (mMin[0] <= mMax[0] && mMin[1] <= mMax[1] && mMin[2] <= mMax[2]);
226 return (mMin[0] < (mMax[0] + t) && mMin[1] < (mMax[1] + t) && mMin[2] < (mMax[2] + t));
231 template<
class VectorType>
235 return (
Vec3d(mMin.asPointer()) +
Vec3d(mMax.asPointer())) * 0.5;
239 template<
class VectorType>
243 if (boost::is_integral<ElementType>::value) {
246 return (mMax - mMin);
251 template<
class VectorType>
256 if (e[0] > e[1] && e[0] > e[2])
return 0;
257 else if (e[1] > e[2])
return 1;
265 template<
class VectorType>
269 if (boost::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);
282 template<
class VectorType>
286 if (boost::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];
299 template<
class VectorType>
303 if (boost::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);
319 template<
class VectorType>
324 for (
size_t i = 0; i < 3; ++i) {
331 template<
class VectorType>
335 for (
size_t 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<
class VectorType>
346 for (
size_t i = 0; i < 3; ++i) {
352 template<
class VectorType>
356 const ElementType size = boost::is_integral<ElementType>::value ? length-1 : length;
357 for (
size_t 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<
class VectorType>
376 template<
class VectorType>
378 operator<<(std::ostream& os, const BBox<VectorType>& b)
380 os << b.min() <<
" -> " << b.max();
388 #endif // OPENVDB_MATH_BBOX_HAS_BEEN_INCLUDED