VTK
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
vtkModifiedBSPTree Class Reference

Generate axis aligned BBox tree for raycasting and other Locator based searches. More...

#include <vtkModifiedBSPTree.h>

Inheritance diagram for vtkModifiedBSPTree:
[legend]
Collaboration diagram for vtkModifiedBSPTree:
[legend]

Public Member Functions

void FreeSearchStructure ()
 
void BuildLocator ()
 
virtual void GenerateRepresentation (int level, vtkPolyData *pd)
 
virtual void GenerateRepresentationLeafs (vtkPolyData *pd)
 
bool InsideCellBounds (double x[3], vtkIdType cell_ID)
 
vtkIdListCollectionGetLeafNodeCellInformation ()
 
virtual int IntersectWithLine (double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId)
 
virtual int IntersectWithLine (double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell)
 
virtual int IntersectWithLine (const double p1[3], const double p2[3], const double tol, vtkPoints *points, vtkIdList *cellIds)
 
virtual vtkIdType FindCell (double x[3], double tol2, vtkGenericCell *GenCell, double pcoords[3], double *weights)
 
- Public Member Functions inherited from vtkAbstractCellLocator
vtkAbstractCellLocatorNewInstance () const
 
virtual void FindCellsWithinBounds (double *bbox, vtkIdList *cells)
 
virtual vtkIdType FindCell (double x[3])
 
virtual void SetNumberOfCellsPerNode (int)
 
virtual int GetNumberOfCellsPerNode ()
 
virtual void SetCacheCellBounds (int)
 
virtual int GetCacheCellBounds ()
 
virtual void CacheCellBoundsOn ()
 
virtual void CacheCellBoundsOff ()
 
virtual void SetRetainCellLists (int)
 
virtual int GetRetainCellLists ()
 
virtual void RetainCellListsOn ()
 
virtual void RetainCellListsOff ()
 
virtual void SetLazyEvaluation (int)
 
virtual int GetLazyEvaluation ()
 
virtual void LazyEvaluationOn ()
 
virtual void LazyEvaluationOff ()
 
virtual void SetUseExistingSearchStructure (int)
 
virtual int GetUseExistingSearchStructure ()
 
virtual void UseExistingSearchStructureOn ()
 
virtual void UseExistingSearchStructureOff ()
 
