VTK  9.2.5
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 =========================================================================*/
222 #ifndef vtkModifiedBSPTree_h
223 #define vtkModifiedBSPTree_h
224 
225 #include "vtkAbstractCellLocator.h"
226 #include "vtkFiltersFlowPathsModule.h" // For export macro
227 #include "vtkSmartPointer.h" // required because it is nice
228 
229 class Sorted_cell_extents_Lists;
230 class BSPNode;
231 class vtkGenericCell;
232 class vtkIdList;
233 class vtkIdListCollection;
234 
235 class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
236 {
237 public:
239 
243  void PrintSelf(ostream& os, vtkIndent indent) override;
245 
250 
251  // Re-use any superclass signatures that we don't override.
254 
261  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
262  double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
263 
273  int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints* points,
274  vtkIdList* cellIds, vtkGenericCell* cell) override;
275 
285  const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
286  {
287  this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
288  }
289 
297  vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
298  double pcoords[3], double* weights) override;
299 
306 
311 
313 
316  void GenerateRepresentation(int level, vtkPolyData* pd) override;
317  void FreeSearchStructure() override;
318  void BuildLocator() override;
319  void ForceBuildLocator() override;
321 
325  void ShallowCopy(vtkAbstractCellLocator* locator) override;
326 
327 protected:
330 
331  void BuildLocatorInternal() override;
332  std::shared_ptr<BSPNode> mRoot; // bounding box root node
333  int npn;
334  int nln;
336 
337  // The main subdivision routine
338  void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
339  vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
340 
341 private:
342  vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
343  void operator=(const vtkModifiedBSPTree&) = delete;
344 };
345 
347 // BSP Node
348 // A BSP Node is a BBox - axis aligned etc etc
350 #ifndef DOXYGEN_SHOULD_SKIP_THIS
351 
352 class BSPNode
353 {
354 public:
355  // Constructor
356  BSPNode(void)
357  {
358  mChild[0] = mChild[1] = mChild[2] = nullptr;
359  for (int i = 0; i < 6; i++)
360  sorted_cell_lists[i] = nullptr;
361  for (int i = 0; i < 3; i++)
362  {
363  this->Bounds[i * 2] = VTK_FLOAT_MAX;
364  this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
365  }
366  }
367  // Destructor
368  ~BSPNode(void)
369  {
370  for (int i = 0; i < 3; i++)
371  delete mChild[i];
372  for (int i = 0; i < 6; i++)
373  delete[] sorted_cell_lists[i];
374  }
375  // Set min box limits
376  void setMin(double minx, double miny, double minz)
377  {
378  this->Bounds[0] = minx;
379  this->Bounds[2] = miny;
380  this->Bounds[4] = minz;
381  }
382  // Set max box limits
383  void setMax(double maxx, double maxy, double maxz)
384  {
385  this->Bounds[1] = maxx;
386  this->Bounds[3] = maxy;
387  this->Bounds[5] = maxz;
388  }
389  //
390  bool Inside(double point[3]) const;
391  // BBox
392  double Bounds[6];
393 
394 protected:
395  // The child nodes of this one (if present - nullptr otherwise)
396  BSPNode* mChild[3];
397  // The axis we subdivide this voxel along
398  int mAxis;
399  // Just for reference
400  int depth;
401  // the number of cells in this node
402  int num_cells;
403  // 6 lists, sorted after the 6 dominant axes
404  vtkIdType* sorted_cell_lists[6];
405  // Order nodes as near/mid far relative to ray
406  void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
407  BSPNode*& Mid, BSPNode*& Far) const;
408  friend class vtkModifiedBSPTree;
409 
410 public:
411  static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
412 };
413 
414 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
415 
416 #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:172
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
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:149
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
@ 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