NL3D::CCubeGrid< TCell > Class Template Reference

#include <cube_grid.h>


Detailed Description

template<class TCell>
class NL3D::CCubeGrid< TCell >

Class used to classify elements in space around a point (good for pointlight raytracing) Elements are copied at insertion, and are duplicated at compilation along the grids. Therefore TCell should be small (ie a pointer). This constraint help because memory is much more reduced when compile is called.

Author:
Matthieu Besson

Lionel Berenguier

Nevrax France

Date:
2001

Definition at line 52 of file cube_grid.h.

Public Member Functions

 CCubeGrid ()
void compile ()
 compile the container, storing in CStaticQuadGrid.

void create (const CVector &center, int nSize)
TCell getSel ()
void insert (const NLMISC::CTriangle &tri, const TCell &cell)
bool isEndSel ()
void nextSel ()
void select (const NLMISC::CVector &v)
 ~CCubeGrid ()

Private Types

enum  gridPos {
  kUp = 0, kDown, kLeft, kRight,
  kFront, kBack
}

Private Member Functions

void project (const NLMISC::CTriangle &tri, NLMISC::CPlane pyr[4], NLMISC::CPlane &gridPlane, sint32 nGridNb, const TCell &cell)

Private Attributes

NLMISC::CVector _Center
bool _Compiled
uint _CurSel
NL3D::CQuadGrid< TCell > _Grids [6]
uint _NumSels
const TCell * _Selection
NL3D::CStaticQuadGrid< TCell > _StaticGrids [6]


Member Enumeration Documentation

template<class TCell>
enum NL3D::CCubeGrid::gridPos [private]
 

Enumeration values:
kUp 
kDown 
kLeft 
kRight 
kFront 
kBack 

Definition at line 78 of file cube_grid.h.

00078 { kUp = 0, kDown, kLeft, kRight, kFront, kBack };


Constructor & Destructor Documentation

template<class TCell>
NL3D::CCubeGrid< TCell >::CCubeGrid  ) 
 

Definition at line 109 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_Grids, NL3D::CQuadGrid< TCell >::changeBase(), NLMISC::CMatrix::identity(), NL3D::CCubeGrid< TCell >::kBack, NL3D::CCubeGrid< TCell >::kDown, NL3D::CCubeGrid< TCell >::kFront, NL3D::CCubeGrid< TCell >::kLeft, NL3D::CCubeGrid< TCell >::kRight, and NLMISC::CMatrix::setRot().

00110 {
00111         NLMISC::CMatrix tmp;
00112         NLMISC::CVector I, J, K;
00113 
00114         // grids[kUp].changeBase(  );
00115         I = NLMISC::CVector(  1,  0,  0 );
00116         J = NLMISC::CVector(  0, -1,  0 );
00117         K = NLMISC::CVector(  0,  0, -1 );
00118         tmp.identity(); tmp.setRot( I, J, K, true );
00119         _Grids[kDown].changeBase( tmp );
00120 
00121         I = NLMISC::CVector(  0,  0,  1 );
00122         J = NLMISC::CVector(  0,  1,  0 );
00123         K = NLMISC::CVector( -1,  0,  0 );
00124         tmp.identity(); tmp.setRot( I, J, K, true);
00125         _Grids[kLeft].changeBase( tmp );
00126 
00127         I = NLMISC::CVector(  0,  0, -1 );
00128         J = NLMISC::CVector(  0,  1,  0 );
00129         K = NLMISC::CVector(  1,  0,  0 );
00130         tmp.identity(); tmp.setRot( I, J, K, true);
00131         _Grids[kRight].changeBase( tmp );
00132 
00133         I = NLMISC::CVector(  1,  0,  0 );
00134         J = NLMISC::CVector(  0,  0,  1 );
00135         K = NLMISC::CVector(  0, -1,  0 );
00136         tmp.identity(); tmp.setRot( I, J, K, true);
00137         _Grids[kFront].changeBase( tmp );
00138 
00139         I = NLMISC::CVector(  1,  0,  0 );
00140         J = NLMISC::CVector(  0,  0, -1 );
00141         K = NLMISC::CVector(  0,  1,  0 );
00142         tmp.identity(); tmp.setRot( I, J, K, true);
00143         _Grids[kBack].changeBase( tmp );
00144 
00145 
00146         _Compiled= false;
00147 }

