vtkHierarchicalBoxDataSet.h 10.8 KB
Newer Older
Berk Geveci's avatar
Berk Geveci committed
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkHierarchicalBoxDataSet.h

Brad King's avatar
Brad King committed
6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
Berk Geveci's avatar
Berk Geveci committed
7
8
9
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

Brad King's avatar
Brad King committed
10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Berk Geveci's avatar
Berk Geveci committed
12
13
14
15
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
// .NAME vtkHierarchicalBoxDataSet - hierarchical dataset of vtkUniformGrids
Burlen Loring's avatar
   
Burlen Loring committed
16
//
Berk Geveci's avatar
Berk Geveci committed
17
// .SECTION Description
Berk Geveci's avatar
Berk Geveci committed
18
// vtkHierarchicalBoxDataSet is a concrete implementation of
19
// vtkCompositeDataSet. The dataset type is restricted to
Berk Geveci's avatar
Berk Geveci committed
20
21
// vtkUniformGrid. Each dataset has an associated vtkAMRBox that represents
// it's region (similar to extent) in space.
Burlen Loring's avatar
   
Burlen Loring committed
22
//
23
24
25
26
27
28
29
30
31
32
33
34
// .SECTION Warning
// To compute the cellId of a cell within a vtkUniformGrid with AMRBox=box, 
// you should not use vtkUniformGrid::ComputeCellId( {x,y,z} ) but instead
// use the following pseudo code:
// for (int i=0; i<3; i++)
//   {
//   cellDims[i] = box.HiCorner[i] - box.LoCorner[i] + 1;
//   }
// vtkIdType cellId =
//   (z-box.LoCorner[2])*cellDims[0]*cellDims[1] +
//   (y-box.LoCorner[1])*cellDims[0] +
//   (x-box.LoCorner[0]);
Burlen Loring's avatar
   
Burlen Loring committed
35
36
37
//
// NOTE vtkAMRBox is used to compute cell visibility, therefor it 
// should be dimensioned according to the visible region.
38

Berk Geveci's avatar
Berk Geveci committed
39
40
41
42

#ifndef __vtkHierarchicalBoxDataSet_h
#define __vtkHierarchicalBoxDataSet_h

43
#include "vtkCompositeDataSet.h"
George Zagaris's avatar
George Zagaris committed
44
#include <vtkstd/vector> // For STL vector
Berk Geveci's avatar
Berk Geveci committed
45

46
class vtkAMRBox;
47
class vtkInformationIdTypeKey;
48
49
class vtkInformationIntegerKey;
class vtkInformationIntegerVectorKey;
Berk Geveci's avatar
Berk Geveci committed
50
51
class vtkUniformGrid;

George Zagaris's avatar
George Zagaris committed
52
53
typedef vtkstd::vector<vtkAMRBox> vtkAMRBoxList;

