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 "vtkAbstractCellLocator.h" 00059 00060 class vtkMatrix4x4; 00061 00062 // Special class defines node for the OBB tree 00063 // 00064 //BTX 00065 // 00066 class VTK_GRAPHICS_EXPORT vtkOBBNode { //;prevent man page generation 00067 public: 00068 vtkOBBNode(); 00069 ~vtkOBBNode(); 00070 00071 double Corner[3]; //center point of this node 00072 double Axes[3][3]; //the axes defining the OBB - ordered from long->short 00073 vtkOBBNode *Parent; //parent node; NULL if root 00074 vtkOBBNode **Kids; //two children of this node; NULL if leaf 00075 vtkIdList *Cells; //list of cells in node 00076 void DebugPrintTree( int level, double *leaf_vol, int *minCells, 00077 int *maxCells ); 00078 }; 00079 //ETX 00080 // 00081 00082 class VTK_GRAPHICS_EXPORT vtkOBBTree : public vtkAbstractCellLocator 00083 { 00084 public: 00085 vtkTypeMacro(vtkOBBTree,vtkAbstractCellLocator); 00086 void PrintSelf(ostream& os, vtkIndent indent); 00087 00090 static vtkOBBTree *New(); 00091 00092 //BTX 00093 /* 00094 if the borland compiler is ever removed, we can use these declarations 00095 instead of reimplementaing the calls in this subclass 00096 using vtkAbstractCellLocator::IntersectWithLine; 00097 using vtkAbstractCellLocator::FindClosestPoint; 00098 using vtkAbstractCellLocator::FindClosestPointWithinRadius; 00099 */ 00100 //ETX 00101 00103 00104 virtual int IntersectWithLine( 00105 double a0[3], double a1[3], double tol, 00106 double& t, double x[3], double pcoords[3], 00107 int &subId) 00108 { 00109 return Superclass:: 00110 IntersectWithLine(a0, a1, tol,t, x, pcoords, subId); 00111 } 00113 00115 00116 virtual int IntersectWithLine( 00117 double a0[3], double a1[3], double tol, 00118 double& t, double x[3], double pcoords[3], 00119 int &subId, vtkIdType &cellId) 00120 { 00121 return Superclass:: 00122 IntersectWithLine(a0, a1, tol,t, x, pcoords, subId, cellId); 00123 } 00125 00127 00135 int IntersectWithLine(const double a0[3], const double a1[3], 00136 vtkPoints *points, vtkIdList *cellIds); 00138 00140 00143 int IntersectWithLine(double a0[3], double a1[3], double tol, 00144 double& t, double x[3], double pcoords[3], 00145 int &subId, vtkIdType &cellId, vtkGenericCell *cell); 00147 00149 00158 virtual void FindClosestPoint( 00159 double x[3], double closestPoint[3], 00160 vtkIdType &cellId, int &subId, double& dist2) 00161 { 00162 Superclass:: 00163 FindClosestPoint(x, closestPoint, cellId, subId, dist2); 00164 } 00166 00168 00169 virtual void FindClosestPoint( 00170 double x[3], double closestPoint[3], 00171 vtkGenericCell *cell, vtkIdType &cellId, 00172 int &subId, double& dist2) 00173 { 00174 Superclass:: 00175 FindClosestPoint(x, closestPoint, cell, cellId, subId, dist2); 00176 } 00178 00180 00181 virtual vtkIdType FindClosestPointWithinRadius( 00182 double x[3], double radius, 00183 double closestPoint[3], vtkIdType &cellId, 00184 int &subId, double& dist2) 00185 { 00186 return Superclass::FindClosestPointWithinRadius 00187 (x, radius, closestPoint, cellId, subId, dist2); 00188 } 00190 00192 00193 virtual vtkIdType FindClosestPointWithinRadius( 00194 double x[3], double radius, 00195 double closestPoint[3], 00196 vtkGenericCell *cell, vtkIdType &cellId, 00197 int &subId, double& dist2) 00198 { 00199 return Superclass::FindClosestPointWithinRadius 00200 (x, radius, closestPoint, cell, cellId, subId, dist2); 00201 } 00203 00205 00206 virtual vtkIdType FindClosestPointWithinRadius( 00207 double x[3], double radius, double closestPoint[3], 00208 vtkGenericCell *cell, vtkIdType &cellId, 00209 int &subId, double& dist2, int &inside) 00210 { 00211 return Superclass::FindClosestPointWithinRadius 00212 (x, radius, closestPoint, cell, cellId, subId, dist2, inside); 00213 } 00215 00217 00220 static void ComputeOBB(vtkPoints *pts, double corner[3], double max[3], 00221 double mid[3], double min[3], double size[3]); 00223 00225 00229 void ComputeOBB(vtkDataSet *input, double corner[3], double max[3], 00230 double mid[3], double min[3], double size[3]); 00232 00237 int InsideOrOutside(const double point[3]); 00238 00239 //BTX 00240 00242 00244 int DisjointOBBNodes( vtkOBBNode *nodeA, vtkOBBNode *nodeB, 00245 vtkMatrix4x4 *XformBtoA ); 00247 00249 int LineIntersectsNode( vtkOBBNode *pA, double b0[3], double b1[3] ); 00250 00252 00253 int TriangleIntersectsNode( vtkOBBNode *pA, 00254 double p0[3], double p1[3], 00255 double p2[3], vtkMatrix4x4 *XformBtoA ); 00257 00259 00261 int IntersectWithOBBTree( vtkOBBTree *OBBTreeB, vtkMatrix4x4 *XformBtoA, 00262 int(*function)( vtkOBBNode *nodeA, 00263 vtkOBBNode *nodeB, 00264 vtkMatrix4x4 *Xform, 00265 void *arg ), 00266 void *data_arg ); 00267 //ETX 00269 00271 00272 void FreeSearchStructure(); 00273 void BuildLocator(); 00275 00284 void GenerateRepresentation(int level, vtkPolyData *pd); 00285 00286 //BTX 00287 protected: 00288 vtkOBBTree(); 00289 ~vtkOBBTree(); 00290 00291 // Compute an OBB from the list of cells given. This used to be 00292 // public but should not have been. A public call has been added 00293 // so that the functionality can be accessed. 00294 void ComputeOBB(vtkIdList *cells, double corner[3], double max[3], 00295 double mid[3], double min[3], double size[3]); 00296 00297 vtkOBBNode *Tree; 00298 void BuildTree(vtkIdList *cells, vtkOBBNode *parent, int level); 00299 vtkPoints *PointsList; 00300 int *InsertedPoints; 00301 int OBBCount; 00302 00303 void DeleteTree(vtkOBBNode *OBBptr); 00304 void GeneratePolygons(vtkOBBNode *OBBptr, int level, int repLevel, 00305 vtkPoints* pts, vtkCellArray *polys); 00306 00307 //ETX 00308 private: 00309 vtkOBBTree(const vtkOBBTree&); // Not implemented. 00310 void operator=(const vtkOBBTree&); // Not implemented. 00311 }; 00312 00313 #endif