VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vtkHyperTreeGrid.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkHyperTreeGrid.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
45 #ifndef __vtkHyperTreeGrid_h
46 #define __vtkHyperTreeGrid_h
47 
48 #include "vtkCommonDataModelModule.h" // For export macro
49 #include "vtkDataSet.h"
50 #include <map> // STL header for dual point coordinates ajustment
51 
52 class vtkHyperTreeCursor;
53 class vtkHyperTree;
54 
55 class vtkBitArray;
56 class vtkCellLinks;
57 class vtkCollection;
58 class vtkDataArray;
59 class vtkDataSetAttributes;
60 class vtkIdTypeArray;
61 class vtkLine;
62 class vtkPixel;
63 class vtkPoints;
64 class vtkVoxel;
65 
66 class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeGrid : public vtkDataSet
67 {
68 public:
69 //BTX
73 //ETX
74 
75  static vtkInformationIntegerKey* LEVELS();
76  static vtkInformationIntegerKey* DIMENSION();
77  static vtkInformationDoubleVectorKey* SIZES();
78  static vtkHyperTreeGrid* New();
79 
80  vtkTypeMacro(vtkHyperTreeGrid, vtkDataSet);
81  void PrintSelf( ostream&, vtkIndent );
82 
84  int GetDataObjectType();
85 
88  void CopyStructure( vtkDataSet* );
89 
91 
92  void SetGridSize( unsigned int[3] );
93  vtkGetVector3Macro(GridSize, unsigned int);
95 
97 
100  vtkSetMacro(TransposedRootIndexing, bool);
101  vtkGetMacro(TransposedRootIndexing, bool);
103  { this->SetTransposedRootIndexing( false ); }
105  { this->SetTransposedRootIndexing( true ); }
107 
109 
111  void SetBranchFactor( unsigned int );
112  vtkGetMacro(BranchFactor, unsigned int);
114 
116 
117  void SetDimension( unsigned int );
118  vtkGetMacro(Dimension, unsigned int);
120 
122  vtkIdType GetNumberOfCells();
123 
125  vtkIdType GetNumberOfPoints();
126 
128  vtkIdType GetNumberOfLeaves();
129 
131  vtkIdType GetNumberOfLevels( vtkIdType );
132 
134  vtkIdType GetNumberOfTrees();
135 
137 
138  void SetXCoordinates( vtkDataArray* );
139  vtkGetObjectMacro(XCoordinates, vtkDataArray);
141 
143 
144  void SetYCoordinates( vtkDataArray* );
145  vtkGetObjectMacro(YCoordinates, vtkDataArray);
147 
149 
150  void SetZCoordinates( vtkDataArray* );
151  vtkGetObjectMacro(ZCoordinates, vtkDataArray);
153 
155 
156  void SetMaterialMask( vtkBitArray* );
157  vtkGetObjectMacro(MaterialMask, vtkBitArray);
159 
161 
162  virtual void SetMaterialMaskIndex( vtkIdTypeArray* );
163  vtkGetObjectMacro(MaterialMaskIndex, vtkIdTypeArray);
165 
167  virtual void GenerateTrees();
168 
171  vtkHyperTreeCursor* NewCursor( vtkIdType );
172 
176  void SubdivideLeaf( vtkHyperTreeCursor*, vtkIdType );
177 
182  virtual double* GetPoint( vtkIdType );
183 
189  virtual void GetPoint( vtkIdType, double[3] );
190 
195  virtual vtkCell* GetCell( vtkIdType );
196 
203  virtual void GetCell( vtkIdType, vtkGenericCell* );
204 
209  virtual int GetCellType( vtkIdType );
210 
216  virtual void GetCellPoints( vtkIdType, vtkIdList* );
217 
220  virtual void GetCellPoints( vtkIdType, vtkIdType&, vtkIdType*& );
221 
227  virtual void GetPointCells( vtkIdType, vtkIdList* );
228 
237  virtual void GetCellNeighbors( vtkIdType, vtkIdList*, vtkIdList* );
238 
242  virtual vtkIdType FindPoint( double x[3] );
243 
245 
255  virtual vtkIdType FindCell( double x[3], vtkCell *cell, vtkIdType cellId,
256  double tol2, int& subId, double pcoords[3],
257  double *weights );
259 
261 
266  virtual vtkIdType FindCell( double x[3], vtkCell *cell,
267  vtkGenericCell *gencell, vtkIdType cellId,
268  double tol2, int& subId, double pcoords[3],
269  double *weights );
271 
273  void Initialize();
274 
276  void InitializeTreeIterator( vtkHyperTreeIterator& );
277 
281  virtual int GetMaxCellSize();
282 
284 
285  void ShallowCopy( vtkDataObject* );
286  void DeepCopy( vtkDataObject* );
288 
294  unsigned long GetActualMemorySize();
295 
297  void GenerateSuperCursorTraversalTable();
298 
299 //BTX
300 #ifndef __WRAP__
301 
302 
305  void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
306  unsigned int,
307  unsigned int,
308  unsigned int,
309  vtkIdType );
310  void InitializeSuperCursor( vtkHyperTreeGridSuperCursor*,
311  vtkIdType );
313 
314 
316  void InitializeSuperCursorChild( vtkHyperTreeGridSuperCursor* parent,
317  vtkHyperTreeGridSuperCursor* child,
318  unsigned int childIdx );
319 #endif
320 //ETX
322 
324 
325  vtkGetMacro(NumberOfChildren, unsigned int);
327 
329 
331  void GetLevelZeroCoordsFromIndex( vtkIdType index,
332  unsigned int &i,
333  unsigned int &j,
334  unsigned int &k );
336 
337 protected:
338  // Constructor with default bounds (0,1, 0,1, 0,1).
340  ~vtkHyperTreeGrid();
341 
342  void ComputeBounds();
343 
344  void GetCell( vtkIdType, vtkCell* );
345 
346  void ComputeDualGrid();
347  vtkPoints* GetPoints();
348  vtkIdTypeArray* GetConnectivity();
349 
350  unsigned int Dimension; // 1, 2 or 3.
351  unsigned int GridSize[3];
352  unsigned int BranchFactor;
353  unsigned int NumberOfChildren;
355 
356  vtkBitArray* MaterialMask;
357  vtkIdTypeArray* MaterialMaskIndex;
358 
359  vtkDataArray* XCoordinates;
360  vtkDataArray* YCoordinates;
361  vtkDataArray* ZCoordinates;
362 
363  std::map<vtkIdType, vtkHyperTree*> HyperTrees;
364 
365  vtkPoints* Points;
366  vtkIdTypeArray* Connectivity;
367  std::map<vtkIdType, bool> PointShifted;
368  std::map<vtkIdType, double> PointShifts[3];
369  std::map<vtkIdType, double> ReductionFactors;
370 
371  void DeleteInternalArrays();
372  void DeleteTrees();
373 
374 //BTX
375 #ifndef __WRAP__
376  void TraverseDualRecursively( vtkHyperTreeGridSuperCursor*, unsigned int );
377 
378  void TraverseDualMaskedLeaf( vtkHyperTreeGridSuperCursor* );
379 
380  void TraverseDualLeaf( vtkHyperTreeGridSuperCursor* );
381 
382  void EvaluateDualCorner( vtkHyperTreeSimpleCursor* );
383 #endif
384 //ETX
385 
386  // Used to advance the super cursor; One Entry per cursor node.
387  // Private.
389  {
390  // For the new node, start with the node in super cursor as parent.
391  unsigned char Parent;
392  // Traverse to this child.
393  unsigned char Child;
394  };
395 
396  // Generalizing for 27 tree. Cannot use 3 bits to encode the child to move to.
397  // Input: root in supercursor(3x3x3=27), child(3x3x3=27)
398  // Output: root, child
399  // It is easier to abstract dimensions when we use a single array.
400  vtkSuperCursorEntry SuperCursorTraversalTable[27*27];
401 
402  // for the GetCell method
403  vtkLine* Line;
405  vtkVoxel* Voxel;
406 
407  // I would like to get rid of this.
408  // Is it a part of the vtkDataSet API?
410  void BuildLinks();
411 
412 //BTX
413  vtkIdType RecursiveFindPoint( double x[3],
414  vtkHyperTreeSimpleCursor* cursor,
415  double* origin, double* size);
416 //ETX
417 
418 public:
419 
420 //BTX
421  // A simplified hyper tree cursor, to be used by the hyper tree
422  // grid supercursor.
423  class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeSimpleCursor
424  {
425  public:
428 
429  void Clear();
430  void Initialize( vtkHyperTreeGrid*, vtkIdType, int[3] );
431  void ToRoot();
432  void ToChild( int );
433  bool IsLeaf();
434  vtkHyperTree* GetTree() { return this->Tree; }
435  vtkIdType GetLeafIndex() { return this->Index; } // Only valid for leaves.
436  vtkIdType GetGlobalNodeIndex();
437  unsigned short GetLevel() { return this->Level; }
438 
439  private:
440  vtkHyperTree* Tree;
441  vtkIdType Index;
442  unsigned short Level;
443  bool Leaf;
444  };
445 
446  class VTKCOMMONDATAMODEL_EXPORT vtkHyperTreeIterator
447  {
448  public:
450 
452  void Initialize( vtkHyperTreeGrid* );
453 
456  vtkHyperTree* GetNextTree( vtkIdType &index );
457 
460  vtkHyperTree* GetNextTree();
461 
462  protected:
463  std::map<vtkIdType, vtkHyperTree*>::iterator Iterator;
465  };
466 
467  // Public structure filters use to move around the tree.
468  // The super cursor keeps neighbor cells so filters can
469  // easily access neighbor to leaves.
470  // The super cursor is 'const'. Methods in vtkHyperTreeGrid
471  // initialize and compute children for moving toward leaves.
473  {
474  double Origin[3];
475  double Size[3];
478  vtkHyperTreeSimpleCursor Cursors[3*3*3];
479 
481  {
482  return this->Cursors + this->MiddleCursorId + idx;
483  }
484  };
485 //ETX
486 
487 private:
488  vtkHyperTreeGrid(const vtkHyperTreeGrid&); // Not implemented.
489  void operator=(const vtkHyperTreeGrid&); // Not implemented.
490 };
491 
492 #endif
std::map< vtkIdType, vtkHyperTree * > HyperTrees
unsigned int NumberOfChildren
A dataset containing a grid of vtkHyperTree instances arranged as a rectilinear grid.
a cell that represents an orthogonal quadrilateral
Definition: vtkPixel.h:39
vtkDataArray * ZCoordinates
unsigned int BranchFactor
provides thread-safe access to cells
Objects that can traverse hypertree nodes.
vtkDataArray * YCoordinates
vtkIdTypeArray * Connectivity
std::map< vtkIdType, bool > PointShifted
vtkIdTypeArray * MaterialMaskIndex
unsigned int Dimension
An object structured as a tree where each node has exactly either 2^n or 3^n children.
Definition: vtkHyperTree.h:133
vtkHyperTreeSimpleCursor * GetCursor(int idx)
std::map< vtkIdType, double > ReductionFactors
vtkCellLinks * Links
vtkBitArray * MaterialMask
general representation of visualization data
Definition: vtkDataObject.h:64
std::map< vtkIdType, vtkHyperTree * >::iterator Iterator
vtkDataArray * XCoordinates