# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NL3D::CQuadGrid Class Template Reference

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

#include <quad_grid.h>

List of all members.

Public Methods

 CQuadGrid (uint memoryBlockSize=NL3D_QUAD_GRID_ALLOC_BLOCKSIZE)
 Default constructor, use axes XY!!!, has a size of 16, and EltSize is 1. More...

 ~CQuadGrid ()
 dtor. More...

Initialization
void changeBase (const NLMISC::CMatrix &base)
 Change the base matrix of the quad grid. More...

void create (uint size, float eltSize)
 Init the container. More...

const NLMISC::CMatrixgetBasis () const
uint getSize () const
float getEltSize () const
Container operation
void clear ()
 Clear the container. More...

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. More...

CIterator insert (const NLMISC::CVector &bboxmin, const NLMISC::CVector &bboxmax, const T &val)
 Insert a new element in the container. More...

Selection
void clearSelection ()
 Clear the selection list Speed is in O(Nelts). More...

void selectAll ()
 Select all the container. More...

void select (const NLMISC::CVector &bboxmin, const NLMISC::CVector &bboxmax)
 Select element intersecting a bounding box. More...

CIterator begin ()
 Return the first iterator of the selected element list. More...

CIterator end ()
 Return the end iterator of the selected element list. More...


Private Methods

void linkToRoot (CBaseNode &root, CBaseNode *ptr)
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
NLMISC::CBlockMemory< CNode *,
false > 
_NodeListBlockMemory

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.

because elements may lies in multiples squares, QuadGrid use lists per square which points on elements. For faster allocation, it uses a CSTLBlockList<>. The entire quadGrid has its own CBlockMemory for the CSTLBlockLists. memoryBlockSize is the same than the blockSize for allocation of nodes.

Author:
Lionel Berenguier , Nevrax France
Date:
2000

Definition at line 76 of file 3d/quad_grid.h.


Constructor & Destructor Documentation

template<class T>
NL3D::CQuadGrid< T >::CQuadGrid uint    memoryBlockSize = NL3D_QUAD_GRID_ALLOC_BLOCKSIZE
 

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

Definition at line 412 of file 3d/quad_grid.h.

References _ChangeBasis, _EltSize, _Size, _SizePower, and NLMISC::CMatrix::identity.

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

dtor.

Definition at line 421 of file 3d/quad_grid.h.

References _Grid, and clear.


Member Function Documentation

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

Definition at line 322 of file 3d/quad_grid.h.

Referenced by select.

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

Definition at line 303 of file 3d/quad_grid.h.

Referenced by NL3D::CQuadGrid< CWaterShape * >::addQuadNodeToSelection.

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

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 641 of file 3d/quad_grid.h.

References _SelectedList, CIterator, and NL3D::CQuadGrid::CBaseNode::Next.

Referenced by clear.

template<class T>
void NL3D::CQuadGrid< T >::changeBase const NLMISC::CMatrix   base
 

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 428 of file 3d/quad_grid.h.

References _ChangeBasis.

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

Clear the container.

Elements are deleted, but the quadgrid is not erased. Speed is in O(Nelts)

Definition at line 454 of file 3d/quad_grid.h.

References _SelectedList, _UnSelectedList, begin, CIterator, end, erase, NL3D::CQuadGrid::CBaseNode::Next, and selectAll.

Referenced by create, and ~CQuadGrid.

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

Clear the selection list Speed is in O(Nelts).

Definition at line 567 of file 3d/quad_grid.h.

References _SelectedList, _UnSelectedList, linkToRoot, and NL3D::CQuadGrid::CBaseNode::Next.

Referenced by select.

template<class T>
void NL3D::CQuadGrid< T >::create uint    size,
float    eltSize
 

Init the container.

container is first clear() ed.

Parameters:
size  is the width and the height of the initial quad tree, in number of square. For performance view, this should be a power of 2, and <=32768. (eg: 256,512, 8, 16 ...)
eltSize  is the width and height of an element. Must be >0. Notice that the quadgrid MUST be square!!

Definition at line 433 of file 3d/quad_grid.h.

References _EltSize, _Grid, _NodeListBlockMemory, _Size, _SizePower, clear, NLMISC::getPowerOf2, and nlassert.

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

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 646 of file 3d/quad_grid.h.

