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 =========================================================================*/
146 #ifndef vtkModifiedBSPTree_h
147 #define vtkModifiedBSPTree_h
148 
149 #include "vtkFiltersFlowPathsModule.h" // For export macro
150 #include "vtkAbstractCellLocator.h"
151 #include "vtkSmartPointer.h" // required because it is nice
152 
153 class Sorted_cell_extents_Lists;
154 class BSPNode;
155 class vtkGenericCell;
156 class vtkIdList;
157 class vtkIdListCollection;
158 
159 class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator {
160  public:
162 
166  void PrintSelf(ostream& os, vtkIndent indent) override;
168 
172  static vtkModifiedBSPTree *New();
173 
174  // Re-use any superclass signatures that we don't override.
177 
181  void FreeSearchStructure() override;
182 
186  void BuildLocator() override;
187 
191  void GenerateRepresentation(int level, vtkPolyData *pd) override;
192 
196  virtual void GenerateRepresentationLeafs(vtkPolyData *pd);
197 
202  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3],
203  double pcoords[3], int &subId, vtkIdType &cellId) override;
204 
209  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3],
210  double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell) override;
211 
220  virtual int IntersectWithLine(
221  const double p1[3], const double p2[3], const double tol,
222  vtkPoints *points, vtkIdList *cellIds);
223 
228  vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell,
229  double pcoords[3], double *weights) override;
230 
231  bool InsideCellBounds(double x[3], vtkIdType cell_ID) override;
232 
238  vtkIdListCollection *GetLeafNodeCellInformation();
239 
240  protected:
242  ~vtkModifiedBSPTree() override;
243  //
244  BSPNode *mRoot; // bounding box root node
245  int npn;
246  int nln;
248 
249  //
250  // The main subdivision routine
251  void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet,
252  vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth);
253 
254  // We provide a function which does the cell/ray test so that
255  // it can be overridden by subclasses to perform special treatment
256  // (Example : Particles stored in tree, have no dimension, so we must
257  // override the cell test to return a value based on some particle size
258  virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3],
259  const double tol, double &t, double ipt[3], double pcoords[3], int &subId);
260 
261  void BuildLocatorIfNeeded();
262  void ForceBuildLocator();
263  void BuildLocatorInternal();
264 private:
265  vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
266  void operator=(const vtkModifiedBSPTree&) = delete;
267 };
268 
270 // BSP Node
271 // A BSP Node is a BBox - axis aligned etc etc
273 #ifndef DOXYGEN_SHOULD_SKIP_THIS
274 
275 class BSPNode {
276  public:
277  // Constructor
278  BSPNode(void) {
279  mChild[0] = mChild[1] = mChild[2] = nullptr;
280  for (int i=0; i<6; i++) sorted_cell_lists[i] = nullptr;
281  for (int i=0; i<3; i++) { this->Bounds[i*2] = VTK_FLOAT_MAX; this->Bounds[i*2+1] = -VTK_FLOAT_MAX; }
282  }
283  // Destructor
284  ~BSPNode(void) {
285  for (int i=0; i<3; i++) delete mChild[i];
286  for (int i=0; i<6; i++) delete []sorted_cell_lists[i];
287  }
288  // Set min box limits
289  void setMin(double minx, double miny, double minz) {
290  this->Bounds[0] = minx; this->Bounds[2] = miny; this->Bounds[4] = minz;
291  }
292  // Set max box limits
293  void setMax(double maxx, double maxy, double maxz) {
294  this->Bounds[1] = maxx; this->Bounds[3] = maxy; this->Bounds[5] = maxz;
295  }
296  //
297  bool Inside(double point[3]) const;
298  // BBox
299  double Bounds[6];
300  protected:
301  // The child nodes of this one (if present - nullptr otherwise)
302  BSPNode *mChild[3];
303  // The axis we subdivide this voxel along
304  int mAxis;
305  // Just for reference
306  int depth;
307  // the number of cells in this node
308  int num_cells;
309  // 6 lists, sorted after the 6 dominant axes
310  vtkIdType *sorted_cell_lists[6];
311  // Order nodes as near/mid far relative to ray
312  void Classify(const double origin[3], const double dir[3],
313  double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const;
314  // Test ray against node BBox : clip t values to extremes
315  bool RayMinMaxT(const double origin[3], const double dir[3],
316  double &rTmin, double &rTmax) const;
317  //
318  friend class vtkModifiedBSPTree;
319  friend class vtkParticleBoxTree;
320  public:
321  static bool VTKFILTERSFLOWPATHS_EXPORT RayMinMaxT(
322  const double bounds[6], const double origin[3], const double dir[3], double &rTmin, double &rTmax);
323  static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
324 };
325 
326 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
327 
328 #endif
virtual void BuildLocator()=0
Build the locator from the input dataset.
virtual bool InsideCellBounds(double x[3], vtkIdType cell_ID)
Quickly test if a point is inside the bounds of a particular cell.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
an abstract base class for locators which find cells
int vtkIdType
Definition: vtkType.h:347
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
provides thread-safe access to cells
#define VTK_FLOAT_MAX
Definition: vtkType.h:167
virtual int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
Return intersection point (if any) of finite line with cells contained in cell locator.
a simple class to control print indentation
Definition: vtkIndent.h:39
virtual vtkIdType FindCell(double x[3])
Returns the Id of the cell containing the point, returns -1 if no cell found.
list of point or cell ids
Definition: vtkIdList.h:36
maintain an ordered list of IdList objects
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void GenerateRepresentation(int level, vtkPolyData *pd)=0
Method to build a representation at a particular level.
represent and manipulate 3D points
Definition: vtkPoints.h:39
Generate axis aligned BBox tree for raycasting and other Locator based searches.