Visual Computing Library
Loading...
Searching...
No Matches
vcl::Box< PointT > Class Template Reference

A class representing a box in N-dimensional space. More...

#include <vclib/space/core/box.h>

Public Types

using PointType = PointT
 The type of point used to represent the corners of the box.
 

Public Member Functions

 Box ()
 The Empty constructor of a box, initializes a null box.
 
 Box (const PointT &p)
 Initializes the box with the given point. The box is a valid empty box (meaning that the minimum and the maximum points are equal).
 
 Box (const PointT &min, const PointT &max)
 Initializes the box with the given minimum and maximum points.
 
PointT & min ()
 Returns a reference to the minimum point of the box.
 
const PointT & min () const
 Returns a const reference to the minimum point of the box.
 
PointT & max ()
 Returns a reference to the maximum point of the box.
 
const PointT & max () const
 Returns a const reference to the maximum point of the box.
 
template<typename Scalar >
auto cast () const
 
bool isNull () const
 Checks whether the box is null or not.
 
bool isEmpty () const
 Checks whether the box is empty or not.
 
bool isInside (const PointT &p) const
 Checks whether a given point is inside the box or not, bounds included.
 
bool isInsideStrict (const PointT &p) const
 Checks whether a given point is inside the box or not, bounds excluded.
 
bool isInsideOpenBox (const PointT &p) const
 Checks if a point is inside the open box (max bound excluded); e.g. p in [min, max).
 
bool overlap (const Box< PointT > &b) const
 Check if two boxes overlap.
 
bool collide (const Box< PointT > &b) const
 Same as Box::overlap.
 
bool intersects (const Box< PointT > &b) const
 Same as Box::overlap.
 
auto diagonal () const
 Calculates the diagonal length of the box.
 
auto squaredDiagonal () const
 Calculates the squared length of the diagonal of the box.
 
PointT center () const
 Calculates the center point of the box.
 
PointT size () const
 Computes the size of the box.
 
auto volume () const
 Computes the volume of the box.
 
auto dim (uint i) const
 Get the length of the box along a given dimension.
 
auto minDim () const
 Calculates the minimum dimension of the box, which is defined as the smallest difference between the maximum and minimum coordinates along any dimension.
 
auto maxDim () const
 Computes the maximum dimension of the box, which is defined as the greater difference between the maximum and minimum coordinates along any dimension.
 
Box< PointT > intersection (const Box< PointT > &b) const
 Computes and returns the intersection between the current box and the given box b.
 
void setNull ()
 Sets the Box to null. A box is considered null if at least one min component is greater than the corresponding max component.
 
void add (const PointT &p)
 Adds the given point to the current box, expanding this box in order to contain also the values of the added point.
 
template<typename Scalar >
void add (const PointT &p, Scalar radius)
 Adds the given point to the current box, expanding this box by a radius around the point, so that it will contain all points within the radius.
 
void add (const Box< PointT > &b)
 Adds the given box to the current box, expanding this box in order that will contain also the b values.
 
void translate (const PointT &p)
 Translates the box by summing the values of p.
 
void serialize (std::ostream &os) const
 Serializes the box to the given output stream.
 
void deserialize (std::istream &is)
 Deserializes the box from the given input stream.
 
bool operator== (const Box< PointT > &b) const
 Compares the current box to another box for equality.
 
bool operator!= (const Box< PointT > &b) const
 Compares the current box to another box for inequality.
 

Static Public Attributes

static const uint DIM = PointT::DIM
 The dimensionality of the box.
 

Private Attributes

PointT mMin
 
PointT mMax
 

Detailed Description

template<PointConcept PointT>
class vcl::Box< PointT >

A class representing a box in N-dimensional space.

The Box class represents an axis-aligned box in N-dimensional space, defined by its minimum and maximum corners. It provides functions for performing various operations on boxes, such as checking if a point is inside the box, computing the box's diagonal, and adding other boxes to the current box. The class is parameterized by a PointConcept, which must provide the DIM constant and the [] operator for accessing the point coordinates.

Template Parameters
PointTA type that satisfies the PointConcept requirements.

Constructor & Destructor Documentation

◆ Box() [1/3]

template<PointConcept PointT>
vcl::Box< PointT >::Box ( )
inline

The Empty constructor of a box, initializes a null box.

See also
setNull

◆ Box() [2/3]

