VTK  9.5.20251201
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
187
188#ifndef vtkModifiedBSPTree_h
189#define vtkModifiedBSPTree_h
190
192#include "vtkFiltersFlowPathsModule.h" // For export macro
193#include "vtkSmartPointer.h" // required because it is nice
194
195VTK_ABI_NAMESPACE_BEGIN
196class Sorted_cell_extents_Lists;
197class BSPNode;
198class vtkGenericCell;
199class vtkIdList;
201
202class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
204public:
206
210 void PrintSelf(ostream& os, vtkIndent indent) override;
212
216 static vtkModifiedBSPTree* New();
217
218 // Reuse any superclass signatures that we don't override.
221
228 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
229 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
230
240 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
241 vtkIdList* cellIds, vtkGenericCell* cell) override;
242
245 * For each intersection with the bounds of a cell, the cellIds
246 * have the relevant information added sort by t. If cellIds is nullptr
247 * pointer, then no information is generated for that list.
248 *
249 * Reimplemented from vtkAbstractCellLocator to showcase that it's a supported function.
250 */
252 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
253 {
254 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
255 }
256
264 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
265 double pcoords[3], double* weights) override;
273
283 void GenerateRepresentation(int level, vtkPolyData* pd) override;
284 void FreeSearchStructure() override;
285 void BuildLocator() override;
286 void ForceBuildLocator() override;
294 void ShallowCopy(vtkAbstractCellLocator* locator) override;
296protected:
299
300 void BuildLocatorInternal() override;
301 std::shared_ptr<BSPNode> mRoot; // bounding box root node
302 int npn;
303 int nln;
304 int tot_depth;
305
306 // The main subdivision routine
307 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
308 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
309
310private:
311 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
312 void operator=(const vtkModifiedBSPTree&) = delete;
313};
314
316// BSP Node
317// A BSP Node is a BBox - axis aligned etc etc
319#ifndef DOXYGEN_SHOULD_SKIP_THIS
320
321class BSPNode
322{
323public:
324 // Constructor
325 BSPNode()
326 {
327 mChild[0] = mChild[1] = mChild[2] = nullptr;
328 for (int i = 0; i < 6; i++)
329 sorted_cell_lists[i] = nullptr;
330 for (int i = 0; i < 3; i++)
331 {
332 this->Bounds[i * 2] = VTK_FLOAT_MAX;
333 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
334 }
335 }
336 // Destructor
337 ~BSPNode()
338 {
339 for (int i = 0; i < 3; i++)
340 delete mChild[i];
341 for (int i = 0; i < 6; i++)
342 delete[] sorted_cell_lists[i];
343 }
344 // Set min box limits
345 void setMin(double minx, double miny, double minz)
346 {
347 this->Bounds[0] = minx;
348 this->Bounds[2] = miny;
349 this->Bounds[4] = minz;
350 }
351 // Set max box limits
352 void setMax(double maxx, double maxy, double maxz)
353 {
354 this->Bounds[1] = maxx;
355 this->Bounds[3] = maxy;
356 this->Bounds[5] = maxz;
357 }
358 //
359 bool Inside(double point[3]) const;
360 // BBox
361 double Bounds[6];
362
363protected:
364 // The child nodes of this one (if present - nullptr otherwise)
365 BSPNode* mChild[3];
366 // The axis we subdivide this voxel along
367 int mAxis;
368 // Just for reference
369 int depth;
370 // the number of cells in this node
371 int num_cells;
372 // 6 lists, sorted after the 6 dominant axes
373 vtkIdType* sorted_cell_lists[6];
374 // Order nodes as near/mid far relative to ray
375 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
376 BSPNode*& Mid, BSPNode*& Far) const;
377 friend class vtkModifiedBSPTree;
378
379public:
380 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
381};
382
383#endif /* DOXYGEN_SHOULD_SKIP_THIS */
384
385VTK_ABI_NAMESPACE_END
386#endif
virtual vtkIdType FindCell(double x[3])
Returns the Id of the cell containing the point, returns -1 if no cell found.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void ShallowCopy(vtkAbstractCellLocator *)
Shallow copy of a vtkAbstractCellLocator.
virtual void FindCellsAlongLine(const double p1[3], const double p2[3], double tolerance, vtkIdList *cells)
Take the passed line segment and intersect it with the data set.
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:166
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition vtkIdList.h:133
a simple class to control print indentation
Definition vtkIndent.h:108
virtual void BuildLocatorInternal()
This function is not pure virtual to maintain backwards compatibility.
Definition vtkLocator.h:211
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition vtkLocator.h:175
virtual void GenerateRepresentation(int level, vtkPolyData *pd)=0
Method to build a representation at a particular level.
virtual void BuildLocator()=0
Build the locator from the input dataset.
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
std::shared_ptr< BSPNode > mRoot
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)
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
represent and manipulate 3D points
Definition vtkPoints.h:139
concrete dataset represents vertices, lines, polygons, and triangle strips
int vtkIdType
Definition vtkType.h:367
#define VTK_FLOAT_MAX
Definition vtkType.h:204