54
class VTK_FILTERING_EXPORT vtkHierarchicalBoxDataSet: public vtkCompositeDataSet
Berk Geveci's avatar
Berk Geveci committed
55
56
57
{
public:
  static vtkHierarchicalBoxDataSet *New();
58
  vtkTypeMacro(vtkHierarchicalBoxDataSet,vtkCompositeDataSet);
Berk Geveci's avatar
Berk Geveci committed
59
60
  void PrintSelf(ostream& os, vtkIndent indent);

61
62
63
64
65
66
  // Descrition:
  // Set & Get the AMR dataset origin
  // The origin is essentially the minimum of all the grids.
  void SetOrigin( const double origin[3] );
  void GetOrigin( double origin[3] );

67
68
69
70
  // Description:
  // Return a new iterator (the iterator has to be deleted by user).
  virtual vtkCompositeDataIterator* NewIterator();

Berk Geveci's avatar
Berk Geveci committed
71
  // Description:
Mathieu Malaterre's avatar
Mathieu Malaterre committed
72
  // Return class name of data type (see vtkType.h for definitions).
Berk Geveci's avatar
Berk Geveci committed
73
74
  virtual int GetDataObjectType() {return VTK_HIERARCHICAL_BOX_DATA_SET;}

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  // Description:
  // Set the number of refinement levels. This call might cause
  // allocation if the new number of levels is larger than the
  // current one.
  void SetNumberOfLevels(unsigned int numLevels);

  // Description:
  // Returns the number of levels.
  unsigned int GetNumberOfLevels();

  // Description:
  // Set the number of data set at a given level.
  void SetNumberOfDataSets(unsigned int level, unsigned int numdatasets);

  // Description:
  // Returns the number of data sets available at any level.
  unsigned int GetNumberOfDataSets(unsigned int level);

  // Description:
  // Sets the data set at the location pointed by the iterator.
  // The iterator does not need to be iterating over this dataset itself. It can
  // be any composite datasite with similar structure (achieve by using
  // CopyStructure).
  // Un-hiding superclass overload.
  virtual void SetDataSet(vtkCompositeDataIterator* iter, vtkDataObject* dataObj)
    { this->Superclass::SetDataSet(iter, dataObj); }

102
103
104
105
106
  // Description:
  // This method returns the root AMR box for the entire root level.
  // The root AMR box covers the entire domain.
  void GetRootAMRBox( vtkAMRBox &root );

107
108
109
110
111
  // Description:
  // This method returns the global AMR box, covering the entire
  // domain, with the prescribed spacing.
  void GetGlobalAMRBoxWithSpacing( vtkAMRBox &box, double h[3] );

112
113
114
115
116
  // Description:
  // Set the dataset pointer for a given node. This will resize the number of
  // levels and the number of datasets in the level to fit level, id requested. 
  void SetDataSet(unsigned int level, unsigned int id, 
                  int LoCorner[3], int HiCorner[3], vtkUniformGrid* dataSet);
117
118
119
120
121
122

  // Description:
  // Set the dataset pointer for a given node without any metadata. This will
  // resize the number of levels and the number of datasets accordingly.
  void SetDataSet(unsigned int level, unsigned int id, vtkUniformGrid* dataSet);

George Zagaris's avatar
George Zagaris committed
123
124
125
126
127
  // Description:
  // Appends the dataset to the given level. This will resize the
  // number of levels and the number of datasets accordingly.
  void AppendDataSet(unsigned int level, vtkUniformGrid* dataSet );

128
129
130
131
132
  // Description:
  // Sets the meta-data object at a given node. This will resize the number
  // of levels and number of datasets acoordingly.
  void SetMetaData(unsigned int level, unsigned int id, const vtkAMRBox &box );

Berk Geveci's avatar
Berk Geveci committed
133
134
//BTX
  // Description:
135
136
  // Set the dataset pointer for a given node. This will resize the number of
  // levels and the number of datasets in the level to fit level, id requested. 
137
138
139
140
  // The information carried by the vtkAMRBox is redundant with the extent
  // of the vtkUniformGrid. However, in case of parallel computation, the
  // vtkAMRBox is defined on each processor whereas the vtkUniformGrid is
  // defined only on the processor that owns it.
Mathieu Malaterre's avatar
Mathieu Malaterre committed
141
142
  void SetDataSet(unsigned int level, unsigned int id, 
                  vtkAMRBox& box, vtkUniformGrid* dataSet);
Berk Geveci's avatar
Berk Geveci committed
143
144

  // Description:
145
146
  // Get a dataset given a level and an id. In case of parallel computation,
  // the dataset can be a null pointer whereas the vtkAMRBox is always defined.
147
148
  vtkUniformGrid* GetDataSet(unsigned int level,
                             unsigned int id,
Berk Geveci's avatar
Berk Geveci committed
149
                             vtkAMRBox& box);
150
  vtkUniformGrid* GetDataSet(unsigned int level,unsigned int id );
151
152
153
154
155

  // Description:
  // Returns the AMR box for the location pointer by the iterator.
  vtkAMRBox GetAMRBox(vtkCompositeDataIterator* iter);

Berk Geveci's avatar
Berk Geveci committed
156
157
//ETX

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Description:
// Get meta-data associated with a level. This may allocate a new
// vtkInformation object if none is already present. Use HasLevelMetaData to
// avoid unnecessary allocations.
  vtkInformation* GetLevelMetaData(unsigned int level)
    { return this->GetChildMetaData(level); }

  // Description:
  // Returns if meta-data exists for a given level.
  int HasLevelMetaData(unsigned int level)
    { return this->HasChildMetaData(level); }

  // Description:
  // Get meta-data associated with a dataset.  This may allocate a new
  // vtkInformation object if none is already present. Use HasMetaData to
  // avoid unnecessary allocations.
  vtkInformation* GetMetaData(unsigned int level, unsigned int index);

176
177
178
179
180
  // Description:
  // Get the AMR box meta-data associated with a given dataset.
  // Returns 1 iff GetMetaData() was successful, else 0.
  int GetMetaData(unsigned int level, unsigned int index, vtkAMRBox &box);

181
182
183
  // Description:
  // Returns if meta-data exists for a given dataset under a given level.
  int HasMetaData(unsigned int level, unsigned int index);
Berk Geveci's avatar
Berk Geveci committed
184

Berk Geveci's avatar
Berk Geveci committed
185
  // Description:
Berk Geveci's avatar
Berk Geveci committed
186
187
188
189
190
191
  // Sets the refinement of a given level. The spacing at level
  // level+1 is defined as spacing(level+1) = spacing(level)/refRatio(level).
  // Note that currently, this is not enforced by this class however
  // some algorithms might not function properly if the spacing in
  // the blocks (vtkUniformGrid) does not match the one described
  // by the refinement ratio.
Berk Geveci's avatar
Berk Geveci committed
192
193
  void SetRefinementRatio(unsigned int level, int refRatio);

194
195
196
197
  // Description:
  // Returns the refinement of a given level.
  int GetRefinementRatio(unsigned int level);

198
199
200
201
  // Description:
  // Returns the refinement ratio for the position pointed by the iterator.
  int GetRefinementRatio(vtkCompositeDataIterator* iter);

Berk Geveci's avatar
Berk Geveci committed
202
203
204
205
206
  // Description:
  // Blank lower level cells if they are overlapped by higher
  // level ones.
  void GenerateVisibilityArrays();

207
  static vtkInformationIntegerVectorKey* BOX();
208
  static vtkInformationIntegerKey* BOX_DIMENSIONALITY();
209
  static vtkInformationIntegerKey* REFINEMENT_RATIO();
210
  static vtkInformationIdTypeKey* NUMBER_OF_BLANKED_POINTS();
211
  static vtkInformationDoubleVectorKey* BOX_ORIGIN();
212
  static vtkInformationDoubleVectorKey* SPACING();
213
214
215
  static vtkInformationIntegerKey* RANK();
  static vtkInformationIntegerKey* BLOCK_ID();
  static vtkInformationIntegerVectorKey* REAL_EXTENT();
216
  static vtkInformationIntegerKey* GEOMETRIC_DESCRIPTION();
217

218
219
220
221
222
223
224
  //BTX
  // Description:
  // Retrieve an instance of this class from an information object.
  static vtkHierarchicalBoxDataSet* GetData(vtkInformation* info);
  static vtkHierarchicalBoxDataSet* GetData(vtkInformationVector* v, int i=0);
  //ETX

225
226
  // Description:
  // Copy the cached scalar range into range.
227
  virtual void GetScalarRange(double range[]);
228
229
230
231
  
  // Description:
  // Return the cached range.
  virtual double *GetScalarRange();
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

  // Description:
  // Unhiding superclass method.
  virtual vtkDataObject* GetDataSet(vtkCompositeDataIterator* iter)
    { return this->Superclass::GetDataSet(iter); }

  // Description:
  // Unhiding superclass method.
  virtual vtkInformation* GetMetaData(vtkCompositeDataIterator* iter)
    { return this->Superclass::GetMetaData(iter); }


  // Description:
  // Unhiding superclass method.
  virtual int HasMetaData(vtkCompositeDataIterator* iter)
    { return this->Superclass::HasMetaData(iter); }
248
249
250
251
252
253
 
  // Description:
  // Given the level and dataset index, returns the flat index provided level
  // and dataset index are valid.
  unsigned int GetFlatIndex(unsigned int level, unsigned int index);

254
255
256
257
258
259
  // Description:
  // Given the flat index, returns the corresponding level and index, idx,
  // of the dataset.
  void GetLevelAndIndex(
      const unsigned int flatIdx, unsigned int &level, unsigned int &idx );

260
261
262
263
264
  // Description:
  // In-line Set & Get
  vtkSetMacro( PadCellVisibility, bool );
  vtkGetMacro( PadCellVisibility, bool );

Berk Geveci's avatar
Berk Geveci committed
265
266
267
268
protected:
  vtkHierarchicalBoxDataSet();
  ~vtkHierarchicalBoxDataSet();

George Zagaris's avatar
George Zagaris committed
269
270
271
272
273
  // Description:
  // Gets the list of higher res boxes from this level at the level, l+1
  void GetHigherResolutionCoarsenedBoxes(
      vtkAMRBoxList &blist, const unsigned int l );

274
275
276
277
278
  // Description:
  // Blanks the grids at level, l, Given the list of high-res boxes at level
  // l+1 coarsened to level l.
  void BlankGridsAtLevel( vtkAMRBoxList &blist, const unsigned int l );

279
280
281
282
283
284
285
286
287
  // Description:
  // Compute the range of the scalars and cache it into ScalarRange
  // only if the cache became invalid (ScalarRangeComputeTime).
  virtual void ComputeScalarRange();
  
  // Cached scalar range
  double ScalarRange[2];
  // Time at which scalar range is computed
  vtkTimeStamp ScalarRangeComputeTime;
Berk Geveci's avatar
Berk Geveci committed
288

289
290
  bool PadCellVisibility;

291
292
293
  // Global Origin
  double origin[3];

Berk Geveci's avatar
Berk Geveci committed
294
private:
295
296
297



Berk Geveci's avatar
Berk Geveci committed
298
299
300
301
302
303
  vtkHierarchicalBoxDataSet(const vtkHierarchicalBoxDataSet&);  // Not implemented.
  void operator=(const vtkHierarchicalBoxDataSet&);  // Not implemented.
};

#endif