VTK
dox/Filtering/vtkHyperOctree.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkHyperOctree.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 =========================================================================*/
00118 #ifndef __vtkHyperOctree_h
00119 #define __vtkHyperOctree_h
00120 
00121 #include "vtkDataSet.h"
00122 
00123 class vtkHyperOctreeLightWeightCursor;
00124 class vtkHyperOctreeCursor;
00125 class vtkHyperOctreeInternal;
00126 class vtkHyperOctreePointsGrabber;
00127 
00128 class vtkHyperOctreeIdSet; // Pimpl idiom
00129 class vtkPolygon;
00130 class vtkIdTypeArray;
00131 class vtkPoints;
00132 class vtkPointLocator;
00133 class vtkOrderedTriangulator;
00134 class vtkDataSetAttributes;
00135 
00136 class vtkLine;
00137 class vtkPixel;
00138 class vtkVoxel;
00139 class vtkCellLinks;
00140 
00141 class VTK_FILTERING_EXPORT vtkHyperOctree : public vtkDataSet
00142 {
00143 public:
00144   static vtkInformationIntegerKey* LEVELS();
00145   static vtkInformationIntegerKey* DIMENSION();
00146   static vtkInformationDoubleVectorKey* SIZES();
00147   static vtkHyperOctree *New();
00148   
00149   vtkTypeMacro(vtkHyperOctree,vtkDataSet);
00150   void PrintSelf(ostream& os, vtkIndent indent);
00151   
00153   int GetDataObjectType();
00154   
00157   void CopyStructure(vtkDataSet *ds);
00158   
00159   // Return the node describes by the path from the root.
00160   // Path is a sequence of number between 0 and 7.
00161   // \pre path_exists: path!=0
00162   // \pre node_exists: IsANode(path)
00163 //  vtkOctree *GetNode(vtkPath *path);
00164   
00168   int GetDimension();
00169   
00173   void SetDimension(int dim);
00174   
00175   // Return if the node for the given path exists or not.
00176   // \pre path_exists: path!=0
00177 //  int IsANode(vtkPath *path);
00178   
00179   // Return if the node for the given path is a leaf or not.
00180   // \pre path_exists: path!=0
00181   // \pre node_exists: IsANode(path)
00182 //  int IsALeaf(vtkPath *path);
00183   
00184   // Measurement: topology
00185   
00188   vtkIdType GetNumberOfCells();
00189   
00191   vtkIdType GetNumberOfLeaves();
00192   
00195   vtkIdType GetNumberOfPoints();
00196   
00203   vtkIdType GetMaxNumberOfPoints(int level);
00204   
00215   vtkIdType GetMaxNumberOfPointsOnBoundary(int level);
00216  
00221   vtkIdType GetMaxNumberOfCellsOnBoundary(int level);
00222   
00225   vtkIdType GetNumberOfLevels();
00226 
00227   // Measurement: geometry
00228   
00230 
00231   vtkSetVector3Macro(Size,double);
00233   
00235 
00236   vtkGetVector3Macro(Size,double);
00238   
00240 
00241   vtkSetVector3Macro(Origin,double);
00242   // Return the origin (position of corner (0,0,0) ) of the root.
00243   vtkGetVector3Macro(Origin,double);
00245   
00248   vtkHyperOctreeCursor *NewCellCursor();
00249     
00253   void SubdivideLeaf(vtkHyperOctreeCursor *leaf);
00254   
00259   void CollapseTerminalNode(vtkHyperOctreeCursor *node);
00260   
00263   virtual double *GetPoint(vtkIdType ptId);
00264 
00268   virtual void GetPoint(vtkIdType id, double x[3]);
00269   
00272   virtual vtkCell *GetCell(vtkIdType cellId);
00273 
00278   virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00279   
00280    
00284   virtual int GetCellType(vtkIdType cellId);
00285 
00287 
00290   virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00291   virtual void GetCellPoints(vtkIdType cellId, vtkIdType& npts,
00292                              vtkIdType* &pts);
00294 
00298   virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00299 
00300   
00302 
00306   virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, 
00307                                 vtkIdList *cellIds);
00309 
00310   virtual vtkIdType FindPoint(double x[3]);
00311 
00313 
00321   virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId,
00322                              double tol2, int& subId, double pcoords[3],
00323                              double *weights);
00325 
00327 
00332   virtual vtkIdType FindCell(double x[3], vtkCell *cell,
00333                              vtkGenericCell *gencell, vtkIdType cellId,
00334                              double tol2, int& subId, double pcoords[3],
00335                              double *weights);
00337   
00339   void Initialize();
00340   
00344   virtual int GetMaxCellSize();
00345   
00347 
00348   void ShallowCopy(vtkDataObject *src);  
00349   void DeepCopy(vtkDataObject *src);
00351   
00353 
00358   void GetPointsOnFace(vtkHyperOctreeCursor *sibling,
00359                        int face,
00360                        int level,
00361                        vtkHyperOctreePointsGrabber *grabber);
00363  
00365 
00370   void GetPointsOnParentFaces(int faces[3],
00371                               int level,
00372                               vtkHyperOctreeCursor *cursor,
00373                               vtkHyperOctreePointsGrabber *grabber);
00375   
00377 
00388   void GetPointsOnEdge(vtkHyperOctreeCursor *sibling,
00389                        int level,
00390                        int axis,
00391                        int k,
00392                        int j,
00393                        vtkHyperOctreePointsGrabber *grabber);
00395   
00397 
00406   void GetPointsOnParentEdge(vtkHyperOctreeCursor *cursor,
00407                              int level,
00408                              int axis,
00409                              int k,
00410                              int j,
00411                              vtkHyperOctreePointsGrabber *grabber);
00413   
00415 
00420   void GetPointsOnEdge2D(vtkHyperOctreeCursor *sibling,
00421                          int edge,
00422                          int level,
00423                          vtkHyperOctreePointsGrabber *grabber);
00425   
00427 
00432   void GetPointsOnParentEdge2D(vtkHyperOctreeCursor *cursor,
00433                                int edge,
00434                                int level,
00435                                vtkHyperOctreePointsGrabber *grabber);
00437   
00440   vtkDataSetAttributes* GetLeafData();
00441   
00443 
00444   void SetDualGridFlag(int flag);
00445   vtkGetMacro(DualGridFlag,int);
00447 
00453   unsigned long GetActualMemorySize();
00454 
00455   //BTX
00457 
00458   static vtkHyperOctree* GetData(vtkInformation* info);
00459   static vtkHyperOctree* GetData(vtkInformationVector* v, int i=0);
00460   //ETX
00462 
00463 protected:
00464   // Constructor with default bounds (0,1, 0,1, 0,1).
00465   vtkHyperOctree();
00466   ~vtkHyperOctree();
00467 
00468   void ComputeBounds();
00469   
00470   int Dimension; // 1, 2 or 3.
00471   
00472   double Size[3]; // size on each axis
00473   double Origin[3]; // position of corner (0,0,0) of the root.
00474   
00475   vtkHyperOctreeInternal *CellTree;
00476 
00477   vtkHyperOctreeCursor *TmpChild; // to avoid allocation in the loop
00478 
00479   //BTX
00480   friend class vtkHyperOctreeLightWeightCursor;
00481   //ETX
00482   
00483   // Initialize the arrays if necessary, then return it.
00484   void UpdateDualArrays();
00485   vtkPoints* GetLeafCenters();
00486   vtkIdTypeArray* GetCornerLeafIds();
00487   vtkPoints *LeafCenters;
00488   vtkIdTypeArray *CornerLeafIds;
00489   
00490   void UpdateGridArrays();
00491   vtkPoints* GetCornerPoints();
00492   vtkIdTypeArray* GetLeafCornerIds();
00493   vtkPoints* CornerPoints;
00494   vtkIdTypeArray* LeafCornerIds;
00495   
00496   void DeleteInternalArrays();
00497 
00498   void TraverseDualRecursively(vtkHyperOctreeLightWeightCursor* neighborhood, 
00499                                unsigned short *xyzIds, int level);
00500   void TraverseGridRecursively(vtkHyperOctreeLightWeightCursor* neighborhood, 
00501                                unsigned char* visited,
00502                                double* origin, double* size);
00503   void EvaluateDualCorner(vtkHyperOctreeLightWeightCursor* neighborhood);
00504   vtkIdType EvaluateGridCorner(int level,vtkHyperOctreeLightWeightCursor* neighborhood,
00505                                unsigned char* visited, int* cornerNeighborIds);
00506 
00507   // This is a table for traversing a neighborhood down an octree.
00508   // 8 children x 27 cursors
00509   // First three bits encode the child,  rest encode the cursor id.
00510   // 8xCursorId + childId.
00511   // This will be shorter when we get rid of the 3x3x3 neighborhood.
00512   // I was using unsigned char, but VS60 optimized build had a problem.
00513   int NeighborhoodTraversalTable[216];
00514   void GenerateGridNeighborhoodTraversalTable();  
00515   void GenerateDualNeighborhoodTraversalTable();  
00516 
00517   // for the GetCell method
00518   vtkLine *Line;
00519   vtkPixel *Pixel;
00520   vtkVoxel *Voxel;
00521 
00522   vtkCellLinks* Links;  
00523   void BuildLinks();
00524 
00525   vtkIdType RecursiveFindPoint(double x[3], 
00526     vtkHyperOctreeLightWeightCursor* cursor, 
00527     double *origin, double *size);
00528 
00529   // This toggles the data set API between the leaf cells and
00530   // the dual grid (leaves are points, corners are cells). 
00531   int DualGridFlag;
00532 
00533 private:
00534   vtkHyperOctree(const vtkHyperOctree&);  // Not implemented.
00535   void operator=(const vtkHyperOctree&);    // Not implemented.
00536 };
00537 
00538 
00539 //BTX
00540 
00541 class VTK_FILTERING_EXPORT vtkHyperOctreeLightWeightCursor
00542 {
00543 public:  
00544   vtkHyperOctreeLightWeightCursor();
00545   ~vtkHyperOctreeLightWeightCursor();
00546 
00547   void Initialize(vtkHyperOctree* tree);
00548   void ToRoot();
00549   void ToChild(int child);
00550   unsigned short GetIsLeaf();
00551   int GetLeafIndex() {return this->Index;} // Only valid for leaves.
00552   vtkHyperOctree* GetTree() { return this->Tree; }
00553   unsigned short GetLevel() {return this->Level;}
00554 private:
00555   vtkHyperOctree* Tree;
00556   int Index;
00557   unsigned short IsLeaf;
00558   unsigned short Level;
00559 };
00560 
00561 //ETX
00562 
00563 #endif