VTK  9.3.0
vtkModifiedBSPTree.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright (c) 1997-2009 John Biddiscombe
3// SPDX-License-Identifier: BSD-3-Clause
141#ifndef vtkModifiedBSPTree_h
142#define vtkModifiedBSPTree_h
143
145#include "vtkFiltersFlowPathsModule.h" // For export macro
146#include "vtkSmartPointer.h" // required because it is nice
147
148VTK_ABI_NAMESPACE_BEGIN
149class Sorted_cell_extents_Lists;
150class BSPNode;
151class vtkGenericCell;
152class vtkIdList;
154
155class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
156{
157public:
159
163 void PrintSelf(ostream& os, vtkIndent indent) override;
165
170
171 // Re-use any superclass signatures that we don't override.
174
181 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
182 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
183
193 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
194 vtkIdList* cellIds, vtkGenericCell* cell) override;
195
205 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
206 {
207 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
208 }
209
217 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
218 double pcoords[3], double* weights) override;
219
226
231
233
236 void GenerateRepresentation(int level, vtkPolyData* pd) override;
237 void FreeSearchStructure() override;
238 void BuildLocator() override;
239 void ForceBuildLocator() override;
241
245 void ShallowCopy(vtkAbstractCellLocator* locator) override;
246
247protected:
250
251 void BuildLocatorInternal() override;
252 std::shared_ptr<BSPNode> mRoot; // bounding box root node
253 int npn;
254 int nln;
256
257 // The main subdivision routine
258 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
259 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
260
261private:
262 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
263 void operator=(const vtkModifiedBSPTree&) = delete;
264};
265
267// BSP Node
268// A BSP Node is a BBox - axis aligned etc etc
270#ifndef DOXYGEN_SHOULD_SKIP_THIS
271
272class BSPNode
273{
274public:
275 // Constructor
276 BSPNode()
277 {
278 mChild[0] = mChild[1] = mChild[2] = nullptr;
279 for (int i = 0; i < 6; i++)
280 sorted_cell_lists[i] = nullptr;
281 for (int i = 0; i < 3; i++)
282 {
283 this->Bounds[i * 2] = VTK_FLOAT_MAX;
284 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
285 }
286 }
287 // Destructor
288 ~BSPNode()
289 {
290 for (int i = 0; i < 3; i++)
291 delete mChild[i];
292 for (int i = 0; i < 6; i++)
293 delete[] sorted_cell_lists[i];
294 }
295 // Set min box limits
296 void setMin(double minx, double miny, double minz)
297 {
298 this->Bounds[0] = minx;
299 this->Bounds[2] = miny;
300 this->Bounds[4] = minz;
301 }
302 // Set max box limits
303 void setMax(double maxx, double maxy, double maxz)
304 {
305 this->Bounds[1] = maxx;
306 this->Bounds[3] = maxy;
307 this->Bounds[5] = maxz;
308 }
309 //
310 bool Inside(double point[3]) const;
311 // BBox
312 double Bounds[6];
313
314protected:
315 // The child nodes of this one (if present - nullptr otherwise)
316 BSPNode* mChild[3];
317 // The axis we subdivide this voxel along
318 int mAxis;
319 // Just for reference
320 int depth;
321 // the number of cells in this node
322 int num_cells;
323 // 6 lists, sorted after the 6 dominant axes
324 vtkIdType* sorted_cell_lists[6];
325 // Order nodes as near/mid far relative to ray
326 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
327 BSPNode*& Mid, BSPNode*& Far) const;
328 friend class vtkModifiedBSPTree;
329
330public:
331 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
332};
333
334#endif /* DOXYGEN_SHOULD_SKIP_THIS */
335
336VTK_ABI_NAMESPACE_END
337#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:62
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition vtkIdList.h:32
a simple class to control print indentation
Definition vtkIndent.h:38
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.
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.
int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints *points, vtkIdList *cellIds, vtkGenericCell *cell) override
Take the passed line segment and intersect it with the data set.
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:38
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:89
int vtkIdType
Definition vtkType.h:315
#define VTK_FLOAT_MAX
Definition vtkType.h:152