VTK  9.0.1
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 
102  vtkIdType FindClosestPointWithinRadius(double radius, const double x[3], double& dist2) override;
104  double radius, const double x[3], double inputDataLength, double& dist2);
106 
113  int InitPointInsertion(vtkPoints* newPts, const double bounds[6]) override;
114 
121  int InitPointInsertion(vtkPoints* newPts, const double bounds[6], vtkIdType estSize) override;
122 
132  void InsertPoint(vtkIdType ptId, const double x[3]) override;
133 
144  vtkIdType InsertNextPoint(const double x[3]) override;
145 
147 
152  vtkIdType IsInsertedPoint(double x, double y, double z) override
153  {
154  double xyz[3];
155  xyz[0] = x;
156  xyz[1] = y;
157  xyz[2] = z;
158  return this->IsInsertedPoint(xyz);
159  };
160  vtkIdType IsInsertedPoint(const double x[3]) override;
162 
172  int InsertUniquePoint(const double x[3], vtkIdType& ptId) override;
173 
181  vtkIdType FindClosestInsertedPoint(const double x[3]) override;
182 
191  void FindClosestNPoints(int N, const double x[3], vtkIdList* result) override;
192 
194 
201  virtual void FindDistributedPoints(int N, const double x[3], vtkIdList* result, int M);
202  virtual void FindDistributedPoints(int N, double x, double y, double z, vtkIdList* result, int M);
204 
211  void FindPointsWithinRadius(double R, const double x[3], vtkIdList* result) override;
212 
219  virtual vtkIdList* GetPointsInBucket(const double x[3], int ijk[3]);
220 
222 
225  vtkGetObjectMacro(Points, vtkPoints);
227 
229 
233  void Initialize() override;
234  void FreeSearchStructure() override;
235  void BuildLocator() override;
236  void GenerateRepresentation(int level, vtkPolyData* pd) override;
238 
239 protected:
240  vtkPointLocator();
241  ~vtkPointLocator() override;
242 
243  // place points in appropriate buckets
244  void GetBucketNeighbors(
245  vtkNeighborPoints* buckets, const int ijk[3], const int ndivs[3], int level);
246  void GetOverlappingBuckets(
247  vtkNeighborPoints* buckets, const double x[3], const int ijk[3], double dist, int level);
248  void GetOverlappingBuckets(vtkNeighborPoints* buckets, const double x[3], double dist,
249  int prevMinLevel[3], int prevMaxLevel[3]);
250  void GenerateFace(int face, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
251  double Distance2ToBucket(const double x[3], const int nei[3]);
252  double Distance2ToBounds(const double x[3], const double bounds[6]);
253 
254  vtkPoints* Points; // Used for merging points
255  int Divisions[3]; // Number of sub-divisions in x-y-z directions
256  int NumberOfPointsPerBucket; // Used with previous boolean to control subdivide
257  vtkIdList** HashTable; // lists of point ids in buckets
258  double H[3]; // width of each bucket in x-y-z directions
259 
263 
264  // These are inlined methods and data members for performance reasons
265  double HX, HY, HZ;
266  double FX, FY, FZ, BX, BY, BZ;
267  vtkIdType XD, YD, ZD, SliceSize;
268 
269  void GetBucketIndices(const double* x, int ijk[3]) const
270  {
271  // Compute point index. Make sure it lies within range of locator.
272  vtkIdType tmp0 = static_cast<vtkIdType>(((x[0] - this->BX) * this->FX));
273  vtkIdType tmp1 = static_cast<vtkIdType>(((x[1] - this->BY) * this->FY));
274  vtkIdType tmp2 = static_cast<vtkIdType>(((x[2] - this->BZ) * this->FZ));
275 
276  ijk[0] = tmp0 < 0 ? 0 : (tmp0 >= this->XD ? this->XD - 1 : tmp0);
277  ijk[1] = tmp1 < 0 ? 0 : (tmp1 >= this->YD ? this->YD - 1 : tmp1);
278  ijk[2] = tmp2 < 0 ? 0 : (tmp2 >= this->ZD ? this->ZD - 1 : tmp2);
279  }
280 
281  vtkIdType GetBucketIndex(const double* x) const
282  {
283  int ijk[3];
284  this->GetBucketIndices(x, ijk);
285  return ijk[0] + ijk[1] * this->XD + ijk[2] * this->SliceSize;
286  }
287 
288  void ComputePerformanceFactors();
289 
290 private:
291  vtkPointLocator(const vtkPointLocator&) = delete;
292  void operator=(const vtkPointLocator&) = delete;
293 };
294 
295 #endif
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkPointLocator::InsertionPointId
vtkIdType InsertionPointId
Definition: vtkPointLocator.h:261
vtkIncrementalPointLocator::InsertUniquePoint
virtual int InsertUniquePoint(const double x[3], vtkIdType &ptId)=0
Insert a point unless there has been a duplicate in the search structure.
VTK_INT_MAX
#define VTK_INT_MAX
Definition: vtkType.h:155
vtkIncrementalPointLocator::IsInsertedPoint
virtual vtkIdType IsInsertedPoint(double x, double y, double z)=0
Determine whether or not a given point has been inserted.
vtkPointLocator::GetBucketIndex
vtkIdType GetBucketIndex(const double *x) const
Definition: vtkPointLocator.h:281
vtkIncrementalPointLocator::InsertPoint
virtual void InsertPoint(vtkIdType ptId, const double x[3])=0
Insert a given point with a specified point index ptId.
vtkPointLocator::HashTable
vtkIdList ** HashTable
Definition: vtkPointLocator.h:257
vtkPointLocator::InsertionLevel
double InsertionLevel
Definition: vtkPointLocator.h:262
vtkPointLocator::FZ
double FZ
Definition: vtkPointLocator.h:266
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkPointLocator
quickly locate points in 3-space
Definition: vtkPointLocator.h:50
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkPointLocator::Points
vtkPoints * Points
Definition: vtkPointLocator.h:254
vtkIncrementalPointLocator::InsertNextPoint
virtual vtkIdType InsertNextPoint(const double x[3])=0
Insert a given point and return the point index.
vtkPointLocator::NumberOfPointsPerBucket
int NumberOfPointsPerBucket
Definition: vtkPointLocator.h:256
vtkX3D::level
@ level
Definition: vtkX3D.h:401
vtkLocator::Initialize
virtual void Initialize()
Initialize locator.
vtkPointLocator::HZ
double HZ
Definition: vtkPointLocator.h:265
vtkPointLocator::ZD
vtkIdType ZD
Definition: vtkPointLocator.h:267
vtkIncrementalPointLocator.h
vtkLocator::GenerateRepresentation
virtual void GenerateRepresentation(int level, vtkPolyData *pd)=0
Method to build a representation at a particular level.
vtkAbstractPointLocator::FindPointsWithinRadius
virtual void FindPointsWithinRadius(double R, const double x[3], vtkIdList *result)=0
Find all points within a specified radius R of position x.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:179
vtkIncrementalPointLocator::FindClosestInsertedPoint
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 ...
vtkIncrementalPointLocator
Abstract class in support of both point location and point insertion.
Definition: vtkIncrementalPointLocator.h:51
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkPointLocator::GetBucketIndices
void GetBucketIndices(const double *x, int ijk[3]) const
Definition: vtkPointLocator.h:269
vtkLocator::BuildLocator
virtual void BuildLocator()=0
Build the locator from the input dataset.
vtkIncrementalPointLocator::InitPointInsertion
virtual int InitPointInsertion(vtkPoints *newPts, const double bounds[6])=0
Initialize the point insertion process.
vtkAbstractPointLocator::FindClosestNPoints
virtual void FindClosestNPoints(int N, const double x[3], vtkIdList *result)=0
Find the closest N points to a position.
vtkPointLocator::IsInsertedPoint
vtkIdType IsInsertedPoint(double x, double y, double z) override
Determine whether point given by x[3] has been inserted into points list.
Definition: vtkPointLocator.h:152
vtkIncrementalPointLocator::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPolyData
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:84
vtkAbstractPointLocator::FindClosestPoint
virtual vtkIdType FindClosestPoint(const double x[3])=0
Given a position x, return the id of the point closest to it.
vtkPointLocator::InsertionTol2
double InsertionTol2
Definition: vtkPointLocator.h:260
vtkLocator::FreeSearchStructure
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
vtkX3D::radius
@ radius
Definition: vtkX3D.h:258
vtkAbstractPointLocator::FindClosestPointWithinRadius
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.