VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkCellLocator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkCellLocator.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00043 #ifndef vtkCellLocator_h
00044 #define vtkCellLocator_h
00045 
00046 #include "vtkCommonDataModelModule.h" // For export macro
00047 #include "vtkAbstractCellLocator.h"
00048 
00049 class vtkNeighborCells;
00050 
00051 class VTKCOMMONDATAMODEL_EXPORT vtkCellLocator : public vtkAbstractCellLocator
00052 {
00053 public:
00054   vtkTypeMacro(vtkCellLocator,vtkAbstractCellLocator);
00055   void PrintSelf(ostream& os, vtkIndent indent);
00056 
00059   static vtkCellLocator *New();
00060 
00062 
00063   void SetNumberOfCellsPerBucket(int N)
00064   { this->SetNumberOfCellsPerNode(N); }
00065   int GetNumberOfCellsPerBucket()
00066   { return this->NumberOfCellsPerNode; }
00068 
00069 //BTX
00070 /*
00071   if the borland compiler is ever removed, we can use these declarations
00072   instead of reimplementaing the calls in this subclass
00073   using vtkAbstractCellLocator::IntersectWithLine;
00074   using vtkAbstractCellLocator::FindClosestPoint;
00075   using vtkAbstractCellLocator::FindClosestPointWithinRadius;
00076 */
00077 //ETX
00078 
00080 
00081   virtual int IntersectWithLine(
00082     double a0[3], double a1[3], double tol,
00083     double& t, double x[3], double pcoords[3],
00084     int &subId)
00085   {
00086     return Superclass::
00087       IntersectWithLine(a0, a1, tol,t, x, pcoords, subId);
00088   }
00090 
00092 
00093   virtual int IntersectWithLine(
00094     double a0[3], double a1[3], double tol,
00095     double& t, double x[3], double pcoords[3],
00096     int &subId, vtkIdType &cellId)
00097   {
00098     return Superclass::
00099       IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId);
00100   }
00102 
00104 
00105   virtual int IntersectWithLine(
00106     const double a0[3], const double a1[3],
00107     vtkPoints *points, vtkIdList *cellIds)
00108   {
00109     return Superclass::
00110       IntersectWithLine(a0, a1, points, cellIds);
00111   }
00113 
00115 
00119   virtual int IntersectWithLine(double a0[3], double a1[3], double tol,
00120                                 double& t, double x[3], double pcoords[3],
00121                                 int &subId, vtkIdType &cellId,
00122                                 vtkGenericCell *cell);
00124 
00126 
00127   virtual void FindClosestPoint(
00128     double x[3], double closestPoint[3],
00129     vtkIdType &cellId, int &subId, double& dist2)
00130   {
00131     Superclass::
00132       FindClosestPoint(x, closestPoint, cellId, subId, dist2);
00133   }
00135 
00137 
00146   virtual void FindClosestPoint(
00147     double x[3], double closestPoint[3],
00148     vtkGenericCell *cell, vtkIdType &cellId,
00149     int &subId, double& dist2);
00151 
00153 
00154   virtual vtkIdType FindClosestPointWithinRadius(
00155     double x[3], double radius,
00156     double closestPoint[3], vtkIdType &cellId,
00157     int &subId, double& dist2)
00158   {
00159     return Superclass::FindClosestPointWithinRadius
00160       (x, radius, closestPoint, cellId, subId, dist2);
00161   }
00163 
00165 
00166   virtual vtkIdType FindClosestPointWithinRadius(
00167     double x[3], double radius,
00168     double closestPoint[3],
00169     vtkGenericCell *cell, vtkIdType &cellId,
00170     int &subId, double& dist2)
00171   {
00172     return Superclass::FindClosestPointWithinRadius
00173       (x, radius, closestPoint, cell, cellId, subId, dist2);
00174   }
00176 
00178 
00194   virtual vtkIdType FindClosestPointWithinRadius(
00195     double x[3], double radius, double closestPoint[3],
00196     vtkGenericCell *cell, vtkIdType &cellId,
00197     int &subId, double& dist2, int &inside);
00199 
00201   virtual vtkIdList *GetCells(int bucket);
00202 
00205   virtual int GetNumberOfBuckets(void);
00206 
00208 
00210   virtual vtkIdType FindCell(double x[3])
00211     { return this->Superclass::FindCell(x); }
00213 
00215 
00218   virtual vtkIdType FindCell(
00219     double x[3], double tol2, vtkGenericCell *GenCell,
00220     double pcoords[3], double *weights);
00222 
00226   virtual void FindCellsWithinBounds(double *bbox, vtkIdList *cells);
00227 
00229 
00234   virtual void FindCellsAlongLine(
00235     double p1[3], double p2[3], double tolerance, vtkIdList *cells);
00237 
00239 
00240   virtual void FreeSearchStructure();
00241   virtual void BuildLocator();
00242   virtual void BuildLocatorIfNeeded();
00243   virtual void ForceBuildLocator();
00244   virtual void BuildLocatorInternal();
00245   virtual void GenerateRepresentation(int level, vtkPolyData *pd);
00247 
00248 protected:
00249   vtkCellLocator();
00250   ~vtkCellLocator();
00251 
00252   void GetBucketNeighbors(int ijk[3], int ndivs, int level);
00253   void GetOverlappingBuckets(double x[3], int ijk[3], double dist,
00254                              int prevMinLevel[3], int prevMaxLevel[3]);
00255 
00256   void ClearCellHasBeenVisited();
00257   void ClearCellHasBeenVisited(int id);
00258 
00259   double Distance2ToBucket(double x[3], int nei[3]);
00260   double Distance2ToBounds(double x[3], double bounds[6]);
00261 
00262   int NumberOfOctants; // number of octants in tree
00263   double Bounds[6]; // bounding box root octant
00264   int NumberOfParents; // number of parent octants
00265   double H[3]; // width of leaf octant in x-y-z directions
00266   int NumberOfDivisions; // number of "leaf" octant sub-divisions
00267   vtkIdList **Tree; // octree
00268 
00269   void MarkParents(void*, int, int, int, int, int);
00270   void GetChildren(int idx, int level, int children[8]);
00271   int GenerateIndex(int offset, int numDivs, int i, int j, int k,
00272                     vtkIdType &idx);
00273   void GenerateFace(int face, int numDivs, int i, int j, int k,
00274                     vtkPoints *pts, vtkCellArray *polys);
00275 
00276   vtkNeighborCells *Buckets;
00277   unsigned char *CellHasBeenVisited;
00278   unsigned char QueryNumber;
00279 
00280   void ComputeOctantBounds(int i, int j, int k);
00281   double OctantBounds[6]; //the bounds of the current octant
00282   int IsInOctantBounds(double x[3], double tol = 0.0)
00283     {
00284     if ( this->OctantBounds[0]-tol <= x[0] && x[0] <= this->OctantBounds[1]+tol &&
00285          this->OctantBounds[2]-tol <= x[1] && x[1] <= this->OctantBounds[3]+tol &&
00286          this->OctantBounds[4]-tol <= x[2] && x[2] <= this->OctantBounds[5]+tol )
00287       {
00288       return 1;
00289       }
00290     else
00291       {
00292       return 0;
00293       }
00294     }
00295 
00296 private:
00297   vtkCellLocator(const vtkCellLocator&);  // Not implemented.
00298   void operator=(const vtkCellLocator&);  // Not implemented.
00299 };
00300 
00301 #endif
00302 
00303