NVIDIA Iray: Math API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mi::math::Bbox< T, DIM > Class Template Reference

Axis-aligned N-dimensional bounding box class template of fixed dimension. More...

Public Types

enum   Uninitialized_tag { UNINITIALIZED_TAG }
  Enum type used to tag a special constructor that does not initialize the elements of the constructed bounding box. More...
 
typedef math::Vector< T, DIM >  Vector
  Corresponding vector type. More...
 
typedef Bbox_struct< T, DIM >  Pod_type
  POD class corresponding to this bounding box. More...
 
typedef Vector  value_type
  Coordinate type. More...
 
typedef Size  size_type
  Size type, unsigned. More...
 
typedef Difference  difference_type
  Difference type, signed. More...
 
typedef Vector pointer
  Mutable pointer to vector. More...
 
typedef const Vector const_pointer
  Const pointer to vector. More...
 
typedef Vector reference
  Mutable reference to vector. More...
 
typedef const Vector const_reference
  Const reference to vector. More...
 

Public Member Functions

void  clear ()
  Reinitializes this bounding box to the empty space. More...
 
  Bbox ()
  Bounding box initialized to the empty space, see also the clear function. More...
 
  Bbox (Uninitialized_tag)
  Bounding box with its elements not initialized. More...
 
  Bbox (const Bbox_struct< T, DIM > &bbox_struct)
  Bounding box initialized from corresponding POD type. More...
 
  Bbox (const Vector &point)
  Bounding box initialized to a single point. More...
 
  Bbox (const Vector &nmin, const Vector &nmax)
  Bounding box initialized to the new extreme corner vectors, nmin and nmax. More...
 
  Bbox (T min_x, T max_x)
  1D bounding box (interval) initialized to the new extreme corner vectors, (min_x) and (max_x). More...
 
  Bbox (T min_x, T min_y, T max_x, T max_y)
  2D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y) and (max_x,max_y). More...
 
  Bbox (T min_x, T min_y, T min_z, T max_x, T max_y, T max_z)
  3D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y,min_z) and (max_x,max_y,max_z). More...
 
template<typename InputIterator >
  Bbox (InputIterator first, InputIterator last)
  Constructs a bounding box from a range [first, last) of items. More...
 
template<typename T2 >
  Bbox (const Bbox< T2, DIM > &other)
  Template constructor that allows explicit conversions from other bounding boxes with assignment compatible element value type. More...
 
Bbox operator= (const Bbox &other)
  Assignment. More...
 
Bbox operator= (const Bbox_struct< T, DIM > &other)
  Assignment from corresponding POD type. More...
 
  operator Bbox_struct< T, DIM > () const
  Conversion to corresponding POD type. More...
 
Vector begin ()
  Returns the pointer to the first vector, min. More...
 
const Vector begin () const
  Returns the pointer to the first vector, min. More...
 
Vector end ()
  Returns the past-the-end pointer. More...
 
const Vector end () const
  Returns the past-the-end pointer. More...
 
Vector operator[] (Size i)
  Returns the vector min for i==0, and the vector max for i==1. More...
 
const Vector operator[] (Size i) const
  Returns the vector min for i==0, and the vector max for i==1. More...
 
bool  empty () const
  Returns true if the box is empty. More...
 
Size  rank () const
  Returns the rank of the bounding box. More...
 
bool  is_point () const
  Returns true the bounding box is a single point. More...
 
bool  is_line () const
  Returns true the bounding box is an axis-aligned line. More...
 
bool  is_plane () const
  Returns true the bounding box is an axis-aligned plane. More...
 
bool  is_volume () const
  Returns true the bounding box has a volume. More...
 
bool  contains (const Vector &vec) const
  Returns true if the point is inside or on the boundary of the bounding box. More...
 
bool  intersects (const Bbox &other) const
  Returns true if this bounding box and the other bounding box intersect in their interiors or on their boundaries. More...
 
void  insert (const Bbox &other)
  Assigns the union of this bounding box and the other bounding box to this bounding box. More...
 
void  insert (const Vector &point)
  Assigns the union of this bounding box and the point to this bounding box. More...
 
template<typename InputIterator >
void  insert (InputIterator first, InputIterator last)
  Inserts a range [first,last) of items into this bounding box. More...
 
Bbox  add_motionbox (const Bbox &vbox, T t) const
  Returns the translation of this bounding box by vectors that are inside the scaled bounding box of vectors, i.e., t*vbox. More...
 
