NL3D::CQuadGrid< T > Class Template Reference

This container is a simple grid, used to quickly find elements. More...

#include <quad_grid.h>

Inherits NL3D::CQuadGridBase.

List of all members.

Classes

class  CBaseNode
 A base node (not circular) for the list of selected or unselected node. More...
class  CIterator
class  CNode
 An element inserted in the quadGrid. More...
class  const_iterator
class  CQuadNode
 A circular list node for the list of node per Quad element. More...

Public Types

typedef std::vector< uintTSelectionShape

Public Member Functions

 CQuadGrid (uint memoryBlockSize=NL3D_QUAD_GRID_ALLOC_BLOCKSIZE)
 Default constructor, use axes XY!!!, has a size of 16, and EltSize is 1.
 ~CQuadGrid ()
 dtor.
CQuadGrid< T > & operator= (const CQuadGrid< T > &o)
 CQuadGrid (const CQuadGrid< T > &o)
Initialization



void changeBase (const NLMISC::CMatrix &base)
 Change the base matrix of the quad grid.
void create (uint size, float eltSize)
 Init the container.
const NLMISC::CMatrixgetBasis () const
uint getSize () const
float getEltSize () const
Container operation



void clear ()
 Clear the container.
CIterator erase (CIterator it)
 Erase an interator from the container Speed is in O(1 * L*H) where L*H is the number of squares surrounded by the element.
CIterator insert (const NLMISC::CVector &bboxmin, const NLMISC::CVector &bboxmax, const T &val)
 Insert a new element in the container.
Selection



void clearSelection ()
 Clear the selection list Speed is in O(Nelts).
void selectAll ()
 Select all the container.
void select (const NLMISC::CVector &bboxmin, const NLMISC::CVector &bboxmax)
 Select element intersecting a bounding box.
void selectRay (const NLMISC::CVector &rayStart, const NLMISC::CVector &rayEnd)
void buildSelectionShape (TSelectionShape &dest, const NLMISC::CPolygon2D &poly) const
 Build a selection from a convex polygon.
void select (const TSelectionShape &shape)
 Select element intersecting a selection shape.
CIterator begin ()
 Return the first iterator of the selected element list.
CIterator end ()
 Return the end iterator of the selected element list.

Private Member Functions

void initCons ()
void linkToRoot (CBaseNode &root, CBaseNode *ptr)
void initSelectStamps () const
void selectQuads (CVector bmin, CVector bmax, sint &x0, sint &x1, sint &y0, sint &y1)
void addToSelection (CNode *ptr)
void addQuadNodeToSelection (CQuadNode &quad)

Private Attributes

std::vector< CQuadNode_Grid
sint _Size
sint _SizePower
float _EltSize
NLMISC::CMatrix _ChangeBasis
CBaseNode _SelectedList
CBaseNode _UnSelectedList
NLMISC::CBlockMemory< CNode_NodeBlockMemory

Friends

class CIterator

Detailed Description

template<class T>
class NL3D::CQuadGrid< T >

This container is a simple grid, used to quickly find elements.

His purpose is similiar to CQuadTree, but it is a simple grid, so test are in O(1), not in O(log n). It is perfect for local lookup (like in collisions). Use it if you want to select small area, not large. Also, for best use, elements should have approximatively the same size, and this size should be little smaller than the size of a grid element...

By default, the quad grid is aligned on XY. (unlike the quadtree!!!)

Unlike the quadtree, the quadgrid is NOT geographicly delimited, ie, its limits "tiles"!! This is why no "center" is required. As a direct consequence, when you select something, you are REALLY not sure that what you select is not a mile away from your selection :) ....

Also, for memory optimisation, no bbox is stored in the quadgrid. Hence no particular selection is made on the Z components...

For maximum allocation speed Efficiency, it uses a CBlockMemory<CNode> to allocate elements at insert(). DefaultBlockSize is 16, but you can change it at construction.

