![]() |
ProtoTracer
1.0
Real-time 3D rendering and animation engine
|
Represents a node in a quadtree structure for spatial partitioning. More...
#include <Node.h>
Public Member Functions | |
Node (const Vector2D &min, const Vector2D &max) | |
Constructs a Node with specified bounds. | |
~Node () | |
Destructor for the Node class. | |
BoundingBox2D * | GetBBox () |
Retrieves the bounding box of the node. | |
Node * | GetChildNodes () |
Retrieves the child nodes of this node. | |
Triangle2D ** | GetEntities () |
Retrieves the entities contained in this node. | |
uint16_t | GetCount () |
Retrieves the current count of entities in the node. | |
void | Expand (uint16_t newCount) |
Expands the node's capacity to accommodate more entities. | |
bool | Insert (Triangle2D *triangle) |
Inserts a triangle entity into the node. | |
void | Subdivide (uint8_t depth=0) |
Subdivides the node into child nodes if needed. | |
bool | IsLeaf () |
Checks if the node is a leaf node (i.e., has no child nodes). | |
Private Member Functions | |
void | CreateChildNodes () |
Creates child nodes for this node. | |
uint16_t | DistributeEntities () |
Distributes entities to child nodes after subdivision. | |
bool | ShouldSubdivide (uint16_t childEntitySum) |
Determines whether the node should be subdivided. | |
Private Attributes | |
uint16_t | count = 0 |
Current number of entities in the node. | |
uint16_t | capacity = 0 |
Capacity of entities allocated in the node. | |
Node * | childNodes = nullptr |
Pointer to the child nodes of this node. | |
Triangle2D ** | entities = nullptr |
Array of entities (triangles) contained in the node. | |
BoundingBox2D | bbox |
Bounding box defining the spatial area of this node. | |
Static Private Attributes | |
static const uint16_t | maxEntities = 8 |
Maximum number of entities a node can hold before subdividing. | |
static const uint8_t | maxDepth = 8 |
Maximum depth of the quadtree. | |
Represents a node in a quadtree structure for spatial partitioning.
~Node | ( | ) |
Destructor for the Node class.
Definition at line 7 of file Node.cpp.
References childNodes, and entities.
|
private |
Creates child nodes for this node.
Definition at line 73 of file Node.cpp.
References bbox, childNodes, BoundingBox2D::GetCenter(), BoundingBox2D::GetMaximum(), BoundingBox2D::GetMinimum(), Vector2D::X, and Vector2D::Y.
Referenced by Subdivide().
|
private |
Distributes entities to child nodes after subdivision.
Definition at line 82 of file Node.cpp.
References childNodes, count, entities, and Insert().
Referenced by Subdivide().
BoundingBox2D * GetBBox | ( | ) |
Retrieves the bounding box of the node.
Definition at line 14 of file Node.cpp.
References bbox.
Referenced by QuadTree::Intersect().
Node * GetChildNodes | ( | ) |
Retrieves the child nodes of this node.
Definition at line 18 of file Node.cpp.
References childNodes.
Referenced by QuadTree::Intersect().
uint16_t GetCount | ( | ) |
Retrieves the current count of entities in the node.
Definition at line 26 of file Node.cpp.
References count.
Referenced by Rasterizer::Rasterize().
Triangle2D ** GetEntities | ( | ) |
Retrieves the entities contained in this node.
Definition at line 22 of file Node.cpp.
References entities.
Referenced by Rasterizer::Rasterize().
bool Insert | ( | Triangle2D * | triangle | ) |
Inserts a triangle entity into the node.
triangle | Pointer to the Triangle2D entity to be inserted. |
Definition at line 43 of file Node.cpp.
References bbox, capacity, count, Triangle2D::DidIntersect(), entities, Expand(), and maxEntities.
Referenced by DistributeEntities(), and QuadTree::Insert().
bool IsLeaf | ( | ) |
Checks if the node is a leaf node (i.e., has no child nodes).
Definition at line 69 of file Node.cpp.
References childNodes.
Referenced by QuadTree::Intersect().
Determines whether the node should be subdivided.
childEntitySum | Total number of entities in child nodes. |
Definition at line 98 of file Node.cpp.
References count.
Referenced by Subdivide().
Subdivides the node into child nodes if needed.
depth | Current depth of the node in the quadtree. |
Definition at line 54 of file Node.cpp.
References childNodes, count, CreateChildNodes(), DistributeEntities(), maxDepth, maxEntities, ShouldSubdivide(), and Subdivide().
Referenced by QuadTree::Rebuild(), and Subdivide().
|
private |
Bounding box defining the spatial area of this node.
Definition at line 31 of file Node.h.
Referenced by CreateChildNodes(), GetBBox(), and Insert().
|
private |
Pointer to the child nodes of this node.
Definition at line 29 of file Node.h.
Referenced by CreateChildNodes(), DistributeEntities(), GetChildNodes(), IsLeaf(), Subdivide(), and ~Node().
|
private |
Current number of entities in the node.
Definition at line 27 of file Node.h.
Referenced by DistributeEntities(), Expand(), GetCount(), Insert(), ShouldSubdivide(), and Subdivide().
|
private |
Array of entities (triangles) contained in the node.
Definition at line 30 of file Node.h.
Referenced by DistributeEntities(), Expand(), GetEntities(), Insert(), and ~Node().
Maximum number of entities a node can hold before subdividing.
Definition at line 25 of file Node.h.
Referenced by Insert(), and Subdivide().