VTK  9.7.20260805
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
127
128#ifndef vtkModifiedBSPTree_h
129#define vtkModifiedBSPTree_h
130
132#include "vtkFiltersFlowPathsModule.h" // For export macro
133#include "vtkSmartPointer.h" // required because it is nice
134
135#include <vector> // For std::vector
136
137VTK_ABI_NAMESPACE_BEGIN
138class Sorted_cell_extents_Lists;
139class BSPNode;
140class vtkGenericCell;
141class vtkIdList;
143
144class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
146public:
148
152 void PrintSelf(ostream& os, vtkIndent indent) override;
154
158 static vtkModifiedBSPTree* New();
159
160 // Reuse any superclass signatures that we don't override.
164
171 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
172 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
173
183 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
184 vtkIdList* cellIds, vtkGenericCell* cell) override;
185
193 vtkIdType FindCell(double x[3], double tol2, vtkGenericCell* GenCell, int& subId,
194 double pcoords[3], double* weights) override;
202
212 void GenerateRepresentation(int level, vtkPolyData* pd) override;
213 void FreeSearchStructure() override;
214 void BuildLocator() override;
215 void ForceBuildLocator() override;
223 void ShallowCopy(vtkAbstractCellLocator* locator) override;
224
225protected:
227 ~vtkModifiedBSPTree() override;
229 void BuildLocatorInternal() override;
230 // Flat storage for all leaf cell ID lists, allocated once during build.
231 // Each leaf occupies a contiguous slice of size 6 * node->num_cells starting
232 // at node->LeavesStart. Within a leaf, the 6 sorted lists are laid out as
233 // [axis 0 mins | axis 0 maxs | axis 1 mins | ... | axis 2 maxs].
234 std::shared_ptr<std::vector<vtkIdType>> Leaves;
235 std::shared_ptr<BSPNode> mRoot; // bounding box root node
236 int npn;
237 int nln;
238 int tot_depth;
239
240 // The main subdivision routine
241 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
242 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth,
243 std::vector<uint8_t>& cellPart);
244
245private:
246 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
247 void operator=(const vtkModifiedBSPTree&) = delete;
248};
249
251// BSP Node
252// A BSP Node is a BBox - axis aligned etc etc
254#ifndef DOXYGEN_SHOULD_SKIP_THIS
255
256class BSPNode
257{
258public:
259 // Constructor
260 BSPNode()
261 {
262 mChild[0] = mChild[1] = mChild[2] = nullptr;
263 for (int i = 0; i < 3; i++)
264 {
265 this->Bounds[i * 2] = VTK_FLOAT_MAX;
266 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
267 }
268 }
269 // Destructor
270 ~BSPNode()
271 {
272 for (int i = 0; i < 3; i++)
273 {
274 delete mChild[i];
275 }
276 }
277 // Set min box limits
278 void setMin(double minx, double miny, double minz)
279 {
280 this->Bounds[0] = minx;
281 this->Bounds[2] = miny;
282 this->Bounds[4] = minz;
283 }
284 // Set max box limits
285 void setMax(double maxx, double maxy, double maxz)
286 {
287 this->Bounds[1] = maxx;
288 this->Bounds[3] = maxy;
289 this->Bounds[5] = maxz;
290 }
291 //
292 bool Inside(double point[3]) const;
293 // BBox
294 double Bounds[6];
295
296protected:
297 // The child nodes of this one (if present - nullptr otherwise)
298 BSPNode* mChild[3];
299 // The axis we subdivide this voxel along
300 int mAxis = 0;
301 // Just for reference
302 int depth = 0;
303 // split-plane position along mAxis (parents only). Used in FindCell to
304 // short-circuit the Inside() test on side children when x is clearly on
305 // the opposite side of the split plane.
306 double pDiv = 0;
307 // the number of cells in this node
308 int num_cells = 0;
309 // Offset into vtkModifiedBSPTree::Leaves where this leaf's 6 sorted cell
310 // lists begin. Each list has length num_cells; layout is contiguous as
311 // [mins[0] | maxs[0] | mins[1] | maxs[1] | mins[2] | maxs[2]].
312 vtkIdType LeavesStart = 0;
313 // Order nodes as near/mid far relative to ray
314 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
315 BSPNode*& Mid, BSPNode*& Far) const;
316 friend class vtkModifiedBSPTree;
317
318public:
319 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
320};
321
322#endif /* DOXYGEN_SHOULD_SKIP_THIS */
323
324VTK_ABI_NAMESPACE_END
325#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:56
provides thread-safe access to cells
maintain an ordered list of IdList objects
list of point or cell ids
Definition vtkIdList.h:26
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:199
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition vtkLocator.h:163
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:31
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition vtkPolyData.h:72
int vtkIdType
Definition vtkType.h:363
#define VTK_FLOAT_MAX
Definition vtkType.h:200