NL3D::CStaticQuadGrid< T > Class Template Reference

#include <static_quad_grid.h>


Detailed Description

template<class T>
class NL3D::CStaticQuadGrid< T >

This class is builded from a CQuadGrid, and is to be used when:

Because elements are duplicated all over cells and only one cell can be selected at a time.

Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 51 of file static_quad_grid.h.

Public Member Functions

 CStaticQuadGrid ()
 Constructor.

 ~CStaticQuadGrid ()
 dtor.

Initialization
void build (CQuadGrid< T > &quadGrid)
void clear ()
Selection
const T * select (const NLMISC::CVector &point, uint &numElts)

Private Member Functions

void selectPoint (CVector point, sint &x0, sint &y0)

Private Attributes

NLMISC::CMatrix _ChangeBasis
std::vector< T > _Elements
float _EltSize
std::vector< CQuadNode_Grid
sint _Size
sint _SizePower


Constructor & Destructor Documentation

template<class T>
NL3D::CStaticQuadGrid< T >::CStaticQuadGrid  ) 
 

Constructor.

Definition at line 146 of file static_quad_grid.h.

References NLMISC::CMatrix::identity().

00147 {
00148         _SizePower=4;
00149         _Size=1<<_SizePower;
00150         _EltSize=1;
00151         _ChangeBasis.identity();
00152         _Grid.resize(_Size * _Size);
00153 }

template<class T>
NL3D::CStaticQuadGrid< T >::~CStaticQuadGrid  ) 
 

dtor.

Definition at line 156 of file static_quad_grid.h.

References NL3D::CStaticQuadGrid< T >::clear().

00157 {
00158         clear();
00159 }


Member Function Documentation

template<class T>
void NL3D::CStaticQuadGrid< T >::build CQuadGrid< T > &  quadGrid  ) 
 

build from a CQuadGrid. Elements are copied, not referenced Elements may be duplicated in all cells they lie into. quadGrid selection is cleared

Definition at line 181 of file static_quad_grid.h.

References NL3D::CQuadGrid< T >::begin(), NL3D::CStaticQuadGrid< T >::clear(), NL3D::CQuadGrid< T >::clearSelection(), NL3D::CQuadGrid< T >::end(), NL3D::CQuadGrid< T >::getBasis(), NL3D::CQuadGrid< T >::getEltSize(), NLMISC::getPowerOf2(), NL3D::CQuadGrid< T >::getSize(), NLMISC::CMatrix::inverted(), NL3D::CQuadGrid< T >::select(), sint, uint, NLMISC::CVector::x, x, NLMISC::CVector::y, y, and NLMISC::CVector::z.

00182 {
00183         clear();
00184         contReset(_Grid);
00185 
00186         // Copy from quadGrid, and init quads
00187         _Size= quadGrid.getSize();
00188         _SizePower= getPowerOf2(_Size);
00189         _EltSize= quadGrid.getEltSize();
00190         _ChangeBasis= quadGrid.getBasis();
00191         _Grid.resize(_Size * _Size);
00192 
00193         NLMISC::CMatrix         invBasis= _ChangeBasis.inverted();
00194 
00195         // Count number of elements per cell, and total copies of elements
00196         uint    totalDupElt= 0;
00197         sint    x,y;
00198         for(y=0; y<_Size; y++)
00199         {
00200                 for(x=0; x<_Size; x++)
00201                 {
00202                         // Select the center of the case
00203                         CVector pos;
00204                         pos.x= (x+0.5f)*_EltSize;
00205                         pos.y= (y+0.5f)*_EltSize;
00206                         pos.z= 0.f;
00207                         // mul by invBasis
00208                         pos= invBasis * pos;
00209                         quadGrid.select(pos, pos);
00210 
00211                         // Count elements.
00212                         uint    n= 0;
00213                         typename CQuadGrid<T>::CIterator        it;
00214                         for(it= quadGrid.begin(); it!=quadGrid.end(); it++)
00215                         {
00216                                 n++;
00217                         }
00218 
00219                         // store.
00220                         _Grid[y*_Size + x].NumNodes= n;
00221                         totalDupElt+= n;
00222                 }
00223         }
00224 
00225         // Resize array copy.
00226         _Elements.resize(totalDupElt);
00227 
00228 
00229         // Then reparse all array, filling _Elements and setup quadNodes ptr.
00230         uint    curDupElt= 0;
00231         for(y=0; y<_Size; y++)
00232         {
00233                 for(x=0; x<_Size; x++)
00234                 {
00235                         // Select the center of the case
00236                         CVector pos;
00237                         pos.x= (x+0.5f)*_EltSize;
00238                         pos.y= (y+0.5f)*_EltSize;
00239                         pos.z= 0.f;
00240                         // mul by invBasis
00241                         pos= invBasis * pos;
00242                         quadGrid.select(pos, pos);
00243 
00244                         // Setup quadNode ptr.
00245                         if (curDupElt < _Elements.size())
00246                                 _Grid[y*_Size + x].Nodes= &_Elements[curDupElt];
00247 
00248                         // For all elements.
00249                         typename CQuadGrid<T>::CIterator        it;
00250                         for(it= quadGrid.begin(); it!=quadGrid.end(); it++)
00251                         {
00252                                 // Copy elt in array.
00253                                 _Elements[curDupElt]= *it;
00254 
00255                                 // Next elt in array.
00256                                 curDupElt++;
00257                         }
00258                 }
00259         }
00260 
00261 
00262         // clean up.
00263         quadGrid.clearSelection();
00264 }

