VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkHyperTreeGrid.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkHyperTreeGrid.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 =========================================================================*/
00046 #ifndef vtkHyperTreeGrid_h
00047 #define vtkHyperTreeGrid_h
00048 
00049 #include "vtkCommonDataModelModule.h" // For export macro
00050 #include "vtkDataSet.h"
00051 #include <map> // STL header for dual point coordinates ajustment
00052 
00053 class vtkHyperTreeCursor;
00054 class vtkHyperTree;
00055 
00056 class vtkBitArray;
00057 class vtkCellLinks;
00058 class vtkCollection;
00059 class vtkDataArray;
00060 class vtkDataSetAttributes;
00061 class vtkIdTypeArray;
00062 class vtkLine;
00063 class vtkPixel;
00064 class vtkPoints;
00065 class vtkVoxel;
00066 
00067 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeGrid : public vtkDataSet
00068 {
00069 public:
00070 //BTX
00071   class vtkHyperTreeSimpleCursor;
00072   class vtkHyperTreeIterator;
00073   struct vtkHyperTreeGridSuperCursor;
00074 //ETX
00075 
00076   static vtkInformationIntegerKey* LEVELS();
00077   static vtkInformationIntegerKey* DIMENSION();
00078   static vtkInformationDoubleVectorKey* SIZES();
00079   static vtkHyperTreeGrid* New();
00080 
00081   vtkTypeMacro(vtkHyperTreeGrid, vtkDataSet);
00082   void PrintSelf( ostream&, vtkIndent );
00083 
00085   int GetDataObjectType();
00086 
00089   void CopyStructure( vtkDataSet* );
00090 
00092 
00093   void SetGridSize( unsigned int[3] );
00094   void SetGridSize( unsigned int i, unsigned int j, unsigned int k );
00095   vtkGetVector3Macro(GridSize, unsigned int);
00097 
00099 
00100   void SetGridExtent(int extent[6]);
00101   void SetGridExtent(int iMin, int iMax, int jMin, int jMax,
00102                      int kMin, int kMax);
00104 
00106 
00109   vtkSetMacro(TransposedRootIndexing, bool);
00110   vtkGetMacro(TransposedRootIndexing, bool);
00111   void SetIndexingModeToKJI()
00112     { this->SetTransposedRootIndexing( false ); }
00113   void SetIndexingModeToIJK()
00114     { this->SetTransposedRootIndexing( true ); }
00116 
00118 
00120   void SetBranchFactor( unsigned int );
00121   vtkGetMacro(BranchFactor, unsigned int);
00123 
00125 
00126   void SetDimension( unsigned int );
00127   vtkGetMacro(Dimension, unsigned int);
00129 
00131   vtkIdType GetNumberOfCells();
00132 
00134   vtkIdType GetNumberOfPoints();
00135 
00137   vtkIdType GetNumberOfLeaves();
00138 
00140   vtkIdType GetNumberOfLevels( vtkIdType );
00141 
00143   vtkIdType GetNumberOfTrees();
00144 
00146 
00147   void SetXCoordinates( vtkDataArray* );
00148   vtkGetObjectMacro(XCoordinates, vtkDataArray);
00150 
00152 
00153   void SetYCoordinates( vtkDataArray* );
00154   vtkGetObjectMacro(YCoordinates, vtkDataArray);
00156 
00158 
00159   void SetZCoordinates( vtkDataArray* );
00160   vtkGetObjectMacro(ZCoordinates, vtkDataArray);
00162 
00164 
00165   void SetMaterialMask( vtkBitArray* );
00166   vtkGetObjectMacro(MaterialMask, vtkBitArray);
00168 
00170 
00171   virtual void SetMaterialMaskIndex( vtkIdTypeArray* );
00172   vtkGetObjectMacro(MaterialMaskIndex, vtkIdTypeArray);
00174 
00176   virtual void GenerateTrees();
00177 
00180   vtkHyperTreeCursor* NewCursor( vtkIdType );
00181 
00185   void SubdivideLeaf( vtkHyperTreeCursor*, vtkIdType );
00186 
00191   virtual double* GetPoint( vtkIdType );
00192 
00198   virtual void GetPoint( vtkIdType, double[3] );
00199 
00204   virtual vtkCell* GetCell( vtkIdType );
00205 
00212   virtual void GetCell( vtkIdType, vtkGenericCell* );
00213 
00218   virtual int GetCellType( vtkIdType );
00219 
00225   virtual void GetCellPoints( vtkIdType, vtkIdList* );
00226 
00229   virtual void GetCellPoints( vtkIdType, vtkIdType&, vtkIdType*& );
00230 
00236   virtual void GetPointCells( vtkIdType, vtkIdList* );
00237 
00246   virtual void GetCellNeighbors( vtkIdType, vtkIdList*, vtkIdList* );
00247 
00251   virtual vtkIdType FindPoint( double x[3] );
00252 
00254 
00264   virtual vtkIdType FindCell( double x[3], vtkCell *cell, vtkIdType cellId,
00265                               double tol2, int& subId, double pcoords[3],
00266                               double *weights );
00268 
00270 
00275   virtual vtkIdType FindCell( double x[3], vtkCell *cell,
00276                               vtkGenericCell *gencell, vtkIdType cellId,
00277                               double tol2, int& subId, double pcoords[3],
00278                               double *weights );
00280 
00282   void Initialize();
00283 
00285   void InitializeTreeIterator( vtkHyperTreeIterator& );
00286 
00290   virtual int GetMaxCellSize();
00291 
00293 
00294   void ShallowCopy( vtkDataObject* );
00295   void DeepCopy( vtkDataObject* );
00297 
00299   int GetExtentType() { return VTK_3D_EXTENT; }
00300 
00306   unsigned long GetActualMemorySize();
00307 
00309   void GenerateSuperCursorTraversalTable();
00310 
00311 //BTX
00312 #ifndef __WRAP__
00313 
00314 
00317   void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
00318                               unsigned int,
00319                               unsigned int,
00320                               unsigned int,
00321                               vtkIdType );
00322   void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
00323                               vtkIdType );
00325 
00326 
00328   void InitializeSuperCursorChild( vtkHyperTreeGridSuperCursor* parent,
00329                                    vtkHyperTreeGridSuperCursor* child,
00330                                    unsigned int childIdx );
00331 #endif
00332 //ETX
00334 
00336 
00337   vtkGetMacro(NumberOfChildren, unsigned int);
00339 
00341 
00343   void GetLevelZeroCoordsFromIndex( vtkIdType index,
00344                                     unsigned int &i,
00345                                     unsigned int &j,
00346                                     unsigned int &k );
00348 
00349 protected:
00350   // Constructor with default bounds (0,1, 0,1, 0,1).
00351   vtkHyperTreeGrid();
00352   ~vtkHyperTreeGrid();
00353 
00354   void ComputeBounds();
00355 
00356   void GetCell( vtkIdType, vtkCell* );
00357 
00358   void ComputeDualGrid();
00359   vtkPoints* GetPoints();
00360   vtkIdTypeArray* GetConnectivity();
00361 
00362   unsigned int Dimension;    // 1, 2 or 3.
00363   unsigned int GridSize[3];
00364   int Extent[6];
00365   unsigned int BranchFactor;
00366   unsigned int NumberOfChildren;
00367   bool TransposedRootIndexing;
00368 
00369   vtkBitArray* MaterialMask;
00370   vtkIdTypeArray* MaterialMaskIndex;
00371 
00372   vtkDataArray* XCoordinates;
00373   vtkDataArray* YCoordinates;
00374   vtkDataArray* ZCoordinates;
00375 
00376   std::map<vtkIdType, vtkHyperTree*> HyperTrees;
00377 
00378   vtkPoints* Points;
00379   vtkIdTypeArray* Connectivity;
00380   std::map<vtkIdType, bool> PointShifted;
00381   std::map<vtkIdType, double> PointShifts[3];
00382   std::map<vtkIdType, double> ReductionFactors;
00383 
00384   void DeleteInternalArrays();
00385   void DeleteTrees();
00386 
00387 //BTX
00388 #if !defined(__WRAP__) && !defined(__WRAP_GCCXML__)
00389   void TraverseDualRecursively( vtkHyperTreeGridSuperCursor*, unsigned int );
00390 
00391   void TraverseDualMaskedLeaf( vtkHyperTreeGridSuperCursor* );
00392 
00393   void TraverseDualLeaf( vtkHyperTreeGridSuperCursor* );
00394 
00395   void EvaluateDualCorner( vtkHyperTreeSimpleCursor* );
00396 #endif
00397 //ETX
00398 
00399   // Used to advance the super cursor; One Entry per cursor node.
00400   // Private.
00401   struct vtkSuperCursorEntry
00402   {
00403     // For the new node, start with the node in super cursor as parent.
00404     unsigned char Parent;
00405     // Traverse to this child.
00406     unsigned char Child;
00407   };
00408 
00409   // Generalizing for 27 tree. Cannot use 3 bits to encode the child to move to.
00410   // Input: root in supercursor(3x3x3=27), child(3x3x3=27)
00411   // Output: root, child
00412   // It is easier to abstract dimensions when we use a single array.
00413   vtkSuperCursorEntry SuperCursorTraversalTable[27*27];
00414 
00415   // for the GetCell method
00416   vtkLine* Line;
00417   vtkPixel* Pixel;
00418   vtkVoxel* Voxel;
00419 
00420   // I would like to get rid of this.
00421   // Is it a part of the vtkDataSet API?
00422   vtkCellLinks* Links;
00423   void BuildLinks();
00424 
00425 //BTX
00426   vtkIdType RecursiveFindPoint( double x[3],
00427                                 vtkHyperTreeSimpleCursor* cursor,
00428                                 double* origin, double* size);
00429 //ETX
00430 
00431 public:
00432 
00433 //BTX
00434   // A simplified hyper tree cursor, to be used by the hyper tree
00435   // grid supercursor.
00436   class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeSimpleCursor
00437   {
00438   public:
00439     vtkHyperTreeSimpleCursor();
00440 
00441     void Clear();
00442     void Initialize( vtkHyperTreeGrid*, vtkIdType, int[3] );
00443     void ToRoot();
00444     void ToChild( int );
00445     bool IsLeaf();
00446     vtkHyperTree* GetTree() { return this->Tree; }
00447     vtkIdType GetLeafIndex() { return this->Index; } // Only valid for leaves.
00448     vtkIdType GetGlobalNodeIndex();
00449     unsigned short GetLevel() { return this->Level; }
00450 
00451   private:
00452     vtkHyperTree* Tree;
00453     vtkIdType Index;
00454     unsigned short Level;
00455     bool Leaf;
00456   };
00457 
00458   class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeIterator
00459   {
00460   public:
00461     vtkHyperTreeIterator() {}
00462 
00464     void Initialize( vtkHyperTreeGrid* );
00465 
00468     vtkHyperTree* GetNextTree( vtkIdType &index );
00469 
00472     vtkHyperTree* GetNextTree();
00473 
00474   protected:
00475     std::map<vtkIdType, vtkHyperTree*>::iterator Iterator;
00476     vtkHyperTreeGrid* Tree;
00477   };
00478 
00479   // Public structure filters use to move around the tree.
00480   // The super cursor keeps neighbor cells so filters can
00481   // easily access neighbor to leaves.
00482   // The super cursor is 'const'.  Methods in vtkHyperTreeGrid
00483   // initialize and compute children for moving toward leaves.
00484   struct vtkHyperTreeGridSuperCursor
00485   {
00486     double Origin[3];
00487     double Size[3];
00488     int NumberOfCursors;
00489     int MiddleCursorId;
00490     vtkHyperTreeSimpleCursor Cursors[3*3*3];
00491 
00492     vtkHyperTreeSimpleCursor* GetCursor( int idx )
00493     {
00494       return this->Cursors + this->MiddleCursorId + idx;
00495     }
00496   };
00497 //ETX
00498 
00499 private:
00500   vtkHyperTreeGrid(const vtkHyperTreeGrid&);  // Not implemented.
00501   void operator=(const vtkHyperTreeGrid&);    // Not implemented.
00502 };
00503 
00504 #endif