Author:
Lionel Berenguier
Nevrax France
Date:
2000

Definition at line 87 of file quad_grid.h.


Member Typedef Documentation

template<class T>
typedef std::vector<uint> NL3D::CQuadGrid< T >::TSelectionShape

Definition at line 95 of file quad_grid.h.


Constructor & Destructor Documentation

template<class T >
NL3D::CQuadGrid< T >::CQuadGrid ( uint  memoryBlockSize = NL3D_QUAD_GRID_ALLOC_BLOCKSIZE  )  [inline]

Default constructor, use axes XY!!!, has a size of 16, and EltSize is 1.

Definition at line 479 of file quad_grid.h.

References NL3D::CQuadGrid< T >::initCons().

template<class T >
NL3D::CQuadGrid< T >::~CQuadGrid (  )  [inline]

dtor.

Definition at line 580 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_Grid, and NL3D::CQuadGrid< T >::clear().

template<class T>
NL3D::CQuadGrid< T >::CQuadGrid ( const CQuadGrid< T > &  o  )  [inline]

Member Function Documentation

template<class T>
void NL3D::CQuadGrid< T >::addQuadNodeToSelection ( CQuadNode quad  )  [inline, private]

Definition at line 384 of file quad_grid.h.

Referenced by NL3D::CQuadGrid< T >::select(), and NL3D::CQuadGrid< T >::selectRay().

template<class T>
void NL3D::CQuadGrid< T >::addToSelection ( CNode ptr  )  [inline, private]
template<class T >
CQuadGrid< T >::CIterator NL3D::CQuadGrid< T >::begin ( void   )  [inline]

Return the first iterator of the selected element list.

begin and end are valid till the next insert. Speed is in O(1)

Definition at line 880 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_SelectedList, NL3D::CQuadGrid< T >::CIterator, and NL3D::CQuadGrid< T >::CBaseNode::Next.

