1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkAMRInformation.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 =========================================================================*/ 15 // .NAME vtkAMRInformation - Meta data that describes the structure of an AMR data set 16 // 17 // .SECTION Description 18 // vtkAMRInformation encaspulates the following meta information for an AMR data set 19 // - a list of vtkAMRBox objects 20 // - Refinement ratio between AMR levels 21 // - Grid spacing for each level 22 // - The file block index for each block 23 // - parent child information, if requested 24 // 25 // .SECTION See Also 26 // vtkOverlappingAMR, vtkAMRBox 27 28 #ifndef vtkAMRInformation_h 29 #define vtkAMRInformation_h 30 31 #include "vtkCommonDataModelModule.h" // For export macro 32 #include "vtkObject.h" 33 #include "vtkAMRBox.h" //for storing AMR Boxes 34 #include "vtkSmartPointer.h" //for ivars 35 #include <vector> //for storing AMR Boxes 36 37 38 typedef std::vector<vtkAMRBox> vtkAMRBoxList; 39 40 class vtkUnsignedIntArray; 41 class vtkIntArray; 42 class vtkDoubleArray; 43 class vtkAMRIndexIterator; 44 45 class VTKCOMMONDATAMODEL_EXPORT vtkAMRInformation : public vtkObject 46 { 47 public: 48 static vtkAMRInformation* New(); 49 vtkTypeMacro(vtkAMRInformation, vtkObject); 50 51 void PrintSelf(ostream& os, vtkIndent indent); 52 53 bool operator==(const vtkAMRInformation& other); 54 55 //Description 56 //Initialize the meta information 57 // numLevels is the number of levels 58 // blocksPerLevel[i] is the number of blocks at level i 59 void Initialize(int numLevels, const int* blocksPerLevel); 60 61 // Description: 62 // returns the value of vtkUniformGrid::GridDescription() of any block 63 vtkGetMacro( GridDescription, int ); 64 void SetGridDescription(int description); 65 66 // Description: 67 // Get the AMR dataset origin 68 // The origin is essentially the minimum of all the grids. 69 void GetOrigin( double origin[3] ); 70 double* GetOrigin(); 71 void SetOrigin(const double* origin); 72 73 // Description: 74 // Return the number of levels GetNumberOfLevels()75 unsigned int GetNumberOfLevels() const 76 { return static_cast<unsigned int>(this->NumBlocks.size()-1);} 77 78 // Description: 79 // Returns the number of datasets at the given levelx 80 unsigned int GetNumberOfDataSets(unsigned int level) const; 81 82 // Description: 83 // Returns total number of datasets GetTotalNumberOfBlocks()84 unsigned int GetTotalNumberOfBlocks() 85 { return this->NumBlocks.back();} 86 87 // Description: 88 // Returns the single index from a pair of indices GetIndex(unsigned int level,unsigned int id)89 int GetIndex(unsigned int level, unsigned int id) const 90 { return this->NumBlocks[level] + id;} 91 92 // Description: 93 // Returns the an index pair given a single index 94 void ComputeIndexPair(unsigned int index, unsigned int& level, unsigned int& id); 95 96 // Description 97 // Returns the bounds of the entire domain 98 const double* GetBounds(); 99 100 // Description 101 // Returns the bounding box of a given box 102 void GetBounds(unsigned int level, unsigned int id, double* bb); 103 104 // Description 105 // Returns the origin of the grid at (level,id) 106 bool GetOrigin(unsigned int level, unsigned int id, double* origin); 107 108 //Description 109 //Return the spacing at the given fiven 110 void GetSpacing(unsigned int level, double spacing[3]); 111 112 bool HasSpacing(unsigned int level); 113 114 // Description: 115 // Methods to set and get the AMR box at a given position 116 void SetAMRBox(unsigned int level, unsigned int id, const vtkAMRBox& box); 117 const vtkAMRBox& GetAMRBox(unsigned int level, unsigned int id) const; 118 119 // Description 120 // return the amr box coarsened to the previous level 121 bool GetCoarsenedAMRBox(unsigned int level, unsigned int id, vtkAMRBox& box) const; 122 123 // Description: 124 // Get/Set the SourceIndex of a block. Typically, this is a file-type specific index 125 // that can be used by a reader to load a particular file block 126 int GetAMRBlockSourceIndex(int index); 127 void SetAMRBlockSourceIndex(int index, int sourceId); 128 129 // Description: 130 // This method computes the refinement ratio at each level. 131 // At each level, l, the refinement ratio r_l is computed by 132 // r_l = D_{l} / D_{l+1}, where D_{l+1} and D_{l} are the grid 133 // spacings at the next and current level respectively. 134 // 135 // .SECTION Assumptions 136 // 1) Within each level, the refinement ratios are the same for all blocks. 137 // 2) The refinement ratio is uniform along each dimension of the block. 138 void GenerateRefinementRatio(); 139 140 // Description: 141 // Returns Wether refinement ratio has been set (either by calling 142 // GenerateRefinementRatio() or by calling SetRefinementRatio() 143 bool HasRefinementRatio(); 144 145 // Description: 146 // Set the refinement ratio at a level. This method should be 147 // called for all levels, if called at all. 148 void SetRefinementRatio(unsigned int level, int ratio); 149 150 // Description: 151 // Returns the refinement of a given level. 152 int GetRefinementRatio(unsigned int level) const; 153 154 // Description: 155 // Set the spacing at a given level 156 void SetSpacing(unsigned int level,const double* h); 157 158 //Description: 159 //Return whether parent child information has been generated 160 bool HasChildrenInformation(); 161 162 // Description: 163 // Return a pointer to Parents of a block. The first entry is the number 164 // of parents the block has followed by its parent ids in level-1. 165 // If none exits it returns NULL. 166 unsigned int *GetParents(unsigned int level, unsigned int index, unsigned int& numParents); 167 168 // Description: 169 // Return a pointer to Children of a block. The first entry is the number 170 // of children the block has followed by its childern ids in level+1. 171 // If none exits it returns NULL. 172 unsigned int *GetChildren(unsigned int level, unsigned int index, unsigned int& numChildren); 173 174 // Description: 175 // Prints the parents and children of a requested block (Debug Routine) 176 void PrintParentChildInfo(unsigned int level, unsigned int index); 177 178 //Description: 179 // Generate the parent/child relationships - needed to be called 180 // before GetParents or GetChildren can be used! 181 void GenerateParentChildInformation(); 182 183 // Description: 184 // Checks whether the meta data is internally consistent. 185 bool Audit(); 186 187 // Description: 188 //Given a point q, find whether q is bounded by the data set at 189 //(level,index). If it is, set cellIdx to the cell index and return 190 //true; otherwise return false 191 bool FindCell(double q[3],unsigned int level, unsigned int index,int &cellIdx); 192 193 // Description: 194 //find the grid that contains the point q at the specified level 195 bool FindGrid(double q[3], int level, unsigned int& gridId); 196 197 //Description 198 //Given a point q, find the highest level grid that contains it. 199 bool FindGrid(double q[3], unsigned int& level, unsigned int& gridId); 200 201 // Description: 202 // Returns internal arrays. GetNumBlocks()203 const std::vector<int>& GetNumBlocks() const 204 { return this->NumBlocks;} 205 GetChildrenAtLevel(unsigned int i)206 std::vector<std::vector<unsigned int> >& GetChildrenAtLevel(unsigned int i) 207 { return this->AllChildren[i];} 208 209 void DeepCopy(vtkAMRInformation *other); 210 211 private: 212 vtkAMRInformation(); 213 ~vtkAMRInformation(); 214 vtkAMRInformation(const vtkAMRInformation&); // Not implemented. 215 void operator=(const vtkAMRInformation&); // Not implemented. 216 217 bool HasValidOrigin(); 218 bool HasValidBounds(); 219 void UpdateBounds(const int level, const int id); 220 void AllocateBoxes(unsigned int n); 221 void GenerateBlockLevel(); 222 void CalculateParentChildRelationShip( unsigned int level, 223 std::vector<std::vector<unsigned int> >& children, 224 std::vector<std::vector<unsigned int> >& parents ); 225 226 //------------------------------------------------------------------------- 227 // Essential information that determines an AMR structure. Must be copied 228 //------------------------------------------------------------------------- 229 int GridDescription; //example: VTK_XYZ_GRID 230 double Origin[3]; //the origin of the whole data set 231 vtkAMRBoxList Boxes; // vtkAMRBoxes, one per data set 232 std::vector<int> NumBlocks; //NumBlocks[i] stores the total number of blocks from level 0 to level i-1 233 234 vtkSmartPointer<vtkIntArray> SourceIndex; //Typically, this maps to a file block index used by the reader 235 vtkSmartPointer<vtkDoubleArray> Spacing; //The grid spacing for all levels 236 double Bounds[6]; //the bounds of the entire domain 237 238 //------------------------------------------------------------------------- 239 // Auxillary information that be computed 240 //------------------------------------------------------------------------- 241 vtkSmartPointer<vtkIntArray> Refinement; //refinement ratio between two adjacent levels 242 vtkSmartPointer<vtkUnsignedIntArray> BlockLevel; //only necessary if need to call ComputeIndexPair 243 244 //parent child information 245 std::vector<std::vector<std::vector<unsigned int> > > AllChildren; 246 std::vector<std::vector<std::vector<unsigned int> > > AllParents; 247 }; 248 249 #endif 250