template<class TCell>
NL3D::CCubeGrid< TCell >::~CCubeGrid  ) 
 

Definition at line 151 of file cube_grid.h.

00152 {
00153 }


Member Function Documentation

template<class TCell>
void NL3D::CCubeGrid< TCell >::compile  ) 
 

compile the container, storing in CStaticQuadGrid.

Definition at line 229 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_CurSel, NL3D::CCubeGrid< TCell >::_Grids, NL3D::CCubeGrid< TCell >::_NumSels, NL3D::CCubeGrid< TCell >::_StaticGrids, NL3D::CStaticQuadGrid< TCell >::build(), nlassert, and uint.

00230 {
00231         nlassert(!_Compiled);
00232         // For all Grids.
00233         uint    i;
00234         for(i=0; i<6; i++)
00235         {
00236                 // build the _StaticGrid
00237                 _StaticGrids[i].build(_Grids[i]);
00238                 // And reset the grid. contReset is necessary to clean the CBlockMemory.
00239                 contReset(_Grids[i]);
00240         }
00241 
00242         // done
00243         _Compiled= true;
00244 
00245         // Clear the Selection
00246         _Selection= NULL;
00247         _CurSel= 0;
00248         _NumSels= 0;
00249 }

template<class TCell>
void NL3D::CCubeGrid< TCell >::create const CVector center,
int  nSize
 

Create the cubeGrid, specifying center of this one, and number of Cells per side.

Definition at line 157 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Center, NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_Grids, NL3D::CQuadGrid< TCell >::create(), NL3D::CCubeGrid< TCell >::kBack, NL3D::CCubeGrid< TCell >::kDown, NL3D::CCubeGrid< TCell >::kFront, NL3D::CCubeGrid< TCell >::kLeft, NL3D::CCubeGrid< TCell >::kRight, NL3D::CCubeGrid< TCell >::kUp, and nlassert.

00158 {
00159         nlassert(!_Compiled);
00160         _Center= center;
00161 
00162         _Grids[kUp].create              ( nSize, 1.0f / ((float)nSize) );
00163         _Grids[kDown].create    ( nSize, 1.0f / ((float)nSize) );
00164         _Grids[kLeft].create    ( nSize, 1.0f / ((float)nSize) );
00165         _Grids[kRight].create   ( nSize, 1.0f / ((float)nSize) );
00166         _Grids[kFront].create   ( nSize, 1.0f / ((float)nSize) );
00167         _Grids[kBack].create    ( nSize, 1.0f / ((float)nSize) );
00168 }

template<class TCell>
TCell NL3D::CCubeGrid< TCell >::getSel  ) 
 

Definition at line 313 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_CurSel, and nlassert.

00314 {
00315         nlassert(_Compiled);
00316         return _Selection[_CurSel];
00317 }

template<class TCell>
void NL3D::CCubeGrid< TCell >::insert const NLMISC::CTriangle tri,
const TCell &  cell
 

Definition at line 172 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Center, NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::kBack, NL3D::CCubeGrid< TCell >::kDown, NL3D::CCubeGrid< TCell >::kFront, NL3D::CCubeGrid< TCell >::kLeft, NL3D::CCubeGrid< TCell >::kRight, NL3D::CCubeGrid< TCell >::kUp, NLMISC::CPlane::make(), nlassert, NL3D::CCubeGrid< TCell >::project(), NLMISC::CTriangle::V0, NLMISC::CTriangle::V1, and NLMISC::CTriangle::V2.

