NL3D::CBSPTree< T >::CBSPNode Class Reference

template<class T>
class NL3D::CBSPTree< T >::CBSPNode


Public Member Functions

 CBSPNode (NLMISC::CTriangle &tri, T &val)
sint32 getNbNode ()
void insert (NLMISC::CTriangle &tri, T &val)
void select (std::vector< CBSPNode * > &sel, CVector &v1, CVector &v2)
 ~CBSPNode ()

Data Fields

Value

Private Attributes

CPlane p
CBSPNodepBack
CBSPNodepFront

Constructor & Destructor Documentation

template<class T>
NL3D::CBSPTree< T >::CBSPNode::CBSPNode NLMISC::CTriangle tri,
T &  val
[inline]
 

Definition at line 87 of file bsp_tree.h.

References NLMISC::CPlane::make(), NLMISC::CPlane::normalize(), NL3D::CBSPTree< T >::CBSPNode::p, NL3D::CBSPTree< T >::CBSPNode::pBack, NL3D::CBSPTree< T >::CBSPNode::pFront, NLMISC::CTriangle::V0, NLMISC::CTriangle::V1, and NLMISC::CTriangle::V2.

Referenced by NL3D::CBSPTree< T >::CBSPNode::insert().

00087                                                          : Value(val), pBack(NULL), pFront(NULL) 
00088                 {
00089                         p.make( tri.V0, tri.V1, tri.V2 );
00090                         p.normalize();
00091                 }

template<class T>
NL3D::CBSPTree< T >::CBSPNode::~CBSPNode  )  [inline]
 

Definition at line 93 of file bsp_tree.h.

References NL3D::CBSPTree< T >::CBSPNode::pBack, and NL3D::CBSPTree< T >::CBSPNode::pFront.

00094                 {
00095                         if( pBack != NULL )
00096                                 delete pBack;
00097                         if( pFront != NULL )
00098                                 delete pFront;
00099                 }


Member Function Documentation

template<class T>
sint32 NL3D::CBSPTree< T >::CBSPNode::getNbNode  )  [inline]
 

Definition at line 163 of file bsp_tree.h.

References NL3D::CBSPTree< T >::CBSPNode::pBack, NL3D::CBSPTree< T >::CBSPNode::pFront, and sint32.

Referenced by NL3D::CBSPTree< T >::getNbNode().

00164                 {
00165                         sint32 nBack = 0, nFront= 0;
00166                         if( pBack != NULL )
00167                                 nBack = pBack->getNbNode();
00168                         if( pFront != NULL )
00169                                 nFront = pFront->getNbNode();
00170                         return 1+nBack+nFront;
00171                 }

template<class T>
void NL3D::CBSPTree< T >::CBSPNode::insert NLMISC::CTriangle tri,
T &  val
[inline]
 

Definition at line 101 of file bsp_tree.h.

References NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CBSPTree< T >::CBSPNode::p, NL3D::CBSPTree< T >::CBSPNode::pBack, NL3D::CBSPTree< T >::CBSPNode::pFront, NLMISC::CTriangle::V0, NLMISC::CTriangle::V1, and NLMISC::CTriangle::V2.

Referenced by NL3D::CBSPTree< T >::insert().

00102                 {
00103                         float   f[3];
00104                         CBSPNode *pCurrent = this;
00105 
00106                         while( true )
00107                         {
00108                                 f[0] = pCurrent->p*tri.V0;
00109                                 f[1] = pCurrent->p*tri.V1,
00110                                 f[2] = pCurrent->p*tri.V2;
00111                                 if( fabs( f[0] ) < 0.00001 ) f[0] = 0.0f;
00112                                 if( fabs( f[1] ) < 0.00001 ) f[1] = 0.0f;
00113                                 if( fabs( f[2] ) < 0.00001 ) f[2] = 0.0f;
00114                                 if( ( f[0] >= 0.0f ) && ( f[1] >= 0.0f ) && ( f[2] >= 0.0f ) )
00115                                 {       // All front
00116                                         if( pCurrent->pFront == NULL )
00117                                         {
00118                                                 pCurrent->pFront = new CBSPNode( tri, val );
00119                                                 return;
00120                                         }
00121                                         else
00122                                         {
00123                                                 pCurrent = pCurrent->pFront;
00124                                         }
00125                                 }
00126                                 else
00127                                 if( ( f[0] <= 0.0f ) && ( f[1] <= 0.0f ) && ( f[2] <= 0.0f ) )
00128                                 {       // All back
00129                                         if( pCurrent->pBack == NULL )
00130                                         {
00131                                                 pCurrent->pBack = new CBSPNode( tri, val );
00132                                                 return;
00133                                         }
00134                                         else
00135                                         {
00136                                                 pCurrent = pCurrent->pBack;
00137                                         }
00138                                 }
00139                                 else
00140                                 {
00141                                         if( pCurrent->pFront == NULL )
00142                                         {
00143                                                 pCurrent->pFront = new CBSPNode( tri, val );
00144                                         }
00145                                         else
00146                                         {
00147                                                 pCurrent->pFront->insert( tri, val );
00148                                         }
00149                                         if( pCurrent->pBack == NULL )
00150                                         {
00151                                                 pCurrent->pBack = new CBSPNode( tri, val );
00152                                         }
00153                                         else
00154                                         {
00155                                                 pCurrent->pBack->insert( tri, val );
00156                                         }
00157                                         return;
00158                                 }
00159                         }
00160                 }

