|
Aleph-w 3.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 | |
| 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 12035 of file geom_algorithms.H.
|
default |
|
inlinestaticprivate |
Checks if a rectangle contains a point.
Definition at line 12120 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 12111 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 12200 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, Aleph::blossom_maximum_cardinality_matching(), build(), entries_, Aleph::AABBTree::Node::entry_idx, Aleph::AABBTree::Node::left, nodes_, Aleph::AABBTree::Node::right, select_kth_by_center(), and union_bbox().
Referenced by build(), build(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
Build the AABB tree from an array of entries.
| entries | Array of (bounding box, index) pairs. |
Definition at line 12284 of file geom_algorithms.H.
References Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), build(), entries_, nodes_, NONE, Aleph::Array< T >::reserve(), root_, and Aleph::Array< T >::size().
|
inlineprivate |
Definition at line 12126 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 12350 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, Aleph::blossom_maximum_cardinality_matching(), 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, and root_.
Referenced by TEST_F(), TEST_F(), Aleph::visualize_aabb_tree(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 12132 of file geom_algorithms.H.
References Aleph::and, Aleph::blossom_maximum_cardinality_matching(), and center_coord().
Referenced by select_kth_by_center().
|
inline |
Find all entries whose bounding box overlaps the query rectangle.
| query | The query bounding box. |
Definition at line 12308 of file geom_algorithms.H.
References Aleph::blossom_maximum_cardinality_matching(), NONE, query(), query_impl(), and root_.
Referenced by query(), TEST_F(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 12237 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, Aleph::blossom_maximum_cardinality_matching(), 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 12322 of file geom_algorithms.H.
References Aleph::blossom_maximum_cardinality_matching(), NONE, query_point_impl(), and root_.
|
inlineprivate |
Definition at line 12255 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, Aleph::blossom_maximum_cardinality_matching(), 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 12331 of file geom_algorithms.H.
References ah_domain_error_if, nodes_, NONE, and root_.
Referenced by TEST_F().
|
inlineprivate |
Definition at line 12153 of file geom_algorithms.H.
References Aleph::blossom_maximum_cardinality_matching(), center_coord(), and insertion_sort_by_center().
Referenced by build().
|
inline |
|
inlinestaticprivate |
Computes the union of two axis-aligned bounding boxes.
Definition at line 12099 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 12092 of file geom_algorithms.H.
Referenced by build(), build(), center_coord(), debug_snapshot(), is_empty(), query_impl(), query_point_impl(), and size().
Internal array storing tree nodes.
Definition at line 12091 of file geom_algorithms.H.
Referenced by build(), build(), debug_snapshot(), query_impl(), query_point_impl(), and root_bbox().
|
staticconstexprprivate |
Definition at line 12094 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 12274 of file geom_algorithms.H.
Referenced by build(), debug_snapshot(), query(), query_point(), and root_bbox().