00173 {
00174         nlassert(!_Compiled);
00175         // Center triangle on _Center.
00176         NLMISC::CTriangle tri= triIn;
00177         tri.V0-= _Center;
00178         tri.V1-= _Center;
00179         tri.V2-= _Center;
00180 
00181         NLMISC::CPlane p[4], gp;
00182         // Construct clip pyramid for grid : UP
00183         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,+1 ), NLMISC::CVector( +1,-1,+1 ) );
00184         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,+1 ), NLMISC::CVector( +1,+1,+1 ) );
00185         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,+1 ), NLMISC::CVector( -1,+1,+1 ) );
00186         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,+1 ), NLMISC::CVector( -1,-1,+1 ) );
00187         gp.make( NLMISC::CVector(0,0,1), NLMISC::CVector(0,0,0.5) );
00188         project( tri, p, gp, kUp, cell );
00189         // Construct clip pyramid for grid : DOWN
00190         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,-1 ), NLMISC::CVector( -1,-1,-1 ) );
00191         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,-1 ), NLMISC::CVector( -1,+1,-1 ) );
00192         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,-1 ), NLMISC::CVector( +1,+1,-1 ) );
00193         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,-1 ), NLMISC::CVector( +1,-1,-1 ) );
00194         gp.make( NLMISC::CVector(0,0,-1), NLMISC::CVector(0,0,-0.5) );
00195         project( tri, p, gp, kDown, cell );
00196         // Construct clip pyramid for grid : LEFT
00197         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,-1 ), NLMISC::CVector( -1,-1,+1 ) );
00198         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,+1 ), NLMISC::CVector( -1,+1,+1 ) );
00199         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,+1 ), NLMISC::CVector( -1,+1,-1 ) );
00200         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,-1 ), NLMISC::CVector( -1,-1,-1 ) );
00201         gp.make( NLMISC::CVector(-1,0,0), NLMISC::CVector(-0.5,0,0) );
00202         project( tri, p, gp, kLeft, cell );
00203         // Construct clip pyramid for grid : RIGHT
00204         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,+1 ), NLMISC::CVector( +1,-1,-1 ) );
00205         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,-1 ), NLMISC::CVector( +1,+1,-1 ) );
00206         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,-1 ), NLMISC::CVector( +1,+1,+1 ) );
00207         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,+1 ), NLMISC::CVector( +1,-1,+1 ) );
00208         gp.make( NLMISC::CVector(1,0,0), NLMISC::CVector(0.5,0,0) );
00209         project( tri, p, gp, kRight, cell );
00210         // Construct clip pyramid for grid : FRONT
00211         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,-1 ), NLMISC::CVector( +1,-1,-1 ) );
00212         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,-1 ), NLMISC::CVector( +1,-1,+1 ) );
00213         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,-1,+1 ), NLMISC::CVector( -1,-1,+1 ) );
00214         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,-1,+1 ), NLMISC::CVector( -1,-1,-1 ) );
00215         gp.make( NLMISC::CVector(0,-1,0), NLMISC::CVector(0,-0.5,0) );
00216         project( tri, p, gp, kFront, cell );
00217         // Construct clip pyramid for grid : BACK
00218         p[0].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,+1 ), NLMISC::CVector( +1,+1,-1 ) );
00219         p[1].make( NLMISC::CVector(0,0,0), NLMISC::CVector( +1,+1,-1 ), NLMISC::CVector( -1,+1,-1 ) );
00220         p[2].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,-1 ), NLMISC::CVector( -1,+1,+1 ) );
00221         p[3].make( NLMISC::CVector(0,0,0), NLMISC::CVector( -1,+1,+1 ), NLMISC::CVector( +1,+1,+1 ) );
00222         gp.make( NLMISC::CVector(0,1,0), NLMISC::CVector(0,0.5,0) );
00223         project( tri, p, gp, kBack, cell );
00224 }

template<class TCell>
bool NL3D::CCubeGrid< TCell >::isEndSel  ) 
 

Definition at line 329 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_CurSel, NL3D::CCubeGrid< TCell >::_NumSels, and nlassert.

00330 {
00331         nlassert(_Compiled);
00332         return (_CurSel == _NumSels);
00333 }

template<class TCell>
void NL3D::CCubeGrid< TCell >::nextSel  ) 
 

Definition at line 321 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_CurSel, and nlassert.

00322 {
00323         nlassert(_Compiled);
00324         ++_CurSel;
00325 }

template<class TCell>
void NL3D::CCubeGrid< TCell >::project const NLMISC::CTriangle tri,
NLMISC::CPlane  pyr[4],
NLMISC::CPlane gridPlane,
sint32  nGridNb,
const TCell &  cell
[private]
 