References CIterator.

Referenced by clear.

template<class T>
CIterator NL3D::CQuadGrid< T >::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.

Parameters:
it  is the iterator to erase.
Returns:
if element is currently selected, the next selected element is returned, (or end()). if the element is not selected, end() is returned.

Referenced by clear.

template<class T>
const NLMISC::CMatrix& NL3D::CQuadGrid< T >::getBasis   const [inline]
 

Definition at line 119 of file 3d/quad_grid.h.

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

Definition at line 121 of file 3d/quad_grid.h.

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

Definition at line 120 of file 3d/quad_grid.h.

template<class T>
CQuadGrid< T >::CIterator NL3D::CQuadGrid< T >::insert const NLMISC::CVector   bboxmin,
const NLMISC::CVector   bboxmax,
const T &    val
 

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 90° 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 516 of file 3d/quad_grid.h.

References _ChangeBasis, _Grid, _NodeBlockMemory, _Size, _SizePower, _UnSelectedList, NLMISC::CBlockMemory< CNode >::allocate, CIterator, linkToRoot, selectQuads, x, and y.

template<class T>
void NL3D::CQuadGrid< T >::linkToRoot CBaseNode   root,
CBaseNode   ptr
[inline, private]
 

Definition at line 251 of file 3d/quad_grid.h.

Referenced by NL3D::CQuadGrid< CWaterShape * >::addToSelection, clearSelection, insert, and selectAll.

template<class T>
void NL3D::CQuadGrid< T >::select const NLMISC::CVector   bboxmin,
const NLMISC::CVector   bboxmax
 

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 613 of file 3d/quad_grid.h.

References _ChangeBasis, _Grid, _Size, _SizePower, addQuadNodeToSelection, clearSelection, selectQuads, x, and y.

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

Select all the container.

Speed is in O(Nelts)

Definition at line 589 of file 3d/quad_grid.h.

References _SelectedList, _UnSelectedList, linkToRoot, and NL3D::CQuadGrid::CBaseNode::Next.

Referenced by clear.

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 261 of file 3d/quad_grid.h.

Referenced by insert, and select.


Friends And Related Function Documentation

template<class T>
friend class CIterator [friend]
 

Definition at line 81 of file 3d/quad_grid.h.

Referenced by begin, clear, end, and insert.


Member Data Documentation

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

Definition at line 238 of file 3d/quad_grid.h.

Referenced by changeBase, CQuadGrid, NL3D::CQuadGrid< CWaterShape * >::getBasis, insert, and select.

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

Definition at line 237 of file 3d/quad_grid.h.

Referenced by CQuadGrid, create, NL3D::CQuadGrid< CWaterShape * >::getEltSize, and NL3D::CQuadGrid< CWaterShape * >::selectQuads.

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

Definition at line 234 of file 3d/quad_grid.h.

Referenced by create, insert, select, and ~CQuadGrid.

template<class T>
NLMISC::CBlockMemory<CNode> NL3D::CQuadGrid::_NodeBlockMemory [private]
 

Definition at line 243 of file 3d/quad_grid.h.

Referenced by insert.

template<class T>
NLMISC::CBlockMemory<CNode*, false> NL3D::CQuadGrid::_NodeListBlockMemory [private]
 

Definition at line 245 of file 3d/quad_grid.h.

Referenced by create.

template<class T>
CBaseNode NL3D::CQuadGrid::_SelectedList [private]
 

Definition at line 240 of file 3d/quad_grid.h.

Referenced by begin, clear, clearSelection, and selectAll.

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

Definition at line 235 of file 3d/quad_grid.h.

Referenced by CQuadGrid, create, NL3D::CQuadGrid< CWaterShape * >::getSize, insert, select, and NL3D::CQuadGrid< CWaterShape * >::selectQuads.

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

Definition at line 236 of file 3d/quad_grid.h.

Referenced by CQuadGrid, create, insert, and select.

template<class T>
CBaseNode NL3D::CQuadGrid::_UnSelectedList [private]
 

Definition at line 241 of file 3d/quad_grid.h.

Referenced by clear, clearSelection, insert, and selectAll.


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