|
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) | |
| 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) |
| 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.
|
inline |
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) |
| std::domain_error | if either interval is empty or reversed |
Definition at line 324 of file quadnode.H.
References ah_domain_error_if, Aleph::blossom_maximum_cardinality_matching(), max_x, max_y, min_x, and min_y.
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 471 of file quadnode.H.
Referenced by 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 423 of file quadnode.H.
References Aleph::and, max_x, max_y, min_x, and min_y.
Referenced by QuadTree::contains(), get_child_to(), QuadTree::insert(), QuadTree::remove(), QuadTree::search(), and QuadTree::search_container_node().
Recursively count all points in a subtree.
Definition at line 286 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching(), count_points(), 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 547 of file quadnode.H.
Referenced by QuadTree::empty().
Apply operation to each point (rvalue reference version).
Definition at line 596 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching().
Apply operation to each point in this node.
| Op | Function object type with signature void(Point&) |
| op | Operation to apply |
Definition at line 588 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 438 of file quadnode.H.
References ah_domain_error_if, Aleph::blossom_maximum_cardinality_matching(), contains(), 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 375 of file quadnode.H.
References color.
Find the eastern neighbor of a node.
Definition at line 205 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching(), get_east_neighbor(), is_leaf(), 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 378 of file quadnode.H.
References level.
|
inlinenoexcept |
Get maximum X coordinate of this region.
Definition at line 487 of file quadnode.H.
References max_x.
Referenced by QuadTree::copy_tree(), QuadTree::split(), and TEST().
|
inlinenoexcept |
Get maximum Y coordinate of this region.
Definition at line 493 of file quadnode.H.
References max_y.
Referenced by QuadTree::copy_tree(), QuadTree::split(), and TEST().
|
inlinenoexcept |
Get midpoint X coordinate.
Definition at line 502 of file quadnode.H.
Referenced by QuadTree::split().
|
inlinenoexcept |
Get midpoint Y coordinate.
Definition at line 505 of file quadnode.H.
Referenced by QuadTree::split().
|
inlinenoexcept |
Get minimum X coordinate of this region.
Definition at line 484 of file quadnode.H.
References min_x.
Referenced by QuadTree::copy_tree(), QuadTree::split(), and TEST().
|
inlinenoexcept |
Get minimum Y coordinate of this region.
Definition at line 490 of file quadnode.H.
References min_y.
Referenced by QuadTree::copy_tree(), QuadTree::split(), and TEST().
|
inlinenoexcept |
Get reference to NE child (for reading/writing via NE_CHILD macro).
Definition at line 366 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 560 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching(), East, get_east_neighbor(), get_neighbors_by_side(), get_north_neighbor(), get_south_neighbor(), get_west_neighbor(), 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::blossom_maximum_cardinality_matching(), East, get_neighbors_by_side(), is_leaf(), 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 Aleph::blossom_maximum_cardinality_matching(), get_north_neighbor(), is_leaf(), 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 478 of file quadnode.H.
References count_points().
Referenced by TEST().
|
inlinenoexcept |
Get reference to NW child (for reading/writing via NW_CHILD macro).
Definition at line 363 of file quadnode.H.
References nw_child.
|
inlinenoexcept |
Get reference to parent node (for reading/writing via PARENT macro).
Definition at line 360 of file quadnode.H.
References parent.
Get reference to the points list (for direct manipulation).
Definition at line 580 of file quadnode.H.
References points.
Referenced by QuadTree::contains_only(), 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 372 of file quadnode.H.
References se_child.
Find the southern neighbor of a node.
Definition at line 183 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching(), get_south_neighbor(), is_leaf(), 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 369 of file quadnode.H.
References sw_child.
Find the western neighbor of a node.
Definition at line 227 of file quadnode.H.
References Aleph::blossom_maximum_cardinality_matching(), get_west_neighbor(), is_leaf(), 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 381 of file quadnode.H.
References color.
Referenced by QuadTree::contains_only(), demo_traversal(), get_east_neighbor(), get_neighbors_by_side(), get_north_neighbor(), get_south_neighbor(), get_west_neighbor(), QuadTree::join(), QuadTree::remove(), QuadTree::search(), QuadTree::search_container_node(), QuadTree::split(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Check if this node is the NE child of its parent.
Definition at line 392 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the NW child of its parent.
Definition at line 384 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the SE child of its parent.
Definition at line 408 of file quadnode.H.
|
inlinenoexcept |
Check if this node is the SW child of its parent.
Definition at line 400 of file quadnode.H.
Remove a point from this node.
| p | Point to remove |
Definition at line 529 of file quadnode.H.
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 514 of file quadnode.H.
References points.
Referenced by QuadTree::search(), QuadTree::search_container_node(), and TEST().
|
inline |
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 |
| std::domain_error | if either interval is empty or reversed |
Definition at line 345 of file quadnode.H.
References ah_domain_error_if, Aleph::blossom_maximum_cardinality_matching(), max_x, max_y, min_x, and min_y.
Referenced by TEST().
|
private |
Node state (White/Gray/Black)
Definition at line 151 of file quadnode.H.
Referenced by add_point(), empty(), get_color(), is_leaf(), and remove_point().
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 QuadNode(), 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 QuadNode(), 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 QuadNode(), 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 QuadNode(), 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().