Definition at line 337 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Grids, NLMISC::CPlane::clipPolygonFront(), NL3D::CQuadGrid< TCell >::insert(), NLMISC::CPlane::intersect(), sint32, NLMISC::CTriangle::V0, NLMISC::CTriangle::V1, NLMISC::CTriangle::V2, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by NL3D::CCubeGrid< TCell >::insert().

00338 {
00339         NLMISC::CVector vIn[7], vOut[7];
00340         sint32 i, nOut;
00341         vIn[0] = tri.V0; vIn[1] = tri.V1; vIn[2] = tri.V2;
00342         nOut = pyr[0].clipPolygonFront( vIn, vOut, 3 );
00343         if( nOut == 0 ) return;
00344         for( i = 0; i < nOut; ++i ) vIn[i] = vOut[i];
00345         nOut = pyr[1].clipPolygonFront( vIn, vOut, nOut );
00346         if( nOut == 0 ) return;
00347         for( i = 0; i < nOut; ++i ) vIn[i] = vOut[i];
00348         nOut = pyr[2].clipPolygonFront( vIn, vOut, nOut );
00349         if( nOut == 0 ) return;
00350         for( i = 0; i < nOut; ++i ) vIn[i] = vOut[i];
00351         nOut = pyr[3].clipPolygonFront( vIn, vOut, nOut );
00352         if( nOut >= 3 )
00353         {
00354                 NLMISC::CVector vMin(1, 1, 1), vMax(-1, -1, -1);
00355                 for( i = 0; i < nOut; ++i )
00356                 {
00357                         vOut[i] = gridPlane.intersect( NLMISC::CVector(0, 0, 0), vOut[i] );
00358                         if( vMin.x > vOut[i].x ) vMin.x = vOut[i].x;
00359                         if( vMin.y > vOut[i].y ) vMin.y = vOut[i].y;
00360                         if( vMin.z > vOut[i].z ) vMin.z = vOut[i].z;
00361                         if( vMax.x < vOut[i].x ) vMax.x = vOut[i].x;
00362                         if( vMax.y < vOut[i].y ) vMax.y = vOut[i].y;
00363                         if( vMax.z < vOut[i].z ) vMax.z = vOut[i].z;
00364                 }
00365                 // Create the bbox
00366                 _Grids[nGridNb].insert( vMin, vMax, cell );
00367         }
00368 }

template<class TCell>
void NL3D::CCubeGrid< TCell >::select const NLMISC::CVector v  ) 
 

Definition at line 253 of file cube_grid.h.

References NL3D::CCubeGrid< TCell >::_Center, NL3D::CCubeGrid< TCell >::_Compiled, NL3D::CCubeGrid< TCell >::_CurSel, NL3D::CCubeGrid< TCell >::_NumSels, NL3D::CCubeGrid< TCell >::_StaticGrids, NLMISC::CPlane::intersect(), NL3D::CCubeGrid< TCell >::kBack, NL3D::CCubeGrid< TCell >::kDown, NL3D::CCubeGrid< TCell >::kFront, NL3D::CCubeGrid< TCell >::kLeft, NL3D::CCubeGrid< TCell >::kRight, NL3D::CCubeGrid< TCell >::kUp, NLMISC::CPlane::make(), nlassert, NL3D::CStaticQuadGrid< TCell >::select(), sint, and v.

