Box¶
#include <Imath/ImathBox.h>
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>
class Box¶ The
Box<V>
template represents an axis-aligned bounding box defined by minimum and maximum values of typeV
.The
min
andmax
members are public.The type
V
is 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.V
must also provide a constructor that takes a float and/or double for use in initializing the box.V
must 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
-
inline constexpr Box() noexcept¶
Construct an empty bounding box.
This initializes the mimimum to std::numeric_limits<V::baseType>::max() and the maximum to std::numeric_limits<V::baseType>::lowest().
Comparison
Manipulation
-
inline void makeEmpty() noexcept¶
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()
.
-
inline void makeInfinite() noexcept¶
Make the box include the entire range of
V
.
Query
-
inline constexpr V size() const noexcept¶
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.
-
inline constexpr V center() const noexcept¶
Return the center of the box.
The center is defined as
(max+min)/2
. The center of an empty box is undefined.
-
inline constexpr bool intersects(const V &point) const noexcept¶
Return true if the given point is inside the box, false otherwise.
-
inline constexpr bool intersects(const Box<V> &box) const noexcept¶
Return true if the given box is inside the box, false otherwise.
-
inline constexpr unsigned int majorAxis() const noexcept¶
Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
inline constexpr bool isEmpty() const noexcept¶
Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
inline constexpr bool hasVolume() const noexcept¶
Return true if the box is larger than a single point, false otherwise.
-
inline constexpr bool isInfinite() const noexcept¶
Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeLowest()
and a maximum ofV::baseTypeMax()
.
-
inline constexpr Box() noexcept¶
-
template<class T>
class Box<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
Constructors and Assignment
-
inline constexpr Box() noexcept¶
Empty by default.
Comparison
Manipulation
-
inline void makeEmpty() noexcept¶
Set the Box to be empty.
A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to std::numeric_limits<T>::max() and the maximum to std::numeric_limits<T>::lowest().
-
inline void makeInfinite() noexcept¶
Make the box include the entire range of T.
Query
-
inline constexpr Vec2<T> size() const noexcept¶
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.
-
inline constexpr Vec2<T> center() const noexcept¶
Return the center of the box.
The center is defined as
(max+min)/2
. The center of an empty box is undefined.
-
inline constexpr bool intersects(const Vec2<T> &point) const noexcept¶
Return true if the given point is inside the box, false otherwise.
-
inline constexpr bool intersects(const Box<Vec2<T>> &box) const noexcept¶
Return true if the given box is inside the box, false otherwise.
-
inline constexpr unsigned int majorAxis() const noexcept¶
Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
inline constexpr bool isEmpty() const noexcept¶
Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
inline constexpr bool hasVolume() const noexcept¶
Return true if the box is larger than a single point, false otherwise.
-
inline constexpr bool isInfinite() const noexcept¶
Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeMin()
and a maximum ofV::baseTypeMax()
.
-
inline constexpr Box() noexcept¶
-
template<class T>
class Box<Vec3<T>>¶ The Box<Vec3> template represents a 3D bounding box defined by minimum and maximum values of type Vec3.
Direct access to bounds
Constructors
-
inline constexpr Box() noexcept¶
Empty by default.
Public Functions
-
inline void makeEmpty() noexcept¶
Set the Box to be empty.
A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to std::numeric_limits<T>::max() and the maximum to std::numeric_limits<T>::lowest().
-
inline void makeInfinite() noexcept¶
Make the box include the entire range of T.
-
inline constexpr Vec3<T> size() const noexcept¶
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.
-
inline constexpr Vec3<T> center() const noexcept¶
Return the center of the box.
The center is defined as (max+min)/2. The center of an empty box is undefined.
-
inline constexpr bool intersects(const Vec3<T> &point) const noexcept¶
Return true if the given point is inside the box, false otherwise.
-
inline constexpr bool intersects(const Box<Vec3<T>> &box) const noexcept¶
Return true if the given box is inside the box, false otherwise.
-
inline constexpr unsigned int majorAxis() const noexcept¶
Return the major axis of the box.
The major axis is the dimension with the greatest difference between maximum and minimum.
-
inline constexpr bool isEmpty() const noexcept¶
Return true if the box is empty, false otherwise.
An empty box’s minimum is greater than its maximum.
-
inline constexpr bool hasVolume() const noexcept¶
Return true if the box is larger than a single point, false otherwise.
-
inline constexpr bool isInfinite() const noexcept¶
Return true if the box contains all points, false otherwise.
An infinite box has a mimimum of
V::baseTypeMin()
and a maximum ofV::baseTypeMax()
.
-
inline constexpr Box() noexcept¶