VTK  9.2.6
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 =========================================================================*/
172 #ifndef vtkModifiedBSPTree_h
173 #define vtkModifiedBSPTree_h
174 
175 #include "vtkAbstractCellLocator.h"
176 #include "vtkFiltersFlowPathsModule.h" // For export macro
177 #include "vtkSmartPointer.h" // required because it is nice
178 
179 class Sorted_cell_extents_Lists;
180 class BSPNode;
181 class vtkGenericCell;
182 class vtkIdList;
183 class vtkIdListCollection;
184 
185 class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
186 {
187 public:
189 
193  void PrintSelf(ostream& os, vtkIndent indent) override;
195 
200 
201  // Re-use any superclass signatures that we don't override.
204 
211  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
212  double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
213 
223  int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints* points,
224  vtkIdList* cellIds, vtkGenericCell* cell) override;
225 
235  const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
236  {
237  this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
238  }
239 
247  vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
248  double pcoords[3], double* weights) override;
249 
256 
261 
263 
266  void GenerateRepresentation(int level, vtkPolyData* pd) override;
267  void FreeSearchStructure() override;
268  void BuildLocator() override;
269  void ForceBuildLocator() override;
271 
275  void ShallowCopy(vtkAbstractCellLocator* locator) override;
276 
277 protected:
280 
281  void BuildLocatorInternal() override;
282  std::shared_ptr<BSPNode> mRoot; // bounding box root node
283  int npn;
284  int nln;
286 
287  // The main subdivision routine
288  void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
289  vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
290 
291 private:
292  vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
293  void operator=(const vtkModifiedBSPTree&) = delete;
294 };
295 
297 // BSP Node
298 // A BSP Node is a BBox - axis aligned etc etc
300 #ifndef DOXYGEN_SHOULD_SKIP_THIS
301 
302 class BSPNode
303 {
304 public:
305  // Constructor
306  BSPNode(void)
307  {
308  mChild[0] = mChild[1] = mChild[2] = nullptr;
309  for (int i = 0; i < 6; i++)
310  sorted_cell_lists[i] = nullptr;
311  for (int i = 0; i < 3; i++)
312  {
313  this->Bounds[i * 2] = VTK_FLOAT_MAX;
314  this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
315  }
316  }
317  // Destructor
318  ~BSPNode(void)
319  {
320  for (int i = 0; i < 3; i++)
321  delete mChild[i];
322  for (int i = 0; i < 6; i++)
323  delete[] sorted_cell_lists[i];
324  }
325  // Set min box limits
326  void setMin(double minx, double miny, double minz)
327  {
328  this->Bounds[0] = minx;
329  this->Bounds[2] = miny;
330  this->Bounds[4] = minz;
331  }
332  // Set max box limits
333  void setMax(double maxx, double maxy, double maxz)
334  {
335  this->Bounds[1] = maxx;
336  this->Bounds[3] = maxy;
337  this->Bounds[5] = maxz;
338  }
339  //
340  bool Inside(double point[3]) const;
341  // BBox
342  double Bounds[6];
343 
344 protected:
345  // The child nodes of this one (if present - nullptr otherwise)
346  BSPNode* mChild[3];
347  // The axis we subdivide this voxel along
348  int mAxis;
349  // Just for reference
350  int depth;
351  // the number of cells in this node
352  int num_cells;
353  // 6 lists, sorted after the 6 dominant axes
354  vtkIdType* sorted_cell_lists[6];
355  // Order nodes as near/mid far relative to ray
356  void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
357  BSPNode*& Mid, BSPNode*& Far) const;
358  friend class vtkModifiedBSPTree;
359 
360 public:
361  static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
362 };
363 
364 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
365 
366 #endif
an abstract base class for locators which find cells
virtual vtkIdType FindCell(double x[3])
Returns the Id of the cell containing the point, returns -1 if no cell found.
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.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:72
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition: vtkIdList.h:43
a simple class to control print indentation
Definition: vtkIndent.h:49
Generate axis aligned BBox tree for ray-casting and other Locator based searches.
int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell) override
Return intersection point (if any) AND the cell which was intersected by the finite line.
void FindCellsAlongLine(const double p1[3], const double p2[3], double tolerance, vtkIdList *cellsIds) override
Take the passed line segment and intersect it with the data set.
int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints *points, vtkIdList *cellIds, vtkGenericCell *cell) override
Take the passed line segment and intersect it with the data set.
void ShallowCopy(vtkAbstractCellLocator *locator) override
Shallow copy of a vtkModifiedBSPTree.
std::shared_ptr< BSPNode > mRoot
~vtkModifiedBSPTree() override
void GenerateRepresentation(int level, vtkPolyData *pd) override
Satisfy vtkLocator abstract interface.
vtkIdListCollection * GetLeafNodeCellInformation()
After subdivision has completed, one may wish to query the tree to find which cells are in which leaf...
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods to print and obtain type-related information.
vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell *GenCell, int &subId, double pcoords[3], double *weights) override
Find the cell containing a given point.
void BuildLocatorInternal() override
This function is not pure virtual to maintain backwards compatibility.
void ForceBuildLocator() override
Satisfy vtkLocator abstract interface.
virtual void GenerateRepresentationLeafs(vtkPolyData *pd)
Generate BBox representation of all leaf nodes.
void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet, vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth)
static vtkModifiedBSPTree * New()
Construct with maximum 32 cells per node.
void FreeSearchStructure() override
Satisfy vtkLocator abstract interface.
void BuildLocator() override
Satisfy vtkLocator abstract interface.
represent and manipulate 3D points
Definition: vtkPoints.h:49
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:100
@ point
Definition: vtkX3D.h:242
@ points
Definition: vtkX3D.h:452
@ level
Definition: vtkX3D.h:401
@ dir
Definition: vtkX3D.h:330
int vtkIdType
Definition: vtkType.h:332
#define VTK_FLOAT_MAX
Definition: vtkType.h:163