void  push_back (const Bbox &other)
  Assigns the union of this bounding box and the other bounding box to this bounding box. More...
 
void  robust_grow (T eps=T(1.0e-5f))
  Robustly grows the bounding box by a value computed automatically from the bounding box dimensions and location in space. More...
 
volume () const
  Returns the volume of the bounding box. More...
 
diagonal_length () const
  Returns the length of the diagonal. More...
 
Size  largest_extent_index () const
  Returns the index of the dimension in which the bounding box has its largest extent, i.e., 0=x, 1=y, 2=z. More...
 
Vector  center () const
  Returns the center point of the bounding box. More...
 

Static Public Member Functions

static Size  size ()
  Constant size of the bounding box. More...
 
static Size  max_size ()
  Constant maximum size of the bounding box. More...
 

Public Attributes

Vector  min
  Elementwise minimal bounding box corner. More...
 
Vector  max
  Elementwise maximal bounding box corner. More...
 

Static Public Attributes

static const Size  DIMENSION = DIM
  Constant dimension of the vectors. More...
 
static const Size  SIZE = 2
  Constant size of the bounding box. More...
 

Detailed Description

template<typename T, Size DIM>
class mi::math::Bbox< T, DIM >

Axis-aligned N-dimensional bounding box class template of fixed dimension.

A bounding box is represented by two mi::math::Vector vectors representing the elementwise minimal box corner, min, and the elementwise largest box corner, max.

An instantiation of the bounding box class template is a model of the STL container concept. It provides random access to its two vectors and corresponding random access iterators.

The template parameters have the following requirements:

  • T: an arithmetic type supporting + - * / == != < > <= >= .
  • DIM: a value > 0 of type mi::Size that defines the fixed dimension of the vectors used to represent the bounding box.
See Also
The underlying POD type mi::math::Bbox_struct.
For the free functions and operators available for bounding boxes see Bounding Box Class.

Member Typedef Documentation

template<typename T, Size DIM>
typedef const Vector* mi::math::Bbox< T, DIM >::const_pointer

Const pointer to vector.

template<typename T, Size DIM>
typedef const Vector& mi::math::Bbox< T, DIM >::const_reference

Const reference to vector.

template<typename T, Size DIM>
typedef Difference mi::math::Bbox< T, DIM >::difference_type

Difference type, signed.

template<typename T, Size DIM>
typedef Bbox_struct<T,DIM> mi::math::Bbox< T, DIM >::Pod_type

POD class corresponding to this bounding box.

template<typename T, Size DIM>
typedef Vector* mi::math::Bbox< T, DIM >::pointer

Mutable pointer to vector.

template<typename T, Size DIM>
typedef Vector& mi::math::Bbox< T, DIM >::reference

Mutable reference to vector.

template<typename T, Size DIM>
typedef Size mi::math::Bbox< T, DIM >::size_type

Size type, unsigned.

template<typename T, Size DIM>
typedef Vector mi::math::Bbox< T, DIM >::value_type

Coordinate type.

template<typename T, Size DIM>
typedef math::Vector<T,DIM> mi::math::Bbox< T, DIM >::Vector

Corresponding vector type.

Member Enumeration Documentation

template<typename T, Size DIM>
enum mi::math::Bbox::Uninitialized_tag

Enum type used to tag a special constructor that does not initialize the elements of the constructed bounding box.

Enumerator
UNINITIALIZED_TAG 

Enum value used to call a special constructor that does not initialize the elements of the constructed bounding box.

Constructor & Destructor Documentation

template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( )
inline

Bounding box initialized to the empty space, see also the clear function.

The vector min is set elementwise to mi::base::numeric_traits<T>::max() and the vector max is set elementwise to mi::base::numeric_traits<T>::negative_max(). This initialization allows to insert points and other bounding boxes; a cleared bounding box will take the value of the first inserted point or bound box.

template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( Uninitialized_tag  )
inlineexplicit

Bounding box with its elements not initialized.

template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( const Bbox_struct< T, DIM > &  bbox_struct)
inline

Bounding box initialized from corresponding POD type.

template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( const Vector point)
inlineexplicit

Bounding box initialized to a single point.

Parameters
point point.
template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( const Vector nmin,
const Vector nmax 
)
inline

Bounding box initialized to the new extreme corner vectors, nmin and nmax.

