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 <vtkstd/vector>//For utility functions. 00041 00042 class VTK_FILTERING_EXPORT vtkAMRBox 00043 { 00044 public: 00046 00047 vtkAMRBox(int dim=3); 00048 // Description: 00049 // Construct a specific 3D box. 00050 vtkAMRBox( 00051 int ilo,int jlo,int klo, 00052 int ihi,int jhi,int khi); 00053 // Description: 00054 // Construct a specific 2D box. 00055 vtkAMRBox( 00056 int ilo,int jlo, 00057 int ihi,int jhi); 00058 // Description: 00059 // Construct a specific box. (ilo,jlo,klo,)(ihi,jhi,khi) 00060 vtkAMRBox(int dim, const int lo[3], const int hi[3]); 00061 vtkAMRBox(const int lo[3], const int hi[3]); 00062 // Description: 00063 // Construct a specific box. (ilo,ihi, jlo,jhi, klo,khi) 00064 vtkAMRBox(int dim, const int dims[6]); 00065 vtkAMRBox(const int dims[6]); 00066 // Description: 00067 // Copy construct this box from another. 00068 vtkAMRBox(const vtkAMRBox &other); 00069 // Description: 00070 // Copy the other box to this box. 00071 vtkAMRBox &operator=(const vtkAMRBox &other); 00072 // Description: 00073 // Set the box to null; 00074 void Invalidate(); 00075 // Description: 00076 // Get/Set the spatial dimension of the box. Only 2 and 3 00077 // are valid. 00078 int GetDimensionality() const { return this->Dimension; } 00079 void SetDimensionality(int dim); 00080 // Description: 00081 // Set the dimensions of the box. ilo,jlo,klo,ihi,jhi,khi 00082 void SetDimensions( 00083 int ilo, int jlo, int klo, 00084 int ihi, int jhi, int khi); 00085 // Description: 00086 // Set the dimensions of the box. (ilo,jlo,klo),(ihi,jhi,khi) 00087 void SetDimensions(const int lo[3], const int hi[3]); 00088 // Description: 00089 // Set the dimensions of the box. (ilo,ihi,jlo,jhi,klo,khi) 00090 void SetDimensions(const int dims[6]); 00091 // Description: 00092 // Get the dimensions of this box. (ilo,jlo,jhi),(ihi,jhi,khi) 00093 void GetDimensions(int lo[3], int hi[3]) const; 00094 // Description: 00095 // Get the dimensions of this box. (ilo,ihi, jlo,jhi, klo,khi) 00096 void GetDimensions(int dims[6]) const; 00097 // Description: 00098 // Get the low corner index. 00099 void GetLoCorner(int lo[3]) const; 00100 const int *GetLoCorner() const { return this->LoCorner; } 00101 // Description: 00102 // Copy the high corner index. 00103 void GetHiCorner(int hi[3]) const; 00104 const int *GetHiCorner() const { return this->HiCorner; } 00105 // Description: 00106 // Gets the number of cells enclosed by the box. 00107 void GetNumberOfCells(int ext[3]) const; 00108 vtkIdType GetNumberOfCells() const; 00109 // Description: 00110 // Gets the number of nodes required to construct 00111 // a physical representation of the box. 00112 void GetNumberOfNodes(int ext[3]) const; 00113 vtkIdType GetNumberOfNodes() const; 00114 // Description: 00115 // Set/Get grid spacing. Refine/coarsen operations update 00116 // the grid spacing. 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 // Description: 00123 // Set/Get world space origin of the data set, The origin 00124 // is the location of the low corner cell's low corner node 00125 // of the data set. Which is not necessarilly the origin of 00126 // this box! For that use GetBoxOrigin(). 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 // Description: 00132 // Get the world space origin of this box. The origin is the 00133 // location of the lower corner cell's lower corner node, 00134 // which is not necessarilly the orgin of the data set! For 00135 // that use GetDataSetOrigin(). The value is computed each time, 00136 // so that operations on the box are are appropriately reflected. 00137 void GetBoxOrigin(double x0[3]) const; 00138 // Description: 00139 // Grows the box in all directions. 00140 void Grow(int byN); 00141 // Description: 00142 // Shrinks the box in all directions. 00143 void Shrink(int byN); 00144 // Description: 00145 // Shifts the box in index space. 00146 void Shift(int i, int j); 00147 void Shift(int i, int j, int k); 00148 void Shift(const int I[3]); 00149 // Description: 00150 // Test if this box is empty/valid. 00151 bool Empty() const; 00152 // Description: 00153 // Test if this box has the same dimensions as another. 00154 bool operator==(const vtkAMRBox &other); 00155 // Description: 00156 // Intersect this box with another box in place. 00157 void operator&=(const vtkAMRBox &rhs); 00158 // Description: 00159 // Test to see if a given cell index is inside this box. 00160 bool Contains(int i,int j,int k) const; 00161 bool Contains(const int I[3]) const; 00162 // Description: 00163 // Test to see if a given box is inside this box. 00164 bool Contains(const vtkAMRBox &other) const; 00165 // Description: 00166 // Refine the box. 00167 void Refine(int r); 00168 // Description: 00169 // Coarsen the box. 00170 void Coarsen(int r); 00171 // Description: 00172 // Send the box to a stream. "(ilo,jlo,jhi),(ihi,jhi,khi)" 00173 ostream &Print(ostream &os) const; 00175 00176 //BTX 00177 // @deprecated Replaced by Contains() as of VTK 5.4. 00178 // Do not use! See Contains(). 00179 VTK_LEGACY(int DoesContainCell(int i, int j, int k)); 00180 // @deprecated Replaced by Contains() as of VTK 5.4. 00181 // Do not use! See Contains(). 00182 VTK_LEGACY(int DoesContainBox(vtkAMRBox const & box) const); 00183 //ETX 00184 00185 public: 00187 00191 int LoCorner[3]; // lo corner cell id. 00192 int HiCorner[3]; // hi corner cell id. 00194 private: 00195 int Dimension; // 2 or 3. 00196 double X0[3]; // Dataset origin (not box origin). low corner cell's, low corner node. 00197 double DX[3]; // grid spacing. 00198 }; 00199 00200 // NOTE 2008-11-10 00201 // Favor the set'ers above to this helper, where ever possible. 00202 // Helper to unroll the loop 00203 template<int dimension> 00204 struct vtkAMRBoxInitializeHelp; 00205 template<int dimension> 00206 void vtkAMRBoxInitialize( 00207 int *LoCorner, 00208 int *HiCorner, // member 00209 const int *loCorner, 00210 const int *hiCorner, // local 00211 vtkAMRBoxInitializeHelp<dimension>* = 0) // dummy parameter for vs6 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 // Convert regions to array index space. VTK arrays 00238 // always start with 0,0,0. 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 // Quick sanity check. 00249 if (!arrayRegion.Contains(destRegion)) 00250 { 00251 vtkGenericWarningMacro( 00252 << "ERROR: Array must enclose the destination region. " 00253 << "Aborting the fill."); 00254 } 00255 // Get the bounds of the indices we fill. 00256 int destLo[3]; 00257 destDims.GetLoCorner(destLo); 00258 int destHi[3]; 00259 destDims.GetHiCorner(destHi); 00260 // Get the array dimensions. 00261 int arrayHi[3]; 00262 arrayDims.GetNumberOfCells(arrayHi); 00263 // Fill. 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