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

class: CQuadTree. More...

#include <quad_tree.h>

List of all members.

Public Methods

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

 ~CQuadTree ()
 dtor. More...

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>
class NL3D::CQuadTree< T >

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<class T>
NL3D::CQuadTree< T >::CQuadTree  
 

Default constructor, use axes XZ.

Definition at line 658 of file quad_tree.h.

References _ChangeBasis, _DepthMax, _QuadRoot, _Selection, _Size, NL3D::CQuadTree::CQuadNode::BBoxMax, NL3D::CQuadTree::CQuadNode::BBoxMin, NLMISC::CMatrix::identity, NL3D::CQuadTree::CBaseNode::Next, and NLMISC::CVector::set.

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

dtor.


Member Function Documentation

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

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.

References _Selection, and NL3D::CQuadTree::CBaseNode::Next.

Referenced by eraseAll.

template<class T>
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.

References _ChangeBasis.

template<class T>
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.

References _QuadRoot, _Selection, NL3D::CQuadTree::CQuadNode::clear, and NL3D::CQuadTree::CBaseNode::Next.

Referenced by create.

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

Clear the selection list.

Definition at line 775 of file quad_tree.h.

References _Selection, and NL3D::CQuadTree::CBaseNode::Next.

Referenced by select, and selectAll.

template<class T>
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.

References _ChangeBasis, _DepthMax, _QuadRoot, _Size, NL3D::CQuadTree::CQuadNode::BBoxMax, NL3D::CQuadTree::CQuadNode::BBoxMin, and clear.

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

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.

References CIterator.

Referenced by eraseAll.

template<class T>
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.

Referenced by eraseAll.

template<class T>
void NL3D::CQuadTree< T >::eraseAll  
 

Erase all elements from the container.

Definition at line 704 of file quad_tree.h.

References begin, CIterator, end, erase, and selectAll.

template<class T>
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.

References _ChangeBasis, _DepthMax, _QuadRoot, _Size, CIterator, NL3D::CQuadTree::CQuadNode::insert, nlassert, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

template<class T>
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.

References _QuadRoot, _Selection, clearSelection, and NL3D::CQuadTree::CQuadNode::select.

template<class T>
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.

References _ChangeBasis, _QuadRoot, _Selection, clearSelection, NL3D::CQuadTree::CQuadNode::select, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by selectRay, and selectSegment.

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

Select all the container.

Definition at line 787 of file quad_tree.h.

References _QuadRoot, _Selection, clearSelection, and NL3D::CQuadTree::CQuadNode::selectAll.

Referenced by eraseAll.

template<class T>
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.

References NLMISC::CMatrix::getJ, NLMISC::CMatrix::getK, NLMISC::CMatrix::identity, NLMISC::CPlane::make, NLMISC::CMatrix::normalize, select, NLMISC::CMatrix::setRot, and NLMISC::CMatrix::XYZ.

template<class T>
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.

References NLMISC::CMatrix::getI, NLMISC::CMatrix::getJ, NLMISC::CMatrix::getK, NLMISC::CMatrix::identity, NLMISC::CPlane::make, NLMISC::CMatrix::normalize, select, NLMISC::CMatrix::setRot, and NLMISC::CMatrix::XYZ.


Friends And Related Function Documentation

template<class T>
friend class CConstIterator [friend]
 

Definition at line 105 of file quad_tree.h.

template<class T>
friend class CIterator [friend]
 

Definition at line 102 of file quad_tree.h.

Referenced by end, eraseAll, and insert.


Member Data Documentation

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

Definition at line 581 of file quad_tree.h.

Referenced by changeBase, CQuadTree, create, insert, and select.

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

Definition at line 579 of file quad_tree.h.

Referenced by CQuadTree, create, and insert.

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

Definition at line 577 of file quad_tree.h.

Referenced by clear, CQuadTree, create, insert, select, and selectAll.

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

Definition at line 578 of file quad_tree.h.

Referenced by begin, clear, clearSelection, CQuadTree, select, and selectAll.

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

Definition at line 580 of file quad_tree.h.

Referenced by CQuadTree, create, and insert.


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