Box¶
The Box class template represents 2D and 3D axis-aligned bounding
boxes, with predefined typedefs for boxes of type short, int,
int64_t, float, and double.
The box is defined by minimum and maximum values along each axis,
represented by Vec2<T> for the Box2 types and by Vec3<T>
for Box3 types.
There are also various utility functions that operate on bounding
boxes defined in ImathBoxAlgo.h and described in Box
Functions.
Example:
#include <Imath/ImathBox.h>
void
box_example()
{
Imath::V3f a (0, 0, 0);
Imath::V3f b (1, 1, 1);
Imath::V3f c (2, 9, 2);
Imath::Box3f box (a);
assert (box.isEmpty());
assert (!box.isInfinite());
assert (!box.hasVolume());
box.extendBy (c);
assert (box.size() == (c-a));
assert (box.intersects (b));
assert (box.max[0] > box.min[0]);
assert (box.max[1] > box.min[1]);
assert (box.max[2] > box.min[2]);
assert (box.hasVolume());
assert (box.majorAxis() == 1);
}
-
template <class V>
classBox¶ The
Box<V>template represents an axis-aligned bounding box defined by minimum and maximum values of typeV.The
minandmaxmembers are public.The type
Vis typically an Imath vector (i.e.V2i,V3f, etc) and must implement an indexoperator[]that returns a type (typically as scalar) that supports assignment, comparison, and arithmetic operators.Vmust also provide a constructor that takes a float and/or double for use in initializing the box.Vmust also provide a functionV::dimensions()which returns the number of dimensions in the class (since its assumed its a vector) preferably, this returns a constant expression, typically 2 or 3.Constructors
-
constexpr
Box()¶ Construct an empty bounding box.
This initializes the mimimum to
std::numeric_limits<V::baseType>::max()and the maximum tostd::numeric_limits<V::baseType>::lowest().
-
constexpr
Box(const V &point)¶ Construct a bounding box that contains a single point.
-
constexpr
Box(const V &minV, const V &maxV)¶ Construct a bounding box with the given minimum and maximum values.
Comparison
Manipulation
-
void
makeEmpty()¶ Set the box to be empty.
A box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to
V::baseTypeMax()and the maximum toV::baseTypeLowest().
-
void
extendBy(const V &point)¶ Extend the box to include the given point.
-
void
makeInfinite()¶ Make the box include the entire range of
V.
Query
-
constexpr V
size() const¶ Return the size of the box.
The size is of type
V, defined as(max-min). An empty box has a size ofV(0), i.e. 0 in each dimension.
-
constexpr V
center() const¶ Return the center of the box.
The center is defined as
(max+min)/2. The center of an empty box is undefined.
-
constexpr bool
intersects(const V &point) const¶ Return true if the given point is inside the box, false otherwise.
-
constexpr bool
intersects(const Box<V> &box) const¶ Return true if the given box is inside the box, false otherwise.
-
constexpr unsigned int
majorAxis() const¶ Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
constexpr bool
isEmpty() const¶ Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
constexpr bool
hasVolume() const¶ Return true if the box is larger than a single point, false otherwise.
-
constexpr bool
isInfinite() const¶ Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeLowest()and a maximum ofV::baseTypeMax().
-
constexpr
-
template <class T>
template<>
classBox<Vec2<T>>¶ The Box<Vec2<T>> template represents a 2D bounding box defined by minimum and maximum values of type Vec2<T>.
The min and max members are public.
Direct access to bounds
-
Vec2<T>
min The minimum value of the box.
-
Vec2<T>
max The maximum value of the box.
Constructors and Assignment
-
constexpr
Box() Empty by default.
Comparison
Manipulation
-
void
makeEmpty() Set the Box to be empty.
A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to numeric_limits<T>::max() and the maximum to
numeric_limits<T>::lowest().
-
void
makeInfinite() Make the box include the entire range of T.
Query
-
constexpr Vec2<T>
size() const Return the size of the box.
The size is of type
V, defined as(max-min). An empty box has a size ofV(0), i.e. 0 in each dimension.
-
constexpr Vec2<T>
center() const Return the center of the box.
The center is defined as
(max+min)/2. The center of an empty box is undefined.
-
constexpr bool
intersects(const Vec2<T> &point) const¶ Return true if the given point is inside the box, false otherwise.
-
constexpr bool
intersects(const Box<Vec2<T>> &box) const¶ Return true if the given box is inside the box, false otherwise.
-
constexpr unsigned int
majorAxis() const Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
constexpr bool
isEmpty() const Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
constexpr bool
hasVolume() const Return true if the box is larger than a single point, false otherwise.
-
constexpr bool
isInfinite() const Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeMin()and a maximum ofV::baseTypeMax().
-
Vec2<T>
-
template <class T>
template<>
classBox<Vec3<T>>¶ The Box<Vec3> template represents a 3D bounding box defined by minimum and maximum values of type Vec3.
Direct access to bounds
-
Vec3<T>
min The minimum value of the box.
-
Vec3<T>
max The maximum value of the box.
Constructors
-
constexpr
Box() Empty by default.
Public Functions
-
void
makeEmpty() Set the Box to be empty.
A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to
numeric_limits<T>::max()and the maximum tonumeric_limits<T>::lowest().
-
void
makeInfinite() Make the box include the entire range of T.
-
constexpr Vec3<T>
size() const Return the size of the box.
The size is of type
V, defined as (max-min). An empty box has a size of V(0), i.e. 0 in each dimension.
-
constexpr Vec3<T>
center() const Return the center of the box.
The center is defined as (max+min)/2. The center of an empty box is undefined.
-
constexpr bool
intersects(const Vec3<T> &point) const¶ Return true if the given point is inside the box, false otherwise.
-
constexpr bool
intersects(const Box<Vec3<T>> &box) const¶ Return true if the given box is inside the box, false otherwise.
-
constexpr unsigned int
majorAxis() const Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
constexpr bool
isEmpty() const Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
constexpr bool
hasVolume() const Return true if the box is larger than a single point, false otherwise.
-
constexpr bool
isInfinite() const Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeMin()and a maximum ofV::baseTypeMax().
-
Vec3<T>