|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Spatial point index for O(log n) nearest-neighbor queries. More...
#include <geom_algorithms.H>
Classes | |
| struct | DebugPartition |
| Represents a spatial partition or leaf in the KD-tree. More... | |
| struct | DebugSnapshot |
| A complete snapshot of the tree for debugging. More... | |
Public Member Functions | |
| KDTreePointSearch (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax) | |
| Construct an empty KD-tree for the given bounding region. | |
| bool | insert (const Point &p) |
| Insert a point. Returns true if inserted, false if duplicate. | |
| bool | contains (const Point &p) const |
| Check if a point exists in the tree. | |
| std::optional< Point > | nearest (const Point &p) const |
Find the nearest neighbor to query point p. | |
| void | range (const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax, DynList< Point > *out) const |
| Collect all points inside the given rectangle. | |
| size_t | size () const noexcept |
| Return the number of points in the tree. | |
| bool | is_empty () const noexcept |
| Return true if the tree is empty. | |
| template<typename Op > | |
| void | for_each (Op &&op) const |
| Apply an operation to every point (inorder traversal). | |
| DebugSnapshot | debug_snapshot () const |
| Build a deterministic geometric partition snapshot for visualization. | |
Static Public Member Functions | |
| static KDTreePointSearch | build (const Array< Point > &points, const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax) |
| Build a balanced KD-tree from a point array. | |
Private Member Functions | |
| Rectangle | extended_bounds () const |
| The bounds, extended to the points outside them, as the tree extends its region to them. | |
Static Private Member Functions | |
| static bool | lexicographic_less (const Point &a, const Point &b) |
| static Array< Point > | unique_points (Array< Point > points) |
Private Attributes | |
| K2Tree | tree |
| Array< Point > | points_ |
| Rectangle | bounds_ |
Spatial point index for O(log n) nearest-neighbor queries.
This is a thin wrapper around K2Tree<> (see tpl_2dtree.H) that provides a convenient interface consistent with the other geometry algorithms in this file.
Definition at line 7644 of file geom_algorithms.H.
|
inline |
Construct an empty KD-tree for the given bounding region.
| xmin | Minimum x of bounding box. |
| ymin | Minimum y of bounding box. |
| xmax | Maximum x of bounding box. |
| ymax | Maximum y of bounding box. |
Definition at line 7726 of file geom_algorithms.H.
|
inlinestatic |
Build a balanced KD-tree from a point array.
| points | Input points (duplicates removed internally). |
| xmin | Minimum x of bounding box. |
| ymin | Minimum y of bounding box. |
| xmax | Maximum x of bounding box. |
| ymax | Maximum y of bounding box. |
Definition at line 7743 of file geom_algorithms.H.
References K2Tree< T >::build(), points_, tree, and unique_points().
Referenced by main(), TEST(), TEST(), TEST_F(), and TEST_F().
|
inline |
Check if a point exists in the tree.
Definition at line 7765 of file geom_algorithms.H.
References K2Tree< T >::contains(), and tree.
Referenced by TEST_F().
|
inline |
Build a deterministic geometric partition snapshot for visualization.
The snapshot uses the current point set and alternates split axis by depth (x/y), producing a balanced partition tree suitable for didactic rendering. Its bounds are those of the tree, extended to the points inserted outside them, as the tree extends its region.
Definition at line 7813 of file geom_algorithms.H.
References Aleph::Array< T >::append(), Aleph::KDTreePointSearch::DebugSnapshot::bounds, Aleph::KDTreePointSearch::DebugPartition::depth, extended_bounds(), Aleph::Point::get_x(), Aleph::Point::get_y(), Aleph::KDTreePointSearch::DebugPartition::is_leaf, Aleph::KDTreePointSearch::DebugSnapshot::partitions, Aleph::KDTreePointSearch::DebugSnapshot::points, points_, Aleph::quicksort_op(), Aleph::KDTreePointSearch::DebugPartition::region, Aleph::KDTreePointSearch::DebugPartition::representative, Aleph::Array< T >::reserve(), Aleph::Array< T >::size(), Aleph::KDTreePointSearch::DebugPartition::split_on_x, and Aleph::KDTreePointSearch::DebugPartition::split_value.
Referenced by TEST_F(), and Aleph::visualize_kdtree_partitions().
|
inlineprivate |
The bounds, extended to the points outside them, as the tree extends its region to them.
Definition at line 7675 of file geom_algorithms.H.
References bounds_, Aleph::Point::get_x(), Aleph::Rectangle::get_xmax(), Aleph::Rectangle::get_xmin(), Aleph::Point::get_y(), Aleph::Rectangle::get_ymax(), Aleph::Rectangle::get_ymin(), and points_.
Referenced by debug_snapshot().
|
inline |
Apply an operation to every point (inorder traversal).
Definition at line 7800 of file geom_algorithms.H.
References K2Tree< T >::for_each(), and tree.
Referenced by TEST_F().
|
inline |
|
inlinenoexcept |
Return true if the tree is empty.
Definition at line 7793 of file geom_algorithms.H.
References K2Tree< T >::is_empty(), and tree.
Referenced by TEST_F().
|
inlinestaticprivate |
Definition at line 7650 of file geom_algorithms.H.
References Aleph::Point::get_x(), and Aleph::Point::get_y().
Referenced by unique_points().
Find the nearest neighbor to query point p.
Definition at line 7771 of file geom_algorithms.H.
References K2Tree< T >::nearest(), and tree.
|
inline |
Collect all points inside the given rectangle.
Definition at line 7777 of file geom_algorithms.H.
References out, K2Tree< T >::range(), and tree.
Referenced by TEST_F().
|
inlinenoexcept |
Return the number of points in the tree.
Definition at line 7787 of file geom_algorithms.H.
References K2Tree< T >::size(), and tree.
|
inlinestaticprivate |
Definition at line 7659 of file geom_algorithms.H.
References lexicographic_less(), Aleph::quicksort_op(), Aleph::Array< T >::reserve(), and Aleph::Array< T >::size().
Referenced by build().
|
private |
Definition at line 7648 of file geom_algorithms.H.
Referenced by extended_bounds().
Definition at line 7647 of file geom_algorithms.H.
Referenced by build(), debug_snapshot(), extended_bounds(), and insert().
|
private |
Definition at line 7646 of file geom_algorithms.H.
Referenced by build(), contains(), for_each(), insert(), is_empty(), nearest(), range(), and size().