NLPACS::CQuadBranch Class Reference

#include <surface_quad.h>

Inheritance diagram for NLPACS::CQuadBranch:

NLPACS::IQuadNode

Public Types

enum  { NoChild = 0, LeafChild, BranchChild }

Public Member Functions

void addVertex (const NLMISC::CVector &v)
bool check () const
 CQuadBranch (uint8 level=0)
 CQuadBranch (const CQuadBranch &branch)
virtual NLMISC::CAABBox getBBox () const
const IQuadNodegetChild (uint child) const
virtual uint8 getLevel () const
virtual float getMaxHeight () const
virtual float getMinHeight () const
bool isLeaf () const
CQuadBranchoperator= (const CQuadBranch &branch)
void serial (NLMISC::IStream &f)
void setChild (uint child, IQuadNode *node)
void translate (const NLMISC::CVector &translation)
 ~CQuadBranch ()

Protected Member Functions

void reduceChildren ()

Protected Attributes

IQuadNode_Children [4]
float _HalfSize
uint8 _Level
float _MaxHeight
float _MaxThickness
float _MinHeight
float _XCenter
float _YCenter

Friends

class CQuadBranch
class CQuadLeaf
class CSurfaceQuadTree

Member Enumeration Documentation

anonymous enum
 

Enumeration values:
NoChild 
LeafChild 
BranchChild 

Definition at line 108 of file surface_quad.h.

00109         {
00110                 NoChild = 0,
00111                 LeafChild,
00112                 BranchChild
00113         };


Constructor & Destructor Documentation

NLPACS::CQuadBranch::CQuadBranch const CQuadBranch branch  ) 
 

Definition at line 142 of file surface_quad.cpp.

Referenced by addVertex(), operator=(), and serial().

00142                                                               : NLPACS::IQuadNode(branch)
00143 {
00144         *this = branch;
00145 }

NLPACS::CQuadBranch::CQuadBranch uint8  level = 0  )  [inline]
 

Definition at line 125 of file surface_quad.h.

References _Children, level, uint, and uint8.

00125 : IQuadNode(level) { uint i; for (i=0; i<4; ++i) _Children[i] = NULL; }

NLPACS::CQuadBranch::~CQuadBranch  )  [inline]
 

Definition at line 126 of file surface_quad.h.

References _Children, and uint.

00126 { uint i; for (i=0; i<4; ++i) delete _Children[i]; }


Member Function Documentation

void NLPACS::CQuadBranch::addVertex const NLMISC::CVector v  )  [virtual]
 

Reimplemented from NLPACS::IQuadNode.

Definition at line 197 of file surface_quad.cpp.

References _Children, NLPACS::IQuadNode::_HalfSize, NLPACS::IQuadNode::_MaxHeight, NLPACS::IQuadNode::_MaxThickness, NLPACS::IQuadNode::_MinHeight, NLPACS::IQuadNode::_XCenter, NLPACS::IQuadNode::_YCenter, NLPACS::IQuadNode::addVertex(), CQuadBranch(), NLPACS::IQuadNode::CQuadLeaf, uint, and v.

00198 {
00199         IQuadNode::addVertex(v);
00200         uint    child;
00201         if (v.x > _XCenter)
00202                 child = (v.y > _YCenter) ? 2 : 1;
00203         else
00204                 child = (v.y > _YCenter) ? 3 : 0;
00205 
00206         if (_Children[child] == NULL)
00207         {
00208                 if (_Level == 2)
00209                 {
00210                         _Children[child] = new CQuadLeaf(_Level-1);
00211                 }
00212                 else
00213                 {
00214                         _Children[child] = new CQuadBranch(_Level-1);
00215                 }
00216 
00217                 _Children[child]->_MaxThickness = _MaxThickness;
00218                 _Children[child]->_HalfSize = _HalfSize/2.0f;
00219                 _Children[child]->_MinHeight = FLT_MAX;
00220                 _Children[child]->_MaxHeight = -FLT_MAX;
00221                 _Children[child]->_XCenter = _XCenter+_Children[child]->_HalfSize*((child == 1 || child == 2) ? 1.0f : -1.0f);
00222                 _Children[child]->_YCenter = _YCenter+_Children[child]->_HalfSize*((child == 2 || child == 3) ? 1.0f : -1.0f);
00223         }
00224 
00225         _Children[child]->addVertex(v);
00226 }

