VTK  9.6.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
207
208#ifndef vtkModifiedBSPTree_h
209#define vtkModifiedBSPTree_h
210
212#include "vtkFiltersFlowPathsModule.h" // For export macro
213#include "vtkSmartPointer.h" // required because it is nice
214
215VTK_ABI_NAMESPACE_BEGIN
216class Sorted_cell_extents_Lists;
217class BSPNode;
218class vtkGenericCell;
219class vtkIdList;
221
222class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
224public:
226
230 void PrintSelf(ostream& os, vtkIndent indent) override;
232
236 static vtkModifiedBSPTree* New();
237
238 // Reuse any superclass signatures that we don't override.
241
248 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
249 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
250
260 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
261 vtkIdList* cellIds, vtkGenericCell* cell) override;
262
265 * For each intersection with the bounds of a cell, the cellIds
266 * have the relevant information added sort by t. If cellIds is nullptr
267 * pointer, then no information is generated for that list.
268 *
269 * Reimplemented from vtkAbstractCellLocator to showcase that it's a supported function.
270 */
272 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
273 {
274 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
275 }
276
284 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
285 double pcoords[3], double* weights) override;
293
303 void GenerateRepresentation(int level, vtkPolyData* pd) override;
304 void FreeSearchStructure() override;
305 void BuildLocator() override;
306 void ForceBuildLocator() override;
314 void ShallowCopy(vtkAbstractCellLocator* locator) override;
316protected:
319
320 void BuildLocatorInternal() override;
321 std::shared_ptr<BSPNode> mRoot; // bounding box root node
322 int npn;
323 int nln;
324 int tot_depth;
325
326 // The main subdivision routine
327 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
328 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
329
330private:
331 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
332 void operator=(const vtkModifiedBSPTree&) = delete;
333};
334
336// BSP Node
337// A BSP Node is a BBox - axis aligned etc etc
339#ifndef DOXYGEN_SHOULD_SKIP_THIS
340
341class BSPNode
342{
343public:
344 // Constructor
345 BSPNode()
346 {
347 mChild[0] = mChild[1] = mChild[2] = nullptr;
348 for (int i = 0; i < 6; i++)
349 sorted_cell_lists[i] = nullptr;
350 for (int i = 0; i < 3; i++)
351 {
352 this->Bounds[i * 2] = VTK_FLOAT_MAX;
353 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
354 }
355 }
356 // Destructor
357 ~BSPNode()
358 {
359 for (int i = 0; i < 3; i++)
360 delete mChild[i];
361 for (int i = 0; i < 6; i++)
362 delete[] sorted_cell_lists[i];
363 }
364 // Set min box limits
365 void setMin(double minx, double miny, double minz)
366 {
367 this->Bounds[0] = minx;
368 this->Bounds[2] = miny;
369 this->Bounds[4] = minz;
370 }
371 // Set max box limits
372 void setMax(double maxx, double maxy, double maxz)
373 {
374 this->Bounds[1] = maxx;
375 this->Bounds[3] = maxy;
376 this->Bounds[5] = maxz;
377 }
378 //
379 bool Inside(double point[3]) const;
380 // BBox
381 double Bounds[6];
382
383protected:
384 // The child nodes of this one (if present - nullptr otherwise)
385 BSPNode* mChild[3];
386 // The axis we subdivide this voxel along
387 int mAxis;
388 // Just for reference
389 int depth;
390 // the number of cells in this node
391 int num_cells;
392 // 6 lists, sorted after the 6 dominant axes
393 vtkIdType* sorted_cell_lists[6];
394 // Order nodes as near/mid far relative to ray
395 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
396 BSPNode*& Mid, BSPNode*& Far) const;
397 friend class vtkModifiedBSPTree;
398
399public:
400 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
401};
402
403#endif /* DOXYGEN_SHOULD_SKIP_THIS */
404
405VTK_ABI_NAMESPACE_END
406#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.
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:368
#define VTK_FLOAT_MAX
Definition vtkType.h:205