Referenced by NL3D::CLightingManager::addDynamicLight(), NL3D::CStaticQuadGrid< T >::build(), NL3D::CLandscape::buildPatchBlocksInBBox(), NL3D::CLandscape::buildTrianglesInBBox(), NL3D::CQuadGrid< T >::clear(), NL3D::CZoneLighter::compilePointLightRT(), NL3D::CInstanceLighter::compilePointLightRT(), NL3D::CShadowPolyReceiver::computeClippedTrisWithPolyClip(), NL3D::CLandscape::computeDynamicLighting(), NL3D::CInstanceLighter::computeSunContribution(), NL3D::CZoneLighter::computeTileFlagsForPositionTowardWater(), NL3D::CScene::findCameraClusterSystemFromRay(), NL3D::CClipTrav::fullSearch(), NL3D::CVisualCollisionManager::getCameraCollision(), NL3D::CShadowPolyReceiver::getCameraCollision(), NL3D::CLightingManager::getDynamicPointLightList(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CVisualCollisionManager::getMeshs(), NL3D::CVisualCollisionManager::getRayCollision(), NL3D::CInstanceLighter::processIGPointLightRT(), NL3D::CZoneLighter::processZonePointLightRT(), NL3D::CVisualCollisionManager::receiveShadowMap(), NL3D::CMiniCol::removeLandScapePart(), NL3D::CLandscape::removeZone(), NL3D::CShadowPolyReceiver::render(), NL3D::CShadowMapManager::renderProject(), NL3D::CShadowPolyReceiver::renderSelection(), NL3D::CMiniCol::snapToGround(), and NL3D::CClipTrav::traverse().

template<class T >
void NL3D::CQuadGrid< T >::buildSelectionShape ( TSelectionShape dest,
const NLMISC::CPolygon2D poly 
) const [inline]
template<class T >
void NL3D::CQuadGrid< T >::changeBase ( const NLMISC::CMatrix base  )  [inline]

Change the base matrix of the quad grid.

For exemple this code init the grid tree in the plane XZ:

 CQuadGrid          grid;
 NLMISC::CMatrix        tmp;
 NLMISC::CVector        I(1,0,0);
 NLMISC::CVector        J(0,0,1);
 NLMISC::CVector        K(0,-1,0);

 tmp.identity();
 tmp.setRot(I,J,K, true);
 quadTree.changeBase (tmp);
Parameters:
base Base of the quad grid

Definition at line 586 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_ChangeBasis.

Referenced by NL3D::CCubeGrid< TCell >::CCubeGrid(), and NL3D::CInstanceLighter::computeSunContribution().

template<class T >
void NL3D::CQuadGrid< T >::clear ( void   )  [inline]
template<class T >
void NL3D::CQuadGrid< T >::clearSelection (  )  [inline]
template<class T >
void NL3D::CQuadGrid< T >::create ( uint  size,
float  eltSize 
) [inline]
template<class T >
CQuadGrid< T >::CIterator NL3D::CQuadGrid< T >::end ( void   )  [inline]

Return the end iterator of the selected element list.

begin and end are valid till the next insert. Speed is in O(1)

Definition at line 885 of file quad_grid.h.

References NL3D::CQuadGrid< T >::CIterator.

Referenced by NL3D::CStaticQuadGrid< T >::build(), NL3D::CLandscape::buildPatchBlocksInBBox(), NL3D::CLandscape::buildTrianglesInBBox(), NL3D::CQuadGrid< T >::clear(), NL3D::CZoneLighter::compilePointLightRT(), NL3D::CInstanceLighter::compilePointLightRT(), NL3D::CShadowPolyReceiver::computeClippedTrisWithPolyClip(), NL3D::CLandscape::computeDynamicLighting(), NL3D::CInstanceLighter::computeSunContribution(), NL3D::CZoneLighter::computeTileFlagsForPositionTowardWater(), NL3D::CQuadGrid< T >::erase(), NL3D::CScene::findCameraClusterSystemFromRay(), NL3D::CClipTrav::fullSearch(), NL3D::CVisualCollisionManager::getCameraCollision(), NL3D::CShadowPolyReceiver::getCameraCollision(), NL3D::CLightingManager::getDynamicPointLightList(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CVisualCollisionManager::getMeshs(), NL3D::CVisualCollisionManager::getRayCollision(), NL3D::CInstanceLighter::processIGPointLightRT(), NL3D::CZoneLighter::processZonePointLightRT(), NL3D::CVisualCollisionManager::receiveShadowMap(), NL3D::CMiniCol::removeLandScapePart(), NL3D::CShadowPolyReceiver::removeTriangle(), NL3D::CLandscape::removeZone(), NL3D::CShadowPolyReceiver::render(), NL3D::CShadowMapManager::renderProject(), NL3D::CShadowPolyReceiver::renderSelection(), NL3D::CMiniCol::snapToGround(), and NL3D::CClipTrav::traverse().

template<class T >
CQuadGrid< T >::CIterator NL3D::CQuadGrid< T >::erase ( typename CQuadGrid< T >::CIterator  it  )  [inline]
template<class T>
const NLMISC::CMatrix& NL3D::CQuadGrid< T >::getBasis (  )  const [inline]

Definition at line 137 of file quad_grid.h.

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

template<class T>
float NL3D::CQuadGrid< T >::getEltSize (  )  const [inline]

Definition at line 139 of file quad_grid.h.

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

template<class T>
uint NL3D::CQuadGrid< T >::getSize ( void   )  const [inline]

Definition at line 138 of file quad_grid.h.

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

template<class T >
void NL3D::CQuadGrid< T >::initCons (  )  [inline, private]
template<class T>
void NL3D::CQuadGrid< T >::initSelectStamps (  )  const [inline, private]
template<class T>
CQuadGrid< T >::CIterator NL3D::CQuadGrid< T >::insert ( const NLMISC::CVector bboxmin,
const NLMISC::CVector bboxmax,
const T val 
) [inline]

Insert a new element in the container.

Speed is in O(1 * L*H) where L*H is the number of squares surrounded by the element

Warning! : bboxmin and bboxmax are multiplied by matrix setuped by changeBase. This work for any matrix with 90deg rotations (min and max are recomputed internally), but not with any rotation (43° ...) because of the nature of AABBox. To do this correclty you should compute the bbox min and max in the basis given in changeBase, and insert() with multiplying min and max with inverse of this basis. eg: CMatrix base= getSomeBase(); CMatrix invBase= base.inverted(); // create quadGrid. CQuadGrid<CTriangle> quadGrid; quadGrid.changeBase(base); quadGrid.create(...); // Insert a triangle tri correctly CAABBox bbox; bbox.setCenter(base * tri.V0); bbox.extend(base * tri.V1); bbox.extend(base * tri.V2); quadGrid.insert(invBase*bbox.getMin(), invBase*bbox.getMax(), tri);

Parameters:
bboxmin is the corner of the bounding box of the element to insert with minimal coordinates.
bboxmax is the corner of the bounding box of the element to insert with maximal coordinates.
val is a reference on the value to insert.

Definition at line 669 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_ChangeBasis, NL3D::CQuadGrid< T >::_Grid, NL3D::CQuadGrid< T >::_NodeBlockMemory, NL3D::CQuadGrid< T >::_Size, NL3D::CQuadGrid< T >::_SizePower, NL3D::CQuadGrid< T >::_UnSelectedList, NLMISC::CBlockMemory< T, __ctor_dtor__ >::allocate(), NL3D::CQuadGrid< T >::CIterator, NL3D::CQuadGrid< T >::CNode::Elt, NL3D::CQuadGrid< T >::linkToRoot(), NL3D::CQuadGrid< T >::CQuadNode::Next, NL3D::CQuadGrid< T >::CBaseNode::Next, nlassert, NL3D::CQuadGrid< T >::CQuadNode::Prev, NL3D::CQuadGrid< T >::CNode::QuadNodes, NLMISC::CObjectVector< T, EnableObjectBehavior >::resize(), NL3D::CQuadGrid< T >::CBaseNode::Selected, and NL3D::CQuadGrid< T >::selectQuads().

Referenced by NL3D::CLightingManager::addDynamicLight(), NL3D::CMiniCol::addFaces(), NL3D::CVisualCollisionManager::addMeshInstanceCollision(), NL3D::CShadowMapManager::addShadowReceiver(), NL3D::CShadowPolyReceiver::addTriangle(), NL3D::CLandscape::addZone(), NL3D::CZoneLighter::compilePointLightRT(), NL3D::CInstanceLighter::compilePointLightRT(), NL3D::CInstanceLighter::computeSunContribution(), NL3D::CLightingManager::insertStaticLightedModel(), NL3D::CZoneLighter::makeQuadGridFromWaterShapes(), NL3D::CCubeGrid< TCell >::project(), and NL3D::CClipTrav::registerCluster().

template<class T>
void NL3D::CQuadGrid< T >::linkToRoot ( CBaseNode root,
CBaseNode ptr 
) [inline, private]
template<class T>
CQuadGrid< T > & NL3D::CQuadGrid< T >::operator= ( const CQuadGrid< T > &  o  )  [inline]
template<class T >
void NL3D::CQuadGrid< T >::select ( const TSelectionShape shape  )  [inline]

Select element intersecting a selection shape.

Clear the selection first.

Definition at line 843 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_Grid, NL3D::CQuadGrid< T >::addQuadNodeToSelection(), and NL3D::CQuadGrid< T >::clearSelection().

template<class T >
void NL3D::CQuadGrid< T >::select ( const NLMISC::CVector bboxmin,
const NLMISC::CVector bboxmax 
) [inline]

Select element intersecting a bounding box.

Clear the selection first. Speed is in O(Nelts * L*H), where L*H is the number of squares surrounded by the selection

Parameters:
bboxmin is the corner of the bounding box used to select
bboxmax is the corner of the bounding box used to select

Definition at line 779 of file quad_grid.h.

References NL3D::CQuadGrid< T >::_ChangeBasis, NL3D::CQuadGrid< T >::_Grid, NL3D::CQuadGrid< T >::_Size, NL3D::CQuadGrid< T >::_SizePower, NL3D::CQuadGrid< T >::addQuadNodeToSelection(), NL3D::CQuadGrid< T >::clearSelection(), and NL3D::CQuadGrid< T >::selectQuads().

Referenced by NL3D::CLightingManager::addDynamicLight(), NL3D::CStaticQuadGrid< T >::build(), NL3D::CLandscape::buildPatchBlocksInBBox(), NL3D::CLandscape::buildTrianglesInBBox(), NL3D::CZoneLighter::compilePointLightRT(), NL3D::CInstanceLighter::compilePointLightRT(), NL3D::CLandscape::computeDynamicLighting(), NL3D::CInstanceLighter::computeSunContribution(), NL3D::CZoneLighter::computeTileFlagsForPositionTowardWater(), NL3D::CScene::findCameraClusterSystemFromRay(), NL3D::CClipTrav::fullSearch(), NL3D::CVisualCollisionManager::getCameraCollision(), NL3D::CShadowPolyReceiver::getCameraCollision(), NL3D::CLightingManager::getDynamicPointLightList(), NL3D::CMiniCol::getFaces(), NL3D::CMiniCol::getGroundNormal(), NL3D::CVisualCollisionManager::getMeshs(), NL3D::CVisualCollisionManager::getRayCollision(), NL3D::CInstanceLighter::processIGPointLightRT(), NL3D::CZoneLighter::processZonePointLightRT(), NL3D::CVisualCollisionManager::receiveShadowMap(), NL3D::CMiniCol::removeLandScapePart(), NL3D::CLandscape::removeZone(), NL3D::CShadowPolyReceiver::render(), NL3D::CShadowMapManager::renderProject(), NL3D::CShadowPolyReceiver::selectPolygon(), NL3D::CMiniCol::snapToGround(), and NL3D::CClipTrav::traverse().

template<class T >
void NL3D::CQuadGrid< T >::selectAll (  )  [inline]
template<class T>
void NL3D::CQuadGrid< T >::selectQuads ( CVector  bmin,
CVector  bmax,
sint x0,
sint x1,
sint y0,
sint y1 
) [inline, private]

Definition at line 323 of file quad_grid.h.

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

template<class T >
void NL3D::CQuadGrid< T >::selectRay ( const NLMISC::CVector rayStart,
const NLMISC::CVector rayEnd 
) [inline]

Friends And Related Function Documentation

template<class T>
friend class CIterator [friend]

Member Data Documentation

template<class T>
NLMISC::CMatrix NL3D::CQuadGrid< T >::_ChangeBasis [private]
template<class T>
float NL3D::CQuadGrid< T >::_EltSize [private]
template<class T>
std::vector<CQuadNode> NL3D::CQuadGrid< T >::_Grid [private]
template<class T>
NLMISC::CBlockMemory<CNode> NL3D::CQuadGrid< T >::_NodeBlockMemory [private]
template<class T>
CBaseNode NL3D::CQuadGrid< T >::_SelectedList [private]
template<class T>
sint NL3D::CQuadGrid< T >::_Size [private]
template<class T>
sint NL3D::CQuadGrid< T >::_SizePower [private]
template<class T>
CBaseNode NL3D::CQuadGrid< T >::_UnSelectedList [private]

The documentation for this class was generated from the following file:

Generated on Thu Jan 7 08:30:10 2010 for NeL by  doxygen 1.6.1