00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00035 #ifndef __vtkAMRBox_h
00036 #define __vtkAMRBox_h
00037 
00038 #include "vtkObject.h"
00039 #include "vtkType.h"
00040 #include <vtkstd/vector>
00041 
00042 class VTK_FILTERING_EXPORT vtkAMRBox
00043 {
00044 public:
00046 
00047   vtkAMRBox(int dim=3);
00048   
00049   
00050   vtkAMRBox(
00051       int ilo,int jlo,int klo,
00052       int ihi,int jhi,int khi);
00053   
00054   
00055   vtkAMRBox(
00056       int ilo,int jlo,
00057       int ihi,int jhi);
00058   
00059   
00060   vtkAMRBox(int dim, const int lo[3], const int hi[3]);
00061   vtkAMRBox(const int lo[3], const int hi[3]);
00062   
00063   
00064   vtkAMRBox(int dim, const int dims[6]);
00065   vtkAMRBox(const int dims[6]);
00066   
00067   
00068   vtkAMRBox(const vtkAMRBox &other);
00069   
00070   
00071   vtkAMRBox &operator=(const vtkAMRBox &other);
00072   
00073   
00074   void Invalidate();
00075   
00076   
00077   
00078   int GetDimensionality() const { return this->Dimension; }
00079   void SetDimensionality(int dim);
00080   
00081   
00082   void SetDimensions(
00083       int ilo, int jlo, int klo,
00084       int ihi, int jhi, int khi);
00085   
00086   
00087   void SetDimensions(const int lo[3], const int hi[3]);
00088   
00089   
00090   void SetDimensions(const int dims[6]);
00091   
00092   
00093   void GetDimensions(int lo[3], int hi[3]) const;
00094   
00095   
00096   void GetDimensions(int dims[6]) const;
00097   
00098   
00099   void GetLoCorner(int lo[3]) const;
00100   const int *GetLoCorner() const { return this->LoCorner; }
00101   
00102   
00103   void GetHiCorner(int hi[3]) const;
00104   const int *GetHiCorner() const { return this->HiCorner; }
00105   
00106   
00107   void GetNumberOfCells(int ext[3]) const;
00108   vtkIdType GetNumberOfCells() const;
00109   
00110   
00111   
00112   void GetNumberOfNodes(int ext[3]) const;
00113   vtkIdType GetNumberOfNodes() const;
00114   
00115   
00116   
00117   const double *GetGridSpacing() const { return this->DX; }
00118   void GetGridSpacing(double dX[3]) const;
00119   void SetGridSpacing(double dx);
00120   void SetGridSpacing(const double dX[3]);
00121   void SetGridSpacing(double dx, double dy, double dz);
00122   
00123   
00124   
00125   
00126   
00127   const double *GetDataSetOrigin() const { return this->X0; }
00128   void GetDataSetOrigin(double X0[3]) const;
00129   void SetDataSetOrigin(const double X0[3]);
00130   void SetDataSetOrigin(double x0, double y0, double z0);
00131   
00132   
00133   
00134   
00135   
00136   
00137   void GetBoxOrigin(double x0[3]) const;
00138   
00139   
00140   void Grow(int byN);
00141   
00142   
00143   void Shrink(int byN);
00144   
00145   
00146   void Shift(int i, int j);
00147   void Shift(int i, int j, int k);
00148   void Shift(const int I[3]);
00149   
00150   
00151   bool Empty() const;
00152   
00153   
00154   bool operator==(const vtkAMRBox &other);
00155   
00156   
00157   void operator&=(const vtkAMRBox &rhs);
00158   
00159   
00160   bool Contains(int i,int j,int k) const;
00161   bool Contains(const int I[3]) const;
00162   
00163   
00164   bool Contains(const vtkAMRBox &other) const;
00165   
00166   
00167   void Refine(int r);
00168   
00169   
00170   void Coarsen(int r);
00171   
00172   
00173   ostream &Print(ostream &os) const;
00175 
00176   
00177   
00178   
00179   VTK_LEGACY(int DoesContainCell(int i, int j, int k));
00180   
00181   
00182   VTK_LEGACY(int DoesContainBox(vtkAMRBox const & box) const);
00183   
00184 
00185 public:
00187 
00191   int LoCorner[3]; 
00192   int HiCorner[3]; 
00194 private:
00195   int Dimension;         
00196   double X0[3];          
00197   double DX[3];          
00198 };
00199 
00200 
00201 
00202 
00203 template<int dimension>
00204 struct vtkAMRBoxInitializeHelp;
00205 template<int dimension>
00206 void vtkAMRBoxInitialize(
00207         int *LoCorner,
00208         int *HiCorner, 
00209         const int *loCorner,
00210         const int *hiCorner, 
00211         vtkAMRBoxInitializeHelp<dimension>* = 0) 
00212   {
00213   for(int i=0; i<dimension; ++i)
00214     {
00215     LoCorner[i] = loCorner[i];
00216     HiCorner[i] = hiCorner[i];
00217     }
00218   for(int i=dimension; i<(3-dimension); ++i)
00219     {
00220     LoCorner[i] = 0;
00221     HiCorner[i] = 0;
00222     }
00223   }
00224 
00225 
00227 
00229 template <typename T>
00230 void FillRegion(
00231         T *pArray,
00232         const vtkAMRBox &arrayRegion,
00233         const vtkAMRBox &destRegion,
00234         T fillValue)
00236 {
00237   
00238   
00239   int ofs[3];
00240   arrayRegion.GetLoCorner(ofs);
00241   ofs[0]=-ofs[0];
00242   ofs[1]=-ofs[1];
00243   ofs[2]=-ofs[2];
00244   vtkAMRBox arrayDims(arrayRegion);
00245   arrayDims.Shift(ofs);
00246   vtkAMRBox destDims(destRegion);
00247   destDims.Shift(ofs);
00248   
00249   if (!arrayRegion.Contains(destRegion))
00250     {
00251     vtkGenericWarningMacro(
00252          << "ERROR: Array must enclose the destination region. "
00253          << "Aborting the fill.");
00254     }
00255   
00256   int destLo[3];
00257   destDims.GetLoCorner(destLo);
00258   int destHi[3];
00259   destDims.GetHiCorner(destHi);
00260   
00261   int arrayHi[3];
00262   arrayDims.GetNumberOfCells(arrayHi);
00263   
00264   for (int k=destLo[2]; k<=destHi[2]; ++k)
00265     {
00266     vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
00267     for (int j=destLo[1]; j<=destHi[1]; ++j) 
00268       {
00269       vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
00270       for (int i=destLo[0]; i<=destHi[0]; ++i)
00271         {
00272         pArray[idx]=fillValue;
00273         ++idx;
00274         }
00275       }
00276     }
00277 }
00278 
00282 void Split(const int N[3], const int minSide[3], vtkstd::vector<vtkAMRBox> &decomp);
00283 
00287 void Split(const int minSide[3], vtkstd::vector<vtkAMRBox> &decomp);
00288 
00289 #endif