GBE::GDynamicGeneratorOctreeNode Class Reference

The generation space is structured with octrees. More...

#include <GDynamicGeneratorAgent.cpp>

Collaboration diagram for GBE::GDynamicGeneratorOctreeNode:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GDynamicGeneratorOctreeNode (QDomElement data, unsigned long rand_seed, const GCS::GVector3 &position, double segment_size)
 ~GDynamicGeneratorOctreeNode ()
void initFromData ()
unsigned long getRandomSeed ()
GCS::GVector3 getPosition ()
double getSegmentSize ()
bool isPositionInsideNode (const GCS::GVector3 &position)
bool isAreaInsideNode (const GVector3 &position, double radius)
bool touchesArea (const GCS::GVector3 &position, double radius)
void setGenerated ()
bool isGenerated ()
QList< GDynamicGeneratorOctreeNode * > getChildNodes ()
bool isNodeExpanded ()
bool expandNode (Util::PseudoRNG &rng)
void reduceNode ()
void reduceGenerated (bool recursive=true)
GDynamicGeneratorOctreeNodegetChildNodeForPosition (const GCS::GVector3 &position)
QList< GDynamicGeneratorOctreeNode * > getChildNodesForArea (const GCS::GVector3 &position, double radius)
GCS::GVector3 getRandomPositionInCube (Util::PseudoRNG &rng)

Protected Attributes

QDomElement Data
unsigned long RandomSeed
GCS::GVector3 Position
double SegmentSize
bool Generated
GDynamicGeneratorOctreeNodeChildren [8]

Detailed Description

The generation space is structured with octrees.

Author:
Raphael Langerhorst Basically a node serves three purposes: 1) It serves as starting point for generating all child nodes in the nodes area, 2) it stores the seed value for the pseudo RNG to generate the child nodes and 3) it stores the size of the area in which a child element would potentially be created.


Constructor & Destructor Documentation

GBE::GDynamicGeneratorOctreeNode::GDynamicGeneratorOctreeNode ( QDomElement  data,
unsigned long  rand_seed,
const GCS::GVector3 position,
double  segment_size 
)

Constructor.

GBE::GDynamicGeneratorOctreeNode::~GDynamicGeneratorOctreeNode (  ) 

Destructor, deletes all child nodes.


Member Function Documentation

bool GBE::GDynamicGeneratorOctreeNode::expandNode ( Util::PseudoRNG &  rng  ) 

Creates all 8 child nodes for this octree node.

Parameters:
rng specifies the random number generator to use.
Returns:
true when all child nodes have been successfully created.

false on out of memory errors.

GDynamicGeneratorOctreeNode * GBE::GDynamicGeneratorOctreeNode::getChildNodeForPosition ( const GCS::GVector3 position  ) 

Returns:
the child node of this octree node that covers given position.

NULL if position is completely outside of this node!

Todo:
write a test case for this.

QList< GDynamicGeneratorOctreeNode * > GBE::GDynamicGeneratorOctreeNode::getChildNodes (  ) 

Returns:
a pointer list with all child nodes.

QList< GDynamicGeneratorOctreeNode * > GBE::GDynamicGeneratorOctreeNode::getChildNodesForArea ( const GCS::GVector3 position,
double  radius 
)

Returns:
all child nodes that cover part of given area;
Todo:
write a test case for this.

GVector3 GBE::GDynamicGeneratorOctreeNode::getPosition (  ) 

Returns:
the position of this node.

GVector3 GBE::GDynamicGeneratorOctreeNode::getRandomPositionInCube ( Util::PseudoRNG &  rng  ) 

Returns:
a deterministic random position based on RandomSeed inside this node's cube.

unsigned long GBE::GDynamicGeneratorOctreeNode::getRandomSeed (  ) 

Returns:
the seed for the RNG for this node.

double GBE::GDynamicGeneratorOctreeNode::getSegmentSize (  ) 

Returns:
the segment size of the enclosing node cube.

void GBE::GDynamicGeneratorOctreeNode::initFromData (  ) 

Reads the random seed from the element data. The random seed is stored in the rs attribute. Additionally all child nodes are initialized from element data as well.

This is the usual procedure when reinitializing an element that is opend - or woken - from the persistent storage.

bool GBE::GDynamicGeneratorOctreeNode::isAreaInsideNode ( const GVector3 position,
double  radius 
)

Returns:
true when given area is enclosed by the cube of this octree node.

bool GBE::GDynamicGeneratorOctreeNode::isGenerated (  ) 

Returns:
true when an element was already created at this node position.
See also:
Generated

bool GBE::GDynamicGeneratorOctreeNode::isNodeExpanded (  ) 

Returns:
true when child nodes are created (so they are in memory).

bool GBE::GDynamicGeneratorOctreeNode::isPositionInsideNode ( const GCS::GVector3 position  ) 

Returns:
true when given position is inside the cube of this octree node.

void GBE::GDynamicGeneratorOctreeNode::reduceGenerated ( bool  recursive = true  ) 

Reduces all child nodes that have been used for element creation (isGenerated()==true)

void GBE::GDynamicGeneratorOctreeNode::reduceNode (  ) 

Deletes all child nodes.

void GBE::GDynamicGeneratorOctreeNode::setGenerated (  ) 

Sets Generated to true.

See also:
Generated

bool GBE::GDynamicGeneratorOctreeNode::touchesArea ( const GCS::GVector3 position,
double  radius 
)

Returns:
true when given area touches the cube of this octree node.


Member Data Documentation

GDynamicGeneratorOctreeNode* GBE::GDynamicGeneratorOctreeNode::Children[8] [protected]

Array of child nodes. Seen FROM positive y: the first four are the first four (mathematical) quadrants and the second four children are the last four quadrants.

QDomElement GBE::GDynamicGeneratorOctreeNode::Data [protected]

Each octreee node directly has access to its data in the element data document. This makes fast updates easily possible. In particular the element data can be kept in sync with the octree with low overhead.

bool GBE::GDynamicGeneratorOctreeNode::Generated [protected]

Set to true when this node is an end node and the element for this node has been created. If this node is not an end node but all child nodes have been used for creating elements then this is also set to true.

This means that if Generated is set to true then the whole cubic area this node covers had been generated. Thus it is possible to reduce nodes and save memory. In the end, when the whole element was created, there will be only one node left: the top node, and its Generated attribute will be set to true.

GCS::GVector3 GBE::GDynamicGeneratorOctreeNode::Position [protected]

The position relative to the element centre.

Todo:
it should somehow be possible to respond to radius changes of the element's form.

unsigned long GBE::GDynamicGeneratorOctreeNode::RandomSeed [protected]

The RNG seed number for this node. THIS is the actual data we need for child generation at the node's position.

double GBE::GDynamicGeneratorOctreeNode::SegmentSize [protected]

Segment size of the enclosing cube. This value is both required to generate positions and sizes of child nodes as well as to be able to "randomly" place the created child element somewhere in this cube. If this second functionality were not given, a randomly created element content (=children of one specific element) could look like a grid.

See also:
Position


The documentation for this class was generated from the following file:
Generated on Thu Nov 16 07:49:19 2006 for G System by  doxygen 1.4.7