template<class T>
void NL3D::CBSPTree< T >::CBSPNode::select std::vector< CBSPNode * > &  sel,
CVector v1,
CVector v2
[inline]
 

Definition at line 174 of file bsp_tree.h.

References NL3D::CBSPTree< T >::CBSPNode::p, NL3D::CBSPTree< T >::CBSPNode::pBack, and NL3D::CBSPTree< T >::CBSPNode::pFront.

Referenced by NL3D::CBSPTree< T >::select().

00175                 {
00176                         float   f[2];
00177                         CBSPNode *pCurrent = this;
00178 
00179                         while( true )
00180                         {
00181                                 f[0] = pCurrent->p*v1;
00182                                 f[1] = pCurrent->p*v2;
00183                                 if( fabs( f[0] ) < 0.00001 ) f[0] = 0.0;
00184                                 if( fabs( f[1] ) < 0.00001 ) f[1] = 0.0;
00185                                 if( ( f[0] >= 0.0 ) && ( f[1] >= 0.0 ) )
00186                                 {       // All front
00187                                         if( pCurrent->pFront == NULL )
00188                                         {
00189                                                 return;
00190                                         }
00191                                         else
00192                                         {
00193                                                 pCurrent = pCurrent->pFront;
00194                                         }
00195                                 }
00196                                 else
00197                                 if( ( f[0] <= 0.0 ) && ( f[1] <= 0.0 ) )
00198                                 {       // All back
00199                                         if( pCurrent->pBack == NULL )
00200                                         {
00201                                                 return;
00202                                         }
00203                                         else
00204                                         {
00205                                                 pCurrent = pCurrent->pBack;
00206                                         }
00207                                 }
00208                                 else
00209                                 {
00210                                         if( sel.size() == sel.capacity() )
00211                                                 sel.reserve( sel.size() + 64 );
00212                                         sel.push_back( this );
00213                                         if( pCurrent->pFront == NULL )
00214                                         {
00215                                         }
00216                                         else
00217                                         {
00218                                                 //CVector newV1 = v1;
00219                                                 //CVector newV2 = v2;
00220                                                 //pCurrent->p.clipSegmentFront( newV1, newV2 );
00221                                                 //pCurrent->pFront->select( sel, newV1, newV2 );
00222                                                 pCurrent->pFront->select( sel, v1, v2 );
00223                                         }
00224                                         if( pCurrent->pBack == NULL )
00225                                         {
00226                                         }
00227                                         else
00228                                         {
00229                                                 //CVector newV1 = v1;
00230                                                 //CVector newV2 = v2;
00231                                                 //pCurrent->p.clipSegmentBack( newV1, newV2 );
00232                                                 //pCurrent->pBack->select( sel, newV1, newV2 );
00233                                                 pCurrent->pBack->select( sel, v1, v2 );                                         
00234                                         }
00235                                         return;
00236                                 }
00237                         }
00238                 }


Field Documentation

template<class T>
CPlane NL3D::CBSPTree< T >::CBSPNode::p [private]
 

Definition at line 79 of file bsp_tree.h.

Referenced by NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CBSPTree< T >::CBSPNode::insert(), and NL3D::CBSPTree< T >::CBSPNode::select().

template<class T>
CBSPNode* NL3D::CBSPTree< T >::CBSPNode::pBack [private]
 

Definition at line 78 of file bsp_tree.h.

Referenced by NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CBSPTree< T >::CBSPNode::getNbNode(), NL3D::CBSPTree< T >::CBSPNode::insert(), NL3D::CBSPTree< T >::CBSPNode::select(), and NL3D::CBSPTree< T >::CBSPNode::~CBSPNode().

template<class T>
CBSPNode * NL3D::CBSPTree< T >::CBSPNode::pFront [private]
 

Definition at line 78 of file bsp_tree.h.

Referenced by NL3D::CBSPTree< T >::CBSPNode::CBSPNode(), NL3D::CBSPTree< T >::CBSPNode::getNbNode(), NL3D::CBSPTree< T >::CBSPNode::insert(), NL3D::CBSPTree< T >::CBSPNode::select(), and NL3D::CBSPTree< T >::CBSPNode::~CBSPNode().

template<class T>
T NL3D::CBSPTree< T >::CBSPNode::Value
 

Definition at line 83 of file bsp_tree.h.


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 06:44:41 2004 for NeL by doxygen 1.3.6