VTK
vtkCellLocator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkCellLocator.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 =========================================================================*/
43 #ifndef __vtkCellLocator_h
44 #define __vtkCellLocator_h
45 
46 #include "vtkAbstractCellLocator.h"
47 
48 class vtkNeighborCells;
49 
51 {
52 public:
54  void PrintSelf(ostream& os, vtkIndent indent);
55 
58  static vtkCellLocator *New();
59 
61 
63  { this->SetNumberOfCellsPerNode(N); }
65  { return this->NumberOfCellsPerNode; }
67 
68 //BTX
69 /*
70  if the borland compiler is ever removed, we can use these declarations
71  instead of reimplementaing the calls in this subclass
72  using vtkAbstractCellLocator::IntersectWithLine;
73  using vtkAbstractCellLocator::FindClosestPoint;
74  using vtkAbstractCellLocator::FindClosestPointWithinRadius;
75 */
76 //ETX
77 
79 
80  virtual int IntersectWithLine(
81  double a0[3], double a1[3], double tol,
82  double& t, double x[3], double pcoords[3],
83  int &subId)
84  {
85  return Superclass::
86  IntersectWithLine(a0, a1, tol,t, x, pcoords, subId);
87  }
89 
91 
92  virtual int IntersectWithLine(
93  double a0[3], double a1[3], double tol,
94  double& t, double x[3], double pcoords[3],
95  int &subId, vtkIdType &cellId)
96  {
97  return Superclass::
98  IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId);
99  }
101 
103 
104  virtual int IntersectWithLine(
105  const double a0[3], const double a1[3],
106  vtkPoints *points, vtkIdList *cellIds)
107  {
108  return Superclass::
109  IntersectWithLine(a0, a1, points, cellIds);
110  }
112 
114 
118  virtual int IntersectWithLine(double a0[3], double a1[3], double tol,
119  double& t, double x[3], double pcoords[3],
120  int &subId, vtkIdType &cellId,
121  vtkGenericCell *cell);
123 
125 
126  virtual void FindClosestPoint(
127  double x[3], double closestPoint[3],
128  vtkIdType &cellId, int &subId, double& dist2)
129  {
130  Superclass::
131  FindClosestPoint(x, closestPoint, cellId, subId, dist2);
132  }
134 
136 
145  virtual void FindClosestPoint(
146  double x[3], double closestPoint[3],
147  vtkGenericCell *cell, vtkIdType &cellId,
148  int &subId, double& dist2);
150 
152 
154  double x[3], double radius,
155  double closestPoint[3], vtkIdType &cellId,
156  int &subId, double& dist2)
157  {
158  return Superclass::FindClosestPointWithinRadius
159  (x, radius, closestPoint, cellId, subId, dist2);
160  }
162 
164 
166  double x[3], double radius,
167  double closestPoint[3],
168  vtkGenericCell *cell, vtkIdType &cellId,
169  int &subId, double& dist2)
170  {
171  return Superclass::FindClosestPointWithinRadius
172  (x, radius, closestPoint, cell, cellId, subId, dist2);
173  }
175 
177 
194  double x[3], double radius, double closestPoint[3],
195  vtkGenericCell *cell, vtkIdType &cellId,
196  int &subId, double& dist2, int &inside);
198 
200  virtual vtkIdList *GetCells(int bucket);
201 
204  virtual int GetNumberOfBuckets(void);
205 
207 
209  virtual vtkIdType FindCell(double x[3])
210  { return this->Superclass::FindCell(x); }
212 
214 
217  virtual vtkIdType FindCell(
218  double x[3], double tol2, vtkGenericCell *GenCell,
219  double pcoords[3], double *weights);
221 
225  virtual void FindCellsWithinBounds(double *bbox, vtkIdList *cells);
226 
228 
233  virtual void FindCellsAlongLine(
234  double p1[3], double p2[3], double tolerance, vtkIdList *cells);
236 
238 
239  virtual void FreeSearchStructure();
240  virtual void BuildLocator();
241  virtual void BuildLocatorIfNeeded();
242  virtual void ForceBuildLocator();
243  virtual void BuildLocatorInternal();
244  virtual void GenerateRepresentation(int level, vtkPolyData *pd);
246 
247 protected:
248  vtkCellLocator();
249  ~vtkCellLocator();
250 
251  void GetBucketNeighbors(int ijk[3], int ndivs, int level);
252  void GetOverlappingBuckets(double x[3], int ijk[3], double dist,
253  int prevMinLevel[3], int prevMaxLevel[3]);
254 
255  void ClearCellHasBeenVisited();
256  void ClearCellHasBeenVisited(int id);
257 
258  double Distance2ToBucket(double x[3], int nei[3]);
259  double Distance2ToBounds(double x[3], double bounds[6]);
260 
261  int NumberOfOctants; // number of octants in tree
262  double Bounds[6]; // bounding box root octant
263  int NumberOfParents; // number of parent octants
264  double H[3]; // width of leaf octant in x-y-z directions
265  int NumberOfDivisions; // number of "leaf" octant sub-divisions
266  vtkIdList **Tree; // octree
267 
268  void MarkParents(void*, int, int, int, int, int);
269  void GetChildren(int idx, int level, int children[8]);
270  int GenerateIndex(int offset, int numDivs, int i, int j, int k,
271  vtkIdType &idx);
272  void GenerateFace(int face, int numDivs, int i, int j, int k,
273  vtkPoints *pts, vtkCellArray *polys);
274 
275  vtkNeighborCells *Buckets;
276  unsigned char *CellHasBeenVisited;
277  unsigned char QueryNumber;
278 
279  void ComputeOctantBounds(int i, int j, int k);
280  double OctantBounds[6]; //the bounds of the current octant
281  int IsInOctantBounds(double x[3])
282  {
283  if ( this->OctantBounds[0] <= x[0] && x[0] <= this->OctantBounds[1] &&
284  this->OctantBounds[2] <= x[1] && x[1] <= this->OctantBounds[3] &&
285  this->OctantBounds[4] <= x[2] && x[2] <= this->OctantBounds[5] )
286  {
287  return 1;
288  }
289  else
290  {
291  return 0;
292  }
293  }
294 
295 private:
296  vtkCellLocator(const vtkCellLocator&); // Not implemented.
297  void operator=(const vtkCellLocator&); // Not implemented.
298 };
299 
300 #endif
301 
302