Nori  23
TBoundingBox< _PointType > Struct Template Reference

Generic n-dimensional bounding box data structure. More...

#include <bbox.h>

Public Types

enum  { Dimension = _PointType::Dimension }
 
typedef _PointType PointType
 
typedef PointType::Scalar Scalar
 
typedef PointType::VectorType VectorType
 

Public Member Functions

 TBoundingBox ()
 Create a new invalid bounding box. More...
 
 TBoundingBox (const PointType &p)
 Create a collapsed bounding box from a single point.
 
 TBoundingBox (const PointType &min, const PointType &max)
 Create a bounding box from two positions.
 
bool operator== (const TBoundingBox &bbox) const
 Test for equality against another bounding box.
 
bool operator!= (const TBoundingBox &bbox) const
 Test for inequality against another bounding box.
 
Scalar getVolume () const
 Calculate the n-dimensional volume of the bounding box.
 
float getSurfaceArea () const
 Calculate the n-1 dimensional volume of the boundary.
 
PointType getCenter () const
 Return the center point.
 
bool contains (const PointType &p, bool strict=false) const
 Check whether a point lies on or inside the bounding box. More...
 
bool contains (const TBoundingBox &bbox, bool strict=false) const
 Check whether a specified bounding box lies on or within the current bounding box. More...
 
bool overlaps (const TBoundingBox &bbox, bool strict=false) const
 Check two axis-aligned bounding boxes for possible overlap. More...
 
Scalar squaredDistanceTo (const PointType &p) const
 Calculate the smallest squared distance between the axis-aligned bounding box and the point p.
 
Scalar distanceTo (const PointType &p) const
 Calculate the smallest distance between the axis-aligned bounding box and the point p.
 
Scalar squaredDistanceTo (const TBoundingBox &bbox) const
 Calculate the smallest square distance between the axis-aligned bounding box and bbox.
 
Scalar distanceTo (const TBoundingBox &bbox) const
 Calculate the smallest distance between the axis-aligned bounding box and bbox.
 
bool isValid () const
 Check whether this is a valid bounding box. More...
 
bool isPoint () const
 Check whether this bounding box has collapsed to a single point.
 
bool hasVolume () const
 Check whether this bounding box has any associated volume.
 
int getMajorAxis () const
 Return the dimension index with the largest associated side length.
 
int getMinorAxis () const
 Return the dimension index with the shortest associated side length.
 
VectorType getExtents () const
 Calculate the bounding box extents. More...
 
void clip (const TBoundingBox &bbox)
 Clip to another bounding box.
 
void reset ()
 Mark the bounding box as invalid. More...
 
void expandBy (const PointType &p)
 Expand the bounding box to contain another point.
 
void expandBy (const TBoundingBox &bbox)
 Expand the bounding box to contain another bounding box.
 
int getLargestAxis () const
 Return the index of the largest axis.
 
PointType getCorner (int index) const
 Return the position of a bounding box corner.
 
std::string toString () const
 Return a string representation of the bounding box.
 
bool rayIntersect (const Ray3f &ray) const
 Check if a ray intersects a bounding box.
 
bool rayIntersect (const Ray3f &ray, float &nearT, float &farT) const
 Return the overlapping region of the bounding box and an unbounded ray.
 

Static Public Member Functions

static TBoundingBox merge (const TBoundingBox &bbox1, const TBoundingBox &bbox2)
 Merge two bounding boxes.
 

Public Attributes

PointType min
 Component-wise minimum.
 
PointType max
 Component-wise maximum.
 

Detailed Description

template<typename _PointType>
struct TBoundingBox< _PointType >

Generic n-dimensional bounding box data structure.

Maintains a minimum and maximum position along each dimension and provides various convenience functions for querying and modifying them.

This class is parameterized by the underlying point data structure, which permits the use of different scalar types and dimensionalities, e.g.

TBoundingBox<Vector3i> integerBBox(Point3i(0, 1, 3), Point3i(4, 5, 6));
TBoundingBox<Vector2d> doubleBBox(Point2d(0.0, 1.0), Point2d(4.0, 5.0));
Generic n-dimensional bounding box data structure.
Definition: bbox.h:42
Generic N-dimensional point data structure based on Eigen::Matrix.
Definition: vector.h:85
Template Parameters
TThe underlying point data type (e.g. Point2d)

Definition at line 42 of file bbox.h.

Constructor & Destructor Documentation

◆ TBoundingBox()

template<typename _PointType >
TBoundingBox< _PointType >::TBoundingBox ( )
inline

Create a new invalid bounding box.

Initializes the components of the minimum and maximum position to $\infty$ and $-\infty$, respectively.

Definition at line 58 of file bbox.h.

Member Function Documentation

◆ contains() [1/2]

template<typename _PointType >
bool TBoundingBox< _PointType >::contains ( const PointType &  p,
bool  strict = false 
) const
inline

Check whether a point lies on or inside the bounding box.

Parameters
pThe point to be tested
strictSet this parameter to true if the bounding box boundary should be excluded in the test

Definition at line 115 of file bbox.h.

◆ contains() [2/2]

template<typename _PointType >
bool TBoundingBox< _PointType >::contains ( const TBoundingBox< _PointType > &  bbox,
bool  strict = false 
) const
inline

Check whether a specified bounding box lies on or within the current bounding box.

Note that by definition, an 'invalid' bounding box (where min= $\infty$ and max= $-\infty$) does not cover any space. Hence, this method will always return true when given such an argument.

Parameters
strictSet this parameter to true if the bounding box boundary should be excluded in the test

Definition at line 136 of file bbox.h.

◆ getExtents()

template<typename _PointType >
VectorType TBoundingBox< _PointType >::getExtents ( ) const
inline

Calculate the bounding box extents.

Returns
max-min

Definition at line 265 of file bbox.h.

◆ isValid()

template<typename _PointType >
bool TBoundingBox< _PointType >::isValid ( ) const
inline

Check whether this is a valid bounding box.

A bounding box bbox is valid when

bbox.min[dim] <= bbox.max[dim]

holds along each dimension dim.

Definition at line 227 of file bbox.h.

◆ overlaps()

template<typename _PointType >
bool TBoundingBox< _PointType >::overlaps ( const TBoundingBox< _PointType > &  bbox,
bool  strict = false 
) const
inline

Check two axis-aligned bounding boxes for possible overlap.

Parameters
strictSet this parameter to true if the bounding box boundary should be excluded in the test
Returns
true If overlap was detected.

Definition at line 154 of file bbox.h.

◆ reset()

template<typename _PointType >
void TBoundingBox< _PointType >::reset ( )
inline

Mark the bounding box as invalid.

This operation sets the components of the minimum and maximum position to $\infty$ and $-\infty$, respectively.

Definition at line 282 of file bbox.h.


The documentation for this struct was generated from the following file: