VTK  9.3.20240423
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
86#ifndef vtkPointLocator_h
87#define vtkPointLocator_h
88
89#include "vtkCommonDataModelModule.h" // For export macro
91
92VTK_ABI_NAMESPACE_BEGIN
93class vtkCellArray;
94class vtkIdList;
95class vtkNeighborPoints;
96class vtkPoints;
97
98class VTKCOMMONDATAMODEL_EXPORT vtkPointLocator : public vtkIncrementalPointLocator
99{
100public:
106
108
112 void PrintSelf(ostream& os, vtkIndent indent) override;
114
116
119 vtkSetVector3Macro(Divisions, int);
120 vtkGetVectorMacro(Divisions, int, 3);
122
124
127 vtkSetClampMacro(NumberOfPointsPerBucket, int, 1, VTK_INT_MAX);
128 vtkGetMacro(NumberOfPointsPerBucket, int);
130
131 // Re-use any superclass signatures that we don't override.
133
140 vtkIdType FindClosestPoint(const double x[3]) override;
141
143
150 vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
152 double radius, const double x[3], double inputDataLength, double& dist2);
154
161 int InitPointInsertion(vtkPoints* newPts, const double bounds[6]) override;
162
169 int InitPointInsertion(vtkPoints* newPts, const double bounds[6], vtkIdType estNumPts) override;
170
180 void InsertPoint(vtkIdType ptId, const double x[3]) override;
181
192 vtkIdType InsertNextPoint(const double x[3]) override;
193
195
200 vtkIdType IsInsertedPoint(double x, double y, double z) override
201 {
202 double xyz[3];
203 xyz[0] = x;
204 xyz[1] = y;
205 xyz[2] = z;
206 return this->IsInsertedPoint(xyz);
207 }
208 vtkIdType IsInsertedPoint(const double x[3]) override;
210
220 int InsertUniquePoint(const double x[3], vtkIdType& ptId) override;
221
229 vtkIdType FindClosestInsertedPoint(const double x[3]) override;
230
239 void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
240
242
249 virtual void FindDistributedPoints(int N, const double x[3], vtkIdList* result, int M);
250 virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList* result, int M);
252
259 void FindPointsWithinRadius(double R, const double x[3], vtkIdList* result) override;
260
267 virtual vtkIdList* GetPointsInBucket(const double x[3], int ijk[3]);
268
270
273 vtkGetObjectMacro(Points, vtkPoints);
275
277
281 void Initialize() override;
282 void FreeSearchStructure() override;
283 void BuildLocator() override;
284 void ForceBuildLocator() override;
285 void GenerateRepresentation(int level, vtkPolyData* pd) override;
287
288protected:
291
292 void BuildLocatorInternal() override;
293
294 // place points in appropriate buckets
296 vtkNeighborPoints* buckets, const int ijk[3], const int ndivs[3], int level);
298 vtkNeighborPoints* buckets, const double x[3], const int ijk[3], double dist, int level);
299 void GetOverlappingBuckets(vtkNeighborPoints* buckets, const double x[3], double dist,
300 int prevMinLevel[3], int prevMaxLevel[3]);
301 void GenerateFace(int face, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
302 double Distance2ToBucket(const double x[3], const int nei[3]);
303 double Distance2ToBounds(const double x[3], const double bounds[6]);
304
305 vtkPoints* Points; // Used for merging points
306 int Divisions[3]; // Number of sub-divisions in x-y-z directions
307 int NumberOfPointsPerBucket; // Used with previous boolean to control subdivide
308 vtkIdList** HashTable; // lists of point ids in buckets
309 double H[3]; // width of each bucket in x-y-z directions
310
314
315 // These are inlined methods and data members for performance reasons
316 double HX, HY, HZ;
317 double FX, FY, FZ, BX, BY, BZ;
318 vtkIdType XD, YD, ZD, SliceSize;
319
320 void GetBucketIndices(const double* x, int ijk[3]) const
321 {
322 // Compute point index. Make sure it lies within range of locator.
323 vtkIdType tmp0 = static_cast<vtkIdType>(((x[0] - this->BX) * this->FX));
324 vtkIdType tmp1 = static_cast<vtkIdType>(((x[1] - this->BY) * this->FY));
325 vtkIdType tmp2 = static_cast<vtkIdType>(((x[2] - this->BZ) * this->FZ));
326
327 ijk[0] = tmp0 < 0 ? 0 : (tmp0 >= this->XD ? this->XD - 1 : tmp0);
328 ijk[1] = tmp1 < 0 ? 0 : (tmp1 >= this->YD ? this->YD - 1 : tmp1);
329 ijk[2] = tmp2 < 0 ? 0 : (tmp2 >= this->ZD ? this->ZD - 1 : tmp2);
330 }
331
332 vtkIdType GetBucketIndex(const double* x) const
333 {
334 int ijk[3];
335 this->GetBucketIndices(x, ijk);
336 return ijk[0] + ijk[1] * this->XD + ijk[2] * this->SliceSize;
337 }
338
340
341private:
342 vtkPointLocator(const vtkPointLocator&) = delete;
343 void operator=(const vtkPointLocator&) = delete;
344};
345
346VTK_ABI_NAMESPACE_END
347#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:133
Abstract class in support of both point location and point insertion.
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
quickly locate points in 3-space
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:139
concrete dataset represents vertices, lines, polygons, and triangle strips
int vtkIdType
Definition vtkType.h:315
#define VTK_INT_MAX
Definition vtkType.h:144