VTK  9.6.1
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
128
129#ifndef vtkModifiedBSPTree_h
130#define vtkModifiedBSPTree_h
131
133#include "vtkFiltersFlowPathsModule.h" // For export macro
134#include "vtkSmartPointer.h" // required because it is nice
135
136VTK_ABI_NAMESPACE_BEGIN
137class Sorted_cell_extents_Lists;
138class BSPNode;
139class vtkGenericCell;
140class vtkIdList;
142
143class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator
145public:
147
151 void PrintSelf(ostream& os, vtkIndent indent) override;
153
157 static vtkModifiedBSPTree* New();
158
159 // Reuse any superclass signatures that we don't override.
162
169 int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
170 double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
171
181 int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
182 vtkIdList* cellIds, vtkGenericCell* cell) override;
183
186 * For each intersection with the bounds of a cell, the cellIds
187 * have the relevant information added sort by t. If cellIds is nullptr
188 * pointer, then no information is generated for that list.
189 *
190 * Reimplemented from vtkAbstractCellLocator to showcase that it's a supported function.
191 */
193 const double p1[3], const double p2[3], double tolerance, vtkIdList* cellsIds) override
194 {
195 this->Superclass::FindCellsAlongLine(p1, p2, tolerance, cellsIds);
196 }
197
205 vtkIdType FindCell(double x[3], double vtkNotUsed(tol2), vtkGenericCell* GenCell, int& subId,
206 double pcoords[3], double* weights) override;
214
224 void GenerateRepresentation(int level, vtkPolyData* pd) override;
225 void FreeSearchStructure() override;
226 void BuildLocator() override;
227 void ForceBuildLocator() override;
235 void ShallowCopy(vtkAbstractCellLocator* locator) override;
237protected:
240
241 void BuildLocatorInternal() override;
242 std::shared_ptr<BSPNode> mRoot; // bounding box root node
243 int npn;
244 int nln;
245 int tot_depth;
246
247 // The main subdivision routine
248 void Subdivide(BSPNode* node, Sorted_cell_extents_Lists* lists, vtkDataSet* dataSet,
249 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int& MaxDepth);
250
251private:
252 vtkModifiedBSPTree(const vtkModifiedBSPTree&) = delete;
253 void operator=(const vtkModifiedBSPTree&) = delete;
254};
255
257// BSP Node
258// A BSP Node is a BBox - axis aligned etc etc
260#ifndef DOXYGEN_SHOULD_SKIP_THIS
261
262class BSPNode
263{
264public:
265 // Constructor
266 BSPNode()
267 {
268 mChild[0] = mChild[1] = mChild[2] = nullptr;
269 for (int i = 0; i < 6; i++)
270 sorted_cell_lists[i] = nullptr;
271 for (int i = 0; i < 3; i++)
272 {
273 this->Bounds[i * 2] = VTK_FLOAT_MAX;
274 this->Bounds[i * 2 + 1] = -VTK_FLOAT_MAX;
275 }
276 }
277 // Destructor
278 ~BSPNode()
279 {
280 for (int i = 0; i < 3; i++)
281 delete mChild[i];
282 for (int i = 0; i < 6; i++)
283 delete[] sorted_cell_lists[i];
284 }
285 // Set min box limits
286 void setMin(double minx, double miny, double minz)
287 {
288 this->Bounds[0] = minx;
289 this->Bounds[2] = miny;
290 this->Bounds[4] = minz;
291 }
292 // Set max box limits
293 void setMax(double maxx, double maxy, double maxz)
294 {
295 this->Bounds[1] = maxx;
296 this->Bounds[3] = maxy;
297 this->Bounds[5] = maxz;
298 }
299 //
300 bool Inside(double point[3]) const;
301 // BBox
302 double Bounds[6];
303
304protected:
305 // The child nodes of this one (if present - nullptr otherwise)
306 BSPNode* mChild[3];
307 // The axis we subdivide this voxel along
308 int mAxis;
309 // Just for reference
310 int depth;
311 // the number of cells in this node
312 int num_cells;
313 // 6 lists, sorted after the 6 dominant axes
314 vtkIdType* sorted_cell_lists[6];
315 // Order nodes as near/mid far relative to ray
316 void Classify(const double origin[3], const double dir[3], double& rDist, BSPNode*& Near,
317 BSPNode*& Mid, BSPNode*& Far) const;
318 friend class vtkModifiedBSPTree;
319
320public:
321 static int VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
322};
323
324#endif /* DOXYGEN_SHOULD_SKIP_THIS */
325
326VTK_ABI_NAMESPACE_END
327#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:57
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:368
#define VTK_FLOAT_MAX
Definition vtkType.h:205