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);
}
typedef Box<V2s> Imath::Box2s

2D box of base type short.

typedef Box<V2i> Imath::Box2i

2D box of base type int.

typedef Box<V2i64> Imath::Box2i64

2D box of base type int64_t.

typedef Box<V2f> Imath::Box2f

2D box of base type float.

typedef Box<V2d> Imath::Box2d

2D box of base type double.

typedef Box<V3s> Imath::Box3s

3D box of base type short.

typedef Box<V3i> Imath::Box3i

3D box of base type int.

typedef Box<V3i64> Imath::Box3i64

3D box of base type int64_t.

typedef Box<V3f> Imath::Box3f

3D box of base type float.

typedef Box<V3d> Imath::Box3d

3D box of base type double.

template<class V>
class Box

The Box<V> template represents an axis-aligned bounding box defined by minimum and maximum values of type V.

The min and max members are public.

The type V is typically an Imath vector (i.e. V2i, V3f, etc) and must implement an index operator[] 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 function V::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.

Direct access to bounds

V min

The minimum value of the box.

V max

The maximum value of the box.

Constructors

constexpr Box()

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().

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

constexpr bool operator==(const Box<V> &src) const

Equality.

constexpr bool operator!=(const Box<V> &src) const

Inequality.

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 to V::baseTypeLowest().

void extendBy(const V &point)

Extend the box to include the given point.

void extendBy(const Box<V> &box)

Extend the box to include the given box.

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 of V(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 ofV::baseTypeLowest() and a maximum of V::baseTypeMax().

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

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.

constexpr Box(const Vec2<T> &point)

Construct a bounding box that contains a single point.

constexpr Box(const Vec2<T> &minT, const Vec2<T> &maxT)

Construct a bounding box with the given minimum and maximum points.

Comparison

constexpr bool operator==(const Box<Vec2<T>> &src) const

Equality.

constexpr bool operator!=(const Box<Vec2<T>> &src) const

Inequality.

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 std::numeric_limits<T>::max() and the maximum to std::numeric_limits<T>::lowest().

void extendBy(const Vec2<T> &point)

Extend the Box to include the given point.

void extendBy(const Box<Vec2<T>> &box)

Extend the Box to include the given box.

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 of V(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 of V::baseTypeMax().

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

Vec3<T> min

The minimum value of the box.

Vec3<T> max

The maximum value of the box.

Constructors

constexpr Box()

Empty by default.

constexpr Box(const Vec3<T> &point)

Construct a bounding box that contains a single point.

constexpr Box(const Vec3<T> &minT, const Vec3<T> &maxT)

Construct a bounding box with the given minimum and maximum points.

Public Functions

constexpr bool operator==(const Box<Vec3<T>> &src) const

Equality.

constexpr bool operator!=(const Box<Vec3<T>> &src) const

Inequality.

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 std::numeric_limits<T>::max() and the maximum to std::numeric_limits<T>::lowest().

void extendBy(const Vec3<T> &point)

Extend the Box to include the given point.

void extendBy(const Box<Vec3<T>> &box)

Extend the Box to include the given box.

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 ofV::baseTypeMin() and a maximum of V::baseTypeMax().