template<PointConcept PointT>
vcl::Box< PointT >::Box ( const PointT &  p)
inline

Initializes the box with the given point. The box is a valid empty box (meaning that the minimum and the maximum points are equal).

Parameters
pThe point to initialize the box with.

◆ Box() [3/3]

template<PointConcept PointT>
vcl::Box< PointT >::Box ( const PointT &  min,
const PointT &  max 
)
inline

Initializes the box with the given minimum and maximum points.

If min > max for any dimension of the points, the box will be invalid.

Parameters
[in]minThe minimum point of the box.
[in]maxThe maximum point of the box.

Member Function Documentation

◆ add() [1/3]

template<PointConcept PointT>
void vcl::Box< PointT >::add ( const Box< PointT > &  b)
inline

Adds the given box to the current box, expanding this box in order that will contain also the b values.

If this box was null, the current box will have the same values of b.

Parameters
[in]bThe box to add to the current box.

◆ add() [2/3]

template<PointConcept PointT>
void vcl::Box< PointT >::add ( const PointT &  p)
inline

Adds the given point to the current box, expanding this box in order to contain also the values of the added point.

If this box was null, both the minimum and maximum points of the box will be set to the given point.

Parameters
[in]pThe point to add to the current box.

◆ add() [3/3]

template<PointConcept PointT>
template<typename Scalar >
void vcl::Box< PointT >::add ( const PointT &  p,
Scalar  radius 
)
inline

Adds the given point to the current box, expanding this box by a radius around the point, so that it will contain all points within the radius.

If this box was null, it will be initialized with the minimum and maximum points obtained by subtracting and adding the radius to the given point.

Template Parameters
ScalarThe data type of the radius.
Parameters
[in]pThe point to add to the current box.
[in]radiusThe radius around the point.

◆ center()

template<PointConcept PointT>
PointT vcl::Box< PointT >::center ( ) const
inline

Calculates the center point of the box.

Returns
The center point of the box.

◆ collide()

template<PointConcept PointT>
bool vcl::Box< PointT >::collide ( const Box< PointT > &  b) const
inline

Same as Box::overlap.

Parameters
[in]bthe box to check the collision with.
Returns
true if the two boxes overlap, false otherwise.

◆ deserialize()

template<PointConcept PointT>
void vcl::Box< PointT >::deserialize ( std::istream &  is)
inline

Deserializes the box from the given input stream.

Parameters
[in]isThe input stream.

◆ diagonal()

template<PointConcept PointT>
auto vcl::Box< PointT >::diagonal ( ) const
inline

Calculates the diagonal length of the box.

Returns
The diagonal length of the box.

◆ dim()

template<PointConcept PointT>
auto vcl::Box< PointT >::dim ( uint  i) const
inline

Get the length of the box along a given dimension.

Parameters
[in]ithe index of the dimension to get the length of.
Returns
The length of the box along the given dimension.
Precondition
i < PointT::DIM.

◆ intersection()

template<PointConcept PointT>
Box< PointT > vcl::Box< PointT >::intersection ( const Box< PointT > &  b) const
inline

Computes and returns the intersection between the current box and the given box b.

Parameters
[in]bThe box to intersect with the current box
Returns
The intersection between the current box and b

◆ intersects()

template<PointConcept PointT>
bool vcl::Box< PointT >::intersects ( const Box< PointT > &  b) const
inline

Same as Box::overlap.

Parameters
[in]bthe box to check the collision with.
Returns
true if the two boxes overlap, false otherwise.

◆ isEmpty()

template<PointConcept PointT>
bool vcl::Box< PointT >::isEmpty ( ) const
inline

Checks whether the box is empty or not.

A box is considered empty if the minimum point and the maximum point are equal.

Returns
True if the box is empty, false otherwise.

◆ isInside()

template<PointConcept PointT>
bool vcl::Box< PointT >::isInside ( const PointT &  p) const
inline

Checks whether a given point is inside the box or not, bounds included.

A point is considered inside the box if its coordinates are greater or equal to the corresponding minimum point and less or equal to the corresponding maximum point for each dimension.

Parameters
[in]pThe point to be checked.
Returns
True if the point is inside the box, false otherwise.

◆ isInsideOpenBox()

template<PointConcept PointT>
bool vcl::Box< PointT >::isInsideOpenBox ( const PointT &  p) const
inline

Checks if a point is inside the open box (max bound excluded); e.g. p in [min, max).

