ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM > Class Template Reference

Implementation of an Axis Aligned Bounding Box. More...

#include <Acts/Utilities/BoundingBox.hpp>

Inheritance diagram for Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >:
[legend]

Public Types

using entity_type = entity_t
 Type of stored entity.
using Size = NamedType<VertexType, struct SizeParameter>
 Strong type to select the correct constructor.
using transform_type = Eigen::Transform<value_type, DIM, Eigen::Affine>
 The transform type based on the value_type.
using value_type = value_t
 The value type used by this class.
using vertex_array_type = Eigen::Array<value_t, DIM, 1>
 Associated array value to VertexType.
using VertexType = Eigen::Matrix<value_t, DIM, 1>
 Re-export vertex type based on value type given.

Public Member Functions

 AxisAlignedBoundingBox (const entity_t *entity, const VertexType &center, const Size &size)
 Constructor from a center position, and a width and height.
 AxisAlignedBoundingBox (const entity_t *entity, const VertexType &vmin, const VertexType &vmax)
 Constructor from an entity pointer, and the min and max vertices.
 AxisAlignedBoundingBox (const self_t &other)=default
 Copy constructor from other bounding box.
 AxisAlignedBoundingBox (const std::vector< self_t * > &boxes, vertex_array_type envelope=vertex_array_type::Zero())
 Constructor from a list of child boxes.
const VertexTypecenter () const
 Get the center position of this bounding box.
void draw (IVisualization3D &helper, Color color={120, 120, 120}, const transform_type &trf=transform_type::Identity()) const
 Draw this bounding box using the given visualization helper.
const entity_t * entity () const
 Return the entity associated with this box.