Parameters
nmin min corner vector
nmax max corner vector
template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( min_x,
max_x 
)
inline

1D bounding box (interval) initialized to the new extreme corner vectors, (min_x) and (max_x).

Precondition
DIM == 1
Parameters
min_x x-coordinate of min corner vector
max_x x coordinate of max corner vector
template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( min_x,
min_y,
max_x,
max_y 
)
inline

2D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y) and (max_x,max_y).

Precondition
DIM == 2
Parameters
min_x x-coordinate of min corner vector
min_y y-coordinate of min corner vector
max_x x coordinate of max corner vector
max_y y coordinate of max corner vector
template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::Bbox ( min_x,
min_y,
min_z,
max_x,
max_y,
max_z 
)
inline

3D bounding box (interval) initialized to the new extreme corner vectors, (min_x,min_y,min_z) and (max_x,max_y,max_z).

Precondition
DIM == 3
Parameters
min_x x-coordinate of min corner vector
min_y y-coordinate of min corner vector
min_z z-coordinate of min corner vector
max_x x coordinate of max corner vector
max_y y coordinate of max corner vector
max_z z coordinate of max corner vector
template<typename T, Size DIM>
template<typename InputIterator >
mi::math::Bbox< T, DIM >::Bbox ( InputIterator  first,
InputIterator  last 
)

Constructs a bounding box from a range [first, last) of items.

The value type of InputIterator can be either Vector to insert points, or it can be Bbox to insert bounding boxes.

Parameters
first first element of the sequence to insert
last past-the-end position of sequence to insert
template<typename T, Size DIM>
template<typename T2 >
mi::math::Bbox< T, DIM >::Bbox ( const Bbox< T2, DIM > &  other)
inlineexplicit

Template constructor that allows explicit conversions from other bounding boxes with assignment compatible element value type.

Member Function Documentation

template<typename T, Size DIM>
Bbox mi::math::Bbox< T, DIM >::add_motionbox ( const Bbox< T, DIM > &  vbox,
t 
) const
inline

Returns the translation of this bounding box by vectors that are inside the scaled bounding box of vectors, i.e., t*vbox.

Precondition
this bounding box and vbox are not empty
Parameters
vbox vector bounding box to add
t scale parameter. A negative scale inverts vbox.
template<typename T, Size DIM>
Vector* mi::math::Bbox< T, DIM >::begin ( )
inline

Returns the pointer to the first vector, min.

template<typename T, Size DIM>
const Vector* mi::math::Bbox< T, DIM >::begin ( ) const
inline

Returns the pointer to the first vector, min.

template<typename T, Size DIM>
Vector mi::math::Bbox< T, DIM >::center ( ) const
inline

Returns the center point of the bounding box.

template<typename T, Size DIM>
void mi::math::Bbox< T, DIM >::clear ( )
inline

Reinitializes this bounding box to the empty space.

The vector min is set elementwise to mi::base::numeric_traits<T>::max() and the vector max is set elementwise to mi::base::numeric_traits<T>::negative_max(). This initialization allows to insert points and other bounding boxes; a cleared bounding box will take the value of the first inserted point or bound box.

template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::contains ( const Vector vec) const
inline

Returns true if the point is inside or on the boundary of the bounding box.

template<typename T, Size DIM>
T mi::math::Bbox< T, DIM >::diagonal_length ( ) const
inline

Returns the length of the diagonal.

Precondition
the bounding box is not empty
template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::empty ( ) const
inline

Returns true if the box is empty.

For example, the box is empty after the default constructor or the clear() method call.

template<typename T, Size DIM>
Vector* mi::math::Bbox< T, DIM >::end ( )
inline

Returns the past-the-end pointer.

The range [begin(),end()) forms the range [min,max].

template<typename T, Size DIM>
const Vector* mi::math::Bbox< T, DIM >::end ( ) const
inline

Returns the past-the-end pointer.

The range [begin(),end()) forms the range [min,max].

template<typename T, Size DIM>
void mi::math::Bbox< T, DIM >::insert ( const Bbox< T, DIM > &  other)
inline

Assigns the union of this bounding box and the other bounding box to this bounding box.

template<typename T, Size DIM>
void mi::math::Bbox< T, DIM >::insert ( const Vector point)
inline

Assigns the union of this bounding box and the point to this bounding box.

template<typename T, Size DIM>
template<typename InputIterator >
void mi::math::Bbox< T, DIM >::insert ( InputIterator  first,
InputIterator  last 
)

