# 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::CQuadTree Template Class Reference

class: CQuadTree. More...

#include <quad_tree.h>

Collaboration diagram for NL3D::CQuadTree:

Collaboration graph
[legend]
List of all members.

Public Methods

 CQuadTree ()
 Default constructor, use axes XZ. More...

 ~CQuadTree ()
 dtor.

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

void create (uint DepthMax, const NLMISC::CVector& center, float size)
 Init the container. More...

Container operation
void clear ()
 Clear the container. Elements are deleted, and the quadtree too (create() is undone). More...

void eraseAll ()
 Erase all elements from the container. More...

void erase (CIterator it)
 Erase an interator from the container. 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. 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...

void select (const std::vector<NLMISC::CPlane> &BVolume)
 Select element with multiple planes. More...

void selectRay (const NLMISC::CVector& source, const NLMISC::CVector& dir)
 Select element with a ray. More...

void selectSegment (const NLMISC::CVector& source, const NLMISC::CVector& dest)
 Select element with a segment. 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 Attributes

CQuadNode _QuadRoot
CBaseNode _Selection
uint _DepthMax
float _Size
NLMISC::CMatrix _ChangeBasis

Friends

class  CIterator
class  CConstIterator

Detailed Description

template<class T> template class NL3D::CQuadTree

class: CQuadTree.

A template CQuadTree.

This first implementation support real-time quad node split, but never merge the quad node. The possibility to merge (delete) empty quads, when an element erase occurs, will be added later.

The quadtree is geometrically delimited. By default, his size is 1*1, centered on (0,0,0). If an element which is out this zone is inserted, then it will ALWAYS be considered selected in select*() methods. By default, the quad tree is aligned on XZ.

Sample code using CQuadTree:

 // My quad tree
 CQuadTree<myType> quadTree;

 // My min and max BoundingBox corner of each element
 CVector minPoint[elementCount]=...;
 CVector maxPoint[elementCount]=...;
 
 // My values
 myType value[elementCount]=...;
 
 // Init the quadTree with recursions depth = 6 (so max 64*64 cells)
 // centered in (0,0,0) with a max size of 10 in the plane XZ
 quadTree.create (6, CVector (0.f, 0.f, 0.f), 10.f);

 // Insert element in the quadTree
 for (int i=0; i<elementCount; i++)
                quadTree.insert (minPoint[i], maxPoint[i], value[i]);

 // [...]
 
 // Clear the selection
 quadTree.clearSelection ();
 
 // Select an element with the X axis as a 3d ray
 quadTree.selectRay (CVector (0,0,0), CVector (1,0,0));
 
        // Get first selected nodes..
 CQuadTree<myType>::CIterator it=quadTree.begin();
 while (it!=quadTree.end())
 {
        // Check what you want...
                
                // Next selected element
        it++;
 }

Definition at line 96 of file quad_tree.h.


Constructor & Destructor Documentation

template<classT>
NL3D::CQuadTree< T >::CQuadTree<T> ( )
 

Default constructor, use axes XZ.

Definition at line 658 of file quad_tree.h.

template<classT>
NL3D::CQuadTree<T>::~CQuadTree<T> ( )
 

dtor.


Member Function Documentation

template<classT>
CQuadTree< T >::CIterator NL3D::CQuadTree< T >::begin ( void )
 

Return the first iterator of the selected element list.

begin and end are valid till the next insert.

Definition at line 884 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::changeBase ( const NLMISC::CMatrix & base )
 

Change the base matrix of the quad tree.

For exemple this code init the quad tree in the plane XY:

 CQuadTree                      quadTree;
 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 tree

Definition at line 669 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::clear ( )
 

Clear the container. Elements are deleted, and the quadtree too (create() is undone).

Definition at line 679 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::clearSelection ( )
 

Clear the selection list.

Definition at line 775 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::create ( uint DepthMax,
const NLMISC::CVector & center,
float size )
 

Init the container.

Parameters:
DepthMax   is the max depth in the tree. The max cell count is (1<<DepthMax)^2
center   is the center of the quad tree
size   is the width and the height of the initial quad tree.

Definition at line 685 of file quad_tree.h.

template<classT>
CQuadTree< T >::CIterator NL3D::CQuadTree< T >::end ( void )
 

Return the end iterator of the selected element list.

begin and end are valid till the next insert.

Definition at line 889 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::erase ( CIterator it )
 

Erase an interator from the container.

Parameters:
it   is the iterator to erase.

Definition at line 723 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::eraseAll ( )
 

Erase all elements from the container.

Definition at line 704 of file quad_tree.h.

template<classT>
CQuadTree< T >::CIterator NL3D::CQuadTree< T >::insert ( const NLMISC::CVector & bboxmin,
const NLMISC::CVector & bboxmax,
const T & val )
 

Insert a new element in the container.

The bounding box of the element MUST be included in the bounding box of the quadtree.

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 736 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::select ( const std::vector< NLMISC::CPlane >& BVolume )
 

Select element with multiple planes.

Intersect with a polytope convex made of planes. The normals of planes must be directed outwards the polytope.

Parameters:
BVolume   is a plane vector

Definition at line 804 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::select ( const NLMISC::CVector & bboxmin,
const NLMISC::CVector & bboxmax )
 

Select element intersecting a bounding box.

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 793 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::selectAll ( )
 

Select all the container.

Definition at line 787 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::selectRay ( const NLMISC::CVector & source,
const NLMISC::CVector & dir )
 

Select element with a ray.

Parameters:
source   is a point in the ray
dir   is the direction off the ray

Definition at line 817 of file quad_tree.h.

template<classT>
void NL3D::CQuadTree< T >::selectSegment ( const NLMISC::CVector & source,
const NLMISC::CVector & dest )
 

Select element with a segment.

Parameters:
source   is the source of the segment
dest   is the destination of the segment

Definition at line 848 of file quad_tree.h.


Friends And Related Function Documentation

template<classT>
class CConstIterator [friend]
 

Definition at line 105 of file quad_tree.h.

template<classT>
class CIterator [friend]
 

Definition at line 102 of file quad_tree.h.


Member Data Documentation

template<classT>
NLMISC::CMatrix NL3D::CQuadTree<T>::_ChangeBasis [private]
 

Definition at line 581 of file quad_tree.h.

template<classT>
uint NL3D::CQuadTree<T>::_DepthMax [private]
 

Definition at line 579 of file quad_tree.h.

template<classT>
CQuadNode NL3D::CQuadTree<T>::_QuadRoot [private]
 

Definition at line 577 of file quad_tree.h.

template<classT>
CBaseNode NL3D::CQuadTree<T>::_Selection [private]
 

Definition at line 578 of file quad_tree.h.

template<classT>
float NL3D::CQuadTree<T>::_Size [private]
 

Definition at line 580 of file quad_tree.h.


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