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
131
132#ifndef vtkModifiedBSPTree_h
133#define vtkModifiedBSPTree_h
134
136#include "vtkFiltersFlowPathsModule.h" // For export macro
137#include "vtkSmartPointer.h" // required because it is nice
138
139VTK_ABI_NAMESPACE_BEGIN
140class Sorted_cell_extents_Lists;
141class BSPNode;
142class vtkGenericCell;
143class vtkIdList;
145
146class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
148public:
150
154 void PrintSelf(ostream& os, vtkIndent indent) override;
156
160 static vtkModifiedBSPTree* New();
161
162 // Reuse any superclass signatures that we don't override.
165
172 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
173 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
174
184 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
185 vtkIdList* cellIds, vtkGenericCell* cell) override;
186
189 * For each intersection with the bounds of a cell, the cellIds
190 * have the relevant information added sort by t. If cellIds is nullptr
191 * pointer, then no information is generated for that list.
192 *
193 * Reimplemented from vtkAbstractCellLocator to showcase that it's a supported function.
194 */
196 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
197 {
198 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
199 }
200
208 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
209 double pcoords[3], double* weights) override;
217
227 void GenerateRepresentation(int level, vtkPolyData* pd) override;
228 void FreeSearchStructure() override;
229 void BuildLocator() override;
230 void ForceBuildLocator() override;
238 void ShallowCopy(vtkAbstractCellLocator* locator) override;
240protected:
243
244 void BuildLocatorInternal() override;
245 std::shared_ptr<BSPNode> mRoot; // bounding box root node
246 int npn;
247 int nln;
248 int tot_depth;
249
250 // The main subdivision routine
251 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
252 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
253
254private:
255 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
256 void operator=(const vtkModifiedBSPTree&) = delete;
257};
258
260// BSP Node
261// A BSP Node is a BBox - axis aligned etc etc
263#ifndef DOXYGEN_SHOULD_SKIP_THIS
264
265class BSPNode
266{
267public:
268 // Constructor
269 BSPNode()
270 {
271 mChild[0] = mChild[1] = mChild[2] = nullptr;
272 for (int i = 0; i < 6; i++)
273 sorted_cell_lists[i] = nullptr;
274 for (int i = 0; i < 3; i++)
275 {
276 this->Bounds[i * 2] = VTK_FLOAT_MAX;
277 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
278 }
279 }
280 // Destructor
281 ~BSPNode()
282 {
283 for (int i = 0; i < 3; i++)
284 delete mChild[i];
285 for (int i = 0; i < 6; i++)
286 delete[] sorted_cell_lists[i];
287 }
288 // Set min box limits
289 void setMin(double minx, double miny, double minz)
290 {
291 this->Bounds[0] = minx;
292 this->Bounds[2] = miny;
293 this->Bounds[4] = minz;
294 }
295 // Set max box limits
296 void setMax(double maxx, double maxy, double maxz)
297 {
298 this->Bounds[1] = maxx;
299 this->Bounds[3] = maxy;
300 this->Bounds[5] = maxz;
301 }
302 //
303 bool Inside(double point[3]) const;
304 // BBox
305 double Bounds[6];
306
307protected:
308 // The child nodes of this one (if present - nullptr otherwise)
309 BSPNode* mChild[3];
310 // The axis we subdivide this voxel along
311 int mAxis;
312 // Just for reference
313 int depth;
314 // the number of cells in this node
315 int num_cells;
316 // 6 lists, sorted after the 6 dominant axes
317 vtkIdType* sorted_cell_lists[6];
318 // Order nodes as near/mid far relative to ray
319 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
320 BSPNode*& Mid, BSPNode*& Far) const;
321 friend class vtkModifiedBSPTree;
322
323public:
324 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
325};
326
327#endif /* DOXYGEN_SHOULD_SKIP_THIS */
328
329VTK_ABI_NAMESPACE_END
330#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:56
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition vtkIdList.h:24
a simple class to control print indentation
Definition vtkIndent.h:29
virtual void BuildLocatorInternal()
This function is not pure virtual to maintain backwards compatibility.
Definition vtkLocator.h:192
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition vtkLocator.h:156
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:30
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
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