VTK  9.1.0
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=========================================================================*/
154#ifndef vtkModifiedBSPTree_h
155#define vtkModifiedBSPTree_h
156
158#include "vtkFiltersFlowPathsModule.h" // For export macro
159#include "vtkSmartPointer.h" // required because it is nice
160
161class Sorted_cell_extents_Lists;
162class BSPNode;
163class vtkGenericCell;
164class vtkIdList;
166
167class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
168{
169public:
171
175 void PrintSelf(ostream& os, vtkIndent indent) override;
177
182
183 // Re-use any superclass signatures that we don't override.
186
190 void FreeSearchStructure() override;
191
195 void BuildLocator() override;
196
200 void GenerateRepresentation(int level, vtkPolyData* pd) override;
201
206
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) override;
213
218 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
219 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
220
229 virtual int IntersectWithLine(const double p1[3], const double p2[3], const double tol,
230 vtkPoints* points, vtkIdList* cellIds);
231
237 double x[3], double tol2, vtkGenericCell* GenCell, double pcoords[3], double* weights) override;
238
239 bool InsideCellBounds(double x[3], vtkIdType cell_ID) override;
240
247
248protected:
251 //
252 BSPNode* mRoot; // bounding box root node
253 int npn;
254 int nln;
256
257 //
258 // The main subdivision routine
259 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
260 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
261
262 // We provide a function which does the cell/ray test so that
263 // it can be overridden by subclasses to perform special treatment
264 // (Example : Particles stored in tree, have no dimension, so we must
265 // override the cell test to return a value based on some particle size
266 virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3],
267 const double tol, double& t, double ipt[3], double pcoords[3], int& subId);
268
272
273private:
274 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
275 void operator=(const vtkModifiedBSPTree&) = delete;
276};
277
279// BSP Node
280// A BSP Node is a BBox - axis aligned etc etc
282#ifndef DOXYGEN_SHOULD_SKIP_THIS
283
284class BSPNode
285{
286public:
287 // Constructor
288 BSPNode(void)
289 {
290 mChild[0] = mChild[1] = mChild[2] = nullptr;
291 for (int i = 0; i < 6; i++)
292 sorted_cell_lists[i] = nullptr;
293 for (int i = 0; i < 3; i++)
294 {
295 this->Bounds[i * 2] = VTK_FLOAT_MAX;
296 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
297 }
298 }
299 // Destructor
300 ~BSPNode(void)
301 {
302 for (int i = 0; i < 3; i++)
303 delete mChild[i];
304 for (int i = 0; i < 6; i++)
305 delete[] sorted_cell_lists[i];
306 }
307 // Set min box limits
308 void setMin(double minx, double miny, double minz)
309 {
310 this->Bounds[0] = minx;
311 this->Bounds[2] = miny;
312 this->Bounds[4] = minz;
313 }
314 // Set max box limits
315 void setMax(double maxx, double maxy, double maxz)
316 {
317 this->Bounds[1] = maxx;
318 this->Bounds[3] = maxy;
319 this->Bounds[5] = maxz;
320 }
321 //
322 bool Inside(double point[3]) const;
323 // BBox
324 double Bounds[6];
325
326protected:
327 // The child nodes of this one (if present - nullptr otherwise)
328 BSPNode* mChild[3];
329 // The axis we subdivide this voxel along
330 int mAxis;
331 // Just for reference
332 int depth;
333 // the number of cells in this node
334 int num_cells;
335 // 6 lists, sorted after the 6 dominant axes
336 vtkIdType* sorted_cell_lists[6];
337 // Order nodes as near/mid far relative to ray
338 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
339 BSPNode*& Mid, BSPNode*& Far) const;
340 // Test ray against node BBox : clip t values to extremes
341 bool RayMinMaxT(const double origin[3], const double dir[3], double& rTmin, double& rTmax) const;
342 //
343 friend class vtkModifiedBSPTree;
344 friend class vtkParticleBoxTree;
345
346public:
347 static bool VTKFILTERSFLOWPATHS_EXPORT RayMinMaxT(const double bounds[6], const double origin[3],
348 const double dir[3], double& rTmin, double& rTmax);
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:66
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition: vtkIdList.h:40
a simple class to control print indentation
Definition: vtkIndent.h:43
Generate axis aligned BBox tree for raycasting and other Locator based searches.
virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3], const double tol, double &t, double ipt[3], double pcoords[3], int &subId)
int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId, vtkIdType &cellId) override
Return intersection point (if any) AND the cell which was intersected by the finite line.
vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell, double pcoords[3], double *weights) override
Test a point to find if it is inside a cell.
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.
virtual int IntersectWithLine(const double p1[3], const double p2[3], const double tol, vtkPoints *points, vtkIdList *cellIds)
Take the passed line segment and intersect it with the data set.
~vtkModifiedBSPTree() override
void GenerateRepresentation(int level, vtkPolyData *pd) override
Generate BBox representation of Nth level.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard Type-Macro.
bool InsideCellBounds(double x[3], vtkIdType cell_ID) override
Quickly test if a point is inside the bounds of a particular cell.
void BuildLocatorIfNeeded()
vtkIdListCollection * GetLeafNodeCellInformation()
After subdivision has completed, one may wish to query the tree to find which cells are in which leaf...
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
Free tree memory.
void BuildLocatorInternal()
void BuildLocator() override
Build Tree.
static vtkModifiedBSPTree * New()
Construct with maximum 32 cells per node.
represent and manipulate 3D points
Definition: vtkPoints.h:43
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:95
@ 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