VTK  9.3.1
vtkOctreePointLocator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-FileCopyrightText: Copyright (c) Sandia Corporation
3 // SPDX-License-Identifier: BSD-3-Clause
4 
25 #ifndef vtkOctreePointLocator_h
26 #define vtkOctreePointLocator_h
27 
29 #include "vtkCommonDataModelModule.h" // For export macro
30 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkCellArray;
33 class vtkIdTypeArray;
35 class vtkPoints;
36 class vtkPolyData;
37 
38 class VTKCOMMONDATAMODEL_EXPORT vtkOctreePointLocator : public vtkAbstractPointLocator
39 {
40 public:
42  void PrintSelf(ostream& os, vtkIndent indent) override;
43 
44  static vtkOctreePointLocator* New();
45 
47 
50  vtkSetMacro(MaximumPointsPerRegion, int);
51  vtkGetMacro(MaximumPointsPerRegion, int);
53 
55 
58  vtkSetMacro(CreateCubicOctants, int);
59  vtkGetMacro(CreateCubicOctants, int);
61 
63 
69  vtkGetMacro(FudgeFactor, double);
70  vtkSetMacro(FudgeFactor, double);
72 
74 
78  double* GetBounds() override;
79  void GetBounds(double* bounds) override;
81 
83 
86  vtkGetMacro(NumberOfLeafNodes, int);
88 
92  void GetRegionBounds(int regionID, double bounds[6]);
93 
97  void GetRegionDataBounds(int leafNodeID, double bounds[6]);
98 
102  int GetRegionContainingPoint(double x, double y, double z);
103 
111  void BuildLocator() override;
112 
116  void ForceBuildLocator() override;
117 
119 
123  vtkIdType FindClosestPoint(const double x[3]) override;
124  vtkIdType FindClosestPoint(double x, double y, double z, double& dist2);
126 
132  vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
133 
135 
140  vtkIdType FindClosestPointInRegion(int regionId, double* x, double& dist2);
141  vtkIdType FindClosestPointInRegion(int regionId, double x, double y, double z, double& dist2);
143 
148  void FindPointsWithinRadius(double radius, const double x[3], vtkIdList* result) override;
149 
158  void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
159 
163  VTK_NEWINSTANCE vtkIdTypeArray* GetPointsInRegion(int leafNodeId);
164 
168  void FreeSearchStructure() override;
169 
174  void GenerateRepresentation(int level, vtkPolyData* pd) override;
175 
182  void FindPointsInArea(double* area, vtkIdTypeArray* ids, bool clearArray = true);
183 
184 protected:
186  ~vtkOctreePointLocator() override;
187 
188  void BuildLocatorInternal() override;
189 
191  vtkOctreePointLocatorNode** LeafNodeList; // indexed by region/node ID
192 
193  void BuildLeafNodeList(vtkOctreePointLocatorNode* node, int& index);
194 
196 
200  int FindRegion(vtkOctreePointLocatorNode* node, float x, float y, float z);
201  int FindRegion(vtkOctreePointLocatorNode* node, double x, double y, double z);
203 
204  static void SetDataBoundsToSpatialBounds(vtkOctreePointLocatorNode* node);
205 
206  static void DeleteAllDescendants(vtkOctreePointLocatorNode* octant);
207 
214  vtkOctreePointLocatorNode* node, double radiusSquared, const double x[3], vtkIdList* ids);
215 
216  // Recursive helper for public FindPointsWithinRadius
217  void AddAllPointsInRegion(vtkOctreePointLocatorNode* node, vtkIdList* ids);
218 
219  // Recursive helper for public FindPointsInArea
220  void FindPointsInArea(vtkOctreePointLocatorNode* node, double* area, vtkIdTypeArray* ids);
221 
222  // Recursive helper for public FindPointsInArea
223  void AddAllPointsInRegion(vtkOctreePointLocatorNode* node, vtkIdTypeArray* ids);
224 
225  void DivideRegion(vtkOctreePointLocatorNode* node, int* ordering, int level);
226 
227  int DivideTest(int size, int level);
228 
229  void AddPolys(vtkOctreePointLocatorNode* node, vtkPoints* pts, vtkCellArray* polys);
230 
235  int FindClosestPointInRegion_(int leafNodeId, double x, double y, double z, double& dist2);
236 
244  int FindClosestPointInSphere(
245  double x, double y, double z, double radius, int skipRegion, double& dist2);
246 
248 
254 
255  double FudgeFactor; // a very small distance, relative to the dataset's size
259 
260  float MaxWidth;
261 
270 
272  void operator=(const vtkOctreePointLocator&) = delete;
273 };
274 VTK_ABI_NAMESPACE_END
275 #endif
virtual void BuildLocator()=0
Build the locator from the input dataset.
an octree spatial decomposition of a set of points
virtual vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double &dist2)=0
Given a position x and a radius r, return the id of the point closest to the point in that radius...
int CreateCubicOctants
If CreateCubicOctants is non-zero, the bounding box of the points will be expanded such that all octa...
virtual double * GetBounds()
Provide an accessor to the bounds.
int MaximumPointsPerRegion
The maximum number of points in a region/octant before it is subdivided.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:315
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:79
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
int NumberOfLeafNodes
The maximum number of points in a region/octant before it is subdivided.
vtkOctreePointLocatorNode ** LeafNodeList
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void BuildLocatorInternal()
This function is not pure virtual to maintain backwards compatibility.
Definition: vtkLocator.h:192
void PrintSelf(ostream &os, vtkIndent indent) override
Standard type and print methods.
abstract class to quickly locate points in 3-space
list of point or cell ids
Definition: vtkIdList.h:22
virtual void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result)=0
Find all points within a specified radius R of position x.
virtual void FindClosestNPoints(int N, const double x[3], vtkIdList *result)=0
Find the closest N points to a position.
#define VTK_NEWINSTANCE
object to represent cell connectivity
Definition: vtkCellArray.h:175
Octree node that has 8 children each of equal size.
vtkOctreePointLocatorNode * Top
virtual vtkIdType FindClosestPoint(const double x[3])=0
Given a position x, return the id of the point closest to it.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void GenerateRepresentation(int level, vtkPolyData *pd)=0
Method to build a representation at a particular level.
represent and manipulate 3D points
Definition: vtkPoints.h:28
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition: vtkLocator.h:156