|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Node for QuadTree spatial data structure. More...
#include <quadnode.H>
Public Types | |
| enum class | Color { White , Gray , Black , Num_Colors } |
| Node color states for quadtree nodes. More... | |
| enum class | Quad { NW , NE , SW , SE , Num_Quads } |
| Quadrant directions for child nodes. More... | |
| enum class | Side { North , South , East , West , Num_Sides } |
| Cardinal directions for neighbor navigation. More... | |
Public Member Functions | |
| QuadNode () noexcept | |
| Default constructor - creates a white (empty) node. | |
| QuadNode (const Geom_Number &_min_x, const Geom_Number &_max_x, const Geom_Number &_min_y, const Geom_Number &_max_y, QuadNode *_parent=nullptr) noexcept | |
| Construct a node with specified region bounds. | |
| QuadNode (const QuadNode &)=delete | |
| void | set_region (const Geom_Number &_min_x, const Geom_Number &_max_x, const Geom_Number &_min_y, const Geom_Number &_max_y) noexcept |
| Set the region boundaries for this node. | |
| QuadNode *& | get_parent () noexcept |
| Get reference to parent node (for reading/writing via PARENT macro). | |
| QuadNode *& | get_nw_child () noexcept |
| Get reference to NW child (for reading/writing via NW_CHILD macro). | |
| QuadNode *& | get_ne_child () noexcept |
| Get reference to NE child (for reading/writing via NE_CHILD macro). | |
| QuadNode *& | get_sw_child () noexcept |
| Get reference to SW child (for reading/writing via SW_CHILD macro). | |
| QuadNode *& | get_se_child () noexcept |
| Get reference to SE child (for reading/writing via SE_CHILD macro). | |
| Color & | get_color () noexcept |
| Get reference to color (for reading/writing via COLOR macro). | |
| unsigned long & | get_level () noexcept |
| Get reference to level (for reading/writing via LEVEL macro). | |
| bool | is_leaf () const noexcept |
| Check if this node is a leaf (has no children). | |
| bool | is_nw_child () const noexcept |
| Check if this node is the NW child of its parent. | |
| bool | is_ne_child () const noexcept |
| Check if this node is the NE child of its parent. | |
| bool | is_sw_child () const noexcept |
| Check if this node is the SW child of its parent. | |
| bool | is_se_child () const noexcept |
| Check if this node is the SE child of its parent. | |
| bool | contains (const Point &p) const noexcept |
| Check if a point is contained in this node's region. | |
| QuadNode * | get_child_to (const Point &p) const |
| Find which child node should contain a given point. | |
| Point & | add_point (const Point &p) |
| Add a point to this node. | |
| size_t | get_num_points () noexcept |
| Get total number of points in this subtree. | |
| const Geom_Number & | get_min_x () const noexcept |
| Get minimum X coordinate of this region. | |
| const Geom_Number & | get_max_x () const noexcept |
| Get maximum X coordinate of this region. | |
| const Geom_Number & | get_min_y () const noexcept |
| Get minimum Y coordinate of this region. | |
| const Geom_Number & | get_max_y () const noexcept |
| Get maximum Y coordinate of this region. | |
| Geom_Number | get_width () const noexcept |
| Get width of this region. | |
| Geom_Number | get_height () const noexcept |
| Get height of this region. | |
| Geom_Number | get_mid_x () const noexcept |
| Get midpoint X coordinate. | |
| Geom_Number | get_mid_y () const noexcept |
| Get midpoint Y coordinate. | |
| Point * | search_point (const Point &p) noexcept |
| Search for a point in this node. | |
| bool | remove_point (const Point &p) |
| Remove a point from this node. | |
| void | empty () noexcept |
| Remove all points from this node and mark it as White. | |
| DynList< QuadNode * > | get_neighbors () |
| Find all adjacent leaf nodes. | |
| DynList< Point > & | get_points_set () noexcept |
| Get reference to the points list (for direct manipulation). | |
| template<class Op > | |
| void | for_each_point (Op &op) |
| Apply operation to each point in this node. | |
| template<class Op > | |
| void | for_each_point (Op &&op=Op()) |
| Apply operation to each point (rvalue reference version). | |
| QuadNode & | operator= (const QuadNode &)=delete |
Static Private Member Functions | |
| static QuadNode * | get_north_neighbor (QuadNode *v) noexcept |
| Find the northern neighbor of a node. | |
| static QuadNode * | get_south_neighbor (QuadNode *v) noexcept |
| Find the southern neighbor of a node. | |
| static QuadNode * | get_east_neighbor (QuadNode *v) noexcept |
| Find the eastern neighbor of a node. | |
| static QuadNode * | get_west_neighbor (QuadNode *v) noexcept |
| Find the western neighbor of a node. | |
| static void | get_neighbors_by_side (QuadNode *node, const Side &side, DynList< QuadNode * > &neighbors) |
| Recursively collect leaf neighbors on a given side. | |
| static size_t | count_points (QuadNode *node) noexcept |
| Recursively count all points in a subtree. | |
Private Attributes | |
| DynList< Point > | points |
| Points stored in this node (only for leaves) | |
| QuadNode * | parent |
| Parent node (nullptr for root) | |
| QuadNode * | nw_child |
| Northwest child. | |
| QuadNode * | ne_child |
| Northeast child. | |
| QuadNode * | sw_child |
| Southwest child. | |
| QuadNode * | se_child |
| Southeast child. | |
| Color | color |
| Node state (White/Gray/Black) | |
| unsigned long | level |
| Depth in the tree (0 for root) | |
| Geom_Number | min_x |
| Minimum X coordinate. | |
| Geom_Number | max_x |
| Maximum X coordinate. | |
| Geom_Number | min_y |
| Minimum Y coordinate. | |
| Geom_Number | max_y |
| Maximum Y coordinate. | |
Node for QuadTree spatial data structure.
QuadNode represents a rectangular region in 2D space that can be recursively subdivided into four quadrants (northwest, northeast, southwest, southeast). Each node can store multiple points and maintains pointers to its parent and four potential children.
Definition at line 93 of file quadnode.H.
|
strong |
Node color states for quadtree nodes.
Colors indicate the state of a node:
| Enumerator | |
|---|---|
| White | Empty leaf node. |
| Gray | Internal node with children. |
| Black | Leaf node with points. |
| Num_Colors | |
Definition at line 104 of file quadnode.H.
|
strong |
Quadrant directions for child nodes.
Identifies which quadrant a child node occupies:
| Enumerator | |
|---|---|
| NW | Northwest quadrant. |
| NE | Northeast quadrant. |
| SW | Southwest quadrant. |
| SE | Southeast quadrant. |
| Num_Quads | |
Definition at line 120 of file quadnode.H.
|
strong |
Cardinal directions for neighbor navigation.
Used to identify neighbors in four cardinal directions.
| Enumerator | |
|---|---|
| North | Northern neighbor. |
| South | Southern neighbor. |
| East | Eastern neighbor. |
| West | Western neighbor. |
| Num_Sides | |
Definition at line 133 of file quadnode.H.
|
inlinenoexcept |
Default constructor - creates a white (empty) node.
Definition at line 307 of file quadnode.H.
|
inlinenoexcept |
Construct a node with specified region bounds.
| _min_x | Minimum X coordinate of the region |
| _max_x | Maximum X coordinate of the region |
| _min_y | Minimum Y coordinate of the region |
| _max_y | Maximum Y coordinate of the region |
| _parent | Parent node (nullptr for root) |
Definition at line 323 of file quadnode.H.
Add a point to this node.
Appends the point to the node's point list and marks it as Black. Should only be called on leaf nodes.
| p | The point to add |
Definition at line 465 of file quadnode.H.
References Aleph::DynList< T >::append(), color, and points.
Referenced by QuadTree::insert(), and QuadTree::split().
Check if a point is contained in this node's region.
A point is contained if min_x <= x < max_x and min_y <= y < max_y. Note: Upper bounds are exclusive.
| p | The point to test |
Definition at line 417 of file quadnode.H.
References Aleph::maps(), max_x, max_y, min_x, and min_y.
Referenced by QuadTree::contains(), get_child_to(), QuadTree::insert(), QuadTree::insert(), QuadTree::search(), and QuadTree::search_container_node().
Recursively count all points in a subtree.
Definition at line 286 of file quadnode.H.
References count_points(), Aleph::maps(), NE_CHILD, NW_CHILD, SE_CHILD, and SW_CHILD.
Referenced by count_points(), and get_num_points().
|
inlinenoexcept |
Remove all points from this node and mark it as White.
Definition at line 539 of file quadnode.H.
References color, Aleph::DynList< T >::empty(), and points.
Referenced by QuadTree::empty().
Apply operation to each point (rvalue reference version).
Definition at line 588 of file quadnode.H.
References Aleph::maps().
Apply operation to each point in this node.
| Op | Function object type with signature void(Point&) |
| op | Operation to apply |
Definition at line 580 of file quadnode.H.
References points.
Find which child node should contain a given point.
Requires that this node is not a leaf and that the point is within this node's region.
| p | Point to locate |
| std::domain_error | if this node doesn't contain p |
Definition at line 432 of file quadnode.H.
References ah_domain_error_if, contains(), Aleph::maps(), ne_child, nw_child, se_child, and sw_child.
Referenced by QuadTree::insert(), QuadTree::remove(), QuadTree::search(), QuadTree::search_container_node(), and QuadTree::split().
|
inlinenoexcept |
Get reference to color (for reading/writing via COLOR macro).
Definition at line 369 of file quadnode.H.
References color.
Find the eastern neighbor of a node.
Definition at line 205 of file quadnode.H.
References get_east_neighbor(), is_leaf(), Aleph::maps(), NE_CHILD, NW_CHILD, PARENT, SE_CHILD, and SW_CHILD.
Referenced by get_east_neighbor(), and get_neighbors().
|
inlinenoexcept |
Get reference to level (for reading/writing via LEVEL macro).
Definition at line 372 of file quadnode.H.
References level.
|
inlinenoexcept |
Get maximum X coordinate of this region.
Definition at line 481 of file quadnode.H.
References max_x.
Referenced by QuadTree::copy_tree(), and QuadTree::split().
|
inlinenoexcept |
Get maximum Y coordinate of this region.
Definition at line 487 of file quadnode.H.
References max_y.
Referenced by QuadTree::copy_tree(), and QuadTree::split().
|
inlinenoexcept |
Get midpoint X coordinate.
Definition at line 496 of file quadnode.H.
Referenced by QuadTree::split().
|
inlinenoexcept |
Get midpoint Y coordinate.
Definition at line 499 of file quadnode.H.
Referenced by QuadTree::split().
|
inlinenoexcept |
Get minimum X coordinate of this region.
Definition at line 478 of file quadnode.H.
References min_x.
Referenced by QuadTree::copy_tree(), and QuadTree::split().
|
inlinenoexcept |
Get minimum Y coordinate of this region.
Definition at line 484 of file quadnode.H.
References min_y.
Referenced by QuadTree::copy_tree(), and QuadTree::split().
|
inlinenoexcept |
Get reference to NE child (for reading/writing via NE_CHILD macro).
Definition at line 360 of file quadnode.H.
References ne_child.
Find all adjacent leaf nodes.
Searches in all four cardinal directions and returns neighboring leaf nodes. Internal nodes are traversed to find their adjacent leaves.
Definition at line 552 of file quadnode.H.
References East, get_east_neighbor(), get_neighbors_by_side(), get_north_neighbor(), get_south_neighbor(), get_west_neighbor(), Aleph::maps(), North, South, and West.
|
inlinestaticprivate |
Recursively collect leaf neighbors on a given side.
Definition at line 249 of file quadnode.H.
References ah_domain_error_if, Aleph::DynList< T >::append(), East, get_neighbors_by_side(), is_leaf(), Aleph::maps(), NE_CHILD, North, NW_CHILD, SE_CHILD, South, SW_CHILD, and West.
Referenced by get_neighbors(), and get_neighbors_by_side().
Find the northern neighbor of a node.
Definition at line 161 of file quadnode.H.
References get_north_neighbor(), is_leaf(), Aleph::maps(), NE_CHILD, NW_CHILD, PARENT, SE_CHILD, and SW_CHILD.
Referenced by get_neighbors(), and get_north_neighbor().
|
inlinenoexcept |
Get total number of points in this subtree.
Definition at line 472 of file quadnode.H.
References count_points().
Referenced by QuadTree::insert().
|
inlinenoexcept |
Get reference to NW child (for reading/writing via NW_CHILD macro).
Definition at line 357 of file quadnode.H.
References nw_child.
|
inlinenoexcept |
Get reference to parent node (for reading/writing via PARENT macro).
Definition at line 354 of file quadnode.H.
References parent.
Get reference to the points list (for direct manipulation).
Definition at line 572 of file quadnode.H.
References points.
Referenced by QuadTree::copy_tree(), demo_traversal(), QuadTree::join(), and QuadTree::split().
|
inlinenoexcept |
Get reference to SE child (for reading/writing via SE_CHILD macro).
Definition at line 366 of file quadnode.H.
References se_child.
Find the southern neighbor of a node.
Definition at line 183 of file quadnode.H.
References get_south_neighbor(), is_leaf(), Aleph::maps(), NE_CHILD, NW_CHILD, PARENT, SE_CHILD, and SW_CHILD.
Referenced by get_neighbors(), and get_south_neighbor().
|
inlinenoexcept |
Get reference to SW child (for reading/writing via SW_CHILD macro).
Definition at line 363 of file quadnode.H.
References sw_child.
Find the western neighbor of a node.
Definition at line 227 of file quadnode.H.
References get_west_neighbor(), is_leaf(), Aleph::maps(), NE_CHILD, NW_CHILD, PARENT, SE_CHILD, and SW_CHILD.
Referenced by get_neighbors(), and get_west_neighbor().
|
inlinenoexcept |
|
inlinenoexcept |
Check if this node is a leaf (has no children).
Definition at line 375 of file quadnode.H.
References color.
Referenced by demo_traversal(), get_east_neighbor(), get_neighbors_by_side(), get_north_neighbor(), get_south_neighbor(), get_west_neighbor(), QuadTree::insert(), QuadTree::join(), QuadTree::remove(), QuadTree::search(), QuadTree::search_container_node(), QuadTree::split(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Check if this node is the NE child of its parent.
Definition at line 386 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the NW child of its parent.
Definition at line 378 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the SE child of its parent.
Definition at line 402 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the SW child of its parent.
Definition at line 394 of file quadnode.H.
Remove a point from this node.
| p | Point to remove |
Definition at line 523 of file quadnode.H.
References points.
Referenced by QuadTree::remove().
Search for a point in this node.
Linear search through the node's point list.
| p | Point to search for |
Definition at line 508 of file quadnode.H.
References points.
Referenced by QuadTree::search(), QuadTree::search_container_node(), and TEST().
|
inlinenoexcept |
Set the region boundaries for this node.
| _min_x | Minimum X coordinate |
| _max_x | Maximum X coordinate |
| _min_y | Minimum Y coordinate |
| _max_y | Maximum Y coordinate |
Definition at line 342 of file quadnode.H.
References Aleph::maps(), max_x, max_y, min_x, and min_y.
|
private |
Node state (White/Gray/Black)
Definition at line 151 of file quadnode.H.
Referenced by add_point(), empty(), get_color(), and is_leaf().
Depth in the tree (0 for root)
Definition at line 152 of file quadnode.H.
Referenced by get_level().
|
private |
Maximum X coordinate.
Definition at line 156 of file quadnode.H.
Referenced by contains(), get_max_x(), get_mid_x(), get_width(), and set_region().
|
private |
Maximum Y coordinate.
Definition at line 158 of file quadnode.H.
Referenced by contains(), get_height(), get_max_y(), get_mid_y(), and set_region().
|
private |
Minimum X coordinate.
Definition at line 155 of file quadnode.H.
Referenced by contains(), get_mid_x(), get_min_x(), get_width(), and set_region().
|
private |
Minimum Y coordinate.
Definition at line 157 of file quadnode.H.
Referenced by contains(), get_height(), get_mid_y(), get_min_y(), and set_region().
|
private |
Northeast child.
Definition at line 147 of file quadnode.H.
Referenced by get_child_to(), and get_ne_child().
|
private |
Northwest child.
Definition at line 146 of file quadnode.H.
Referenced by get_child_to(), and get_nw_child().
|
private |
Parent node (nullptr for root)
Definition at line 145 of file quadnode.H.
Referenced by get_parent(), is_ne_child(), is_nw_child(), is_se_child(), and is_sw_child().
Points stored in this node (only for leaves)
Definition at line 143 of file quadnode.H.
Referenced by add_point(), empty(), for_each_point(), get_points_set(), remove_point(), and search_point().
|
private |
Southeast child.
Definition at line 149 of file quadnode.H.
Referenced by get_child_to(), and get_se_child().
|
private |
Southwest child.
Definition at line 148 of file quadnode.H.
Referenced by get_child_to(), and get_sw_child().