const self_t * getLeftChild () const
 Get the left child (i.e.
const self_t * getSkip () const
 Get the skip node for this box.
bool hasEntity () const
 Check whether this node as an associated entity.
template<std::size_t sides>
bool intersect (const Frustum< value_type, DIM, sides > &fr) const
 Check if a frustum intersects with this bounding box.
bool intersect (const Ray< value_type, DIM > &ray) const
 Implements the slab method for Ray/AABB intersections.
bool intersect (const VertexType &point) const
 Calculate whether a point is inside this box.
const VertexTypemax () const
 Get the maximum vertex.
const VertexTypemin () const
 Get the minimum vertex.
AxisAlignedBoundingBoxoperator= (const self_t &other)=default
 Copy assignment operator from other bounding box.
void setEntity (const entity_t *entity)
 Set the entity associated with with this box.
void setSkip (self_t *skip)
 Set the skip node (bounding box).
std::ostream & svg (std::ostream &os, value_type w, value_type h, value_type unit=10, const std::string &label="", const std::string &fillcolor="grey") const
 Draw this bounding box as SVG.
std::ostream & toStream (std::ostream &os) const
 Write information about this bounding box to a stream.
void transform (const transform_type &trf)
 Transforms this bounding box using the given transform.
self_t transformed (const transform_type &trf) const
 Transforms this bounding box using the given transform.

Static Public Member Functions

static std::pair< VertexType, VertexTypewrap (const std::vector< const self_t * > &boxes, vertex_array_type envelope=vertex_array_type::Zero())
 Helper function to calculate the size of a bounding box enclosing boxes.
static std::pair< VertexType, VertexTypewrap (const std::vector< self_t * > &boxes, vertex_array_type envelope=vertex_array_type::Zero())
 Helper function to calculate the size of a bounding box enclosing boxes.
static std::pair< VertexType, VertexTypewrap (const std::vector< self_t > &boxes, vertex_array_type envelope=vertex_array_type::Zero())
 Helper function to calculate the size of a bounding box enclosing boxes.

Static Public Attributes

static const std::size_t dim = DIM
 Re-export dimension from template parameter.

Detailed Description

template<typename entity_t, typename value_t, std::size_t DIM>
class Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >

Implementation of an Axis Aligned Bounding Box.

This type is compatible with 2D and 3D boxes

Member Typedef Documentation

◆ entity_type

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::entity_type = entity_t

Type of stored entity.

◆ Size

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::Size = NamedType<VertexType, struct SizeParameter>

Strong type to select the correct constructor.

◆ transform_type

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::transform_type = Eigen::Transform<value_type, DIM, Eigen::Affine>

The transform type based on the value_type.

◆ value_type

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::value_type = value_t

The value type used by this class.

◆ vertex_array_type

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::vertex_array_type = Eigen::Array<value_t, DIM, 1>

Associated array value to VertexType.

◆ VertexType

template<typename entity_t, typename value_t, std::size_t DIM>
using Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::VertexType = Eigen::Matrix<value_t, DIM, 1>

Re-export vertex type based on value type given.

Constructor & Destructor Documentation

◆ AxisAlignedBoundingBox() [1/4]

template<typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::AxisAlignedBoundingBox ( const self_t & other)
default

Copy constructor from other bounding box.

Parameters
otherThe other bounding box to copy from

◆ AxisAlignedBoundingBox() [2/4]

template<typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::AxisAlignedBoundingBox ( const entity_t * entity,
const VertexType & vmin,
const VertexType & vmax )

Constructor from an entity pointer, and the min and max vertices.

Parameters
entityThe entity to store
vminThe minimum vertex.
vmaxThe maximum vertex.

◆ AxisAlignedBoundingBox() [3/4]

template<typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::AxisAlignedBoundingBox ( const entity_t * entity,
const VertexType & center,
const Size & size )

Constructor from a center position, and a width and height.

Parameters
entityThe entity to store
centerThe center position
sizeThe size (width and height) of the box.
Note
The special type size is required to disambiguate this constructor from the other one above. It is a wrapper around a simple Vector3.

◆ AxisAlignedBoundingBox() [4/4]

template<typename entity_t, typename value_t, std::size_t DIM>
Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::AxisAlignedBoundingBox ( const std::vector< self_t * > & boxes,
vertex_array_type envelope = vertex_array_type::Zero() )
explicit

Constructor from a list of child boxes.

This box will wrap around all boxes contained in boxes, and additional envelope can be given.

Parameters
boxesVector of child boxes to store in this bounding box.
envelopeEnvelope that will be added/subtracted to the dimension.

Member Function Documentation

◆ center()

template<typename entity_t, typename value_t, std::size_t DIM>
const VertexType & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::center ( ) const

Get the center position of this bounding box.

Returns
The center position

◆ draw()

template<typename entity_t, typename value_t, std::size_t DIM>
void Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::draw ( IVisualization3D & helper,
Color color = {120, 120, 120},
const transform_type & trf = transform_type::Identity() ) const

Draw this bounding box using the given visualization helper.

This method is only available for the 3D case.

Parameters
helperThe visualization helper to write to
colorThe color to use for drawing
trfAn optional transform to apply first.

◆ entity()

template<typename entity_t, typename value_t, std::size_t DIM>
const entity_t * Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::entity ( ) const

Return the entity associated with this box.

This might be nullptr if there is no entity attached.

Returns
The entity pointer, might be nullptr

◆ getLeftChild()

template<typename entity_t, typename value_t, std::size_t DIM>
const self_t * Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::getLeftChild ( ) const

Get the left child (i.e.

the first of the children that are inside this bounding box).

Returns
The lest most child.

◆ getSkip()

template<typename entity_t, typename value_t, std::size_t DIM>
const self_t * Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::getSkip ( ) const

Get the skip node for this box.

Returns
The skip node pointer

◆ hasEntity()

template<typename entity_t, typename value_t, std::size_t DIM>
bool Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::hasEntity ( ) const

Check whether this node as an associated entity.

If it does not have one, this is a purely abstract container box.

Returns
Whether the box has an entity attached.

◆ intersect() [1/3]

template<typename entity_t, typename value_t, std::size_t DIM>
template<std::size_t sides>
bool Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::intersect ( const Frustum< value_type, DIM, sides > & fr) const

Check if a frustum intersects with this bounding box.

This method implements an algorithm similar to the one described in "Optimized View Frustum Culling Algorithms for Bounding Boxes (2012)" [2] (https://doi.org/10.1080/10867651.2000.10487517), but drops some of the more sophisticated optimization.

Parameters
frThe frustum
Returns
Whether the frustum intersects this AABB

◆ intersect() [2/3]

template<typename entity_t, typename value_t, std::size_t DIM>
bool Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::intersect ( const Ray< value_type, DIM > & ray) const

Implements the slab method for Ray/AABB intersections.

See https://tavianator.com/fast-branchless-raybounding-box-intersections/, https://tavianator.com/fast-branchless-raybounding-box-intersections-part-2-nans/, https://medium.com/@bromanz/another-view-on-the-classic-ray-aabb-intersection-algorithm-for-bvh-traversal-41125138b525 The original algorithms is described in "Graphics Gems (1990)" [1] (https://doi.org/10.1016/B978-0-08-050753-8.50084-X)

Note
This implementation may treat parallel rays on any of the slabs as outside due to how NaNs are handled by Eigen. See https://eigen.tuxfamily.org/bz/show_bug.cgi?id=564
Parameters
rayThe ray to intersect with
Returns
Whether the ray intersects this AABB

◆ intersect() [3/3]

template<typename entity_t, typename value_t, std::size_t DIM>
bool Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::intersect ( const VertexType & point) const

Calculate whether a point is inside this box.

Parameters
pointThe point to test.
Returns
Whether the point is inside or not.

◆ max()

template<typename entity_t, typename value_t, std::size_t DIM>
const VertexType & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::max ( ) const

Get the maximum vertex.

Returns
The maximum vertex

◆ min()

template<typename entity_t, typename value_t, std::size_t DIM>
const VertexType & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::min ( ) const

Get the minimum vertex.

Returns
The minimum vertex

◆ operator=()

template<typename entity_t, typename value_t, std::size_t DIM>
AxisAlignedBoundingBox & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::operator= ( const self_t & other)
default

Copy assignment operator from other bounding box.

Parameters
otherThe other AABB
Returns
Reference to this bounding box after copying

◆ setEntity()

template<typename entity_t, typename value_t, std::size_t DIM>
void Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::setEntity ( const entity_t * entity)

Set the entity associated with with this box.

Parameters
entityThe entity

◆ setSkip()

template<typename entity_t, typename value_t, std::size_t DIM>
void Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::setSkip ( self_t * skip)

Set the skip node (bounding box).

Parameters
skipThe target skip node pointer

◆ svg()

template<typename entity_t, typename value_t, std::size_t DIM>
std::ostream & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::svg ( std::ostream & os,
value_type w,
value_type h,
value_type unit = 10,
const std::string & label = "",
const std::string & fillcolor = "grey" ) const

Draw this bounding box as SVG.

This method is only available for the 2D case.

Parameters
osThe output stream to write to
wThe width of the output SVG.
hThe height of the output SVG.
unitA scale factor to apply before drawing
labelA label to put next to the box.
fillcolorColor to fill the box with.
Returns
The outstream given in os.

◆ toStream()

template<typename entity_t, typename value_t, std::size_t DIM>
std::ostream & Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::toStream ( std::ostream & os) const

Write information about this bounding box to a stream.

Parameters
osThe output stream.
Returns
The stream given as an argument.

◆ transform()

template<typename entity_t, typename value_t, std::size_t DIM>
void Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::transform ( const transform_type & trf)

Transforms this bounding box using the given transform.

This method modifies the box it is called on.

Parameters
trfThe transform

◆ transformed()

template<typename entity_t, typename value_t, std::size_t DIM>
self_t Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::transformed ( const transform_type & trf) const

Transforms this bounding box using the given transform.

This method returns a copy of this box, with the transformation applied, and leaves this instance unchanged.

Parameters
trfThe transform
Returns
The transformed bounding box

◆ wrap() [1/3]

template<typename entity_t, typename value_t, std::size_t DIM>
std::pair< VertexType, VertexType > Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::wrap ( const std::vector< const self_t * > & boxes,
vertex_array_type envelope = vertex_array_type::Zero() )
static

Helper function to calculate the size of a bounding box enclosing boxes.

Parameters
boxesThe boxes to wrap (const pointers)
envelopeOptional envelop to add/subtract to dimension.
Returns
Pair of vertices: min and max.

◆ wrap() [2/3]

template<typename entity_t, typename value_t, std::size_t DIM>
std::pair< VertexType, VertexType > Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::wrap ( const std::vector< self_t * > & boxes,
vertex_array_type envelope = vertex_array_type::Zero() )
static

Helper function to calculate the size of a bounding box enclosing boxes.

Overload which accepts non-const boxes in boxes.

Parameters
boxesThe boxes to wrap (non-const pointers)
envelopeOptional envelop to add/subtract to dimension.
Returns
Pair of vertices: min and max.

◆ wrap() [3/3]

template<typename entity_t, typename value_t, std::size_t DIM>
std::pair< VertexType, VertexType > Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::wrap ( const std::vector< self_t > & boxes,
vertex_array_type envelope = vertex_array_type::Zero() )
static

Helper function to calculate the size of a bounding box enclosing boxes.

Overload which accepts a vector in boxes which owns the instances

Parameters
boxesThe boxes to wrap (by-value vector)
envelopeOptional envelop to add/subtract to dimension.
Returns
Pair of vertices: min and max.

Member Data Documentation

◆ dim

template<typename entity_t, typename value_t, std::size_t DIM>
const std::size_t Acts::AxisAlignedBoundingBox< entity_t, value_t, DIM >::dim = DIM
static

Re-export dimension from template parameter.