VTK  9.7.1
vtkCellLocator.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
35 #ifndef vtkCellLocator_h
36 #define vtkCellLocator_h
37 
38 #include "vtkAbstractCellLocator.h"
39 #include "vtkCommonDataModelModule.h" // For export macro
40 #include "vtkNew.h" // For vtkNew
41 
42 VTK_ABI_NAMESPACE_BEGIN
43 class vtkIntArray;
44 
45 class VTKCOMMONDATAMODEL_EXPORT vtkCellLocator : public vtkAbstractCellLocator
46 {
47 public:
49 
53  void PrintSelf(ostream& os, vtkIndent indent) override;
55 
60  static vtkCellLocator* New();
61 
67 
68  // Reuse any superclass signatures that we don't override.
74 
81  int IntersectWithLine(const double p1[3], const double p2[3], double tol, double& t, double x[3],
82  double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) override;
83 
93  int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points,
94  vtkIdList* cellIds, vtkGenericCell* cell) override;
95 
105  void FindClosestPoint(const double x[3], double closestPoint[3], vtkGenericCell* cell,
106  vtkIdType& cellId, int& subId, double& dist2) override
107  {
108  this->Superclass::FindClosestPoint(x, closestPoint, cell, cellId, subId, dist2);
109  }
110 
131  vtkIdType FindClosestPointWithinRadius(double x[3], double radius, double closestPoint[3],
132  vtkGenericCell* cell, vtkIdType& cellId, int& subId, double& dist2, int& inside) override;
133 
141  vtkIdType FindCell(double x[3], double tol2, vtkGenericCell* GenCell, int& subId,
142  double pcoords[3], double* weights) override;
143 
148  void FindCellsWithinBounds(double* bbox, vtkIdList* cells) override;
149 
151 
154  void FreeSearchStructure() override;
155  void BuildLocator() override;
156  void ForceBuildLocator() override;
157  void GenerateRepresentation(int level, vtkPolyData* pd) override;
159 
163  virtual vtkIdList* GetCells(int bucket);
164 
169  virtual int GetNumberOfBuckets();
170 
176  void ShallowCopy(vtkAbstractCellLocator* locator) override;
177 
178 protected:
179  vtkCellLocator();
180  ~vtkCellLocator() override;
181 
182  void BuildLocatorInternal() override;
183 
184  //------------------------------------------------------------------------------
186  {
187  public:
188  vtkNeighborCells(int size);
189 
190  inline int GetNumberOfNeighbors();
191 
192  inline void Reset();
193 
194  inline int* GetPoint(int i);
195 
196  inline int InsertNextPoint(int* x);
197 
198  protected:
200  };
201 
202  void GetOverlappingBuckets(vtkNeighborCells& buckets, const double x[3], double dist,
203  int prevMinLevel[3], int prevMaxLevel[3]);
204 
205  inline void GetBucketIndices(const double x[3], int ijk[3]);
206 
207  double Distance2ToBucket(const double x[3], int nei[3]);
208  double Distance2ToBounds(const double x[3], double bounds[6]);
209 
210  int NumberOfOctants; // number of octants in tree
211  double Bounds[6]; // bounding box root octant
212  double H[3]; // width of leaf octant in x-y-z directions
213  int NumberOfDivisions; // number of "leaf" octant sub-divisions
214  std::shared_ptr<std::vector<vtkSmartPointer<vtkIdList>>> TreeSharedPtr;
216 
217  void MarkParents(const vtkSmartPointer<vtkIdList>&, int, int, int, int, int);
218  int GenerateIndex(int offset, int numDivs, int i, int j, int k, vtkIdType& idx);
219  void GenerateFace(
220  int face, int numDivs, int i, int j, int k, vtkPoints* pts, vtkCellArray* polys);
221  void ComputeOctantBounds(double octantBounds[6], int i, int j, int k);
222 
223 private:
224  vtkCellLocator(const vtkCellLocator&) = delete;
225  void operator=(const vtkCellLocator&) = delete;
226 };
227 
228 VTK_ABI_NAMESPACE_END
229 #endif
virtual void BuildLocator()=0
Build the locator from the input dataset.
virtual vtkIdType FindClosestPointWithinRadius(double x[3], double radius, double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
Return the closest point within a specified radius and the cell which is closest to the point x...
virtual void FindCellsWithinBounds(double *bbox, vtkIdList *cells)
Return a list of unique cell ids inside of a given bounding box.
virtual void SetNumberOfCellsPerNode(int)
Specify the preferred/maximum number of cells in each node/bucket.
an abstract base class for locators which find cells
vtkSmartPointer< vtkIdList > * Tree
std::shared_ptr< std::vector< vtkSmartPointer< vtkIdList > > > TreeSharedPtr
int GetNumberOfCellsPerBucket()
void SetNumberOfCellsPerBucket(int N)
Specify the average number of cells in each octant.
int vtkIdType
Definition: vtkType.h:363
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:71
virtual void FreeSearchStructure()=0
Free the memory required for the spatial data structure.
provides thread-safe access to cells
virtual void FindClosestPoint(const double x[3], double closestPoint[3], vtkIdType &cellId, int &subId, double &dist2)
Return the closest point and the cell which is closest to the point x.
dynamic, self-adjusting array of int
Definition: vtkIntArray.h:35
virtual void ShallowCopy(vtkAbstractCellLocator *)
Shallow copy of a vtkAbstractCellLocator.
octree-based spatial search object to quickly locate cells
void FindClosestPoint(const double x[3], double closestPoint[3], vtkGenericCell *cell, vtkIdType &cellId, int &subId, double &dist2) override
Return the closest point and the cell which is closest to the point x.
virtual int IntersectWithLine(const double p1[3], const double p2[3], double tol, double &t, double x[3], double pcoords[3], int &subId)
Return intersection point (if any) of finite line with cells contained in cell locator.
a simple class to control print indentation
Definition: vtkIndent.h:28
virtual void BuildLocatorInternal()
This function is not pure virtual to maintain backwards compatibility.
Definition: vtkLocator.h:199
list of point or cell ids
Definition: vtkIdList.h:25
object to represent cell connectivity
Definition: vtkCellArray.h:177
void GetPoint(int i, int j, int k, double pnt[3])
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void FindCellsAlongLine(const double p1[3], const double p2[3], double tol, vtkIdList *cells)
Take the passed line segment and intersect it with the data set.
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:30
virtual void ForceBuildLocator()
Build the locator from the input dataset (even if UseExistingSearchStructure is on).
Definition: vtkLocator.h:163
vtkNew< vtkIntArray > Points
vtkIdType FindCell(double x[3])
Returns the Id of the cell containing the point, returns -1 if no cell found.