|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Axis-aligned bounding box tree for spatial queries. More...
#include <geom_algorithms.H>
Classes | |
| struct | DebugNode |
| Structure used for debugging and visualizing the tree structure. More... | |
| struct | DebugSnapshot |
| A snapshot of the entire tree for debugging. More... | |
| struct | Entry |
| An entry in the tree, consisting of a bounding box and a user-defined index. More... | |
| struct | Node |
| Internal tree node structure. More... | |
Public Member Functions | |
| AABBTree ()=default | |
| AABBTree (const AABBTree &other)=default | |
| Copy the entries and the nodes of another tree. | |
| AABBTree (AABBTree &&other) noexcept | |
| Take the entries and the nodes of another tree, which is left empty. | |
| AABBTree & | operator= (const AABBTree &other)=default |
| Copy the entries and the nodes of another tree. | |
| AABBTree & | operator= (AABBTree &&other) noexcept |
| Exchange this tree with another, which is left with the previous entries of this one. | |
| void | swap (AABBTree &other) noexcept |
| Exchange in O(1) the entries and the nodes of this tree and another. | |
| void | build (const Array< Entry > &entries) |
| Build the AABB tree from an array of entries. | |
| Array< size_t > | query (const Rectangle &query) const |
| Find all entries whose bounding box overlaps the query rectangle. | |
| Array< size_t > | query_point (const Point &p) const |
| Find all entries whose bounding box contains the query point. | |
| Rectangle | root_bbox () const |
| Return the root bounding box (union of all entries). | |
| size_t | size () const |
| Number of entries. | |
| bool | is_empty () const |
| Whether the tree is empty. | |
| DebugSnapshot | debug_snapshot () const |
| Return the full tree structure for visualization/debug. | |
Private Member Functions | |
| Geom_Number | center_coord (const size_t entry_idx, const bool split_x) const |
| void | insertion_sort_by_center (Array< size_t > &idx, const size_t lo, const size_t hi, const bool split_x) const |
| void | select_kth_by_center (Array< size_t > &idx, size_t lo, size_t hi, const size_t kth, const bool split_x) const |
| size_t | build (Array< size_t > &idx, const size_t lo, const size_t hi) |
| void | query_impl (const size_t ni, const Rectangle &q, Array< size_t > &results) const |
| void | query_point_impl (const size_t ni, const Point &p, Array< size_t > &results) const |
Static Private Member Functions | |
| static Rectangle | union_bbox (const Rectangle &a, const Rectangle &b) |
| Computes the union of two axis-aligned bounding boxes. | |
| static bool | boxes_overlap (const Rectangle &a, const Rectangle &b) |
| Checks if two rectangles overlap. | |
| static bool | box_contains_point (const Rectangle &r, const Point &p) |
| Checks if a rectangle contains a point. | |
Private Attributes | |
| Array< Node > | nodes_ |
| Internal array storing tree nodes. | |
| Array< Entry > | entries_ |
| Original entries stored in the tree. | |
| size_t | root_ = NONE |
Static Private Attributes | |
| static constexpr size_t | NONE = ~static_cast<size_t>(0) |
Axis-aligned bounding box tree for spatial queries.
An AABB tree organizes a collection of axis-aligned bounding boxes (rectangles) in a binary tree to accelerate spatial queries such as:
The tree is built top-down by splitting the input boxes along the longest axis of the enclosing bounding box. Each internal node stores the union bounding box of its children.
Definition at line 11706 of file geom_algorithms.H.
|
default |
|
default |
Copy the entries and the nodes of another tree.
| [in] | other | tree to copy. |
| std::bad_alloc | if the arrays cannot be allocated. |
|
inlinenoexcept |
Take the entries and the nodes of another tree, which is left empty.
The implicit move took the arrays but copied the index of the root: the moved-from tree then read a root that it no longer had.
| [in,out] | other | tree to move from. |
Definition at line 11965 of file geom_algorithms.H.
|
inlinestaticprivate |
Checks if a rectangle contains a point.
Definition at line 11791 of file geom_algorithms.H.
References Aleph::and, Aleph::Point::get_x(), Aleph::Point::get_y(), and r.
Referenced by query_point_impl().
|
inlinestaticprivate |
Checks if two rectangles overlap.
Definition at line 11782 of file geom_algorithms.H.
References Aleph::and, Aleph::Rectangle::get_xmax(), Aleph::Rectangle::get_xmin(), Aleph::Rectangle::get_ymax(), and Aleph::Rectangle::get_ymin().
Referenced by query_impl().
|
inlineprivate |
Definition at line 11871 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, build(), entries_, Aleph::AABBTree::Node::entry_idx, Aleph::Rectangle::get_xmax(), Aleph::Rectangle::get_xmin(), Aleph::Rectangle::get_ymax(), Aleph::Rectangle::get_ymin(), Aleph::AABBTree::Node::left, nodes_, Aleph::AABBTree::Node::right, select_kth_by_center(), and union_bbox().
Referenced by build(), build(), Moved_From_Case< AABBTree >::make(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Moved_From_Case< AABBTree >::use().
Build the AABB tree from an array of entries.
| entries | Array of (bounding box, index) pairs. |
Definition at line 12005 of file geom_algorithms.H.
References Aleph::Array< T >::append(), build(), entries_, nodes_, NONE, Aleph::Array< T >::reserve(), root_, and Aleph::Array< T >::size().
|
inlineprivate |
Definition at line 11797 of file geom_algorithms.H.
References entries_.
Referenced by insertion_sort_by_center(), and select_kth_by_center().
|
inline |
Return the full tree structure for visualization/debug.
Definition at line 12071 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, entries_, Aleph::AABBTree::Node::entry_idx, Aleph::AABBTree::Node::is_leaf(), Aleph::AABBTree::Node::left, Aleph::AABBTree::DebugSnapshot::nodes, nodes_, NONE, Aleph::AABBTree::Node::right, Aleph::AABBTree::DebugSnapshot::root, and root_.
Referenced by Moved_From_Case< AABBTree >::is_empty(), TEST_F(), TEST_F(), Aleph::visualize_aabb_tree(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 11803 of file geom_algorithms.H.
References Aleph::and, and center_coord().
Referenced by select_kth_by_center().
|
inline |
Whether the tree is empty.
Definition at line 12065 of file geom_algorithms.H.
References entries_.
Referenced by Moved_From_Case< AABBTree >::is_empty(), TEST_F(), TEST_F(), and Moved_From_Case< AABBTree >::use().
Exchange this tree with another, which is left with the previous entries of this one.
| [in,out] | other | tree to move from. |
Definition at line 11983 of file geom_algorithms.H.
References swap().
Copy the entries and the nodes of another tree.
| [in] | other | tree to copy. |
| std::bad_alloc | if the arrays cannot be allocated. |
Find all entries whose bounding box overlaps the query rectangle.
| query | The query bounding box. |
Definition at line 12029 of file geom_algorithms.H.
References NONE, query(), query_impl(), and root_.
Referenced by query(), TEST_F(), Moved_From_Case< AABBTree >::use(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 11908 of file geom_algorithms.H.
References Aleph::Array< T >::append(), Aleph::AABBTree::Node::bbox, boxes_overlap(), entries_, Aleph::AABBTree::Node::entry_idx, Aleph::AABBTree::Node::is_leaf(), Aleph::AABBTree::Node::left, nodes_, NONE, query_impl(), and Aleph::AABBTree::Node::right.
Referenced by query(), and query_impl().
Find all entries whose bounding box contains the query point.
| p | The query point. |
Definition at line 12043 of file geom_algorithms.H.
References NONE, query_point_impl(), and root_.
Referenced by TEST_F(), TEST_F(), and Moved_From_Case< AABBTree >::use().
|
inlineprivate |
Definition at line 11926 of file geom_algorithms.H.
References Aleph::Array< T >::append(), Aleph::AABBTree::Node::bbox, box_contains_point(), entries_, Aleph::AABBTree::Node::entry_idx, Aleph::AABBTree::Node::is_leaf(), Aleph::AABBTree::Node::left, nodes_, NONE, query_point_impl(), and Aleph::AABBTree::Node::right.
Referenced by query_point(), and query_point_impl().
|
inline |
Return the root bounding box (union of all entries).
Definition at line 12052 of file geom_algorithms.H.
References ah_domain_error_if, nodes_, NONE, and root_.
Referenced by TEST_F(), and Moved_From_Case< AABBTree >::use().
|
inlineprivate |
Definition at line 11824 of file geom_algorithms.H.
References center_coord(), and insertion_sort_by_center().
Referenced by build().
|
inline |
Number of entries.
Definition at line 12059 of file geom_algorithms.H.
References entries_.
Referenced by main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Moved_From_Case< AABBTree >::use().
|
inlinenoexcept |
Exchange in O(1) the entries and the nodes of this tree and another.
| [in,out] | other | tree to exchange with. |
Definition at line 11993 of file geom_algorithms.H.
References entries_, nodes_, and root_.
Referenced by operator=().
|
inlinestaticprivate |
Computes the union of two axis-aligned bounding boxes.
Definition at line 11770 of file geom_algorithms.H.
References Aleph::Rectangle::get_xmax(), Aleph::Rectangle::get_xmin(), Aleph::Rectangle::get_ymax(), and Aleph::Rectangle::get_ymin().
Referenced by build().
Original entries stored in the tree.
Definition at line 11763 of file geom_algorithms.H.
Referenced by build(), build(), center_coord(), debug_snapshot(), is_empty(), query_impl(), query_point_impl(), size(), and swap().
Internal array storing tree nodes.
Definition at line 11762 of file geom_algorithms.H.
Referenced by build(), build(), debug_snapshot(), query_impl(), query_point_impl(), root_bbox(), and swap().
|
staticconstexprprivate |
Definition at line 11765 of file geom_algorithms.H.
Referenced by build(), debug_snapshot(), query(), query_impl(), query_point(), query_point_impl(), and root_bbox().
|
private |
Definition at line 11945 of file geom_algorithms.H.
Referenced by build(), debug_snapshot(), query(), query_point(), root_bbox(), and swap().