VTK  9.6.20260605
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
186
187#ifndef vtkModifiedBSPTree_h
188#define vtkModifiedBSPTree_h
189
191#include "vtkFiltersFlowPathsModule.h" // For export macro
192#include "vtkSmartPointer.h" // required because it is nice
193
194#include <vector> // For std::vector
195
196VTK_ABI_NAMESPACE_BEGIN
197class Sorted_cell_extents_Lists;
198class BSPNode;
199class vtkGenericCell;
200class vtkIdList;
202
203class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
205public:
207
211 void PrintSelf(ostream& os, vtkIndent indent) override;
213
217 static vtkModifiedBSPTree* New();
218
219 // Reuse any superclass signatures that we don't override.
223
230 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
231 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
232
242 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
243 vtkIdList* cellIds, vtkGenericCell* cell) override;
244
252 vtkIdType FindCell(double x[3], double tol2, vtkGenericCell* GenCell, int& subId,
253 double pcoords[3], double* weights) override;
261
271 void GenerateRepresentation(int level, vtkPolyData* pd) override;
272 void FreeSearchStructure() override;
273 void BuildLocator() override;
274 void ForceBuildLocator() override;
282 void ShallowCopy(vtkAbstractCellLocator* locator) override;
283
284protected:
286 ~vtkModifiedBSPTree() override;
288 void BuildLocatorInternal() override;
289 // Flat storage for all leaf cell ID lists, allocated once during build.
290 // Each leaf occupies a contiguous slice of size 6 * node->num_cells starting
291 // at node->LeavesStart. Within a leaf, the 6 sorted lists are laid out as
292 // [axis 0 mins | axis 0 maxs | axis 1 mins | ... | axis 2 maxs].
293 std::shared_ptr<std::vector<vtkIdType>> Leaves;
294 std::shared_ptr<BSPNode> mRoot; // bounding box root node
295 int npn;
296 int nln;
297 int tot_depth;
298
299 // The main subdivision routine
300 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
301 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth,
302 std::vector<uint8_t>& cellPart);
303
304private:
305 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
306 void operator=(const vtkModifiedBSPTree&) = delete;
307};
308
310// BSP Node
311// A BSP Node is a BBox - axis aligned etc etc
313#ifndef DOXYGEN_SHOULD_SKIP_THIS
314
315class BSPNode
316{
317public:
318 // Constructor
319 BSPNode()
320 {
321 mChild[0] = mChild[1] = mChild[2] = nullptr;
322 for (int i = 0; i < 3; i++)
323 {
324 this->Bounds[i * 2] = VTK_FLOAT_MAX;
325 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
326 }
327 }
328 // Destructor
329 ~BSPNode()
330 {
331 for (int i = 0; i < 3; i++)
332 {
333 delete mChild[i];
334 }
335 }
336 // Set min box limits
337 void setMin(double minx, double miny, double minz)
338 {
339 this->Bounds[0] = minx;
340 this->Bounds[2] = miny;
341 this->Bounds[4] = minz;
342 }
343 // Set max box limits
344 void setMax(double maxx, double maxy, double maxz)
345 {
346 this->Bounds[1] = maxx;
347 this->Bounds[3] = maxy;
348 this->Bounds[5] = maxz;
349 }
350 //
351 bool Inside(double point[3]) const;
352 // BBox
353 double Bounds[6];
354
355protected:
356 // The child nodes of this one (if present - nullptr otherwise)
357 BSPNode* mChild[3];
358 // The axis we subdivide this voxel along
359 int mAxis = 0;
360 // Just for reference
361 int depth = 0;
362 // split-plane position along mAxis (parents only). Used in FindCell to
363 // short-circuit the Inside() test on side children when x is clearly on
364 // the opposite side of the split plane.
365 double pDiv = 0;
366 // the number of cells in this node
367 int num_cells = 0;
368 // Offset into vtkModifiedBSPTree::Leaves where this leaf's 6 sorted cell
369 // lists begin. Each list has length num_cells; layout is contiguous as
370 // [mins[0] | maxs[0] | mins[1] | maxs[1] | mins[2] | maxs[2]].
371 vtkIdType LeavesStart = 0;
372 // Order nodes as near/mid far relative to ray
373 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
374 BSPNode*& Mid, BSPNode*& Far) const;
375 friend class vtkModifiedBSPTree;
376
377public:
378 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
379};
380
381#endif /* DOXYGEN_SHOULD_SKIP_THIS */
382
383VTK_ABI_NAMESPACE_END
384#endif
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.
vtkIdType FindCell(double x[3])
Returns the Id of the cell containing the point, returns -1 if no cell found.
void FindCellsAlongLine(const double p1[3], const double p2[3], double tol, 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.
vtkAbstractCellLocator()
Find the cell containing a given point.
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:135
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:218
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition vtkLocator.h:182
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...
std::shared_ptr< std::vector< vtkIdType > > Leaves
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, std::vector< uint8_t > &cellPart)
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:140
concrete dataset represents vertices, lines, polygons, and triangle strips
int vtkIdType
Definition vtkType.h:363
#define VTK_FLOAT_MAX
Definition vtkType.h:200