VTK  9.5.2
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
190
191#ifndef vtkModifiedBSPTree_h
192#define vtkModifiedBSPTree_h
193
195#include "vtkFiltersFlowPathsModule.h" // For export macro
196#include "vtkSmartPointer.h" // required because it is nice
197
198VTK_ABI_NAMESPACE_BEGIN
199class Sorted_cell_extents_Lists;
200class BSPNode;
201class vtkGenericCell;
202class vtkIdList;
204
205class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
207public:
209
213 void PrintSelf(ostream& os, vtkIndent indent) override;
215
219 static vtkModifiedBSPTree* New();
220
221 // Reuse any superclass signatures that we don't override.
224
231 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
232 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
233
243 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
244 vtkIdList* cellIds, vtkGenericCell* cell) override;
245
248 * For each intersection with the bounds of a cell, the cellIds
249 * have the relevant information added sort by t. If cellIds is nullptr
250 * pointer, then no information is generated for that list.
251 *
252 * Reimplemented from vtkAbstractCellLocator to showcase that it's a supported function.
253 */
255 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
256 {
257 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
258 }
259
267 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
268 double pcoords[3], double* weights) override;
276
286 void GenerateRepresentation(int level, vtkPolyData* pd) override;
287 void FreeSearchStructure() override;
288 void BuildLocator() override;
289 void ForceBuildLocator() override;
297 void ShallowCopy(vtkAbstractCellLocator* locator) override;
299protected:
302
303 void BuildLocatorInternal() override;
304 std::shared_ptr<BSPNode> mRoot; // bounding box root node
305 int npn;
306 int nln;
307 int tot_depth;
308
309 // The main subdivision routine
310 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
311 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
312
313private:
314 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
315 void operator=(const vtkModifiedBSPTree&) = delete;
316};
317
319// BSP Node
320// A BSP Node is a BBox - axis aligned etc etc
322#ifndef DOXYGEN_SHOULD_SKIP_THIS
323
324class BSPNode
325{
326public:
327 // Constructor
328 BSPNode()
329 {
330 mChild[0] = mChild[1] = mChild[2] = nullptr;
331 for (int i = 0; i < 6; i++)
332 sorted_cell_lists[i] = nullptr;
333 for (int i = 0; i < 3; i++)
334 {
335 this->Bounds[i * 2] = VTK_FLOAT_MAX;
336 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
337 }
338 }
339 // Destructor
340 ~BSPNode()
341 {
342 for (int i = 0; i < 3; i++)
343 delete mChild[i];
344 for (int i = 0; i < 6; i++)
345 delete[] sorted_cell_lists[i];
346 }
347 // Set min box limits
348 void setMin(double minx, double miny, double minz)
349 {
350 this->Bounds[0] = minx;
351 this->Bounds[2] = miny;
352 this->Bounds[4] = minz;
353 }
354 // Set max box limits
355 void setMax(double maxx, double maxy, double maxz)
356 {
357 this->Bounds[1] = maxx;
358 this->Bounds[3] = maxy;
359 this->Bounds[5] = maxz;
360 }
361 //
362 bool Inside(double point[3]) const;
363 // BBox
364 double Bounds[6];
365
366protected:
367 // The child nodes of this one (if present - nullptr otherwise)
368 BSPNode* mChild[3];
369 // The axis we subdivide this voxel along
370 int mAxis;
371 // Just for reference
372 int depth;
373 // the number of cells in this node
374 int num_cells;
375 // 6 lists, sorted after the 6 dominant axes
376 vtkIdType* sorted_cell_lists[6];
377 // Order nodes as near/mid far relative to ray
378 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
379 BSPNode*& Mid, BSPNode*& Far) const;
380 friend class vtkModifiedBSPTree;
381
382public:
383 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
384};
385
386#endif /* DOXYGEN_SHOULD_SKIP_THIS */
387
388VTK_ABI_NAMESPACE_END
389#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:165
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.
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
void Subdivide(vtkPointData *inPd, vtkCellData *inCd, vtkIdType cellId, vtkDataArray *cellScalars)
double Bounds[6]
int vtkIdType
Definition vtkType.h:332
#define VTK_FLOAT_MAX
Definition vtkType.h:169