bool NLPACS::CQuadBranch::check  )  const [virtual]
 

Reimplemented from NLPACS::IQuadNode.

Definition at line 228 of file surface_quad.cpp.

References _Children, NLPACS::IQuadNode::check(), and uint.

00229 {
00230         if (!IQuadNode::check())
00231                 return false;
00232 
00233         uint    child;
00234         for (child=0; child<4; ++child)
00235                 if (_Children[child] != NULL && !_Children[child]->check())
00236                         return false;
00237         return true;
00238 }

virtual NLMISC::CAABBox NLPACS::IQuadNode::getBBox  )  const [inline, virtual, inherited]
 

Definition at line 62 of file surface_quad.h.

References NLPACS::IQuadNode::_HalfSize, NLPACS::IQuadNode::_XCenter, NLPACS::IQuadNode::_YCenter, NLMISC::CAABBox::setCenter(), and NLMISC::CAABBox::setHalfSize().

Referenced by NLPACS::CSurfaceQuadTree::getInterpZ(), and NLPACS::CSurfaceQuadTree::getLeaf().

00063         {
00064                 NLMISC::CAABBox bbox;
00065                 bbox.setCenter(NLMISC::CVector(_XCenter, _YCenter, 0.0f));
00066                 bbox.setHalfSize(NLMISC::CVector(_HalfSize, _HalfSize, 10000.0f));
00067                 return bbox;
00068         }

const IQuadNode* NLPACS::CQuadBranch::getChild uint  child  )  const [inline, virtual]
 

Implements NLPACS::IQuadNode.

Definition at line 129 of file surface_quad.h.

References _Children, nlerror, and uint.

00130         {
00131                 if (child > 3)  nlerror("Can't access child %d on the branch", child);
00132                 return _Children[child];
00133         }

virtual uint8 NLPACS::IQuadNode::getLevel  )  const [inline, virtual, inherited]
 

Definition at line 55 of file surface_quad.h.

References uint8.

00055 { return _Level; }

virtual float NLPACS::IQuadNode::getMaxHeight  )  const [inline, virtual, inherited]
 

Definition at line 54 of file surface_quad.h.

References NLPACS::IQuadNode::_MaxHeight.

Referenced by NLPACS::CSurfaceQuadTree::compile(), NLPACS::CLocalRetriever::getHeight(), and reduceChildren().

00054 { return _MaxHeight; }

virtual float NLPACS::IQuadNode::getMinHeight  )  const [inline, virtual, inherited]
 

Definition at line 53 of file surface_quad.h.

References NLPACS::IQuadNode::_MinHeight.

Referenced by NLPACS::CSurfaceQuadTree::compile(), NLPACS::CLocalRetriever::getHeight(), and reduceChildren().

00053 { return _MinHeight; }

bool NLPACS::CQuadBranch::isLeaf  )  const [inline, virtual]
 

Implements NLPACS::IQuadNode.

Definition at line 128 of file surface_quad.h.

00128 { return false; }

NLPACS::CQuadBranch & NLPACS::CQuadBranch::operator= const CQuadBranch branch  ) 
 

Definition at line 147 of file surface_quad.cpp.

References _Children, CQuadBranch(), NLPACS::IQuadNode::CQuadLeaf, NLPACS::IQuadNode::isLeaf(), and uint.

