VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkAMRBox.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 =========================================================================*/ 00035 #ifndef __vtkAMRBox_h 00036 #define __vtkAMRBox_h 00037 00038 #include "vtkObject.h" 00039 #include "vtkType.h" //For utility functions. 00040 #include <vector> // STL Header 00041 00042 class VTK_FILTERING_EXPORT vtkAMRBox 00043 { 00044 public: 00046 vtkAMRBox(int dim=3); 00047 00049 00050 vtkAMRBox( 00051 int ilo,int jlo,int klo, 00052 int ihi,int jhi,int khi); 00054 00056 00057 vtkAMRBox( 00058 int ilo,int jlo, 00059 int ihi,int jhi); 00061 00063 00064 vtkAMRBox(int dim, const int lo[3], const int hi[3]); 00065 vtkAMRBox(const int lo[3], const int hi[3]); 00067 00069 00070 vtkAMRBox(int dim, const int dims[6]); 00071 vtkAMRBox(const int dims[6]); 00073 00075 vtkAMRBox(const vtkAMRBox &other); 00076 00078 vtkAMRBox &operator=(const vtkAMRBox &other); 00079 00081 void Invalidate(); 00082 00084 00085 int GetDimensionality() const { return this->Dimension; } 00086 void SetDimensionality(int dim); 00088 00090 00091 void SetDimensions( 00092 int ilo, int jlo, int klo, 00093 int ihi, int jhi, int khi); 00095 00097 void SetDimensions(const int lo[3], const int hi[3]); 00098 00100 void SetDimensions(const int dims[6]); 00101 00103 void GetDimensions(int lo[3], int hi[3]) const; 00104 00106 void GetDimensions(int dims[6]) const; 00107 00109 00110 void GetLoCorner(int lo[3]) const; 00111 const int *GetLoCorner() const { return this->LoCorner; } 00113 00115 00116 void GetHiCorner(int hi[3]) const; 00117 const int *GetHiCorner() const { return this->HiCorner; } 00119 00121 00122 void GetNumberOfCells(int ext[3]) const; 00123 vtkIdType GetNumberOfCells() const; 00125 00127 00129 void GetNumberOfNodes(int ext[3]) const; 00130 vtkIdType GetNumberOfNodes() const; 00132 00134 00136 const double *GetGridSpacing() const { return this->DX; } 00137 void GetGridSpacing(double dX[3]) const; 00138 void SetGridSpacing(double dx); 00139 void SetGridSpacing(const double dX[3]); 00140 void SetGridSpacing(double dx, double dy, double dz); 00142 00144 00148 const double *GetDataSetOrigin() const { return this->X0; } 00149 void GetDataSetOrigin(double X0[3]) const; 00150 void SetDataSetOrigin(const double X0[3]); 00151 void SetDataSetOrigin(double x0, double y0, double z0); 00153 00159 void GetBoxOrigin(double x0[3]) const; 00160 00162 void Grow(int byN); 00163 00165 void Shrink(int byN); 00166 00168 00169 void Shift(int i, int j); 00170 void Shift(int i, int j, int k); 00171 void Shift(const int I[3]); 00173 00175 bool Empty() const; 00176 00178 bool operator==(const vtkAMRBox &other); 00179 00181 void operator&=(const vtkAMRBox &rhs); 00182 00184 00185 bool Contains(int i,int j,int k) const; 00186 bool Contains(const int I[3]) const; 00188 00190 bool Contains(const vtkAMRBox &other) const; 00191 00193 void Refine(int r); 00194 00196 void Coarsen(int r); 00197 00199 ostream &Print(ostream &os) const; 00200 00201 //BTX 00202 // @deprecated Replaced by Contains() as of VTK 5.4. 00203 // Do not use! See Contains(). 00204 VTK_LEGACY(int DoesContainCell(int i, int j, int k)); 00205 // @deprecated Replaced by Contains() as of VTK 5.4. 00206 // Do not use! See Contains(). 00207 VTK_LEGACY(int DoesContainBox(vtkAMRBox const & box) const); 00208 //ETX 00209 00210 public: 00212 00216 int LoCorner[3]; // lo corner cell id. 00217 int HiCorner[3]; // hi corner cell id. 00219 00220 private: 00221 int Dimension; // 2 or 3. 00222 double X0[3]; // Dataset origin (not box origin). low corner cell's, low corner node. 00223 double DX[3]; // grid spacing. 00224 }; 00225 00226 // NOTE 2008-11-10 00227 // Favor the set'ers above to this helper, where ever possible. 00228 // Helper to unroll the loop 00229 template<int dimension> 00230 struct vtkAMRBoxInitializeHelp; 00231 template<int dimension> 00232 void vtkAMRBoxInitialize( 00233 int *LoCorner, 00234 int *HiCorner, // member 00235 const int *loCorner, 00236 const int *hiCorner, // local 00237 vtkAMRBoxInitializeHelp<dimension>* = 0) // dummy parameter for vs6 00238 { 00239 for(int i=0; i<dimension; ++i) 00240 { 00241 LoCorner[i] = loCorner[i]; 00242 HiCorner[i] = hiCorner[i]; 00243 } 00244 for(int i=dimension; i<(3-dimension); ++i) 00245 { 00246 LoCorner[i] = 0; 00247 HiCorner[i] = 0; 00248 } 00249 } 00250 00251 //***************************************************************************** 00253 00255 template <typename T> 00256 void FillRegion( 00257 T *pArray, 00258 const vtkAMRBox &arrayRegion, 00259 const vtkAMRBox &destRegion, 00260 T fillValue) 00261 { 00262 // Convert regions to array index space. VTK arrays 00263 // always start with 0,0,0. 00264 int ofs[3]; 00265 arrayRegion.GetLoCorner(ofs); 00266 ofs[0]=-ofs[0]; 00267 ofs[1]=-ofs[1]; 00268 ofs[2]=-ofs[2]; 00269 vtkAMRBox arrayDims(arrayRegion); 00270 arrayDims.Shift(ofs); 00271 vtkAMRBox destDims(destRegion); 00272 destDims.Shift(ofs); 00273 // Quick sanity check. 00274 if (!arrayRegion.Contains(destRegion)) 00275 { 00276 vtkGenericWarningMacro( 00277 << "ERROR: Array must enclose the destination region. " 00278 << "Aborting the fill."); 00279 } 00280 // Get the bounds of the indices we fill. 00281 int destLo[3]; 00282 destDims.GetLoCorner(destLo); 00283 int destHi[3]; 00284 destDims.GetHiCorner(destHi); 00285 // Get the array dimensions. 00286 int arrayHi[3]; 00287 arrayDims.GetNumberOfCells(arrayHi); 00288 // Fill. 00289 for (int k=destLo[2]; k<=destHi[2]; ++k) 00290 { 00291 vtkIdType kOfs=k*arrayHi[0]*arrayHi[1]; 00292 for (int j=destLo[1]; j<=destHi[1]; ++j) 00293 { 00294 vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0]; 00295 for (int i=destLo[0]; i<=destHi[0]; ++i) 00296 { 00297 pArray[idx]=fillValue; 00298 ++idx; 00299 } 00300 } 00301 } 00302 } 00304 00308 void Split(const int N[3], const int minSide[3], std::vector<vtkAMRBox> &decomp); 00309 00313 void Split(const int minSide[3], std::vector<vtkAMRBox> &decomp); 00314 00315 #endif