VTK
vtkModifiedBSPTree.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkModifiedBSPTree.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 /*=========================================================================
17  This code is derived from an earlier work and is distributed
18  with permission from, and thanks to
19 
20  ------------------------------------------
21  Copyright (C) 1997-2000 John Biddiscombe
22  Rutherford Appleton Laboratory,
23  Chilton, Oxon, England
24  ------------------------------------------
25  Copyright (C) 2000-2004 John Biddiscombe
26  Skipping Mouse Software Ltd,
27  Blewbury, England
28  ------------------------------------------
29  Copyright (C) 2004-2009 John Biddiscombe
30  CSCS - Swiss National Supercomputing Centre
31  Galleria 2 - Via Cantonale
32  CH-6928 Manno, Switzerland
33  ------------------------------------
34 =========================================================================*/
145 #ifndef _vtkModifiedBSPTree_h
146 #define _vtkModifiedBSPTree_h
147 
148 #include "vtkFiltersFlowPathsModule.h" // For export macro
149 #include "vtkAbstractCellLocator.h"
150 #include "vtkSmartPointer.h" // required because it is nice
151 
152 //BTX
153 class Sorted_cell_extents_Lists;
154 class BSPNode;
155 class vtkGenericCell;
156 class vtkIdList;
157 class vtkIdListCollection;
158 //ETX
159 
161  public:
163 
165  void PrintSelf(ostream& os, vtkIndent indent);
167 
170 
171  // Re-use any superclass signatures that we don't override.
174 
177 
179  void BuildLocator();
180 
181 //BTX
183  virtual void GenerateRepresentation(int level, vtkPolyData *pd);
184 
187 
189 
191  virtual int IntersectWithLine(
192  double p1[3], double p2[3], double tol, double &t, double x[3],
193  double pcoords[3], int &subId, vtkIdType &cellId);
195 
197 
200  virtual int IntersectWithLine(
201  double p1[3], double p2[3], double tol, double &t, double x[3],
202  double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell);
204 
206 
212  virtual int IntersectWithLine(
213  const double p1[3], const double p2[3], const double tol,
214  vtkPoints *points, vtkIdList *cellIds);
216 
218 
220  virtual vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell,
221  double pcoords[3], double *weights);
223 
224  bool InsideCellBounds(double x[3], vtkIdType cell_ID);
225 
230 
231 //ETX
232  protected:
235  //
236  BSPNode *mRoot; // bounding box root node
237  int npn;
238  int nln;
240 //BTX
241  //
242  // The main subdivision routine
243  void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet,
244  vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth);
245 
246  // We provide a function which does the cell/ray test so that
247  // it can be overriden by subclasses to perform special treatment
248  // (Example : Particles stored in tree, have no dimension, so we must
249  // override the cell test to return a value based on some particle size
250  virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3],
251  const double tol, double &t, double ipt[3], double pcoords[3], int &subId);
252 
253 //ETX
257 private:
258  vtkModifiedBSPTree(const vtkModifiedBSPTree&); // Not implemented.
259  void operator=(const vtkModifiedBSPTree&); // Not implemented.
260 };
261 
262 //BTX
263 
265 // BSP Node
266 // A BSP Node is a BBox - axis aligned etc etc
268 #ifndef DOXYGEN_SHOULD_SKIP_THIS
269 
270 class BSPNode {
271  public:
272  // Constructor
273  BSPNode(void) {
274  mChild[0] = mChild[1] = mChild[2] = NULL;
275  for (int i=0; i<6; i++) sorted_cell_lists[i] = NULL;
276  for (int i=0; i<3; i++) { this->Bounds[i*2] = VTK_FLOAT_MAX; this->Bounds[i*2+1] = -VTK_FLOAT_MAX; }
277  }
278  // Destructor
279  ~BSPNode(void) {
280  for (int i=0; i<3; i++) delete mChild[i];
281  for (int i=0; i<6; i++) delete []sorted_cell_lists[i];
282  }
283  // Set min box limits
284  void setMin(double minx, double miny, double minz) {
285  this->Bounds[0] = minx; this->Bounds[2] = miny; this->Bounds[4] = minz;
286  }
287  // Set max box limits
288  void setMax(double maxx, double maxy, double maxz) {
289  this->Bounds[1] = maxx; this->Bounds[3] = maxy; this->Bounds[5] = maxz;
290  }
291  //
292  bool Inside(double point[3]) const;
293  // BBox
294  double Bounds[6];
295  protected:
296  // The child nodes of this one (if present - NULL otherwise)
298  // The axis we subdivide this voxel along
299  int mAxis;
300  // Just for reference
301  int depth;
302  // the number of cells in this node
304  // 6 lists, sorted after the 6 dominant axes
306  // Order nodes as near/mid far relative to ray
307  void Classify(const double origin[3], const double dir[3],
308  double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const;
309  // Test ray against node BBox : clip t values to extremes
310  bool RayMinMaxT(const double origin[3], const double dir[3],
311  double &rTmin, double &rTmax) const;
312  //
313  friend class vtkModifiedBSPTree;
314  friend class vtkParticleBoxTree;
315  public:
317  const double bounds[6], const double origin[3], const double dir[3], double &rTmin, double &rTmax);
318  static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
319 };
320 
321 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
322 
323 //ETX
324 
325 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:39
BSPNode::Bounds
double Bounds[6]
Definition: vtkModifiedBSPTree.h:294
vtkgl::weights
const GLbyte * weights
Definition: vtkgl.h:12766
BSPNode::mAxis
int mAxis
Definition: vtkModifiedBSPTree.h:299
vtkAbstractCellLocator::IntersectWithLine
virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
BSPNode::RayMinMaxT
static bool VTKFILTERSFLOWPATHS_EXPORT RayMinMaxT(const double bounds[6], const double origin[3], const double dir[3], double &rTmin, double &rTmax)
BSPNode::num_cells
int num_cells
Definition: vtkModifiedBSPTree.h:303
vtkModifiedBSPTree::Subdivide
void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet, vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth)
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkModifiedBSPTree::npn
int npn
Definition: vtkModifiedBSPTree.h:237
vtkModifiedBSPTree::IntersectWithLine
virtual int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints *points, vtkIdList *cellIds)
vtkModifiedBSPTree::FindCell
virtual vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell, double pcoords[3], double *weights)
BSPNode::setMax
void setMax(double maxx, double maxy, double maxz)
Definition: vtkModifiedBSPTree.h:288
vtkModifiedBSPTree::mRoot
BSPNode * mRoot
Definition: vtkModifiedBSPTree.h:236
vtkModifiedBSPTree::BuildLocatorInternal
void BuildLocatorInternal()
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkModifiedBSPTree::IntersectWithLine
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)
vtkAbstractCellLocator.h
VTKFILTERSFLOWPATHS_EXPORT
#define VTKFILTERSFLOWPATHS_EXPORT
Definition: vtkFiltersFlowPathsModule.h:15
vtkModifiedBSPTree::InsideCellBounds
bool InsideCellBounds(double x[3], vtkIdType cell_ID)
vtkAbstractCellLocator::FindCell
virtual vtkIdType FindCell(double x[3])
vtkX3D::dir
@ dir
Definition: vtkX3D.h:324
vtkFiltersFlowPathsModule.h
BSPNode::Classify
void Classify(const double origin[3], const double dir[3], double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const
vtkgl::x
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
vtkModifiedBSPTree::IntersectCellInternal
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)
BSPNode::depth
int depth
Definition: vtkModifiedBSPTree.h:301
BSPNode::mChild
BSPNode * mChild[3]
Definition: vtkModifiedBSPTree.h:297
BSPNode::setMin
void setMin(double minx, double miny, double minz)
Definition: vtkModifiedBSPTree.h:284
BSPNode::sorted_cell_lists
vtkIdType * sorted_cell_lists[6]
Definition: vtkModifiedBSPTree.h:305
vtkgl::points
GLsizei const GLfloat * points
Definition: vtkgl.h:14786
vtkModifiedBSPTree::GetLeafNodeCellInformation
vtkIdListCollection * GetLeafNodeCellInformation()
BSPNode::Inside
bool Inside(double point[3]) const
vtkModifiedBSPTree::BuildLocatorIfNeeded
void BuildLocatorIfNeeded()
vtkgl::depth
GLint GLint GLsizei GLsizei GLsizei depth
Definition: vtkgl.h:11316
vtkX3D::point
@ point
Definition: vtkX3D.h:236
vtkModifiedBSPTree::BuildLocator
void BuildLocator()
vtkModifiedBSPTree::GenerateRepresentationLeafs
virtual void GenerateRepresentationLeafs(vtkPolyData *pd)
vtkModifiedBSPTree::vtkModifiedBSPTree
vtkModifiedBSPTree()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkSmartPointer.h
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkModifiedBSPTree::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkIdListCollection
maintain an unordered list of dataarray objects
Definition: vtkIdListCollection.h:31
VTK_FLOAT_MAX
#define VTK_FLOAT_MAX
Definition: vtkType.h:140
BSPNode::~BSPNode
~BSPNode(void)
Definition: vtkModifiedBSPTree.h:279
vtkgl::level
GLint level
Definition: vtkgl.h:11316
vtkModifiedBSPTree::~vtkModifiedBSPTree
~vtkModifiedBSPTree()
vtkModifiedBSPTree::nln
int nln
Definition: vtkModifiedBSPTree.h:238
vtkAbstractCellLocator
an abstract base class for locators which find cells
Definition: vtkAbstractCellLocator.h:50
vtkDataSet
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
vtkModifiedBSPTree::GenerateRepresentation
virtual void GenerateRepresentation(int level, vtkPolyData *pd)
vtkgl::t
GLdouble GLdouble t
Definition: vtkgl.h:11602
vtkModifiedBSPTree::New
static vtkModifiedBSPTree * New()
BSPNode::RayMinMaxT
bool RayMinMaxT(const double origin[3], const double dir[3], double &rTmin, double &rTmax) const
vtkModifiedBSPTree::IntersectWithLine
virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId)
vtkModifiedBSPTree::tot_depth
int tot_depth
Definition: vtkModifiedBSPTree.h:239
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
BSPNode::getDominantAxis
static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3])
vtkGenericCell
provides thread-safe access to cells
Definition: vtkGenericCell.h:42
vtkModifiedBSPTree::FreeSearchStructure
void FreeSearchStructure()
vtkModifiedBSPTree::ForceBuildLocator
void ForceBuildLocator()
vtkModifiedBSPTree
Generate axis aligned BBox tree for raycasting and other Locator based searches.
Definition: vtkModifiedBSPTree.h:160
BSPNode::vtkParticleBoxTree
friend class vtkParticleBoxTree
Definition: vtkModifiedBSPTree.h:314
BSPNode::BSPNode
BSPNode(void)
Definition: vtkModifiedBSPTree.h:273
BSPNode
Definition: vtkModifiedBSPTree.h:270