VTK
dox/Filters/FlowPaths/vtkModifiedBSPTree.h
Go to the documentation of this file.
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 "vtkFiltersFlowPathsModule.h" // For export macro
00149 #include "vtkAbstractCellLocator.h"
00150 #include "vtkSmartPointer.h"     // required because it is nice
00151 
00152 //BTX
00153 class Sorted_cell_extents_Lists;
00154 class BSPNode;
00155 class vtkGenericCell;
00156 class vtkIdList;
00157 class vtkIdListCollection;
00158 //ETX
00159 
00160 class VTKFILTERSFLOWPATHS_EXPORT vtkModifiedBSPTree : public vtkAbstractCellLocator {
00161   public:
00163 
00164   vtkTypeMacro(vtkModifiedBSPTree,vtkAbstractCellLocator);
00165   void PrintSelf(ostream& os, vtkIndent indent);
00167 
00169   static vtkModifiedBSPTree *New();
00170 
00171 //BTX
00172   using vtkAbstractCellLocator::IntersectWithLine;
00173   using vtkAbstractCellLocator::FindClosestPoint;
00174   using vtkAbstractCellLocator::FindClosestPointWithinRadius;
00175 //ETX
00176 
00178   void FreeSearchStructure();
00179 
00181   void BuildLocator();
00182 
00183 //BTX
00185   virtual void GenerateRepresentation(int level, vtkPolyData *pd);
00186 
00188   virtual void GenerateRepresentationLeafs(vtkPolyData *pd);
00189 
00191 
00193   virtual int IntersectWithLine(
00194     double p1[3], double p2[3], double tol, double& t, double x[3],
00195     double pcoords[3], int &subId)
00196     { return this->Superclass::IntersectWithLine(p1, p2, tol, t, x, pcoords, subId); }
00198 
00200 
00202   virtual int IntersectWithLine(
00203     double p1[3], double p2[3], double tol, double &t, double x[3],
00204     double pcoords[3], int &subId, vtkIdType &cellId);
00206 
00208 
00211   virtual int IntersectWithLine(
00212     double p1[3], double p2[3], double tol, double &t, double x[3],
00213     double pcoords[3], int &subId, vtkIdType &cellId, vtkGenericCell *cell);
00215 
00217 
00226   virtual int IntersectWithLine(
00227     const double p1[3], const double p2[3],
00228     vtkPoints *points, vtkIdList *cellIds)
00229     { return this->Superclass::IntersectWithLine(p1, p2, points, cellIds); }
00231 
00233 
00239   virtual int IntersectWithLine(
00240     const double p1[3], const double p2[3], const double tol,
00241     vtkPoints *points, vtkIdList *cellIds);
00243 
00245 
00247   virtual vtkIdType FindCell(double x[3])
00248     { return this->Superclass::FindCell(x); }
00250 
00252 
00254   virtual vtkIdType FindCell(double x[3], double tol2, vtkGenericCell *GenCell,
00255     double pcoords[3], double *weights);
00257 
00258   bool InsideCellBounds(double x[3], vtkIdType cell_ID);
00259 
00263   vtkIdListCollection *GetLeafNodeCellInformation();
00264 
00265 //ETX
00266   protected:
00267    vtkModifiedBSPTree();
00268   ~vtkModifiedBSPTree();
00269   //
00270   BSPNode  *mRoot;               // bounding box root node
00271   int       npn;
00272   int       nln;
00273   int       tot_depth;
00274 //BTX
00275   //
00276   // The main subdivision routine
00277   void Subdivide(BSPNode *node, Sorted_cell_extents_Lists *lists, vtkDataSet *dataSet,
00278     vtkIdType nCells, int depth, int maxlevel, vtkIdType maxCells, int &MaxDepth);
00279 
00280   // We provide a function which does the cell/ray test so that
00281   // it can be overriden by subclasses to perform special treatment
00282   // (Example : Particles stored in tree, have no dimension, so we must
00283   // override the cell test to return a value based on some particle size
00284   virtual int IntersectCellInternal(vtkIdType cell_ID, const double p1[3], const double p2[3],
00285     const double tol, double &t, double ipt[3], double pcoords[3], int &subId);
00286 
00287 //ETX
00288   void BuildLocatorIfNeeded();
00289   void ForceBuildLocator();
00290   void BuildLocatorInternal();
00291 private:
00292   vtkModifiedBSPTree(const vtkModifiedBSPTree&);  // Not implemented.
00293   void operator=(const vtkModifiedBSPTree&);      // Not implemented.
00294 };
00295 
00296 //BTX
00297 
00299 // BSP Node
00300 // A BSP Node is a BBox - axis aligned etc etc
00302 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00303 
00304 class BSPNode {
00305   public:
00306     // Constructor
00307     BSPNode(void) {
00308       mChild[0] = mChild[1] = mChild[2] = NULL;
00309       for (int i=0; i<6; i++) sorted_cell_lists[i] = NULL;
00310       for (int i=0; i<3; i++) { bounds[i*2] = VTK_FLOAT_MAX; bounds[i*2+1] = -VTK_FLOAT_MAX; }
00311     }
00312     // Destructor
00313     ~BSPNode(void) {
00314       for (int i=0; i<3; i++) if (mChild[i]) delete mChild[i];
00315       for (int i=0; i<6; i++) if (sorted_cell_lists[i]) delete []sorted_cell_lists[i];
00316     }
00317     // Set min box limits
00318     void setMin(double minx, double miny, double minz) {
00319       bounds[0] = minx; bounds[2] = miny; bounds[4] = minz;
00320     }
00321     // Set max box limits
00322     void setMax(double maxx, double maxy, double maxz) {
00323       bounds[1] = maxx; bounds[3] = maxy; bounds[5] = maxz;
00324     }
00325     //
00326     bool Inside(double point[3]) const;
00327     // BBox
00328     double       bounds[6];
00329   protected:
00330     // The child nodes of this one (if present - NULL otherwise)
00331     BSPNode   *mChild[3];
00332     // The axis we subdivide this voxel along
00333     int        mAxis;
00334     // Just for reference
00335     int        depth;
00336     // the number of cells in this node
00337     int        num_cells;
00338     // 6 lists, sorted after the 6 dominant axes
00339     vtkIdType *sorted_cell_lists[6];
00340     // Order nodes as near/mid far relative to ray
00341     void Classify(const double origin[3], const double dir[3],
00342       double &rDist, BSPNode *&Near, BSPNode *&Mid, BSPNode *&Far) const;
00343     // Test ray against node BBox : clip t values to extremes
00344     bool RayMinMaxT(const double origin[3], const double dir[3],
00345       double &rTmin, double &rTmax) const;
00346     //
00347     friend class vtkModifiedBSPTree;
00348     friend class vtkParticleBoxTree;
00349   public:
00350   static bool VTKFILTERSFLOWPATHS_EXPORT RayMinMaxT(
00351     const double bounds[6], const double origin[3], const double dir[3], double &rTmin, double &rTmax);
00352   static int  VTKFILTERSFLOWPATHS_EXPORT getDominantAxis(const double dir[3]);
00353 };
00354 
00355 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
00356 
00357 //ETX
00358 
00359 #endif