ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Node Class Reference

Represents a node in a quadtree structure for spatial partitioning. More...

#include <Node.h>

Collaboration diagram for Node:

Public Member Functions

 Node (const Vector2D &min, const Vector2D &max)
 Constructs a Node with specified bounds.
 
 ~Node ()
 Destructor for the Node class.
 
BoundingBox2DGetBBox ()
 Retrieves the bounding box of the node.
 
NodeGetChildNodes ()
 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.
 
NodechildNodes = 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.
 

Detailed Description

Represents a node in a quadtree structure for spatial partitioning.

Definition at line 23 of file Node.h.

Constructor & Destructor Documentation

◆ Node()

Node ( const Vector2D min,
const Vector2D max 
)

Constructs a Node with specified bounds.

Parameters
minMinimum bounds of the node.
maxMaximum bounds of the node.

Definition at line 5 of file Node.cpp.

◆ ~Node()

~Node ( )

Destructor for the Node class.

Definition at line 7 of file Node.cpp.

References childNodes, and entities.

Member Function Documentation

◆ CreateChildNodes()

void CreateChildNodes ( )
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().

◆ DistributeEntities()

uint16_t DistributeEntities ( )
private

Distributes entities to child nodes after subdivision.

Returns
The number of entities successfully distributed to child nodes.

Definition at line 82 of file Node.cpp.

References childNodes, count, entities, and Insert().

Referenced by Subdivide().

◆ Expand()

void Expand ( uint16_t  newCount)

Expands the node's capacity to accommodate more entities.

Parameters
newCountNew capacity for the node.

Definition at line 30 of file Node.cpp.

References capacity, count, and entities.

Referenced by Insert().

◆ GetBBox()

BoundingBox2D * GetBBox ( )

Retrieves the bounding box of the node.

Returns
Pointer to the BoundingBox2D object.

Definition at line 14 of file Node.cpp.

References bbox.

Referenced by QuadTree::Intersect().

◆ GetChildNodes()

Node * GetChildNodes ( )

Retrieves the child nodes of this node.

Returns
Pointer to the array of child nodes.

Definition at line 18 of file Node.cpp.

References childNodes.

Referenced by QuadTree::Intersect().

◆ GetCount()

uint16_t GetCount ( )

Retrieves the current count of entities in the node.

Returns
Number of entities in the node.

Definition at line 26 of file Node.cpp.

References count.

Referenced by Rasterizer::Rasterize().

◆ GetEntities()

Triangle2D ** GetEntities ( )

Retrieves the entities contained in this node.

Returns
Pointer to the array of Triangle2D entities.

Definition at line 22 of file Node.cpp.

References entities.

Referenced by Rasterizer::Rasterize().

◆ Insert()

bool Insert ( Triangle2D triangle)

Inserts a triangle entity into the node.

Parameters
trianglePointer to the Triangle2D entity to be inserted.
Returns
True if the entity was successfully inserted, otherwise false.

Definition at line 43 of file Node.cpp.

References bbox, capacity, count, Triangle2D::DidIntersect(), entities, Expand(), and maxEntities.

Referenced by DistributeEntities(), and QuadTree::Insert().

◆ IsLeaf()

bool IsLeaf ( )

Checks if the node is a leaf node (i.e., has no child nodes).

Returns
True if the node is a leaf, otherwise false.

Definition at line 69 of file Node.cpp.

References childNodes.

Referenced by QuadTree::Intersect().

◆ ShouldSubdivide()

bool ShouldSubdivide ( uint16_t  childEntitySum)
private

Determines whether the node should be subdivided.

Parameters
childEntitySumTotal number of entities in child nodes.
Returns
True if the node should subdivide, otherwise false.

Definition at line 98 of file Node.cpp.

References count.

Referenced by Subdivide().

◆ Subdivide()

void Subdivide ( uint8_t  depth = 0)

Subdivides the node into child nodes if needed.

Parameters
depthCurrent 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().

Member Data Documentation

◆ bbox

BoundingBox2D bbox
private

Bounding box defining the spatial area of this node.

Definition at line 31 of file Node.h.

Referenced by CreateChildNodes(), GetBBox(), and Insert().

◆ capacity

uint16_t capacity = 0
private

Capacity of entities allocated in the node.

Definition at line 28 of file Node.h.

Referenced by Expand(), and Insert().

◆ childNodes

Node* childNodes = nullptr
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().

◆ count

uint16_t count = 0
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().

◆ entities

Triangle2D** entities = nullptr
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().

◆ maxDepth

const uint8_t maxDepth = 8
staticprivate

Maximum depth of the quadtree.

Definition at line 26 of file Node.h.

Referenced by Subdivide().

◆ maxEntities

const uint16_t maxEntities = 8
staticprivate

Maximum number of entities a node can hold before subdividing.

Definition at line 25 of file Node.h.

Referenced by Insert(), and Subdivide().


The documentation for this class was generated from the following files: