VTK  9.7.1
vtkPointLocator.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
41 #ifndef vtkPointLocator_h
42 #define vtkPointLocator_h
43 
44 #include "vtkCommonDataModelModule.h" // For export macro
46 #include "vtkMathUtilities.h" // for SafeCastFromDouble
47 
48 #include <algorithm> // for std::min/std::max
49 
50 VTK_ABI_NAMESPACE_BEGIN
51 class vtkCellArray;
52 class vtkIdList;
53 class vtkNeighborPoints;
54 class vtkPoints;
55 
56 class VTKCOMMONDATAMODEL_EXPORT vtkPointLocator : public vtkIncrementalPointLocator
57 {
58 public:
63  static vtkPointLocator* New();
64 
66 
70  void PrintSelf(ostream& os, vtkIndent indent) override;
72 
74 
77  vtkSetVector3Macro(Divisions, int);
78  vtkGetVectorMacro(Divisions, int, 3);
80 
82 
85  vtkSetClampMacro(NumberOfPointsPerBucket, int, 1, VTK_INT_MAX);
86  vtkGetMacro(NumberOfPointsPerBucket, int);
88 
89  // Reuse any superclass signatures that we don't override.
91 
98  vtkIdType FindClosestPoint(const double x[3]) override;
99 
101 
108  vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
110  double radius, const double x[3], double inputDataLength, double& dist2);
112 
119  int InitPointInsertion(vtkPoints* newPts, const double bounds[6]) override;
120 
127  int InitPointInsertion(vtkPoints* newPts, const double bounds[6], vtkIdType estNumPts) override;
128 
138  void InsertPoint(vtkIdType ptId, const double x[3]) override;
139 
150  vtkIdType InsertNextPoint(const double x[3]) override;
151 
153 
161  vtkIdType IsInsertedPoint(double x, double y, double z) override
162  {
163  double xyz[3];
164  xyz[0] = x;
165  xyz[1] = y;
166  xyz[2] = z;
167  return this->IsInsertedPoint(xyz);
168  }
169  vtkIdType IsInsertedPoint(const double x[3]) override;
171 
181  int InsertUniquePoint(const double x[3], vtkIdType& ptId) override;
182 
192  vtkIdType FindClosestInsertedPoint(const double x[3]) override;
193 
202  void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
203 
205 
212  virtual void FindDistributedPoints(int N, const double x[3], vtkIdList* result, int M);
213  virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList* result, int M);
215 
222  void FindPointsWithinRadius(double R, const double x[3], vtkIdList* result) override;
223 
230  virtual vtkIdList* GetPointsInBucket(const double x[3], int ijk[3]);
231 
233 
236  vtkGetObjectMacro(Points, vtkPoints);
238 
240 
244  void Initialize() override;
245  void FreeSearchStructure() override;
246  void BuildLocator() override;
247  void ForceBuildLocator() override;
248  void GenerateRepresentation(int level, vtkPolyData* pd) override;
250 
251 protected:
252  vtkPointLocator();
253  ~vtkPointLocator() override;
254 
255  void BuildLocatorInternal() override;
256 
257  // place points in appropriate buckets
258  void GetBucketNeighbors(
259  vtkNeighborPoints* buckets, const int ijk[3], const int ndivs[3], int level);
260  void GetOverlappingBuckets(
261  vtkNeighborPoints* buckets, const double x[3], const int ijk[3], double dist, int level);
262  void GetOverlappingBuckets(vtkNeighborPoints* buckets, const double x[3], double dist,
263  int prevMinLevel[3], int prevMaxLevel[3]);
264  void GenerateFace(int face, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
265  double Distance2ToBucket(const double x[3], const int nei[3]);
266  double Distance2ToBounds(const double x[3], const double bounds[6]);
267 
268  vtkPoints* Points; // Used for merging points
269  int Divisions[3]; // Number of sub-divisions in x-y-z directions
270  int NumberOfPointsPerBucket; // Used with previous boolean to control subdivide
271  vtkIdList** HashTable; // lists of point ids in buckets
272  double H[3]; // width of each bucket in x-y-z directions
273 
277 
278  // These are inlined methods and data members for performance reasons
279  double HX, HY, HZ;
280  double FX, FY, FZ, BX, BY, BZ;
281  vtkIdType XD, YD, ZD, SliceSize;
282 
283  void GetBucketIndices(const double* x, int ijk[3]) const
284  {
285  // Compute point index. SafeCastFromDouble clamps to the integer type limits
286  // (mapping NaN to 0) so casting a coordinate far outside the locator bounds
287  // (e.g. VTK_DOUBLE_MAX) is not undefined behavior. Make sure it then lies
288  // within the range of the locator.
289  vtkIdType tmp0 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[0] - this->BX) * this->FX);
290  vtkIdType tmp1 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[1] - this->BY) * this->FY);
291  vtkIdType tmp2 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[2] - this->BZ) * this->FZ);
292 
293  ijk[0] = std::min(std::max<vtkIdType>(tmp0, 0), this->XD - 1);
294  ijk[1] = std::min(std::max<vtkIdType>(tmp1, 0), this->YD - 1);
295  ijk[2] = std::min(std::max<vtkIdType>(tmp2, 0), this->ZD - 1);
296  }
297 
298  vtkIdType GetBucketIndex(const double* x) const
299  {
300  int ijk[3];
301  this->GetBucketIndices(x, ijk);
302  return ijk[0] + ijk[1] * this->XD + ijk[2] * this->SliceSize;
303  }
304 
305  void ComputePerformanceFactors();
306 
307 private:
308  vtkPointLocator(const vtkPointLocator&) = delete;
309  void operator=(const vtkPointLocator&) = delete;
310 };
311 
312 VTK_ABI_NAMESPACE_END
313 #endif
vtkIdType GetBucketIndex(const double *x) const
vtkIdType IsInsertedPoint(double x, double y, double z) override
Determine whether point given by x[3] has been inserted into points list.
void GetBucketIndices(const double *x, int ijk[3]) const
virtual void BuildLocator()=0
Build the locator from the input dataset.
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...
quickly locate points in 3-space
virtual int InsertUniquePoint(const double x[3], vtkIdType &ptId)=0
Insert a point unless there has been a duplicate in the search structure.
vtkIdType InsertionPointId
virtual vtkIdType IsInsertedPoint(double x, double y, double z)=0
Determine whether or not a given point has been inserted.
#define VTK_INT_MAX
Definition: vtkType.h:192
vtkIdList ** HashTable
Abstract class in support of both point location and point insertion.
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
virtual int InitPointInsertion(vtkPoints *newPts, const double bounds[6])=0
Initialize the point insertion process.
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:199
list of point or cell ids
Definition: vtkIdList.h:25
vtkPoints * Points
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard type and print methods.
object to represent cell connectivity
Definition: vtkCellArray.h:177
virtual vtkIdType InsertNextPoint(const double x[3])=0
Insert a given point and return the point index.
virtual vtkIdType FindClosestInsertedPoint(const double x[3])=0
Given a point x assumed to be covered by the search structure, return the index of the closest point ...
virtual vtkIdType FindClosestPoint(const double x[3])=0
Given a position x, return the id of the point closest to it.
virtual void Initialize()
Initialize locator.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void InsertPoint(vtkIdType ptId, const double x[3])=0
Insert a given point with a specified point index ptId.
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:30
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition: vtkLocator.h:163