VTK  9.6.20260706
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
89
90#ifndef vtkPointLocator_h
91#define vtkPointLocator_h
92
93#include "vtkCommonDataModelModule.h" // For export macro
95#include "vtkMathUtilities.h" // for SafeCastFromDouble
96
97#include <algorithm> // for std::min/std::max
98
99VTK_ABI_NAMESPACE_BEGIN
100class vtkCellArray;
101class vtkIdList;
102class vtkNeighborPoints;
103class vtkPoints;
104
105class VTKCOMMONDATAMODEL_EXPORT vtkPointLocator : public vtkIncrementalPointLocator
106{
107public:
113
115
119 void PrintSelf(ostream& os, vtkIndent indent) override;
121
123
126 vtkSetVector3Macro(Divisions, int);
127 vtkGetVectorMacro(Divisions, int, 3);
129
131
134 vtkSetClampMacro(NumberOfPointsPerBucket, int, 1, VTK_INT_MAX);
135 vtkGetMacro(NumberOfPointsPerBucket, int);
137
138 // Reuse any superclass signatures that we don't override.
140
147 vtkIdType FindClosestPoint(const double x[3]) override;
148
150
157 vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
159 double radius, const double x[3], double inputDataLength, double& dist2);
161
168 int InitPointInsertion(vtkPoints* newPts, const double bounds[6]) override;
169
176 int InitPointInsertion(vtkPoints* newPts, const double bounds[6], vtkIdType estNumPts) override;
177
187 void InsertPoint(vtkIdType ptId, const double x[3]) override;
188
199 vtkIdType InsertNextPoint(const double x[3]) override;
200
202
210 vtkIdType IsInsertedPoint(double x, double y, double z) override
211 {
212 double xyz[3];
213 xyz[0] = x;
214 xyz[1] = y;
215 xyz[2] = z;
216 return this->IsInsertedPoint(xyz);
217 }
218 vtkIdType IsInsertedPoint(const double x[3]) override;
220
230 int InsertUniquePoint(const double x[3], vtkIdType& ptId) override;
231
241 vtkIdType FindClosestInsertedPoint(const double x[3]) override;
242
251 void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
252
254
261 virtual void FindDistributedPoints(int N, const double x[3], vtkIdList* result, int M);
262 virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList* result, int M);
264
271 void FindPointsWithinRadius(double R, const double x[3], vtkIdList* result) override;
272
279 virtual vtkIdList* GetPointsInBucket(const double x[3], int ijk[3]);
280
282
285 vtkGetObjectMacro(Points, vtkPoints);
287
289
293 void Initialize() override;
294 void FreeSearchStructure() override;
295 void BuildLocator() override;
296 void ForceBuildLocator() override;
297 void GenerateRepresentation(int level, vtkPolyData* pd) override;
299
300protected:
303
304 void BuildLocatorInternal() override;
305
306 // place points in appropriate buckets
308 vtkNeighborPoints* buckets, const int ijk[3], const int ndivs[3], int level);
310 vtkNeighborPoints* buckets, const double x[3], const int ijk[3], double dist, int level);
311 void GetOverlappingBuckets(vtkNeighborPoints* buckets, const double x[3], double dist,
312 int prevMinLevel[3], int prevMaxLevel[3]);
313 void GenerateFace(int face, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
314 double Distance2ToBucket(const double x[3], const int nei[3]);
315 double Distance2ToBounds(const double x[3], const double bounds[6]);
316
317 vtkPoints* Points; // Used for merging points
318 int Divisions[3]; // Number of sub-divisions in x-y-z directions
319 int NumberOfPointsPerBucket; // Used with previous boolean to control subdivide
320 vtkIdList** HashTable; // lists of point ids in buckets
321 double H[3]; // width of each bucket in x-y-z directions
322
326
327 // These are inlined methods and data members for performance reasons
328 double HX, HY, HZ;
329 double FX, FY, FZ, BX, BY, BZ;
331
332 void GetBucketIndices(const double* x, int ijk[3]) const
333 {
334 // Compute point index. SafeCastFromDouble clamps to the integer type limits
335 // (mapping NaN to 0) so casting a coordinate far outside the locator bounds
336 // (e.g. VTK_DOUBLE_MAX) is not undefined behavior. Make sure it then lies
337 // within the range of the locator.
338 vtkIdType tmp0 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[0] - this->BX) * this->FX);
339 vtkIdType tmp1 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[1] - this->BY) * this->FY);
340 vtkIdType tmp2 = vtkMathUtilities::SafeCastFromDouble<vtkIdType>((x[2] - this->BZ) * this->FZ);
341
342 ijk[0] = std::min(std::max<vtkIdType>(tmp0, 0), this->XD - 1);
343 ijk[1] = std::min(std::max<vtkIdType>(tmp1, 0), this->YD - 1);
344 ijk[2] = std::min(std::max<vtkIdType>(tmp2, 0), this->ZD - 1);
345 }
346
347 vtkIdType GetBucketIndex(const double* x) const
348 {
349 int ijk[3];
350 this->GetBucketIndices(x, ijk);
351 return ijk[0] + ijk[1] * this->XD + ijk[2] * this->SliceSize;
352 }
353
355
356private:
357 vtkPointLocator(const vtkPointLocator&) = delete;
358 void operator=(const vtkPointLocator&) = delete;
359};
360
361VTK_ABI_NAMESPACE_END
362#endif
virtual vtkIdType FindClosestPoint(const double x[3])=0
Given a position x, return the id of the point closest to it.
object to represent cell connectivity
list of point or cell ids
Definition vtkIdList.h:135
virtual vtkIdType IsInsertedPoint(double x, double y, double z)=0
Determine whether or not a given point has been inserted.
a simple class to control print indentation
Definition vtkIndent.h:108
void InsertPoint(vtkIdType ptId, const double x[3]) override
Incrementally insert a point into search structure with a particular index value.
int InitPointInsertion(vtkPoints *newPts, const double bounds[6]) override
Initialize the point insertion process.
vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double &dist2) override
Given a position x and a radius r, return the id of the point closest to the point in that radius.
vtkIdType IsInsertedPoint(double x, double y, double z) override
Determine whether point given by x[3] has been inserted into points list.
void BuildLocator() override
See vtkLocator interface documentation.
void FindClosestNPoints(int N, const double x[3], vtkIdList *result) override
Find the closest N points to a position.
virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList *result, int M)
Find the closest points to a position such that each octant of space around the position contains at ...
virtual vtkIdList * GetPointsInBucket(const double x[3], int ijk[3])
Given a position x, return the list of points in the bucket that contains the point.
static vtkPointLocator * New()
Construct with automatic computation of divisions, averaging 25 points per bucket.
void GetBucketIndices(const double *x, int ijk[3]) const
void GetBucketNeighbors(vtkNeighborPoints *buckets, const int ijk[3], const int ndivs[3], int level)
virtual void FindDistributedPoints(int N, const double x[3], vtkIdList *result, int M)
Find the closest points to a position such that each octant of space around the position contains at ...
void FreeSearchStructure() override
See vtkLocator interface documentation.
vtkIdList ** HashTable
void BuildLocatorInternal() override
This function is not pure virtual to maintain backwards compatibility.
void ForceBuildLocator() override
See vtkLocator interface documentation.
void Initialize() override
See vtkLocator interface documentation.
vtkIdType FindClosestPoint(const double x[3]) override
Given a position x, return the id of the point closest to it.
double Distance2ToBucket(const double x[3], const int nei[3])
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for type management and printing.
virtual vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double inputDataLength, double &dist2)
Given a position x and a radius r, return the id of the point closest to the point in that radius.
void ComputePerformanceFactors()
vtkIdType IsInsertedPoint(const double x[3]) override
Determine whether point given by x[3] has been inserted into points list.
~vtkPointLocator() override
void GenerateRepresentation(int level, vtkPolyData *pd) override
See vtkLocator interface documentation.
void GenerateFace(int face, int i, int j, int k, vtkPoints *pts, vtkCellArray *polys)
vtkIdType InsertionPointId
void GetOverlappingBuckets(vtkNeighborPoints *buckets, const double x[3], double dist, int prevMinLevel[3], int prevMaxLevel[3])
void GetOverlappingBuckets(vtkNeighborPoints *buckets, const double x[3], const int ijk[3], double dist, int level)
vtkIdType GetBucketIndex(const double *x) const
vtkIdType InsertNextPoint(const double x[3]) override
Incrementally insert a point into search structure.
int InsertUniquePoint(const double x[3], vtkIdType &ptId) override
Determine whether point given by x[3] has been inserted into points list.
void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result) override
Find all points within a specified radius R of position x.
double Distance2ToBounds(const double x[3], const double bounds[6])
int InitPointInsertion(vtkPoints *newPts, const double bounds[6], vtkIdType estNumPts) override
Initialize the point insertion process.
vtkIdType FindClosestInsertedPoint(const double x[3]) override
Given a position x, return the id of the point closest to it.
represent and manipulate 3D points
Definition vtkPoints.h:140
concrete dataset represents vertices, lines, polygons, and triangle strips
A SafeCastFromDouble(double value)
Cast from double, and clamp to output type limits to avoid overlow.
int vtkIdType
Definition vtkType.h:363
#define VTK_INT_MAX
Definition vtkType.h:192