Template Class AxisAlignedBoundingBox¶
Defined in File BoundingBox.hpp
Nested Relationships¶
Class Documentation¶
-
template<typename
entity_t
, typenamevalue_t
, size_tDIM
>
classActs
::
AxisAlignedBoundingBox
¶ Implementation of an Axis Aligned Bounding Box.
This type is compatible with 2D and 3D boxes
Public Types
-
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
Public Functions
-
AxisAlignedBoundingBox
(const self_t &other) = default¶ Copy constructor from other bounding box.
- Parameters
other
: The other AABB
-
AxisAlignedBoundingBox
(const entity_t *entity, const VertexType &vmin, const VertexType &vmax)¶ Constructor from an entity pointer, and the min and max vertices.
- Parameters
entity
: The entity to storevmin
: The minimum vertex.vmax
: The maximum vertex.
-
AxisAlignedBoundingBox
(const entity_t *entity, const VertexType ¢er, const Size &size)¶ Constructor from a center position, and a width and height.
- Note
The special type
size
is required to disambiguate this constructor from the other one above. It is a wrapper around a simpleVector3
.- Parameters
entity
: The entity to storecenter
: The center positionsize
: The size (width and height) of the box.
-
AxisAlignedBoundingBox
(const std::vector<self_t*> &boxes, vertex_array_type envelope = vertex_array_type::Zero())¶ Constructor from a list of child boxes.
This box will wrap around all boxes contained in
boxes
, and additional envelope can be given.- Parameters
boxes
: Vector of child boxes to store in this bounding box.envelope
: Envelope that will be added/subtracted to the dimension.
-
const VertexType &
center
() const¶ Get the center position of this bounding box.
- Return
The center position
-
template<size_t
D
= DIM, std::enable_if_t<D == 3, int> = 0>
voiddraw
(IVisualization3D &helper, std::array<int, 3> 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.
- Template Parameters
D
: (used for SFINAE)
- Parameters
helper
: The visualization helper to write tocolor
: The color to use for drawingtrf
: An optional transform to apply first.
-
const entity_t *
entity
() const¶ Return the entity associated with this box.
This might be nullptr if there is no entity attached.
- Return
The entity pointer, might be nullptr
-
const self_t *
getLeftChild
() const¶ Get the left child (i.e.
the first of the children that are inside this bounding box).
- Return
The lest most child.
-
const self_t *
getSkip
() const¶ Get the skip node for this box.
- Return
The skip node pointer
-
bool
hasEntity
() const¶ Check whether this node as an associated entity.
If it does not have one, this is a purely abstract container box.
- Return
Whether the box has an entity attached.
-
bool
intersect
(const VertexType &point) const¶ Calculate whether a point is inside this box.
- Return
Whether the point is inside or not.
- Parameters
point
: The point to test.
-
bool
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
- Note
This implementation may treat parallel rays on any of the slabs as outside due to how
NaNs
are handled by Eigen. See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=564- Return
Whether the ray intersects this AABB
- Parameters
ray
: The ray to intersect with
-
template<size_t
sides
>
boolintersect
(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, but drops some of the more sophisticated optimization.
- Return
Whether the frustum intersects this AABB
- Parameters
fr
: The frustum
-
const VertexType &
max
() const¶ Get the maximum vertex.
- Return
The maximum vertex
-
const VertexType &
min
() const¶ Get the minimum vertex.
- Return
The minimum vertex
-
void
setEntity
(const entity_t *entity)¶ Set the entity associated with with this box.
- Parameters
entity
: The entity
-
void
setSkip
(self_t *skip)¶ Set the skip node (bounding box)
- Parameters
skip
: The target skip node pointer
-
template<size_t
D
= DIM, std::enable_if_t<D == 2, int> = 0>
std::ostream &svg
(std::ostream &os, value_type w, value_type h, value_type unit = 10, std::string label = "", std::string fillcolor = "grey") const¶ Draw this bounding box as SVG.
This method is only available for the 2D case.
- Return
The outstream given in
os
.- Template Parameters
D
: (used for SFINAE)
- Parameters
os
: The output stream to write tow
: The width of the output SVG.h
: The height of the output SVG.unit
: A scale factor to apply before drawinglabel
: A label to put next to the box.fillcolor
: Color to fill the box with.
-
std::ostream &
toStream
(std::ostream &os) const¶ Write information about this bounding box to a stream.
- Return
The stream given as an argument.
- Parameters
os
: The output stream.
-
void
transform
(const transform_type &trf)¶ Transforms this bounding box using the given transform.
This method modifies the box it is called on.
- Parameters
trf
: The transform
-
self_t
transformed
(const transform_type &trf) const¶ Transforms this bounding box using the given transfom.
This method returns a copy of this box, with the transformation applied, and leaves this instance unchanged.
- Return
The transformed bounding box
- Parameters
trf
: The transform
-
template<size_t
D
, std::enable_if_t<D == 3, int>>
std::pair<typename Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::VertexType, typename Acts::AxisAlignedBoundingBox<entity_t, value_t, DIM>::VertexType>transformVertices
(const transform_type &trf) const¶
Public Static Functions
-
std::pair<VertexType, VertexType>
wrap
(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
.- Return
Pair of vertixes: min and max.
- Parameters
boxes
: The boxes to wrap (const pointers)envelope
: Optional envelop to add/subtract to dimension.
-
std::pair<VertexType, VertexType>
wrap
(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
.Overload which accepts non-const boxes in
boxes
.- Return
Pair of vertixes: min and max.
- Parameters
boxes
: The boxes to wrap (non-const pointers)envelope
: Optional envelop to add/subtract to dimension.
-
std::pair<VertexType, VertexType>
wrap
(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
.Overload which accepts a vector in
boxes
which owns the instances- Return
Pair of vertixes: min and max.
- Parameters
boxes
: The boxes to wrap (by-value vector)envelope
: Optional envelop to add/subtract to dimension.
-
using