VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Filters/General/vtkOBBTree.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkOBBTree.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 =========================================================================*/
00055 #ifndef vtkOBBTree_h
00056 #define vtkOBBTree_h
00057 
00058 #include "vtkFiltersGeneralModule.h" // For export macro
00059 #include "vtkAbstractCellLocator.h"
00060 
00061 class vtkMatrix4x4;
00062 
00063 // Special class defines node for the OBB tree
00064 //
00065 //BTX
00066 //
00067 class VTKFILTERSGENERAL_EXPORT vtkOBBNode { //;prevent man page generation
00068 public:
00069   vtkOBBNode();
00070   ~vtkOBBNode();
00071 
00072   double Corner[3]; //center point of this node
00073   double Axes[3][3]; //the axes defining the OBB - ordered from long->short
00074   vtkOBBNode *Parent; //parent node; NULL if root
00075   vtkOBBNode **Kids; //two children of this node; NULL if leaf
00076   vtkIdList *Cells; //list of cells in node
00077   void DebugPrintTree( int level, double *leaf_vol, int *minCells,
00078                        int *maxCells );
00079 
00080 private:
00081   vtkOBBNode(const vtkOBBNode& other); // no copy constructor
00082   vtkOBBNode& operator=(const vtkOBBNode& rhs); // no copy assignment
00083 };
00084 //ETX
00085 //
00086 
00087 class VTKFILTERSGENERAL_EXPORT vtkOBBTree : public vtkAbstractCellLocator
00088 {
00089 public:
00090   vtkTypeMacro(vtkOBBTree,vtkAbstractCellLocator);
00091   void PrintSelf(ostream& os, vtkIndent indent);
00092 
00095   static vtkOBBTree *New();
00096 
00097 //BTX
00098 /*
00099   if the borland compiler is ever removed, we can use these declarations
00100   instead of reimplementaing the calls in this subclass
00101   using vtkAbstractCellLocator::IntersectWithLine;
00102   using vtkAbstractCellLocator::FindClosestPoint;
00103   using vtkAbstractCellLocator::FindClosestPointWithinRadius;
00104 */
00105 //ETX
00106 
00108 
00109   virtual int IntersectWithLine(
00110     double a0[3], double a1[3], double tol,
00111     double& t, double x[3], double pcoords[3],
00112     int &subId)
00113   {
00114     return Superclass::
00115       IntersectWithLine(a0, a1, tol,t, x, pcoords, subId);
00116   }
00118 
00120 
00121   virtual int IntersectWithLine(
00122     double a0[3], double a1[3], double tol,
00123     double& t, double x[3], double pcoords[3],
00124     int &subId, vtkIdType &cellId)
00125   {
00126     return Superclass::
00127       IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId);
00128   }
00130 
00132 
00140   int IntersectWithLine(const double a0[3], const double a1[3],
00141                         vtkPoints *points, vtkIdList *cellIds);
00143 
00145 
00148   int IntersectWithLine(double a0[3], double a1[3], double tol,
00149                         double& t, double x[3], double pcoords[3],
00150                         int &subId, vtkIdType &cellId, vtkGenericCell *cell);
00152 
00154 
00163   virtual void FindClosestPoint(
00164     double x[3], double closestPoint[3],
00165     vtkIdType &cellId, int &subId, double& dist2)
00166   {
00167     Superclass::
00168       FindClosestPoint(x, closestPoint, cellId, subId, dist2);
00169   }
00171 
00173 
00174   virtual void FindClosestPoint(
00175     double x[3], double closestPoint[3],
00176     vtkGenericCell *cell, vtkIdType &cellId,
00177     int &subId, double& dist2)
00178   {
00179     Superclass::
00180       FindClosestPoint(x, closestPoint, cell, cellId, subId, dist2);
00181   }
00183 
00185 
00186   virtual vtkIdType FindClosestPointWithinRadius(
00187     double x[3], double radius,
00188     double closestPoint[3], vtkIdType &cellId,
00189     int &subId, double& dist2)
00190   {
00191     return Superclass::FindClosestPointWithinRadius
00192       (x, radius, closestPoint, cellId, subId, dist2);
00193   }
00195 
00197 
00198   virtual vtkIdType FindClosestPointWithinRadius(
00199     double x[3], double radius,
00200     double closestPoint[3],
00201     vtkGenericCell *cell, vtkIdType &cellId,
00202     int &subId, double& dist2)
00203   {
00204     return Superclass::FindClosestPointWithinRadius
00205       (x, radius, closestPoint, cell, cellId, subId, dist2);
00206   }
00208 
00210 
00211   virtual vtkIdType FindClosestPointWithinRadius(
00212     double x[3], double radius, double closestPoint[3],
00213     vtkGenericCell *cell, vtkIdType &cellId,
00214     int &subId, double& dist2, int &inside)
00215   {
00216     return Superclass::FindClosestPointWithinRadius
00217       (x, radius, closestPoint, cell, cellId, subId, dist2, inside);
00218   }
00220 
00222 
00225   static void ComputeOBB(vtkPoints *pts, double corner[3], double max[3],
00226                   double mid[3], double min[3], double size[3]);
00228 
00230 
00234   void ComputeOBB(vtkDataSet *input, double corner[3], double max[3],
00235                   double mid[3], double min[3], double size[3]);
00237 
00242   int InsideOrOutside(const double point[3]);
00243 
00244   //BTX
00245 
00247 
00249   int DisjointOBBNodes( vtkOBBNode *nodeA, vtkOBBNode *nodeB,
00250                         vtkMatrix4x4 *XformBtoA );
00252 
00254   int LineIntersectsNode( vtkOBBNode *pA, double b0[3], double b1[3] );
00255 
00257 
00258   int TriangleIntersectsNode( vtkOBBNode *pA,
00259                               double p0[3], double p1[3],
00260                               double p2[3], vtkMatrix4x4 *XformBtoA );
00262 
00264 
00266   int IntersectWithOBBTree( vtkOBBTree *OBBTreeB, vtkMatrix4x4 *XformBtoA,
00267                             int(*function)( vtkOBBNode *nodeA,
00268                                             vtkOBBNode *nodeB,
00269                                             vtkMatrix4x4 *Xform,
00270                                             void *arg ),
00271                             void *data_arg );
00272   //ETX
00274 
00276 
00277   void FreeSearchStructure();
00278   void BuildLocator();
00280 
00289   void GenerateRepresentation(int level, vtkPolyData *pd);
00290 
00291   //BTX
00292 protected:
00293   vtkOBBTree();
00294   ~vtkOBBTree();
00295 
00296   // Compute an OBB from the list of cells given.  This used to be
00297   // public but should not have been.  A public call has been added
00298   // so that the functionality can be accessed.
00299   void ComputeOBB(vtkIdList *cells, double corner[3], double max[3],
00300                        double mid[3], double min[3], double size[3]);
00301 
00302   vtkOBBNode *Tree;
00303   void BuildTree(vtkIdList *cells, vtkOBBNode *parent, int level);
00304   vtkPoints *PointsList;
00305   int *InsertedPoints;
00306   int OBBCount;
00307 
00308   void DeleteTree(vtkOBBNode *OBBptr);
00309   void GeneratePolygons(vtkOBBNode *OBBptr, int level, int repLevel,
00310                         vtkPoints* pts, vtkCellArray *polys);
00311 
00312   //ETX
00313 private:
00314   vtkOBBTree(const vtkOBBTree&);  // Not implemented.
00315   void operator=(const vtkOBBTree&);  // Not implemented.
00316 };
00317 
00318 #endif