00148 {
00149         IQuadNode::operator=(branch);
00150 
00151         uint    child;
00152         for (child=0; child<4; ++child)
00153         {
00154                 _Children[child] = NULL;
00155                 if (branch._Children[child] != NULL)
00156                 {
00157                         if (branch._Children[child]->isLeaf())
00158                         {
00159                                 CQuadLeaf       *newLeaf = new CQuadLeaf();
00160                                 *newLeaf = *((CQuadLeaf *)(branch._Children[child]));
00161                                 _Children[child] = newLeaf;
00162                         }
00163                         else
00164                         {
00165                                 CQuadBranch     *newBranch = new CQuadBranch();
00166                                 *newBranch = *((CQuadBranch *)(branch._Children[child]));
00167                                 _Children[child] = newBranch;
00168                         }
00169                 }
00170         }
00171         return *this;
00172 }

void NLPACS::CQuadBranch::reduceChildren  )  [protected]
 

Definition at line 174 of file surface_quad.cpp.

References _Children, NLPACS::IQuadNode::CQuadLeaf, NLPACS::IQuadNode::getMaxHeight(), NLPACS::IQuadNode::getMinHeight(), NLPACS::IQuadNode::isLeaf(), and uint.

00175 {
00176         uint    i;
00177 
00178         for (i=0; i<4; ++i)
00179         {
00180                 if (_Children[i] != NULL &&
00181                         !_Children[i]->isLeaf() &&
00182                         _Children[i]->getMaxHeight()-_Children[i]->getMinHeight() <= _MaxThickness)
00183                 {
00184                         CQuadLeaf       *leaf = new CQuadLeaf();
00185                         *((IQuadNode *)leaf) = *_Children[i];
00186                         delete _Children[i];
00187                         _Children[i] = leaf;
00188                 }
00189                 else if (_Children[i] != NULL &&
00190                                  !_Children[i]->isLeaf())
00191                 {
00192                         ((CQuadBranch *)_Children[i])->reduceChildren();
00193                 }
00194         }
00195 }

void NLPACS::CQuadBranch::serial NLMISC::IStream f  )  [virtual]
 

Reimplemented from NLPACS::IQuadNode.

Definition at line 246 of file surface_quad.cpp.

References _Children, BranchChild, CQuadBranch(), NLPACS::IQuadNode::CQuadLeaf, NLPACS::IQuadNode::isLeaf(), NLMISC::IStream::isReading(), LeafChild, nlerror, NoChild, NLPACS::CQuadLeaf::serial(), NLMISC::IStream::serial(), uint, and uint8.

Referenced by NLPACS::CSurfaceQuadTree::serial().

00247 {
00248         IQuadNode::serial(f);
00249 
00250         uint    child;
00251         for (child=0; child<4; ++child)
00252         {
00253                 uint8   childType = 0;
00254 
00255                 if (f.isReading())
00256                 {
00257                         CQuadLeaf       *leaf; 
00258                         CQuadBranch     *branch;
00259                         f.serial(childType);
00260                         switch (childType)
00261                         {
00262                         case NoChild:
00263                                 _Children[child] = NULL;
00264                                 break;
00265                         case LeafChild:
00266                                 leaf = new CQuadLeaf(); 
00267                                 _Children[child] = leaf;
00268                                 leaf->serial(f);
00269                                 break;
00270                         case BranchChild:
00271                                 branch = new CQuadBranch();;
00272                                 _Children[child] = branch;
00273                                 branch->serial(f);
00274                                 break;
00275                         default:
00276                                 nlerror("While serializing (read) CQuadBranch: unknown child type");
00277                                 break;
00278                         }
00279                 }
00280                 else
00281                 {
00282                         if (_Children[child] == NULL)
00283                         {
00284                                 childType = NoChild;
00285                                 f.serial(childType);
00286                         }
00287                         else
00288                         {
00289                                 childType = (_Children[child]->isLeaf()) ? LeafChild : BranchChild;
00290                                 f.serial(childType);
00291                                 _Children[child]->serial(f);
00292                         }
00293                 }
00294         }
00295 }