virtual int IntersectWithLine (double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
 
virtual int IntersectWithLine (const double p1[3], const double p2[3], vtkPoints *points, vtkIdList *cellIds)
 
virtual void FindClosestPoint (double x[3], double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
 
virtual void FindClosestPoint (double x[3], double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2)
 
virtual vtkIdType FindClosestPointWithinRadius (double x[3], double radius, double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
 
virtual vtkIdType FindClosestPointWithinRadius (double x[3], double radius, double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2)
 
virtual vtkIdType FindClosestPointWithinRadius (double x[3], double radius, double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2, int &inside)
 
virtual void FindCellsAlongLine (double p1[3], double p2[3], double tolerance, vtkIdList *cells)
 
- Public Member Functions inherited from vtkLocator
vtkLocatorNewInstance () const
 
virtual void Update ()
 
virtual void Initialize ()
 
virtual void SetDataSet (vtkDataSet *)
 
virtual vtkDataSetGetDataSet ()
 
virtual void SetMaxLevel (int)
 
virtual int GetMaxLevel ()
 
virtual int GetLevel ()
 
virtual void SetAutomatic (int)
 
virtual int GetAutomatic ()
 
virtual void AutomaticOn ()
 
virtual void AutomaticOff ()
 
virtual void SetTolerance (double)
 
virtual double GetTolerance ()
 
virtual unsigned long GetBuildTime ()
 
virtual void Register (vtkObjectBase *o)
 
virtual void UnRegister (vtkObjectBase *o)
 
- Public Member Functions inherited from vtkObject
vtkObjectNewInstance () const
 
virtual void DebugOn ()
 
virtual void DebugOff ()
 
bool GetDebug ()
 
void SetDebug (bool debugFlag)
 
virtual void Modified ()
 
virtual unsigned long GetMTime ()
 
unsigned long AddObserver (unsigned long event, vtkCommand *, float priority=0.0f)
 
unsigned long AddObserver (const char *event, vtkCommand *, float priority=0.0f)
 
vtkCommandGetCommand (unsigned long tag)
 
void RemoveObserver (vtkCommand *)
 
void RemoveObservers (unsigned long event, vtkCommand *)
 
void RemoveObservers (const char *event, vtkCommand *)
 
int HasObserver (unsigned long event, vtkCommand *)
 
int HasObserver (const char *event, vtkCommand *)
 
void RemoveObserver (unsigned long tag)
 
void RemoveObservers (unsigned long event)
 
void RemoveObservers (const char *event)
 
void RemoveAllObservers ()
 
int HasObserver (unsigned long event)
 
int HasObserver (const char *event)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, void(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
template<class U , class T >
unsigned long AddObserver (unsigned long event, U observer, bool(T::*callback)(vtkObject *, unsigned long, void *), float priority=0.0f)
 
int InvokeEvent (unsigned long event, void *callData)
 
int InvokeEvent (const char *event, void *callData)
 
int InvokeEvent (unsigned long event)
 
int InvokeEvent (const char *event)
 
- Public Member Functions inherited from vtkObjectBase
const char * GetClassName () const
 
virtual void Delete ()
 
virtual void FastDelete ()
 
void Print (ostream &os)
 
void SetReferenceCount (int)
 
void PrintRevisions (ostream &)
 
virtual void PrintHeader (ostream &os, vtkIndent indent)
 
virtual void PrintTrailer (ostream &os, vtkIndent indent)
 
int GetReferenceCount ()
 

Static Public Member Functions

static vtkModifiedBSPTreeNew ()
 
- Static Public Member Functions inherited from vtkAbstractCellLocator
static int IsTypeOf (const char *type)
 
static vtkAbstractCellLocatorSafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkLocator
static int IsTypeOf (const char *type)
 
static vtkLocatorSafeDownCast (vtkObjectBase *o)
 
- Static Public Member Functions inherited from vtkObject
static int IsTypeOf (const char *type)
 
static vtkObjectSafeDownCast (vtkObjectBase *o)
 
static vtkObjectNew ()
 
static void BreakOnError ()
 
static void SetGlobalWarningDisplay (int val)
 
static void GlobalWarningDisplayOn ()
 
static void GlobalWarningDisplayOff ()
 
static int GetGlobalWarningDisplay ()
 
- Static Public Member Functions inherited from vtkObjectBase
static int IsTypeOf (const char *name)
 
static vtkObjectBaseNew ()
 

Protected Member Functions

 vtkModifiedBSPTree ()
 
 ~vtkModifiedBSPTree ()
 
void Subdivide (BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet, vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth)
 
virtual int IntersectCellInternal (vtkIdType cell_ID, const double p1[3], const double p2[3], const double tol, double &t, double ipt[3], double pcoords[3], int &subId)
 
void BuildLocatorIfNeeded ()
 
void ForceBuildLocator ()
 
void BuildLocatorInternal ()
 
- Protected Member Functions inherited from vtkAbstractCellLocator
 vtkAbstractCellLocator ()
 
 ~vtkAbstractCellLocator ()
 
virtual bool StoreCellBounds ()
 
virtual void FreeCellBounds ()
 
- Protected Member Functions inherited from vtkLocator
virtual void ReportReferences (vtkGarbageCollector *)
 
 vtkLocator ()
 
 ~vtkLocator ()
 
- Protected Member Functions inherited from vtkObject
 vtkObject ()
 
virtual ~vtkObject ()
 
virtual void RegisterInternal (vtkObjectBase *, int check)
 
virtual void UnRegisterInternal (vtkObjectBase *, int check)
 
void InternalGrabFocus (vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
 
void InternalReleaseFocus ()
 
- Protected Member Functions inherited from vtkObjectBase
 vtkObjectBase ()
 
virtual ~vtkObjectBase ()
 
virtual void CollectRevisions (ostream &)
 
 vtkObjectBase (const vtkObjectBase &)
 
void operator= (const vtkObjectBase &)
 

Protected Attributes

BSPNodemRoot
 
int npn
 
int nln
 
int tot_depth
 
- Protected Attributes inherited from vtkAbstractCellLocator
int NumberOfCellsPerNode
 
int RetainCellLists
 
int CacheCellBounds
 
int LazyEvaluation
 
int UseExistingSearchStructure
 
vtkGenericCellGenericCell
 
double(* CellBounds )[6]
 
- Protected Attributes inherited from vtkLocator
vtkDataSetDataSet
 
int Automatic
 
double Tolerance
 
int MaxLevel
 
int Level
 
vtkTimeStamp BuildTime
 
- Protected Attributes inherited from vtkObject
bool Debug
 
vtkTimeStamp MTime
 
vtkSubjectHelper * SubjectHelper
 
- Protected Attributes inherited from vtkObjectBase
vtkAtomicInt32 ReferenceCount
 
vtkWeakPointerBase ** WeakPointers
 
typedef vtkAbstractCellLocator Superclass
 
static int IsTypeOf (const char *type)
 
static vtkModifiedBSPTreeSafeDownCast (vtkObjectBase *o)
 
virtual int IsA (const char *type)
 
vtkModifiedBSPTreeNewInstance () const
 
void PrintSelf (ostream &os, vtkIndent indent)
 
virtual vtkObjectBaseNewInstanceInternal () const
 

Additional Inherited Members

- Public Types inherited from vtkAbstractCellLocator
typedef vtkLocator Superclass
 
- Public Types inherited from vtkLocator
typedef vtkObject Superclass
 
- Public Types inherited from vtkObject
typedef vtkObjectBase Superclass
 

Detailed Description

Generate axis aligned BBox tree for raycasting and other Locator based searches.

vtkModifiedBSPTree creates an evenly balanced BSP tree using a top down implementation. Axis aligned split planes are found which evenly divide cells into two buckets. Generally a split plane will intersect some cells and these are usually stored in both child nodes of the current parent. (Or split into separate cells which we cannot consider in this case). Storing cells in multiple buckets creates problems associated with multiple tests against rays and increases the required storage as complex meshes will have many cells straddling a split plane (and further splits may cause multiple copies of these).

During a discussion with Arno Formella in 1998 he suggested using a third child node to store objects which straddle split planes. I've not seen this published (Yes! - see below), but thought it worth trying. This implementation of the BSP tree creates a third child node for storing cells laying across split planes, the third cell may overlap the other two, but the two 'proper' nodes otherwise conform to usual BSP rules.

The advantage of this implementation is cells only ever lie in one node and mailbox testing is avoided. All BBoxes are axis aligned and a ray cast uses an efficient search strategy based on near/far nodes and rejects all BBoxes using simple tests.

For fast raytracing, 6 copies of cell lists are stored in each leaf node each list is in axis sorted order +/- x,y,z and cells are always tested in the direction of the ray dominant axis. Once an intersection is found any cell or BBox with a closest point further than the I-point can be instantly rejected and raytracing stops as soon as no nodes can be closer than the current best intersection point.

The addition of the 'middle' node upsets the optimal balance of the tree, but is a minor overhead during the raytrace. Each child node is contracted such that it tightly fits all cells inside it, enabling further ray/box rejections.

This class is intended for persons requiring many ray tests and is optimized for this purpose. As no cell ever lies in more than one leaf node, and parent nodes do not maintain cell lists, the memory overhead of the sorted cell lists is 6*num_cells*4 for 6 lists of ints, each num_cells in length. The memory requirement of the nodes themselves is usually of minor significance.

Subdividision is controlled by MaxCellsPerNode - any node with more than this number will be subdivided providing a good split plane can be found and the max depth is not exceeded.

The average cells per leaf will usually be around half the MaxCellsPerNode, though the middle node is usually sparsely populated and lowers the average slightly. The middle node will not be created when not needed. Subdividing down to very small cells per node is not generally suggested as then the 6 stored cell lists are effectively redundant.

Values of MaxcellsPerNode of around 16->128 depending on dataset size will usually give good results.

Cells are only sorted into 6 lists once - before tree creation, each node segments the lists and passes them down to the new child nodes whilst maintaining sorted order. This makes for an efficient subdivision strategy.

NB. The following reference has been sent to me {formella-1995-ray, author = "Arno Formella and Christian Gill", title = "{Ray Tracing: A Quantitative Analysis and a New Practical Algorithm}", journal = "{The Visual Computer}", year = "{1995}", month = dec, pages = "{465--476}", volume = "{11}", number = "{9}", publisher = "{Springer}", keywords = "{ray tracing, space subdivision, plane traversal, octree, clustering, benchmark scenes}", annote = "{We present a new method to accelerate the process of finding nearest ray–object intersections in ray tracing. The algorithm consumes an amount of memory more or less linear in the number of objects. The basic ideas can be characterized with a modified BSP–tree and plane traversal. Plane traversal is a fast linear time algorithm to find the closest intersection point in a list of bounding volumes hit by a ray. We use plane traversal at every node of the high outdegree BSP–tree. Our implementation is competitive to fast ray tracing programs. We present a benchmark suite which allows for an extensive comparison of ray tracing algorithms.}", }

Thanks:
John Biddiscombe for developing and contributing this class
Todo:

Implement intersection heap for testing rays against transparent objects

Style:

This class is currently maintained by J. Biddiscombe who has specially requested that the code style not be modified to the kitware standard. Please respect the contribution of this class by keeping the style as close as possible to the author's original.

Tests:
vtkModifiedBSPTree (Tests)

Definition at line 160 of file vtkModifiedBSPTree.h.

Member Typedef Documentation

Standard Type-Macro

Definition at line 164 of file vtkModifiedBSPTree.h.

Constructor & Destructor Documentation

vtkModifiedBSPTree::vtkModifiedBSPTree ( )
protected
vtkModifiedBSPTree::~vtkModifiedBSPTree ( )
protected

Member Function Documentation

static int vtkModifiedBSPTree::IsTypeOf ( const char *  type)
static

Standard Type-Macro

virtual int vtkModifiedBSPTree::IsA ( const char *  type)
virtual

Standard Type-Macro

Reimplemented from vtkAbstractCellLocator.

static vtkModifiedBSPTree* vtkModifiedBSPTree::SafeDownCast ( vtkObjectBase o)
static

Standard Type-Macro

virtual vtkObjectBase* vtkModifiedBSPTree::NewInstanceInternal ( ) const
protectedvirtual

Standard Type-Macro

Reimplemented from vtkAbstractCellLocator.

vtkModifiedBSPTree* vtkModifiedBSPTree::NewInstance ( ) const

Standard Type-Macro

void vtkModifiedBSPTree::PrintSelf ( ostream &  os,
vtkIndent  indent 
)
virtual

Standard Type-Macro

Reimplemented from vtkAbstractCellLocator.

static vtkModifiedBSPTree* vtkModifiedBSPTree::New ( )
static

Construct with maximum 32 cells per node. (average 16->31)

void vtkModifiedBSPTree::FreeSearchStructure ( )
virtual

Free tree memory

Implements vtkLocator.

void vtkModifiedBSPTree::BuildLocator ( )
virtual

Build Tree

Implements vtkLocator.

virtual void vtkModifiedBSPTree::GenerateRepresentation ( int  level,
vtkPolyData pd 
)
virtual

Generate BBox representation of Nth level

Implements vtkLocator.

virtual void vtkModifiedBSPTree::GenerateRepresentationLeafs ( vtkPolyData pd)
virtual

Generate BBox representation of all leaf nodes

virtual int vtkModifiedBSPTree::IntersectWithLine ( double  p1[3],
double  p2[3],
double  tol,
double t,
double  x[3],
double  pcoords[3],
int subId,
vtkIdType cellId 
)
virtual

Return intersection point (if any) AND the cell which was intersected by the finite line. Uses fast tree-search BBox rejection tests.

Reimplemented from vtkAbstractCellLocator.

virtual int vtkModifiedBSPTree::IntersectWithLine ( double  p1[3],
double  p2[3],
double  tol,
double t,
double  x[3],
double  pcoords[3],
int subId,
vtkIdType cellId,
vtkGenericCell cell 
)
virtual

Return intersection point (if any) AND the cell which was intersected by the finite line. The cell is returned as a cell id and as a generic cell.

Reimplemented from vtkAbstractCellLocator.

virtual int vtkModifiedBSPTree::IntersectWithLine ( const double  p1[3],
const double  p2[3],
const double  tol,
vtkPoints points,
vtkIdList cellIds 
)
virtual

Take the passed line segment and intersect it with the data set. The return value of the function is 0 if no intersections were found. For each intersection found, the vtkPoints and CellIds objects have the relevant information added in order of intersection increasing from ray start to end. If either vtkPoints or CellIds are NULL pointers, then no information is generated for that list.

virtual vtkIdType vtkModifiedBSPTree::FindCell ( double  x[3],
double  tol2,
vtkGenericCell GenCell,
double  pcoords[3],
double weights 
)
virtual

Test a point to find if it is inside a cell. Returns the cellId if inside or -1 if not.

Reimplemented from vtkAbstractCellLocator.

bool vtkModifiedBSPTree::InsideCellBounds ( double  x[3],
vtkIdType  cell_ID 
)
virtual

Quickly test if a point is inside the bounds of a particular cell. Some locators cache cell bounds and this function can make use of fast access to the data.

Reimplemented from vtkAbstractCellLocator.

vtkIdListCollection* vtkModifiedBSPTree::GetLeafNodeCellInformation ( )

After subdivision has completed, one may wish to query the tree to find which cells are in which leaf nodes. This function returns a list which holds a cell Id list for each leaf node.

void vtkModifiedBSPTree::Subdivide ( BSPNode node,
Sorted_cell_extents_Lists *  lists,
vtkDataSet dataSet,
vtkIdType  nCells,
int  depth,
int  maxlevel,
vtkIdType  maxCells,
int MaxDepth 
)
protected
virtual int vtkModifiedBSPTree::IntersectCellInternal ( vtkIdType  cell_ID,
const double  p1[3],
const double  p2[3],
const double  tol,
double t,
double  ipt[3],
double  pcoords[3],
int subId 
)
protectedvirtual
void vtkModifiedBSPTree::BuildLocatorIfNeeded ( )
protected
void vtkModifiedBSPTree::ForceBuildLocator ( )
protected
void vtkModifiedBSPTree::BuildLocatorInternal ( )
protected

Member Data Documentation

BSPNode* vtkModifiedBSPTree::mRoot
protected

Definition at line 236 of file vtkModifiedBSPTree.h.

int vtkModifiedBSPTree::npn
protected

Definition at line 237 of file vtkModifiedBSPTree.h.

int vtkModifiedBSPTree::nln
protected

Definition at line 238 of file vtkModifiedBSPTree.h.

int vtkModifiedBSPTree::tot_depth
protected

Definition at line 239 of file vtkModifiedBSPTree.h.


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