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 
169  static vtkModifiedBSPTree *New();
170 
171  // Re-use any superclass signatures that we don't override.
174 
176  void FreeSearchStructure();
177 
179  void BuildLocator();
180 
181 //BTX
183  virtual void GenerateRepresentation(int level, vtkPolyData *pd);
184 
186  virtual void GenerateRepresentationLeafs(vtkPolyData *pd);
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 
229  vtkIdListCollection *GetLeafNodeCellInformation();
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
254  void BuildLocatorIfNeeded();
255  void ForceBuildLocator();
256  void BuildLocatorInternal();
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
#define VTKFILTERSFLOWPATHS_EXPORT
virtual void BuildLocator()=0
bool Inside(double point[3]) const
virtual bool InsideCellBounds(double x[3], vtkIdType cell_ID)
abstract class to specify dataset behavior
Definition: vtkDataSet.h:61
BSPNode * mChild[3]
an abstract base class for locators which find cells
static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3])
void Classify(const double origin[3], const double dir[3], double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const
int vtkIdType
Definition: vtkType.h:275
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:83
virtual void FreeSearchStructure()=0
provides thread-safe access to cells
bool RayMinMaxT(const double origin[3], const double dir[3], double &rTmin, double &rTmax) const
void PrintSelf(ostream &os, vtkIndent indent)
#define VTK_FLOAT_MAX
Definition: vtkType.h:140
void setMax(double maxx, double maxy, double maxz)
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual vtkIdType FindCell(double x[3])
list of point or cell ids
Definition: vtkIdList.h:35
friend class vtkParticleBoxTree
void setMin(double minx, double miny, double minz)
virtual int IntersectWithLine(double p1[3], double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
maintain an unordered list of dataarray objects
vtkIdType * sorted_cell_lists[6]
static vtkObject * New()
virtual void GenerateRepresentation(int level, vtkPolyData *pd)=0
double Bounds[6]
represent and manipulate 3D points
Definition: vtkPoints.h:38
Generate axis aligned BBox tree for raycasting and other Locator based searches.