VTK
|
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 //ETX 00081 // 00082 00083 class VTKFILTERSGENERAL_EXPORT vtkOBBTree : public vtkAbstractCellLocator 00084 { 00085 public: 00086 vtkTypeMacro(vtkOBBTree,vtkAbstractCellLocator); 00087 void PrintSelf(ostream& os, vtkIndent indent); 00088 00091 static vtkOBBTree *New(); 00092 00093 //BTX 00094 /* 00095 if the borland compiler is ever removed, we can use these declarations 00096 instead of reimplementaing the calls in this subclass 00097 using vtkAbstractCellLocator::IntersectWithLine; 00098 using vtkAbstractCellLocator::FindClosestPoint; 00099 using vtkAbstractCellLocator::FindClosestPointWithinRadius; 00100 */ 00101 //ETX 00102 00104 00105 virtual int IntersectWithLine( 00106 double a0[3], double a1[3], double tol, 00107 double& t, double x[3], double pcoords[3], 00108 int &subId) 00109 { 00110 return Superclass:: 00111 IntersectWithLine(a0, a1, tol,t, x, pcoords, subId); 00112 } 00114 00116 00117 virtual int IntersectWithLine( 00118 double a0[3], double a1[3], double tol, 00119 double& t, double x[3], double pcoords[3], 00120 int &subId, vtkIdType &cellId) 00121 { 00122 return Superclass:: 00123 IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId); 00124 } 00126 00128 00136 int IntersectWithLine(const double a0[3], const double a1[3], 00137 vtkPoints *points, vtkIdList *cellIds); 00139 00141 00144 int IntersectWithLine(double a0[3], double a1[3], double tol, 00145 double& t, double x[3], double pcoords[3], 00146 int &subId, vtkIdType &cellId, vtkGenericCell *cell); 00148 00150 00159 virtual void FindClosestPoint( 00160 double x[3], double closestPoint[3], 00161 vtkIdType &cellId, int &subId, double& dist2) 00162 { 00163 Superclass:: 00164 FindClosestPoint(x, closestPoint, cellId, subId, dist2); 00165 } 00167 00169 00170 virtual void FindClosestPoint( 00171 double x[3], double closestPoint[3], 00172 vtkGenericCell *cell, vtkIdType &cellId, 00173 int &subId, double& dist2) 00174 { 00175 Superclass:: 00176 FindClosestPoint(x, closestPoint, cell, cellId, subId, dist2); 00177 } 00179 00181 00182 virtual vtkIdType FindClosestPointWithinRadius( 00183 double x[3], double radius, 00184 double closestPoint[3], vtkIdType &cellId, 00185 int &subId, double& dist2) 00186 { 00187 return Superclass::FindClosestPointWithinRadius 00188 (x, radius, closestPoint, cellId, subId, dist2); 00189 } 00191 00193 00194 virtual vtkIdType FindClosestPointWithinRadius( 00195 double x[3], double radius, 00196 double closestPoint[3], 00197 vtkGenericCell *cell, vtkIdType &cellId, 00198 int &subId, double& dist2) 00199 { 00200 return Superclass::FindClosestPointWithinRadius 00201 (x, radius, closestPoint, cell, cellId, subId, dist2); 00202 } 00204 00206 00207 virtual vtkIdType FindClosestPointWithinRadius( 00208 double x[3], double radius, double closestPoint[3], 00209 vtkGenericCell *cell, vtkIdType &cellId, 00210 int &subId, double& dist2, int &inside) 00211 { 00212 return Superclass::FindClosestPointWithinRadius 00213 (x, radius, closestPoint, cell, cellId, subId, dist2, inside); 00214 } 00216 00218 00221 static void ComputeOBB(vtkPoints *pts, double corner[3], double max[3], 00222 double mid[3], double min[3], double size[3]); 00224 00226 00230 void ComputeOBB(vtkDataSet *input, double corner[3], double max[3], 00231 double mid[3], double min[3], double size[3]); 00233 00238 int InsideOrOutside(const double point[3]); 00239 00240 //BTX 00241 00243 00245 int DisjointOBBNodes( vtkOBBNode *nodeA, vtkOBBNode *nodeB, 00246 vtkMatrix4x4 *XformBtoA ); 00248 00250 int LineIntersectsNode( vtkOBBNode *pA, double b0[3], double b1[3] ); 00251 00253 00254 int TriangleIntersectsNode( vtkOBBNode *pA, 00255 double p0[3], double p1[3], 00256 double p2[3], vtkMatrix4x4 *XformBtoA ); 00258 00260 00262 int IntersectWithOBBTree( vtkOBBTree *OBBTreeB, vtkMatrix4x4 *XformBtoA, 00263 int(*function)( vtkOBBNode *nodeA, 00264 vtkOBBNode *nodeB, 00265 vtkMatrix4x4 *Xform, 00266 void *arg ), 00267 void *data_arg ); 00268 //ETX 00270 00272 00273 void FreeSearchStructure(); 00274 void BuildLocator(); 00276 00285 void GenerateRepresentation(int level, vtkPolyData *pd); 00286 00287 //BTX 00288 protected: 00289 vtkOBBTree(); 00290 ~vtkOBBTree(); 00291 00292 // Compute an OBB from the list of cells given. This used to be 00293 // public but should not have been. A public call has been added 00294 // so that the functionality can be accessed. 00295 void ComputeOBB(vtkIdList *cells, double corner[3], double max[3], 00296 double mid[3], double min[3], double size[3]); 00297 00298 vtkOBBNode *Tree; 00299 void BuildTree(vtkIdList *cells, vtkOBBNode *parent, int level); 00300 vtkPoints *PointsList; 00301 int *InsertedPoints; 00302 int OBBCount; 00303 00304 void DeleteTree(vtkOBBNode *OBBptr); 00305 void GeneratePolygons(vtkOBBNode *OBBptr, int level, int repLevel, 00306 vtkPoints* pts, vtkCellArray *polys); 00307 00308 //ETX 00309 private: 00310 vtkOBBTree(const vtkOBBTree&); // Not implemented. 00311 void operator=(const vtkOBBTree&); // Not implemented. 00312 }; 00313 00314 #endif