VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/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 "vtkCommonDataModelModule.h" // For export macro
00122 #include "vtkDataSet.h"
00123 
00124 class vtkHyperOctreeLightWeightCursor;
00125 class vtkHyperOctreeCursor;
00126 class vtkHyperOctreeInternal;
00127 class vtkHyperOctreePointsGrabber;
00128 
00129 class vtkHyperOctreeIdSet; // Pimpl idiom
00130 class vtkPolygon;
00131 class vtkIdTypeArray;
00132 class vtkPoints;
00133 class vtkPointLocator;
00134 class vtkOrderedTriangulator;
00135 class vtkDataSetAttributes;
00136 
00137 class vtkLine;
00138 class vtkPixel;
00139 class vtkVoxel;
00140 class vtkCellLinks;
00141 
00142 class VTKCOMMONDATAMODEL_EXPORT vtkHyperOctree : public vtkDataSet
00143 {
00144 public:
00145   static vtkInformationIntegerKey* LEVELS();
00146   static vtkInformationIntegerKey* DIMENSION();
00147   static vtkInformationDoubleVectorKey* SIZES();
00148   static vtkHyperOctree *New();
00149 
00150   vtkTypeMacro(vtkHyperOctree,vtkDataSet);
00151   void PrintSelf(ostream& os, vtkIndent indent);
00152 
00154   int GetDataObjectType();
00155 
00158   void CopyStructure(vtkDataSet *ds);
00159 
00160   // Return the node describes by the path from the root.
00161   // Path is a sequence of number between 0 and 7.
00162   // \pre path_exists: path!=0
00163   // \pre node_exists: IsANode(path)
00164 //  vtkOctree *GetNode(vtkPath *path);
00165 
00169   int GetDimension();
00170 
00174   void SetDimension(int dim);
00175 
00176   // Return if the node for the given path exists or not.
00177   // \pre path_exists: path!=0
00178 //  int IsANode(vtkPath *path);
00179 
00180   // Return if the node for the given path is a leaf or not.
00181   // \pre path_exists: path!=0
00182   // \pre node_exists: IsANode(path)
00183 //  int IsALeaf(vtkPath *path);
00184 
00185   // Measurement: topology
00186 
00189   vtkIdType GetNumberOfCells();
00190 
00192   vtkIdType GetNumberOfLeaves();
00193 
00196   vtkIdType GetNumberOfPoints();
00197 
00204   vtkIdType GetMaxNumberOfPoints(int level);
00205 
00216   vtkIdType GetMaxNumberOfPointsOnBoundary(int level);
00217 
00222   vtkIdType GetMaxNumberOfCellsOnBoundary(int level);
00223 
00226   vtkIdType GetNumberOfLevels();
00227 
00228   // Measurement: geometry
00229 
00231 
00232   vtkSetVector3Macro(Size,double);
00234 
00236 
00237   vtkGetVector3Macro(Size,double);
00239 
00241 
00242   vtkSetVector3Macro(Origin,double);
00243   // Return the origin (position of corner (0,0,0) ) of the root.
00244   vtkGetVector3Macro(Origin,double);
00246 
00249   vtkHyperOctreeCursor *NewCellCursor();
00250 
00254   void SubdivideLeaf(vtkHyperOctreeCursor *leaf);
00255 
00260   void CollapseTerminalNode(vtkHyperOctreeCursor *node);
00261 
00264   virtual double *GetPoint(vtkIdType ptId);
00265 
00269   virtual void GetPoint(vtkIdType id, double x[3]);
00270 
00273   virtual vtkCell *GetCell(vtkIdType cellId);
00274 
00279   virtual void GetCell(vtkIdType cellId, vtkGenericCell *cell);
00280 
00281 
00285   virtual int GetCellType(vtkIdType cellId);
00286 
00288 
00291   virtual void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds);
00292   virtual void GetCellPoints(vtkIdType cellId, vtkIdType& npts,
00293                              vtkIdType* &pts);
00295 
00299   virtual void GetPointCells(vtkIdType ptId, vtkIdList *cellIds);
00300 
00301 
00303 
00307   virtual void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00308                                 vtkIdList *cellIds);
00310 
00311   virtual vtkIdType FindPoint(double x[3]);
00312 
00314 
00322   virtual vtkIdType FindCell(double x[3], vtkCell *cell, vtkIdType cellId,
00323                              double tol2, int& subId, double pcoords[3],
00324                              double *weights);
00326 
00328 
00333   virtual vtkIdType FindCell(double x[3], vtkCell *cell,
00334                              vtkGenericCell *gencell, vtkIdType cellId,
00335                              double tol2, int& subId, double pcoords[3],
00336                              double *weights);
00338 
00340   void Initialize();
00341 
00345   virtual int GetMaxCellSize();
00346 
00348 
00349   void ShallowCopy(vtkDataObject *src);
00350   void DeepCopy(vtkDataObject *src);
00352 
00354 
00359   void GetPointsOnFace(vtkHyperOctreeCursor *sibling,
00360                        int face,
00361                        int level,
00362                        vtkHyperOctreePointsGrabber *grabber);
00364 
00366 
00371   void GetPointsOnParentFaces(int faces[3],
00372                               int level,
00373                               vtkHyperOctreeCursor *cursor,
00374                               vtkHyperOctreePointsGrabber *grabber);
00376 
00378 
00389   void GetPointsOnEdge(vtkHyperOctreeCursor *sibling,
00390                        int level,
00391                        int axis,
00392                        int k,
00393                        int j,
00394                        vtkHyperOctreePointsGrabber *grabber);
00396 
00398 
00407   void GetPointsOnParentEdge(vtkHyperOctreeCursor *cursor,
00408                              int level,
00409                              int axis,
00410                              int k,
00411                              int j,
00412                              vtkHyperOctreePointsGrabber *grabber);
00414 
00416 
00421   void GetPointsOnEdge2D(vtkHyperOctreeCursor *sibling,
00422                          int edge,
00423                          int level,
00424                          vtkHyperOctreePointsGrabber *grabber);
00426 
00428 
00433   void GetPointsOnParentEdge2D(vtkHyperOctreeCursor *cursor,
00434                                int edge,
00435                                int level,
00436                                vtkHyperOctreePointsGrabber *grabber);
00438 
00441   vtkDataSetAttributes* GetLeafData();
00442 
00444 
00445   void SetDualGridFlag(int flag);
00446   vtkGetMacro(DualGridFlag,int);
00448 
00454   unsigned long GetActualMemorySize();
00455 
00456   //BTX
00458 
00459   static vtkHyperOctree* GetData(vtkInformation* info);
00460   static vtkHyperOctree* GetData(vtkInformationVector* v, int i=0);
00461   //ETX
00463 
00464 protected:
00465   // Constructor with default bounds (0,1, 0,1, 0,1).
00466   vtkHyperOctree();
00467   ~vtkHyperOctree();
00468 
00469   void ComputeBounds();
00470 
00471   int Dimension; // 1, 2 or 3.
00472 
00473   double Size[3]; // size on each axis
00474   double Origin[3]; // position of corner (0,0,0) of the root.
00475 
00476   vtkHyperOctreeInternal *CellTree;
00477 
00478   vtkHyperOctreeCursor *TmpChild; // to avoid allocation in the loop
00479 
00480   //BTX
00481   friend class vtkHyperOctreeLightWeightCursor;
00482   //ETX
00483 
00484   // Initialize the arrays if necessary, then return it.
00485   void UpdateDualArrays();
00486   vtkPoints* GetLeafCenters();
00487   vtkIdTypeArray* GetCornerLeafIds();
00488   vtkPoints *LeafCenters;
00489   vtkIdTypeArray *CornerLeafIds;
00490 
00491   void UpdateGridArrays();
00492   vtkPoints* GetCornerPoints();
00493   vtkIdTypeArray* GetLeafCornerIds();
00494   vtkPoints* CornerPoints;
00495   vtkIdTypeArray* LeafCornerIds;
00496 
00497   void DeleteInternalArrays();
00498 
00499   void TraverseDualRecursively(vtkHyperOctreeLightWeightCursor* neighborhood,
00500                                unsigned short *xyzIds, int level);
00501   void TraverseGridRecursively(vtkHyperOctreeLightWeightCursor* neighborhood,
00502                                unsigned char* visited,
00503                                double* origin, double* size);
00504   void EvaluateDualCorner(vtkHyperOctreeLightWeightCursor* neighborhood);
00505   vtkIdType EvaluateGridCorner(int level,vtkHyperOctreeLightWeightCursor* neighborhood,
00506                                unsigned char* visited, int* cornerNeighborIds);
00507 
00508   // This is a table for traversing a neighborhood down an octree.
00509   // 8 children x 27 cursors
00510   // First three bits encode the child,  rest encode the cursor id.
00511   // 8xCursorId + childId.
00512   // This will be shorter when we get rid of the 3x3x3 neighborhood.
00513   // I was using unsigned char, but VS60 optimized build had a problem.
00514   int NeighborhoodTraversalTable[216];
00515   void GenerateGridNeighborhoodTraversalTable();
00516   void GenerateDualNeighborhoodTraversalTable();
00517 
00518   // for the GetCell method
00519   vtkLine *Line;
00520   vtkPixel *Pixel;
00521   vtkVoxel *Voxel;
00522 
00523   vtkCellLinks* Links;
00524   void BuildLinks();
00525 
00526   vtkIdType RecursiveFindPoint(double x[3],
00527     vtkHyperOctreeLightWeightCursor* cursor,
00528     double *origin, double *size);
00529 
00530   // This toggles the data set API between the leaf cells and
00531   // the dual grid (leaves are points, corners are cells).
00532   int DualGridFlag;
00533 
00534 private:
00535   vtkHyperOctree(const vtkHyperOctree&);  // Not implemented.
00536   void operator=(const vtkHyperOctree&);    // Not implemented.
00537 };
00538 
00539 
00540 //BTX
00541 
00542 class VTKCOMMONDATAMODEL_EXPORT vtkHyperOctreeLightWeightCursor
00543 {
00544 public:
00545   vtkHyperOctreeLightWeightCursor();
00546   void Initialize(vtkHyperOctree* tree);
00547   void ToRoot();
00548   void ToChild(int child);
00549   unsigned short GetIsLeaf();
00550   int GetLeafIndex() {return this->Index;} // Only valid for leaves.
00551   vtkHyperOctree* GetTree() { return this->Tree; }
00552   unsigned short GetLevel() {return this->Level;}
00553 private:
00554   vtkHyperOctree* Tree;
00555   int Index;
00556   unsigned short IsLeaf;
00557   unsigned short Level;
00558 };
00559 
00560 //ETX
00561 
00562 #endif