VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkModifiedBSPTree.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 =========================================================================*/ 00015 00016 /*========================================================================= 00017 This code is derived from an earlier work and is distributed 00018 with permission from, and thanks to 00019 00020 ------------------------------------------ 00021 Copyright (C) 1997-2000 John Biddiscombe 00022 Rutherford Appleton Laboratory, 00023 Chilton, Oxon, England 00024 ------------------------------------------ 00025 Copyright (C) 2000-2004 John Biddiscombe 00026 Skipping Mouse Software Ltd, 00027 Blewbury, England 00028 ------------------------------------------ 00029 Copyright (C) 2004-2009 John Biddiscombe 00030 CSCS - Swiss National Supercomputing Centre 00031 Galleria 2 - Via Cantonale 00032 CH-6928 Manno, Switzerland 00033 ------------------------------------ 00034 =========================================================================*/ 00145 #ifndef _vtkModifiedBSPTree_h 00146 #define _vtkModifiedBSPTree_h 00147 00148 #include "vtkAbstractCellLocator.h" 00149 #include "vtkSmartPointer.h" // required because it is nice 00150 00151 //BTX 00152 class Sorted_cell_extents_Lists; 00153 class BSPNode; 00154 class vtkGenericCell; 00155 class vtkIdList; 00156 class vtkIdListCollection; 00157 //ETX 00158 00159 class VTK_GRAPHICS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator { 00160 public: 00162 00163 vtkTypeMacro(vtkModifiedBSPTree,vtkAbstractCellLocator); 00164 void PrintSelf(ostream& os, vtkIndent indent); 00166 00168 static vtkModifiedBSPTree *New(); 00169 00170 //BTX 00171 using vtkAbstractCellLocator::IntersectWithLine; 00172 using vtkAbstractCellLocator::FindClosestPoint; 00173 using vtkAbstractCellLocator::FindClosestPointWithinRadius; 00174 //ETX 00175 00177 void FreeSearchStructure(); 00178 00180 void BuildLocator(); 00181 00182 //BTX 00184 virtual void GenerateRepresentation(int level, vtkPolyData *pd); 00185 00187 virtual void GenerateRepresentationLeafs(vtkPolyData *pd); 00188 00190 00192 virtual int IntersectWithLine( 00193 double p1[3], double p2[3], double tol, double& t, double x[3], 00194 double pcoords[3], int &subId) 00195 { return this->Superclass::IntersectWithLine(p1, p2, tol, t, x, pcoords, subId); } 00197 00199 00201 virtual int IntersectWithLine( 00202 double p1[3], double p2[3], double tol, double &t, double x[3], 00203 double pcoords[3], int &subId, vtkIdType &cellId); 00205 00207 00210 virtual int IntersectWithLine( 00211 double p1[3], double p2[3], double tol, double &t, double x[3], 00212 double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell); 00214 00216 00225 virtual int IntersectWithLine( 00226 const double p1[3], const double p2[3], 00227 vtkPoints *points, vtkIdList *cellIds) 00228 { return this->Superclass::IntersectWithLine(p1, p2, points, cellIds); } 00230 00232 00238 virtual int IntersectWithLine( 00239 const double p1[3], const double p2[3], const double tol, 00240 vtkPoints *points, vtkIdList *cellIds); 00242 00244 00246 virtual vtkIdType FindCell(double x[3]) 00247 { return this->Superclass::FindCell(x); } 00249 00251 00253 virtual vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell, 00254 double pcoords[3], double *weights); 00256 00257 bool InsideCellBounds(double x[3], vtkIdType cell_ID); 00258 00262 vtkIdListCollection *GetLeafNodeCellInformation(); 00263 00264 //ETX 00265 protected: 00266 vtkModifiedBSPTree(); 00267 ~vtkModifiedBSPTree(); 00268 // 00269 BSPNode *mRoot; // bounding box root node 00270 int npn; 00271 int nln; 00272 int tot_depth; 00273 //BTX 00274 // 00275 // The main subdivision routine 00276 void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet, 00277 vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth); 00278 00279 // We provide a function which does the cell/ray test so that 00280 // it can be overriden by subclasses to perform special treatment 00281 // (Example : Particles stored in tree, have no dimension, so we must 00282 // override the cell test to return a value based on some particle size 00283 virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3], 00284 const double tol, double &t, double ipt[3], double pcoords[3], int &subId); 00285 00286 //ETX 00287 void BuildLocatorIfNeeded(); 00288 void ForceBuildLocator(); 00289 void BuildLocatorInternal(); 00290 private: 00291 vtkModifiedBSPTree(const vtkModifiedBSPTree&); // Not implemented. 00292 void operator=(const vtkModifiedBSPTree&); // Not implemented. 00293 }; 00294 00295 //BTX 00296 00298 // BSP Node 00299 // A BSP Node is a BBox - axis aligned etc etc 00301 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00302 00303 class BSPNode { 00304 public: 00305 // Constructor 00306 BSPNode(void) { 00307 mChild[0] = mChild[1] = mChild[2] = NULL; 00308 for (int i=0; i<6; i++) sorted_cell_lists[i] = NULL; 00309 for (int i=0; i<3; i++) { bounds[i*2] = VTK_LARGE_FLOAT; bounds[i*2+1] = -VTK_LARGE_FLOAT; } 00310 } 00311 // Destructor 00312 ~BSPNode(void) { 00313 for (int i=0; i<3; i++) if (mChild[i]) delete mChild[i]; 00314 for (int i=0; i<6; i++) if (sorted_cell_lists[i]) delete []sorted_cell_lists[i]; 00315 } 00316 // Set min box limits 00317 void setMin(double minx, double miny, double minz) { 00318 bounds[0] = minx; bounds[2] = miny; bounds[4] = minz; 00319 } 00320 // Set max box limits 00321 void setMax(double maxx, double maxy, double maxz) { 00322 bounds[1] = maxx; bounds[3] = maxy; bounds[5] = maxz; 00323 } 00324 // 00325 bool Inside(double point[3]) const; 00326 // BBox 00327 double bounds[6]; 00328 protected: 00329 // The child nodes of this one (if present - NULL otherwise) 00330 BSPNode *mChild[3]; 00331 // The axis we subdivide this voxel along 00332 int mAxis; 00333 // Just for reference 00334 int depth; 00335 // the number of cells in this node 00336 int num_cells; 00337 // 6 lists, sorted after the 6 dominant axes 00338 vtkIdType *sorted_cell_lists[6]; 00339 // Order nodes as near/mid far relative to ray 00340 void Classify(const double origin[3], const double dir[3], 00341 double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const; 00342 // Test ray against node BBox : clip t values to extremes 00343 bool RayMinMaxT(const double origin[3], const double dir[3], 00344 double &rTmin, double &rTmax) const; 00345 // 00346 friend class vtkModifiedBSPTree; 00347 friend class vtkParticleBoxTree; 00348 public: 00349 static bool VTK_GRAPHICS_EXPORT RayMinMaxT( 00350 const double bounds[6], const double origin[3], const double dir[3], double &rTmin, double &rTmax); 00351 static int VTK_GRAPHICS_EXPORT getDominantAxis(const double dir[3]); 00352 }; 00353 00354 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 00355 00356 //ETX 00357 00358 #endif