VTK  9.2.6
vtkPointLocator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPointLocator.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
98 #ifndef vtkPointLocator_h
99 #define vtkPointLocator_h
100 
101 #include "vtkCommonDataModelModule.h" // For export macro
103 
104 class vtkCellArray;
105 class vtkIdList;
106 class vtkNeighborPoints;
107 class vtkPoints;
108 
109 class VTKCOMMONDATAMODEL_EXPORT vtkPointLocator : public vtkIncrementalPointLocator
110 {
111 public:
116  static vtkPointLocator* New();
117 
119 
123  void PrintSelf(ostream& os, vtkIndent indent) override;
125 
127 
130  vtkSetVector3Macro(Divisions, int);
131  vtkGetVectorMacro(Divisions, int, 3);
133 
135 
138  vtkSetClampMacro(NumberOfPointsPerBucket, int, 1, VTK_INT_MAX);
139  vtkGetMacro(NumberOfPointsPerBucket, int);
141 
142  // Re-use any superclass signatures that we don't override.
144 
151  vtkIdType FindClosestPoint(const double x[3]) override;
152 
154 
161  vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
163  double radius, const double x[3], double inputDataLength, double& dist2);
165 
172  int InitPointInsertion(vtkPoints* newPts, const double bounds[6]) override;
173 
180  int InitPointInsertion(vtkPoints* newPts, const double bounds[6], vtkIdType estNumPts) override;
181 
191  void InsertPoint(vtkIdType ptId, const double x[3]) override;
192 
203  vtkIdType InsertNextPoint(const double x[3]) override;
204 
206 
211  vtkIdType IsInsertedPoint(double x, double y, double z) override
212  {
213  double xyz[3];
214  xyz[0] = x;
215  xyz[1] = y;
216  xyz[2] = z;
217  return this->IsInsertedPoint(xyz);
218  };
219  vtkIdType IsInsertedPoint(const double x[3]) override;
221 
231  int InsertUniquePoint(const double x[3], vtkIdType& ptId) override;
232 
240  vtkIdType FindClosestInsertedPoint(const double x[3]) override;
241 
250  void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
251 
253 
260  virtual void FindDistributedPoints(int N, const double x[3], vtkIdList* result, int M);
261  virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList* result, int M);
263 
270  void FindPointsWithinRadius(double R, const double x[3], vtkIdList* result) override;
271 
278  virtual vtkIdList* GetPointsInBucket(const double x[3], int ijk[3]);
279 
281 
284  vtkGetObjectMacro(Points, vtkPoints);
286 
288 
292  void Initialize() override;
293  void FreeSearchStructure() override;
294  void BuildLocator() override;
295  void ForceBuildLocator() override;
296  void GenerateRepresentation(int level, vtkPolyData* pd) override;
298 
299 protected:
301  ~vtkPointLocator() override;
302 
303  void BuildLocatorInternal() override;
304 
305  // place points in appropriate buckets
307  vtkNeighborPoints* buckets, const int ijk[3], const int ndivs[3], int level);
309  vtkNeighborPoints* buckets, const double x[3], const int ijk[3], double dist, int level);
310  void GetOverlappingBuckets(vtkNeighborPoints* buckets, const double x[3], double dist,
311  int prevMinLevel[3], int prevMaxLevel[3]);
312  void GenerateFace(int face, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
313  double Distance2ToBucket(const double x[3], const int nei[3]);
314  double Distance2ToBounds(const double x[3], const double bounds[6]);
315 
316  vtkPoints* Points; // Used for merging points
317  int Divisions[3]; // Number of sub-divisions in x-y-z directions
318  int NumberOfPointsPerBucket; // Used with previous boolean to control subdivide
319  vtkIdList** HashTable; // lists of point ids in buckets
320  double H[3]; // width of each bucket in x-y-z directions
321 
325 
326  // These are inlined methods and data members for performance reasons
327  double HX, HY, HZ;
328  double FX, FY, FZ, BX, BY, BZ;
329  vtkIdType XD, YD, ZD, SliceSize;
330 
331  void GetBucketIndices(const double* x, int ijk[3]) const
332  {
333  // Compute point index. Make sure it lies within range of locator.
334  vtkIdType tmp0 = static_cast<vtkIdType>(((x[0] - this->BX) * this->FX));
335  vtkIdType tmp1 = static_cast<vtkIdType>(((x[1] - this->BY) * this->FY));
336  vtkIdType tmp2 = static_cast<vtkIdType>(((x[2] - this->BZ) * this->FZ));
337 
338  ijk[0] = tmp0 < 0 ? 0 : (tmp0 >= this->XD ? this->XD - 1 : tmp0);
339  ijk[1] = tmp1 < 0 ? 0 : (tmp1 >= this->YD ? this->YD - 1 : tmp1);
340  ijk[2] = tmp2 < 0 ? 0 : (tmp2 >= this->ZD ? this->ZD - 1 : tmp2);
341  }
342 
343  vtkIdType GetBucketIndex(const double* x) const
344  {
345  int ijk[3];
346  this->GetBucketIndices(x, ijk);
347  return ijk[0] + ijk[1] * this->XD + ijk[2] * this->SliceSize;
348  }
349 
351 
352 private:
353  vtkPointLocator(const vtkPointLocator&) = delete;
354  void operator=(const vtkPointLocator&) = delete;
355 };
356 
357 #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
Definition: vtkCellArray.h:296
list of point or cell ids
Definition: vtkIdList.h:143
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:119
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 ...
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
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.
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)
vtkPoints * Points
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:149
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
@ level
Definition: vtkX3D.h:401
@ radius
Definition: vtkX3D.h:258
int vtkIdType
Definition: vtkType.h:332
#define VTK_INT_MAX
Definition: vtkType.h:155