void NLPACS::CQuadBranch::setChild uint  child,
IQuadNode node
[inline]
 

Definition at line 134 of file surface_quad.h.

References _Children, nlerror, and uint.

00135         {
00136                 if (child > 3)  nlerror("Can't set child %d on the branch", child);
00137                 _Children[child] = node;
00138         }

void NLPACS::CQuadBranch::translate const NLMISC::CVector translation  )  [inline, virtual]
 

Reimplemented from NLPACS::IQuadNode.

Definition at line 142 of file surface_quad.h.

References _Children, NLPACS::IQuadNode::translate(), and uint.

00143         {
00144                 IQuadNode::translate(translation);
00145                 uint    i;
00146                 for (i=0; i<4; ++i)
00147                         if (_Children[i] != NULL)
00148                                 _Children[i]->translate(translation);
00149         }


Friends And Related Function Documentation

friend class CQuadBranch [friend, inherited]
 

Definition at line 43 of file surface_quad.h.

friend class CQuadLeaf [friend, inherited]
 

Definition at line 42 of file surface_quad.h.

Referenced by addVertex(), operator=(), reduceChildren(), and serial().

friend class CSurfaceQuadTree [friend]
 

Reimplemented from NLPACS::IQuadNode.

Definition at line 119 of file surface_quad.h.


Field Documentation

IQuadNode* NLPACS::CQuadBranch::_Children[4] [protected]
 

Definition at line 116 of file surface_quad.h.

Referenced by addVertex(), check(), CQuadBranch(), getChild(), operator=(), reduceChildren(), serial(), setChild(), translate(), and ~CQuadBranch().

float NLPACS::IQuadNode::_HalfSize [protected, inherited]
 

Definition at line 48 of file surface_quad.h.

Referenced by addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), NLPACS::IQuadNode::getBBox(), and NLPACS::IQuadNode::serial().

uint8 NLPACS::IQuadNode::_Level [protected, inherited]
 

Definition at line 47 of file surface_quad.h.

float NLPACS::IQuadNode::_MaxHeight [protected, inherited]
 

Definition at line 44 of file surface_quad.h.

Referenced by NLPACS::IQuadNode::addVertex(), addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), NLPACS::IQuadNode::check(), NLPACS::IQuadNode::getMaxHeight(), NLPACS::IQuadNode::serial(), and NLPACS::IQuadNode::translate().

float NLPACS::IQuadNode::_MaxThickness [protected, inherited]
 

Definition at line 46 of file surface_quad.h.

Referenced by addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), and NLPACS::IQuadNode::serial().

float NLPACS::IQuadNode::_MinHeight [protected, inherited]
 

Definition at line 44 of file surface_quad.h.

Referenced by NLPACS::IQuadNode::addVertex(), addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), NLPACS::IQuadNode::check(), NLPACS::IQuadNode::getMinHeight(), NLPACS::IQuadNode::serial(), and NLPACS::IQuadNode::translate().

float NLPACS::IQuadNode::_XCenter [protected, inherited]
 

Definition at line 48 of file surface_quad.h.

Referenced by addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), NLPACS::IQuadNode::getBBox(), NLPACS::CSurfaceQuadTree::getInterpZ(), NLPACS::CSurfaceQuadTree::getLeaf(), NLPACS::IQuadNode::serial(), and NLPACS::IQuadNode::translate().

float NLPACS::IQuadNode::_YCenter [protected, inherited]
 

Definition at line 48 of file surface_quad.h.

Referenced by addVertex(), NLPACS::CSurfaceQuadTree::addVertex(), NLPACS::IQuadNode::getBBox(), NLPACS::CSurfaceQuadTree::getInterpZ(), NLPACS::CSurfaceQuadTree::getLeaf(), NLPACS::IQuadNode::serial(), and NLPACS::IQuadNode::translate().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:21:16 2004 for NeL by doxygen 1.3.6