VTK
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 =========================================================================*/
00045 #ifndef __vtkHyperTreeGrid_h
00046 #define __vtkHyperTreeGrid_h
00047 
00048 #include "vtkCommonDataModelModule.h" // For export macro
00049 #include "vtkDataSet.h"
00050 #include <map> // STL header for dual point coordinates ajustment
00051 
00052 class vtkHyperTreeCursor;
00053 class vtkHyperTree;
00054 
00055 class vtkBitArray;
00056 class vtkCellLinks;
00057 class vtkCollection;
00058 class vtkDataArray;
00059 class vtkDataSetAttributes;
00060 class vtkIdTypeArray;
00061 class vtkLine;
00062 class vtkPixel;
00063 class vtkPoints;
00064 class vtkVoxel;
00065 
00066 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeGrid : public vtkDataSet
00067 {
00068 public:
00069 //BTX
00070   class vtkHyperTreeSimpleCursor;
00071   class vtkHyperTreeIterator;
00072   struct vtkHyperTreeGridSuperCursor;
00073 //ETX
00074 
00075   static vtkInformationIntegerKey* LEVELS();
00076   static vtkInformationIntegerKey* DIMENSION();
00077   static vtkInformationDoubleVectorKey* SIZES();
00078   static vtkHyperTreeGrid* New();
00079 
00080   vtkTypeMacro(vtkHyperTreeGrid, vtkDataSet);
00081   void PrintSelf( ostream&, vtkIndent );
00082 
00084   int GetDataObjectType();
00085 
00088   void CopyStructure( vtkDataSet* );
00089 
00091 
00092   void SetGridSize( unsigned int[3] );
00093   vtkGetVector3Macro(GridSize, unsigned int);
00095 
00097 
00100   vtkSetMacro(TransposedRootIndexing, bool);
00101   vtkGetMacro(TransposedRootIndexing, bool);
00102   void SetIndexingModeToKJI()
00103     { this->SetTransposedRootIndexing( false ); }
00104   void SetIndexingModeToIJK()
00105     { this->SetTransposedRootIndexing( true ); }
00107 
00109 
00111   void SetBranchFactor( unsigned int );
00112   vtkGetMacro(BranchFactor, unsigned int);
00114 
00116 
00117   void SetDimension( unsigned int );
00118   vtkGetMacro(Dimension, unsigned int);
00120 
00122   vtkIdType GetNumberOfCells();
00123 
00125   vtkIdType GetNumberOfPoints();
00126 
00128   vtkIdType GetNumberOfLeaves();
00129 
00131   vtkIdType GetNumberOfLevels( vtkIdType );
00132 
00134   vtkIdType GetNumberOfTrees();
00135 
00137 
00138   void SetXCoordinates( vtkDataArray* );
00139   vtkGetObjectMacro(XCoordinates, vtkDataArray);
00141 
00143 
00144   void SetYCoordinates( vtkDataArray* );
00145   vtkGetObjectMacro(YCoordinates, vtkDataArray);
00147 
00149 
00150   void SetZCoordinates( vtkDataArray* );
00151   vtkGetObjectMacro(ZCoordinates, vtkDataArray);
00153 
00155 
00156   void SetMaterialMask( vtkBitArray* );
00157   vtkGetObjectMacro(MaterialMask, vtkBitArray);
00159 
00161 
00162   virtual void SetMaterialMaskIndex( vtkIdTypeArray* );
00163   vtkGetObjectMacro(MaterialMaskIndex, vtkIdTypeArray);
00165 
00167   virtual void GenerateTrees();
00168 
00171   vtkHyperTreeCursor* NewCursor( vtkIdType );
00172 
00176   void SubdivideLeaf( vtkHyperTreeCursor*, vtkIdType );
00177 
00182   virtual double* GetPoint( vtkIdType );
00183 
00189   virtual void GetPoint( vtkIdType, double[3] );
00190 
00195   virtual vtkCell* GetCell( vtkIdType );
00196 
00203   virtual void GetCell( vtkIdType, vtkGenericCell* );
00204 
00209   virtual int GetCellType( vtkIdType );
00210 
00216   virtual void GetCellPoints( vtkIdType, vtkIdList* );
00217 
00220   virtual void GetCellPoints( vtkIdType, vtkIdType&, vtkIdType*& );
00221 
00227   virtual void GetPointCells( vtkIdType, vtkIdList* );
00228 
00237   virtual void GetCellNeighbors( vtkIdType, vtkIdList*, vtkIdList* );
00238 
00242   virtual vtkIdType FindPoint( double x[3] );
00243 
00245 
00255   virtual vtkIdType FindCell( double x[3], vtkCell *cell, vtkIdType cellId,
00256                               double tol2, int& subId, double pcoords[3],
00257                               double *weights );
00259 
00261 
00266   virtual vtkIdType FindCell( double x[3], vtkCell *cell,
00267                               vtkGenericCell *gencell, vtkIdType cellId,
00268                               double tol2, int& subId, double pcoords[3],
00269                               double *weights );
00271 
00273   void Initialize();
00274 
00276   void InitializeTreeIterator( vtkHyperTreeIterator& );
00277 
00281   virtual int GetMaxCellSize();
00282 
00284 
00285   void ShallowCopy( vtkDataObject* );
00286   void DeepCopy( vtkDataObject* );
00288 
00294   unsigned long GetActualMemorySize();
00295 
00297   void GenerateSuperCursorTraversalTable();
00298 
00299 //BTX
00300 #ifndef __WRAP__
00301 
00302 
00305   void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
00306                               unsigned int,
00307                               unsigned int,
00308                               unsigned int,
00309                               vtkIdType );
00310   void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
00311                               vtkIdType );
00313 
00314 
00316   void InitializeSuperCursorChild( vtkHyperTreeGridSuperCursor* parent,
00317                                    vtkHyperTreeGridSuperCursor* child,
00318                                    unsigned int childIdx );
00319 #endif
00320 //ETX
00322 
00324 
00325   vtkGetMacro(NumberOfChildren, unsigned int);
00327 
00329 
00331   void GetLevelZeroCoordsFromIndex( vtkIdType index,
00332                                     unsigned int &i,
00333                                     unsigned int &j,
00334                                     unsigned int &k );
00336 
00337 protected:
00338   // Constructor with default bounds (0,1, 0,1, 0,1).
00339   vtkHyperTreeGrid();
00340   ~vtkHyperTreeGrid();
00341 
00342   void ComputeBounds();
00343 
00344   void GetCell( vtkIdType, vtkCell* );
00345 
00346   void ComputeDualGrid();
00347   vtkPoints* GetPoints();
00348   vtkIdTypeArray* GetConnectivity();
00349 
00350   unsigned int Dimension;    // 1, 2 or 3.
00351   unsigned int GridSize[3];
00352   unsigned int BranchFactor;
00353   unsigned int NumberOfChildren;
00354   bool TransposedRootIndexing;
00355 
00356   vtkBitArray* MaterialMask;
00357   vtkIdTypeArray* MaterialMaskIndex;
00358 
00359   vtkDataArray* XCoordinates;
00360   vtkDataArray* YCoordinates;
00361   vtkDataArray* ZCoordinates;
00362 
00363   std::map<vtkIdType, vtkHyperTree*> HyperTrees;
00364 
00365   vtkPoints* Points;
00366   vtkIdTypeArray* Connectivity;
00367   std::map<vtkIdType, bool> PointShifted;
00368   std::map<vtkIdType, double> PointShifts[3];
00369   std::map<vtkIdType, double> ReductionFactors;
00370 
00371   void DeleteInternalArrays();
00372   void DeleteTrees();
00373 
00374 //BTX
00375 #ifndef __WRAP__
00376   void TraverseDualRecursively( vtkHyperTreeGridSuperCursor*, unsigned int );
00377 
00378   void TraverseDualMaskedLeaf( vtkHyperTreeGridSuperCursor* );
00379 
00380   void TraverseDualLeaf( vtkHyperTreeGridSuperCursor* );
00381 
00382   void EvaluateDualCorner( vtkHyperTreeSimpleCursor* );
00383 #endif
00384 //ETX
00385 
00386   // Used to advance the super cursor; One Entry per cursor node.
00387   // Private.
00388   struct vtkSuperCursorEntry
00389   {
00390     // For the new node, start with the node in super cursor as parent.
00391     unsigned char Parent;
00392     // Traverse to this child.
00393     unsigned char Child;
00394   };
00395 
00396   // Generalizing for 27 tree. Cannot use 3 bits to encode the child to move to.
00397   // Input: root in supercursor(3x3x3=27), child(3x3x3=27)
00398   // Output: root, child
00399   // It is easier to abstract dimensions when we use a single array.
00400   vtkSuperCursorEntry SuperCursorTraversalTable[27*27];
00401 
00402   // for the GetCell method
00403   vtkLine* Line;
00404   vtkPixel* Pixel;
00405   vtkVoxel* Voxel;
00406 
00407   // I would like to get rid of this.
00408   // Is it a part of the vtkDataSet API?
00409   vtkCellLinks* Links;
00410   void BuildLinks();
00411 
00412 //BTX
00413   vtkIdType RecursiveFindPoint( double x[3],
00414                                 vtkHyperTreeSimpleCursor* cursor,
00415                                 double* origin, double* size);
00416 //ETX
00417 
00418 public:
00419 
00420 //BTX
00421   // A simplified hyper tree cursor, to be used by the hyper tree
00422   // grid supercursor.
00423   class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeSimpleCursor
00424   {
00425   public:
00426     vtkHyperTreeSimpleCursor();
00427     ~vtkHyperTreeSimpleCursor();
00428 
00429     void Clear();
00430     void Initialize( vtkHyperTreeGrid*, vtkIdType, int[3] );
00431     void ToRoot();
00432     void ToChild( int );
00433     bool IsLeaf();
00434     vtkHyperTree* GetTree() { return this->Tree; }
00435     vtkIdType GetLeafIndex() { return this->Index; } // Only valid for leaves.
00436     vtkIdType GetGlobalNodeIndex();
00437     unsigned short GetLevel() { return this->Level; }
00438 
00439   private:
00440     vtkHyperTree* Tree;
00441     vtkIdType Index;
00442     unsigned short Level;
00443     bool Leaf;
00444   };
00445 
00446   class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeIterator
00447   {
00448   public:
00449     vtkHyperTreeIterator() {}
00450 
00452     void Initialize( vtkHyperTreeGrid* );
00453 
00456     vtkHyperTree* GetNextTree( vtkIdType &index );
00457 
00460     vtkHyperTree* GetNextTree();
00461 
00462   protected:
00463     std::map<vtkIdType, vtkHyperTree*>::iterator Iterator;
00464     vtkHyperTreeGrid* Tree;
00465   };
00466 
00467   // Public structure filters use to move around the tree.
00468   // The super cursor keeps neighbor cells so filters can
00469   // easily access neighbor to leaves.
00470   // The super cursor is 'const'.  Methods in vtkHyperTreeGrid
00471   // initialize and compute children for moving toward leaves.
00472   struct vtkHyperTreeGridSuperCursor
00473   {
00474     double Origin[3];
00475     double Size[3];
00476     int NumberOfCursors;
00477     int MiddleCursorId;
00478     vtkHyperTreeSimpleCursor Cursors[3*3*3];
00479 
00480     vtkHyperTreeSimpleCursor* GetCursor( int idx )
00481     {
00482       return this->Cursors + this->MiddleCursorId + idx;
00483     }
00484   };
00485 //ETX
00486 
00487 private:
00488   vtkHyperTreeGrid(const vtkHyperTreeGrid&);  // Not implemented.
00489   void operator=(const vtkHyperTreeGrid&);    // Not implemented.
00490 };
00491 
00492 #endif