VTK
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 =========================================================================*/
39 #ifndef vtkPointLocator_h
40 #define vtkPointLocator_h
41 
42 #include "vtkCommonDataModelModule.h" // For export macro
44 
45 class vtkCellArray;
46 class vtkIdList;
47 class vtkNeighborPoints;
48 class vtkPoints;
49 
50 class VTKCOMMONDATAMODEL_EXPORT vtkPointLocator : public vtkIncrementalPointLocator
51 {
52 public:
57  static vtkPointLocator *New();
58 
60 
64  void PrintSelf(ostream& os, vtkIndent indent) override;
66 
68 
71  vtkSetVector3Macro(Divisions,int);
72  vtkGetVectorMacro(Divisions,int,3);
74 
76 
79  vtkSetClampMacro(NumberOfPointsPerBucket,int,1,VTK_INT_MAX);
80  vtkGetMacro(NumberOfPointsPerBucket,int);
82 
83  // Re-use any superclass signatures that we don't override.
85 
92  vtkIdType FindClosestPoint(const double x[3]) override;
93 
95 
103  double radius, const double x[3], double& dist2) override;
105  double radius, const double x[3],
106  double inputDataLength, double& dist2);
108 
115  int InitPointInsertion(vtkPoints *newPts,
116  const double bounds[6]) override;
117 
124  int InitPointInsertion(vtkPoints *newPts, const double bounds[6],
125  vtkIdType estSize) override;
126 
136  void InsertPoint(vtkIdType ptId, const double x[3]) override;
137 
148  vtkIdType InsertNextPoint(const double x[3]) override;
149 
151 
156  vtkIdType IsInsertedPoint(double x, double y, double z) override
157  {
158  double xyz[3];
159  xyz[0] = x; xyz[1] = y; xyz[2] = z;
160  return this->IsInsertedPoint (xyz);
161  };
162  vtkIdType IsInsertedPoint(const double x[3]) override;
164 
174  int InsertUniquePoint(const double x[3], vtkIdType &ptId) override;
175 
183  vtkIdType FindClosestInsertedPoint(const double x[3]) override;
184 
193  void FindClosestNPoints(int N, const double x[3],
194  vtkIdList *result) override;
195 
197 
204  virtual void FindDistributedPoints(int N, const double x[3],
205  vtkIdList *result, int M);
206  virtual void FindDistributedPoints(int N, double x, double y,
207  double z, vtkIdList *result, int M);
209 
216  void FindPointsWithinRadius(double R, const double x[3],
217  vtkIdList *result) override;
218 
225  virtual vtkIdList *GetPointsInBucket(const double x[3], int ijk[3]);
226 
228 
231  vtkGetObjectMacro(Points, vtkPoints);
233 
235 
239  void Initialize() override;
240  void FreeSearchStructure() override;
241  void BuildLocator() override;
242  void GenerateRepresentation(int level, vtkPolyData *pd) override;
244 
245 protected:
246  vtkPointLocator();
247  ~vtkPointLocator() override;
248 
249  // place points in appropriate buckets
250  void GetBucketNeighbors(vtkNeighborPoints* buckets,
251  const int ijk[3], const int ndivs[3], int level);
252  void GetOverlappingBuckets(vtkNeighborPoints* buckets,
253  const double x[3], const int ijk[3], double dist,
254  int level);
255  void GetOverlappingBuckets(vtkNeighborPoints* buckets,
256  const double x[3], double dist,
257  int prevMinLevel[3],
258  int prevMaxLevel[3]);
259  void GenerateFace(int face, int i, int j, int k,
260  vtkPoints *pts, vtkCellArray *polys);
261  double Distance2ToBucket(const double x[3], const int nei[3]);
262  double Distance2ToBounds(const double x[3], const double bounds[6]);
263 
264  vtkPoints *Points; // Used for merging points
265  int Divisions[3]; // Number of sub-divisions in x-y-z directions
266  int NumberOfPointsPerBucket; //Used with previous boolean to control subdivide
267  vtkIdList **HashTable; // lists of point ids in buckets
268  double H[3]; // width of each bucket in x-y-z directions
269 
273 
274  // These are inlined methods and data members for performance reasons
275  double HX, HY, HZ;
276  double FX, FY, FZ, BX, BY, BZ;
277  vtkIdType XD, YD, ZD, SliceSize;
278 
279  void GetBucketIndices(const double *x, int ijk[3]) const
280  {
281  // Compute point index. Make sure it lies within range of locator.
282  vtkIdType tmp0 = static_cast<vtkIdType>(((x[0] - this->BX) * this->FX));
283  vtkIdType tmp1 = static_cast<vtkIdType>(((x[1] - this->BY) * this->FY));
284  vtkIdType tmp2 = static_cast<vtkIdType>(((x[2] - this->BZ) * this->FZ));
285 
286  ijk[0] = tmp0 < 0 ? 0 : (tmp0 >= this->XD ? this->XD-1 : tmp0);
287  ijk[1] = tmp1 < 0 ? 0 : (tmp1 >= this->YD ? this->YD-1 : tmp1);
288  ijk[2] = tmp2 < 0 ? 0 : (tmp2 >= this->ZD ? this->ZD-1 : tmp2);
289  }
290 
291  vtkIdType GetBucketIndex(const double *x) const
292  {
293  int ijk[3];
294  this->GetBucketIndices(x, ijk);
295  return ijk[0] + ijk[1]*this->XD + ijk[2]*this->SliceSize;
296  }
297 
298  void ComputePerformanceFactors();
299 
300 private:
301  vtkPointLocator(const vtkPointLocator&) = delete;
302  void operator=(const vtkPointLocator&) = delete;
303 };
304 
305 #endif
vtkIdType IsInsertedPoint(double x, double y, double z) override
Determine whether point given by x[3] has been inserted into points list.
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 duplciate 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.
vtkIdType GetBucketIndex(const double *x) const
#define VTK_INT_MAX
Definition: vtkType.h:157
vtkIdList ** HashTable
Abstract class in support of both point location and point insertion.
int vtkIdType
Definition: vtkType.h:345
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.
void GetBucketIndices(const double *x, int ijk[3]) const
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:33
list of point or cell ids
Definition: vtkIdList.h:30
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:44
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:33