Inserts a range [first,last) of items into this bounding box.

The value type of InputIterator can be either Vector to insert points, or it can be Bbox to insert bounding boxes.

Parameters
first first element of the sequence to insert
last past-the-end position of sequence to insert
template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::intersects ( const Bbox< T, DIM > &  other) const
inline

Returns true if this bounding box and the other bounding box intersect in their interiors or on their boundaries.

template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::is_line ( ) const
inline

Returns true the bounding box is an axis-aligned line.

Returns
true if rank() returns 1
template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::is_plane ( ) const
inline

Returns true the bounding box is an axis-aligned plane.

Returns
true if rank() returns 2
template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::is_point ( ) const
inline

Returns true the bounding box is a single point.

template<typename T, Size DIM>
bool mi::math::Bbox< T, DIM >::is_volume ( ) const
inline

Returns true the bounding box has a volume.

Returns
true if rank() returns 3
template<typename T, Size DIM>
Size mi::math::Bbox< T, DIM >::largest_extent_index ( ) const
inline

Returns the index of the dimension in which the bounding box has its largest extent, i.e., 0=x, 1=y, 2=z.

template<typename T, Size DIM>
static Size mi::math::Bbox< T, DIM >::max_size ( )
inlinestatic

Constant maximum size of the bounding box.

template<typename T, Size DIM>
mi::math::Bbox< T, DIM >::operator Bbox_struct< T, DIM > ( ) const
inline

Conversion to corresponding POD type.

template<typename T, Size DIM>
Bbox& mi::math::Bbox< T, DIM >::operator= ( const Bbox< T, DIM > &  other)
inline

Assignment.

template<typename T, Size DIM>
Bbox& mi::math::Bbox< T, DIM >::operator= ( const Bbox_struct< T, DIM > &  other)
inline

Assignment from corresponding POD type.

template<typename T, Size DIM>
Vector& mi::math::Bbox< T, DIM >::operator[] ( Size  i)
inline

Returns the vector min for i==0, and the vector max for i==1.

template<typename T, Size DIM>
const Vector& mi::math::Bbox< T, DIM >::operator[] ( Size  i) const
inline

Returns the vector min for i==0, and the vector max for i==1.

template<typename T, Size DIM>
void mi::math::Bbox< T, DIM >::push_back ( const Bbox< T, DIM > &  other)
inline

Assigns the union of this bounding box and the other bounding box to this bounding box.

Makes the bounding box compatible with the std::back_inserter function, which allows you to use STL functions, such as std::copy to compute the union of a sequence of bounding boxes.

template<typename T, Size DIM>
Size mi::math::Bbox< T, DIM >::rank ( ) const
inline

Returns the rank of the bounding box.

Returns
0 if the bounding box is a point or empty, 1 if it is an axis-aligned line, 2 if it is an axis-aligned plane, and 3 if it has a volume.
template<typename T, Size DIM>
void mi::math::Bbox< T, DIM >::robust_grow ( eps = T(1.0e-5f))

Robustly grows the bounding box by a value computed automatically from the bounding box dimensions and location in space.

If a bounding box is far away from the origin, just enlarging the bounding box by eps * (largest box extent) may result in cancellation. To avoid cancellation problems, this method computes the value for enlarging the box by computing coordinatewise the sum of the absolute values of the min and max coordinates and the bounding box extent. It takes then the maximum of all these sums, multiplies it by eps, adds it to bbox.max and subtracts it from bbox.min, enlarging the bounding box by an equal amount on all sides. grow factor

template<typename T, Size DIM>
static Size mi::math::Bbox< T, DIM >::size ( )
inlinestatic

Constant size of the bounding box.

template<typename T, Size DIM>
T mi::math::Bbox< T, DIM >::volume ( ) const
inline

Returns the volume of the bounding box.

Member Data Documentation

template<typename T, Size DIM>
const Size mi::math::Bbox< T, DIM >::DIMENSION = DIM
static

Constant dimension of the vectors.

template<typename T, Size DIM>
Vector mi::math::Bbox< T, DIM >::max

Elementwise maximal bounding box corner.

template<typename T, Size DIM>
Vector mi::math::Bbox< T, DIM >::min

Elementwise minimal bounding box corner.

template<typename T, Size DIM>
const Size mi::math::Bbox< T, DIM >::SIZE = 2
static

Constant size of the bounding box.