Parameters
[in]pthe point to check if is inside the current box.
Returns
true if p is inside the open box, false otherwise.

◆ isInsideStrict()

template<PointConcept PointT>
bool vcl::Box< PointT >::isInsideStrict ( const PointT &  p) const
inline

Checks whether a given point is inside the box or not, bounds excluded.

A point is considered inside the box if its coordinates are greater than the corresponding minimum point and less than the corresponding maximum point for each dimension.

Parameters
[in]pThe point to be checked.
Returns
True if the point is inside the box, false otherwise.

◆ isNull()

template<PointConcept PointT>
bool vcl::Box< PointT >::isNull ( ) const
inline

Checks whether the box is null or not.

A box is considered null if at least one minimum component is greater than the corresponding maximum component.

Returns
True if the box is null, false otherwise.

◆ max() [1/2]

template<PointConcept PointT>
PointT & vcl::Box< PointT >::max ( )
inline

Returns a reference to the maximum point of the box.

Returns
A reference to the maximum point of the box.

◆ max() [2/2]

template<PointConcept PointT>
const PointT & vcl::Box< PointT >::max ( ) const
inline

Returns a const reference to the maximum point of the box.

Returns
A const reference to the maximum point of the box.

◆ maxDim()

template<PointConcept PointT>
auto vcl::Box< PointT >::maxDim ( ) const
inline

Computes the maximum dimension of the box, which is defined as the greater difference between the maximum and minimum coordinates along any dimension.

Returns
The maximum dimension of the box.

◆ min() [1/2]

template<PointConcept PointT>
PointT & vcl::Box< PointT >::min ( )
inline

Returns a reference to the minimum point of the box.

Returns
A reference to the minimum point of the box.

◆ min() [2/2]

template<PointConcept PointT>
const PointT & vcl::Box< PointT >::min ( ) const
inline

Returns a const reference to the minimum point of the box.

Returns
A const reference to the minimum point of the box.

◆ minDim()

template<PointConcept PointT>
auto vcl::Box< PointT >::minDim ( ) const
inline

Calculates the minimum dimension of the box, which is defined as the smallest difference between the maximum and minimum coordinates along any dimension.

Returns
The minimum dimension of the box.

◆ operator!=()

template<PointConcept PointT>
bool vcl::Box< PointT >::operator!= ( const Box< PointT > &  b) const
inline

Compares the current box to another box for inequality.

Parameters
[in]bThe box to compare to.
Returns
True if the boxes are not equal, false otherwise.

◆ operator==()

template<PointConcept PointT>
bool vcl::Box< PointT >::operator== ( const Box< PointT > &  b) const
inline

Compares the current box to another box for equality.

Parameters
[in]bThe box to compare to.
Returns
True if the boxes are equal, false otherwise.

◆ overlap()

template<PointConcept PointT>
bool vcl::Box< PointT >::overlap ( const Box< PointT > &  b) const
inline

Check if two boxes overlap.

Parameters
[in]bthe box to check the collision with.
Returns
true if the two boxes overlap, false otherwise.

◆ serialize()

template<PointConcept PointT>
void vcl::Box< PointT >::serialize ( std::ostream &  os) const
inline

Serializes the box to the given output stream.

Parameters
[in]osThe output stream.

◆ setNull()

template<PointConcept PointT>
void vcl::Box< PointT >::setNull ( )
inline

Sets the Box to null. A box is considered null if at least one min component is greater than the corresponding max component.

This member function sets all the min values to the max representable Scalar and the max values to lowest representable Scalar.

◆ size()

template<PointConcept PointT>
PointT vcl::Box< PointT >::size ( ) const
inline

Computes the size of the box.

Returns
The size of the box as a point, i.e., the difference between the bounding box max and min.

◆ squaredDiagonal()

template<PointConcept PointT>
auto vcl::Box< PointT >::squaredDiagonal ( ) const
inline

Calculates the squared length of the diagonal of the box.

Returns
The squared length of the diagonal of the box.

◆ translate()

template<PointConcept PointT>
void vcl::Box< PointT >::translate ( const PointT &  p)
inline

Translates the box by summing the values of p.

Parameters
[in]pThe point to translate the box by

◆ volume()

template<PointConcept PointT>
auto vcl::Box< PointT >::volume ( ) const
inline

Computes the volume of the box.

Returns
The volume of the box.

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