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 =========================================================================*/ 00031 #ifndef vtkAMRBox_h 00032 #define vtkAMRBox_h 00033 00034 #include "vtkCommonDataModelModule.h" // For export macro 00035 #include "vtkObject.h" 00036 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition 00037 00038 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox 00039 { 00040 public: 00042 vtkAMRBox(); 00043 00045 vtkAMRBox(const vtkAMRBox &other); 00046 00048 00049 vtkAMRBox( 00050 int ilo,int jlo,int klo, 00051 int ihi,int jhi,int khi); 00053 00055 00056 vtkAMRBox( 00057 int ilo,int jlo, 00058 int ihi,int jhi); 00060 00062 00065 vtkAMRBox(const double* origin, const int* dimensions, const double* spacing, 00066 const double* globalOrigin, int gridDescription=VTK_XYZ_GRID); 00068 00070 vtkAMRBox(const int lo[3], const int hi[3]); 00071 00072 vtkAMRBox(const int dims[6]); 00073 00074 00076 vtkAMRBox &operator=(const vtkAMRBox &other); 00077 00078 virtual ~vtkAMRBox(){} 00079 00081 00082 void Invalidate() 00083 { 00084 this->LoCorner[0]=this->LoCorner[1]=this->LoCorner[2]=0; 00085 this->HiCorner[0]=this->HiCorner[1]=this->HiCorner[2]=-2; 00086 } 00088 00091 bool EmptyDimension(int i) const{ return HiCorner[i]<=LoCorner[i]-1;} 00092 00094 00095 void SetDimensions( 00096 int ilo, int jlo, int klo, 00097 int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID); 00099 00101 void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID); 00102 00104 void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID); 00105 00107 void GetDimensions(int lo[3], int hi[3]) const; 00108 00110 void GetDimensions(int dims[6]) const; 00111 00113 00114 vtkIdType GetNumberOfCells() const; 00115 void GetNumberOfCells(int num[3]) const; 00117 00119 00121 void GetNumberOfNodes(int ext[3]) const; 00122 vtkIdType GetNumberOfNodes() const; 00124 00128 int ComputeDimension() const; 00129 00131 00132 const int *GetLoCorner() const { return this->LoCorner; } 00133 const int *GetHiCorner() const { return this->HiCorner; } 00135 00139 void GetValidHiCorner(int hi[3]) const; 00140 00141 bool Empty() const 00142 {return this->IsInvalid();} 00143 00145 00146 bool IsInvalid() const 00147 { 00148 return ((this->HiCorner[0] < this->LoCorner[0]-1) || 00149 (this->HiCorner[1] < this->LoCorner[1]-1) || 00150 (this->HiCorner[2] < this->LoCorner[2]-1)); 00151 } 00153 00157 bool operator==(const vtkAMRBox &other) const; 00158 00160 00163 bool operator!=(const vtkAMRBox &other) const 00164 { return( !(*this == other) ); } 00166 00168 ostream &Print(ostream &os) const; 00169 00171 00176 void Serialize( unsigned char*& buffer, vtkIdType &bytesize ); 00177 void Serialize(int* buffer) const; 00179 00182 void Deserialize( unsigned char* buffer, const vtkIdType &bytesize ); 00183 00188 bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const; 00189 00190 bool DoesIntersect(const vtkAMRBox &other) const; 00191 00193 void Coarsen(int r); 00194 00196 void Refine(int r); 00197 00199 00200 void Grow(int byN); 00201 void Shrink(int byN); 00203 00205 00206 void Shift(int i, int j, int k); 00207 void Shift(const int I[3]); 00209 00213 bool Intersect(const vtkAMRBox &other); 00214 00216 00217 bool Contains(int i,int j,int k) const; 00218 bool Contains(const int I[3]) const; 00220 00222 bool Contains(const vtkAMRBox&) const; 00223 00227 void GetGhostVector(int r, int nghost[6]) const; 00228 00230 void RemoveGhosts(int r); 00231 00232 public: 00236 static vtkIdType GetBytesize(){return 6*sizeof(int); }; 00237 00239 static int GetCellLinearIndex(const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3] ); 00240 00242 static void GetBounds(const vtkAMRBox& box, const double origin[3], const double spacing[3],double bounds[6]) ; 00243 00246 static void GetBoxOrigin(const vtkAMRBox& box, const double X0[3], const double spacing[3],double x0[3]); 00247 00250 static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3], double x, double y, double z ); 00251 00253 00254 static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3], 00255 const double h[3], const double x[3], int ijk[3], double pcoords[3]); 00257 00258 protected: 00260 void Initialize( ); 00261 00266 bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q); 00267 00268 private: 00269 int LoCorner[3]; // lo corner cell id. 00270 int HiCorner[3]; // hi corner cell id. 00271 00273 00276 void BuildAMRBox( 00277 const int ilo, const int jlo, const int klo, 00278 const int ihi, const int jhi, const int khi ); 00279 }; 00281 00282 00283 //***************************************************************************** 00285 00287 template <typename T> 00288 void FillRegion( 00289 T *pArray, 00290 const vtkAMRBox &arrayRegion, 00291 const vtkAMRBox &destRegion, 00292 T fillValue) 00293 { 00294 // Convert regions to array index space. VTK arrays 00295 // always start with 0,0,0. 00296 int ofs[3]; 00297 ofs[0]=-arrayRegion.GetLoCorner()[0]; 00298 ofs[1]=-arrayRegion.GetLoCorner()[1]; 00299 ofs[2]=-arrayRegion.GetLoCorner()[2]; 00300 vtkAMRBox arrayDims(arrayRegion); 00301 arrayDims.Shift(ofs); 00302 vtkAMRBox destDims(destRegion); 00303 destDims.Shift(ofs); 00304 // Quick sanity check. 00305 if (!arrayRegion.Contains(destRegion)) 00306 { 00307 vtkGenericWarningMacro( 00308 << "ERROR: Array must enclose the destination region. " 00309 << "Aborting the fill."); 00310 } 00311 // Get the bounds of the indices we fill. 00312 const int* destLo = destDims.GetLoCorner(); 00313 int destHi[3]; 00314 destDims.GetValidHiCorner(destHi); 00315 // Get the array dimensions. 00316 int arrayHi[3]; 00317 arrayDims.GetNumberOfCells(arrayHi); 00318 // Fill. 00319 for (int k=destLo[2]; k<=destHi[2]; ++k) 00320 { 00321 vtkIdType kOfs=k*arrayHi[0]*arrayHi[1]; 00322 for (int j=destLo[1]; j<=destHi[1]; ++j) 00323 { 00324 vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0]; 00325 for (int i=destLo[0]; i<=destHi[0]; ++i) 00326 { 00327 pArray[idx]=fillValue; 00328 ++idx; 00329 } 00330 } 00331 } 00333 00334 } 00335 00336 #endif 00337 // VTK-HeaderTest-Exclude: vtkAMRBox.h