template<class T>
void NL3D::CStaticQuadGrid< T >::clear  ) 
 

Clear all the container. Elements are deleted, and the quadgrid is erased.

Definition at line 164 of file static_quad_grid.h.

References NLMISC::CMatrix::identity().

Referenced by NL3D::CStaticQuadGrid< T >::build(), and NL3D::CStaticQuadGrid< T >::~CStaticQuadGrid().

00165 {
00166         // Just clear all vectors
00167         _Elements.clear();
00168         _Grid.clear();
00169 
00170         // reset
00171         _SizePower=4;
00172         _Size=1<<_SizePower;
00173         _EltSize=1;
00174         _ChangeBasis.identity();
00175         _Grid.resize(_Size * _Size);
00176 }

template<class T>
const T * NL3D::CStaticQuadGrid< T >::select const NLMISC::CVector point,
uint numElts
 

Select elements at a given point Speed is in O(1), because the array of the cell is returned. NULL if size==0.

Parameters:
point is the point used to select
numElts number of elements returned
Returns:
a ptr on array of elements

Definition at line 269 of file static_quad_grid.h.

References NL3D::CStaticQuadGrid< T >::CQuadNode::Nodes, NL3D::CStaticQuadGrid< T >::CQuadNode::NumNodes, NL3D::CStaticQuadGrid< T >::selectPoint(), sint, uint, x, and y.

00270 {
00271         CVector         point= _ChangeBasis * pointIn;
00272 
00273         // Select the case.
00274         sint    x, y;
00275         selectPoint(point, x, y);
00276 
00277         // get ref on the selection
00278         CQuadNode       &quadNode= _Grid[y*_Size + x];
00279         numElts= quadNode.NumNodes;
00280 
00281         return quadNode.Nodes;
00282 }

template<class T>
void NL3D::CStaticQuadGrid< T >::selectPoint CVector  point,
sint x0,
sint y0
[inline, private]
 

Definition at line 114 of file static_quad_grid.h.

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

00115         {
00116                 point/= _EltSize;
00117                 x0= (sint)(floor(point.x));
00118                 y0= (sint)(floor(point.y));
00119 
00120                 x0&= _Size-1;
00121                 y0&= _Size-1;
00122         }


Field Documentation

template<class T>
NLMISC::CMatrix NL3D::CStaticQuadGrid< T >::_ChangeBasis [private]
 

Definition at line 110 of file static_quad_grid.h.

template<class T>
std::vector<T> NL3D::CStaticQuadGrid< T >::_Elements [private]
 

Definition at line 105 of file static_quad_grid.h.

template<class T>
float NL3D::CStaticQuadGrid< T >::_EltSize [private]
 

Definition at line 109 of file static_quad_grid.h.

template<class T>
std::vector<CQuadNode> NL3D::CStaticQuadGrid< T >::_Grid [private]
 

Definition at line 106 of file static_quad_grid.h.

template<class T>
sint NL3D::CStaticQuadGrid< T >::_Size [private]
 

Definition at line 107 of file static_quad_grid.h.

template<class T>
sint NL3D::CStaticQuadGrid< T >::_SizePower [private]
 

Definition at line 108 of file static_quad_grid.h.


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 07:47:26 2004 for NeL by doxygen 1.3.6