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=========================================================================*/
160#ifndef vtkModifiedBSPTree_h
161#define vtkModifiedBSPTree_h
162
164#include "vtkFiltersFlowPathsModule.h" // For export macro
165#include "vtkSmartPointer.h" // required because it is nice
166
167class Sorted_cell_extents_Lists;
168class BSPNode;
169class vtkGenericCell;
170class vtkIdList;
172
173class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
174{
175public:
177
181 void PrintSelf(ostream& os, vtkIndent indent) override;
183
188
189 // Re-use any superclass signatures that we don't override.
192
199 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
200 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
201
211 int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints* points,
212 vtkIdList* cellIds, vtkGenericCell* cell) override;
213
223 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
224 {
225 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
226 }
227
235 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
236 double pcoords[3], double* weights) override;
237
244
249
251
254 void GenerateRepresentation(int level, vtkPolyData* pd) override;
255 void FreeSearchStructure() override;
256 void BuildLocator() override;
257 void ForceBuildLocator() override;
259
263 void ShallowCopy(vtkAbstractCellLocator* locator) override;
264
265protected:
268
269 void BuildLocatorInternal() override;
270 std::shared_ptr<BSPNode> mRoot; // bounding box root node
271 int npn;
272 int nln;
274
275 // The main subdivision routine
276 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
277 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
278
279private:
280 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
281 void operator=(const vtkModifiedBSPTree&) = delete;
282};
283
285// BSP Node
286// A BSP Node is a BBox - axis aligned etc etc
288#ifndef DOXYGEN_SHOULD_SKIP_THIS
289
290class BSPNode
291{
292public:
293 // Constructor
294 BSPNode(void)
295 {
296 mChild[0] = mChild[1] = mChild[2] = nullptr;
297 for (int i = 0; i < 6; i++)
298 sorted_cell_lists[i] = nullptr;
299 for (int i = 0; i < 3; i++)
300 {
301 this->Bounds[i * 2] = VTK_FLOAT_MAX;
302 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
303 }
304 }
305 // Destructor
306 ~BSPNode(void)
307 {
308 for (int i = 0; i < 3; i++)
309 delete mChild[i];
310 for (int i = 0; i < 6; i++)
311 delete[] sorted_cell_lists[i];
312 }
313 // Set min box limits
314 void setMin(double minx, double miny, double minz)
315 {
316 this->Bounds[0] = minx;
317 this->Bounds[2] = miny;
318 this->Bounds[4] = minz;
319 }
320 // Set max box limits
321 void setMax(double maxx, double maxy, double maxz)
322 {
323 this->Bounds[1] = maxx;
324 this->Bounds[3] = maxy;
325 this->Bounds[5] = maxz;
326 }
327 //
328 bool Inside(double point[3]) const;
329 // BBox
330 double Bounds[6];
331
332protected:
333 // The child nodes of this one (if present - nullptr otherwise)
334 BSPNode* mChild[3];
335 // The axis we subdivide this voxel along
336 int mAxis;
337 // Just for reference
338 int depth;
339 // the number of cells in this node
340 int num_cells;
341 // 6 lists, sorted after the 6 dominant axes
342 vtkIdType* sorted_cell_lists[6];
343 // Order nodes as near/mid far relative to ray
344 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
345 BSPNode*& Mid, BSPNode*& Far) const;
346 friend class vtkModifiedBSPTree;
347
348public:
349 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
350};
351
352#endif /* DOXYGEN_SHOULD_SKIP_THIS */
353
354#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:57
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition vtkIdList.h:31
a simple class to control print indentation
Definition vtkIndent.h:34
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods to print and obtain type-related information.
vtkIdListCollection * GetLeafNodeCellInformation()
After subdivision has completed, one may wish to query the tree to find which cells are in which leaf...
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)
void FreeSearchStructure() override
Satisfy vtkLocator abstract interface.
void BuildLocator() override
Satisfy vtkLocator abstract interface.
static vtkModifiedBSPTree * New()
Construct with maximum 32 cells per node.
represent and manipulate 3D points
Definition vtkPoints.h:34
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:85
int vtkIdType
Definition vtkType.h:332
#define VTK_FLOAT_MAX
Definition vtkType.h:163