00254 {
00255         nlassert(_Compiled);
00256         // Center triangle on _Center.
00257         NLMISC::CVector v= vIn-_Center;
00258 
00259 
00260         sint    nSelGrid= -1;
00261         NLMISC::CPlane gp;
00262         // Get the plane
00263         if( ( -v.z <= v.x ) && ( v.x <= v.z ) &&
00264                 ( -v.z <= v.y ) && ( v.y <= v.z ) &&
00265                 ( 0.0f <= v.z ) )
00266         {
00267                 nSelGrid = kUp;
00268                 gp.make( NLMISC::CVector(0,0,1), NLMISC::CVector(0,0,0.5) );
00269         }
00270         if( ( v.z <= v.x ) && ( v.x <= -v.z ) &&
00271                 ( v.z <= v.y ) && ( v.y <= -v.z ) &&
00272                 ( v.z <= 0.0f ) )
00273         {
00274                 nSelGrid = kDown;
00275                 gp.make( NLMISC::CVector(0,0,-1), NLMISC::CVector(0,0,-0.5) );
00276         }
00277         if( ( v.x <= 0.0f ) &&
00278                 ( v.x <= v.y ) && ( v.y <= -v.x ) &&
00279                 ( v.x <= v.z ) && ( v.z <= -v.x ) )
00280         {
00281                 nSelGrid = kLeft;
00282                 gp.make( NLMISC::CVector(-1,0,0), NLMISC::CVector(-0.5,0,0) );
00283         }
00284         if( ( 0.0f <= v.x ) &&
00285                 ( -v.x <= v.y ) && ( v.y <= v.x ) &&
00286                 ( -v.x <= v.z ) && ( v.z <= v.x ) )
00287         {
00288                 nSelGrid = kRight;
00289                 gp.make( NLMISC::CVector(1,0,0), NLMISC::CVector(0.5,0,0) );
00290         }
00291         if( ( v.y <= v.x ) && ( v.x <= -v.y ) &&
00292                 ( v.y <= 0.0f ) &&
00293                 ( v.y <= v.z ) && ( v.z <= -v.y ) )
00294         {
00295                 nSelGrid = kFront;
00296                 gp.make( NLMISC::CVector(0,-1,0), NLMISC::CVector(0,-0.5,0) );
00297         }
00298         if( ( -v.y <= v.x ) && ( v.x <= v.y ) &&
00299                 ( 0.0f <= v.y ) &&
00300                 ( -v.y <= v.z ) && ( v.z <= v.y ) )
00301         {
00302                 nSelGrid = kBack;
00303                 gp.make( NLMISC::CVector(0,1,0), NLMISC::CVector(0,0.5,0) );
00304         }
00305         nlassert(nSelGrid!=-1);
00306         NLMISC::CVector newV = gp.intersect( NLMISC::CVector(0,0,0), v );
00307         _Selection= _StaticGrids[nSelGrid].select(newV, _NumSels);
00308         _CurSel = 0;
00309 }


Field Documentation

template<class TCell>
NLMISC::CVector NL3D::CCubeGrid< TCell >::_Center [private]
 

Definition at line 76 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::create(), NL3D::CCubeGrid< TCell >::insert(), and NL3D::CCubeGrid< TCell >::select().

template<class TCell>
bool NL3D::CCubeGrid< TCell >::_Compiled [private]
 

Definition at line 85 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::CCubeGrid(), NL3D::CCubeGrid< TCell >::compile(), NL3D::CCubeGrid< TCell >::create(), NL3D::CCubeGrid< TCell >::getSel(), NL3D::CCubeGrid< TCell >::insert(), NL3D::CCubeGrid< TCell >::isEndSel(), NL3D::CCubeGrid< TCell >::nextSel(), and NL3D::CCubeGrid< TCell >::select().

template<class TCell>
uint NL3D::CCubeGrid< TCell >::_CurSel [private]
 

Definition at line 89 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::compile(), NL3D::CCubeGrid< TCell >::getSel(), NL3D::CCubeGrid< TCell >::isEndSel(), NL3D::CCubeGrid< TCell >::nextSel(), and NL3D::CCubeGrid< TCell >::select().

template<class TCell>
NL3D::CQuadGrid<TCell> NL3D::CCubeGrid< TCell >::_Grids[6] [private]
 

Definition at line 80 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::CCubeGrid(), NL3D::CCubeGrid< TCell >::compile(), NL3D::CCubeGrid< TCell >::create(), and NL3D::CCubeGrid< TCell >::project().

template<class TCell>
uint NL3D::CCubeGrid< TCell >::_NumSels [private]
 

Definition at line 90 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::compile(), NL3D::CCubeGrid< TCell >::isEndSel(), and NL3D::CCubeGrid< TCell >::select().

template<class TCell>
const TCell* NL3D::CCubeGrid< TCell >::_Selection [private]
 

Definition at line 88 of file cube_grid.h.

template<class TCell>
NL3D::CStaticQuadGrid<TCell> NL3D::CCubeGrid< TCell >::_StaticGrids[6] [private]
 

Definition at line 82 of file cube_grid.h.

Referenced by NL3D::CCubeGrid< TCell >::compile(), and NL3D::CCubeGrid< TCell >::select().


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