|
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 12063 of file geom_algorithms.H.
|
default |
|
inlinestaticprivate |
Checks if a rectangle contains a point.
Definition at line 12147 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 12137 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 12226 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, build(), Aleph::divide_and_conquer_partition_dp(), 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(), and TEST_F().
Build the AABB tree from an array of entries.
| entries | Array of (bounding box, index) pairs. |
Definition at line 12308 of file geom_algorithms.H.
References Aleph::Array< T >::append(), build(), Aleph::divide_and_conquer_partition_dp(), entries_, nodes_, NONE, Aleph::Array< T >::reserve(), root_, and Aleph::Array< T >::size().
|
inlineprivate |
Definition at line 12154 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 12368 of file geom_algorithms.H.
References Aleph::AABBTree::DebugNode::bbox, Aleph::AABBTree::Node::bbox, Aleph::AABBTree::DebugNode::depth, Aleph::divide_and_conquer_partition_dp(), entries_, Aleph::AABBTree::Node::entry_idx, Aleph::AABBTree::DebugNode::entry_index, Aleph::AABBTree::DebugNode::is_leaf, Aleph::AABBTree::Node::is_leaf(), Aleph::AABBTree::DebugNode::left, Aleph::AABBTree::Node::left, Aleph::AABBTree::DebugNode::node_index, nodes_, NONE, Aleph::AABBTree::DebugNode::right, Aleph::AABBTree::Node::right, root_, and Aleph::AABBTree::DebugNode::user_index.
Referenced by TEST_F(), Aleph::visualize_aabb_tree(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 12162 of file geom_algorithms.H.
References Aleph::and, center_coord(), and Aleph::divide_and_conquer_partition_dp().
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 12332 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), NONE, query(), query_impl(), and root_.
Referenced by query(), TEST_F(), and Aleph::visualize_aabb_tree_query().
|
inlineprivate |
Definition at line 12263 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, boxes_overlap(), Aleph::divide_and_conquer_partition_dp(), 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 12346 of file geom_algorithms.H.
References Aleph::divide_and_conquer_partition_dp(), NONE, query_point_impl(), and root_.
|
inlineprivate |
Definition at line 12280 of file geom_algorithms.H.
References Aleph::AABBTree::Node::bbox, box_contains_point(), Aleph::divide_and_conquer_partition_dp(), 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 12355 of file geom_algorithms.H.
References ah_domain_error_if, nodes_, NONE, and root_.
Referenced by TEST_F().
|
inlineprivate |
Definition at line 12181 of file geom_algorithms.H.
References center_coord(), Aleph::divide_and_conquer_partition_dp(), and insertion_sort_by_center().
Referenced by build().
|
inline |
|
inlinestaticprivate |
Computes the union of two axis-aligned bounding boxes.
Definition at line 12124 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 12117 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 12116 of file geom_algorithms.H.
Referenced by build(), build(), debug_snapshot(), query_impl(), query_point_impl(), and root_bbox().
|
staticconstexprprivate |
Definition at line 12119 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 12298 of file geom_algorithms.H.
Referenced by build(), debug_snapshot(), query(), query_point(), and root_bbox().