File BoundingBox.hpp¶
-
namespace Acts
Note
This file is foreseen for the
Geometry
module to replaceExtent
Functions
-
template<typename box_t>
box_t *make_octree(std::vector<std::unique_ptr<box_t>> &store, const std::vector<box_t*> &prims, size_t max_depth = 1, typename box_t::value_type envelope1 = 0)¶ Build an octree from a list of bounding boxes.
Note
store
andprims
do not need to contain the same objects.store
is only used to pass ownership back to the caller while preserving memory location.- Template Parameters
box_t – Works will all box types.
- Parameters
store – Owns the created boxes by means of
std::unique_ptr
.prims – Boxes to store. This is a read only vector.
max_depth – No subdivisions beyond this level.
envelope1 – Envelope to add/subtract to dimensions in all directions.
- Returns
Pointer to the top most bounding box, containing the entire octree
-
template<typename T, typename U, size_t V>
std::ostream &operator<<(std::ostream &os, const AxisAlignedBoundingBox<T, U, V> &box)¶ Overload of the << operator for bounding boxes.
- Template Parameters
T – entity type
U – value type
V – dimension
- Parameters
os – The output stream
box – The bounding box
- Returns
The given output stream.
-
template<typename entity_t, typename value_t, size_t DIM>
class AxisAlignedBoundingBox - #include <Acts/Utilities/BoundingBox.hpp>
Implementation of an Axis Aligned Bounding Box.
This type is compatible with 2D and 3D boxes
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.
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 store
vmin – 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 store
center – The center position
size – 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 ¢er() const
Get the center position of this bounding box.
- Returns
The center position
-
template<size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
void draw(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 to
color – The color to use for drawing
trf – 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.
- Returns
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).
- Returns
The lest most child.
-
const self_t *getSkip() const
Get the skip node for this box.
- Returns
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.
- Returns
Whether the box has an entity attached.
-
bool intersect(const VertexType &point) const
Calculate whether a point is inside this box.
- Parameters
point – The point to test.
- Returns
Whether the point is inside or not.
-
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- Parameters
ray – The ray to intersect with
- Returns
Whether the ray intersects this AABB
-
template<size_t sides>
bool 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, but drops some of the more sophisticated optimization.
- Parameters
fr – The frustum
- Returns
Whether the frustum intersects this AABB
-
const VertexType &max() const
Get the maximum vertex.
- Returns
The maximum vertex
-
const VertexType &min() const
Get the minimum vertex.
- Returns
The minimum vertex
-
AxisAlignedBoundingBox &operator=(const self_t &other) = default
Copy assignment operator from other bounding box.
- Parameters
other – The other AABB
-
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, 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.
- Template Parameters
D – (used for SFINAE)
- Parameters
os – The output stream to write to
w – The width of the output SVG.
h – The height of the output SVG.
unit – A scale factor to apply before drawing
label – A label to put next to the box.
fillcolor – Color to fill the box with.
- Returns
The outstream given in
os
.
-
std::ostream &toStream(std::ostream &os) const
Write information about this bounding box to a stream.
- Parameters
os – The output stream.
- Returns
The stream given as an argument.
-
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.
- Parameters
trf – The transform
- Returns
The transformed bounding box
Public Static Functions
-
static 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
.- Parameters
boxes – The boxes to wrap (const pointers)
envelope – Optional envelop to add/subtract to dimension.
- Returns
Pair of vertixes: min and max.
-
static 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
.- Parameters
boxes – The boxes to wrap (non-const pointers)
envelope – Optional envelop to add/subtract to dimension.
- Returns
Pair of vertixes: min and max.
-
static 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- Parameters
boxes – The boxes to wrap (by-value vector)
envelope – Optional envelop to add/subtract to dimension.
- Returns
Pair of vertixes: min and max.
Public Static Attributes
-
static const size_t dim = DIM
Re-export dimension from template parameter.
Private Types
-
using self_t = AxisAlignedBoundingBox<entity_t, value_t, DIM>¶
Private self type to capture template parameters.
Private Functions
-
template<size_t D = DIM, std::enable_if_t<D == 2, int> = 0>
std::pair<VertexType, VertexType> transformVertices(const transform_type &trf) const¶
-
template<size_t D = DIM, std::enable_if_t<D == 3, int> = 0>
std::pair<VertexType, VertexType> transformVertices(const transform_type &trf) const¶
Private Members
-
VertexType m_center¶
-
vertex_array_type m_iwidth¶
-
VertexType m_vmax¶
-
VertexType m_vmin¶
-
vertex_array_type m_width¶
-
template<typename T, typename P>
class NamedType¶ Strong type helper, not public This is only used to provide sensible tag-dispatch below.
Public Functions
-
struct SizeParameter¶
SizeParameter Tag.
-
using entity_type = entity_t
-
template<typename box_t>