VTK
vtkAMRBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAMRBox.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 =========================================================================*/
35 #ifndef __vtkAMRBox_h
36 #define __vtkAMRBox_h
37 
38 #include "vtkObject.h"
39 #include "vtkType.h" //For utility functions.
40 #include <vtkstd/vector> // STL Header
41 
43 {
44 public:
46  vtkAMRBox(int dim=3);
47 
49 
50  vtkAMRBox(
51  int ilo,int jlo,int klo,
52  int ihi,int jhi,int khi);
54 
56 
57  vtkAMRBox(
58  int ilo,int jlo,
59  int ihi,int jhi);
61 
63 
64  vtkAMRBox(int dim, const int lo[3], const int hi[3]);
65  vtkAMRBox(const int lo[3], const int hi[3]);
67 
69 
70  vtkAMRBox(int dim, const int dims[6]);
71  vtkAMRBox(const int dims[6]);
73 
75  vtkAMRBox(const vtkAMRBox &other);
76 
78  vtkAMRBox &operator=(const vtkAMRBox &other);
79 
81  void Invalidate();
82 
84 
85  int GetDimensionality() const { return this->Dimension; }
86  void SetDimensionality(int dim);
88 
90 
91  void SetDimensions(
92  int ilo, int jlo, int klo,
93  int ihi, int jhi, int khi);
95 
97  void SetDimensions(const int lo[3], const int hi[3]);
98 
100  void SetDimensions(const int dims[6]);
101 
103  void GetDimensions(int lo[3], int hi[3]) const;
104 
106  void GetDimensions(int dims[6]) const;
107 
109 
110  void GetLoCorner(int lo[3]) const;
111  const int *GetLoCorner() const { return this->LoCorner; }
113 
115 
116  void GetHiCorner(int hi[3]) const;
117  const int *GetHiCorner() const { return this->HiCorner; }
119 
121 
122  void GetNumberOfCells(int ext[3]) const;
123  vtkIdType GetNumberOfCells() const;
125 
127 
129  void GetNumberOfNodes(int ext[3]) const;
130  vtkIdType GetNumberOfNodes() const;
132 
134 
136  const double *GetGridSpacing() const { return this->DX; }
137  void GetGridSpacing(double dX[3]) const;
138  void SetGridSpacing(double dx);
139  void SetGridSpacing(const double dX[3]);
140  void SetGridSpacing(double dx, double dy, double dz);
142 
144 
148  const double *GetDataSetOrigin() const { return this->X0; }
149  void GetDataSetOrigin(double X0[3]) const;
150  void SetDataSetOrigin(const double X0[3]);
151  void SetDataSetOrigin(double x0, double y0, double z0);
153 
159  void GetBoxOrigin(double x0[3]) const;
160 
162  void Grow(int byN);
163 
165  void Shrink(int byN);
166 
168 
169  void Shift(int i, int j);
170  void Shift(int i, int j, int k);
171  void Shift(const int I[3]);
173 
175  bool Empty() const;
176 
178  bool operator==(const vtkAMRBox &other);
179 
181  void operator&=(const vtkAMRBox &rhs);
182 
184 
185  bool Contains(int i,int j,int k) const;
186  bool Contains(const int I[3]) const;
188 
190  bool Contains(const vtkAMRBox &other) const;
191 
193  void Refine(int r);
194 
196  void Coarsen(int r);
197 
199  ostream &Print(ostream &os) const;
200 
201  //BTX
202  // @deprecated Replaced by Contains() as of VTK 5.4.
203  // Do not use! See Contains().
204  VTK_LEGACY(int DoesContainCell(int i, int j, int k));
205  // @deprecated Replaced by Contains() as of VTK 5.4.
206  // Do not use! See Contains().
207  VTK_LEGACY(int DoesContainBox(vtkAMRBox const & box) const);
208  //ETX
209 
210 public:
212 
216  int LoCorner[3]; // lo corner cell id.
217  int HiCorner[3]; // hi corner cell id.
219 
220 private:
221  int Dimension; // 2 or 3.
222  double X0[3]; // Dataset origin (not box origin). low corner cell's, low corner node.
223  double DX[3]; // grid spacing.
224 };
225 
226 // NOTE 2008-11-10
227 // Favor the set'ers above to this helper, where ever possible.
228 // Helper to unroll the loop
229 template<int dimension>
230 struct vtkAMRBoxInitializeHelp;
231 template<int dimension>
233  int *LoCorner,
234  int *HiCorner, // member
235  const int *loCorner,
236  const int *hiCorner, // local
237  vtkAMRBoxInitializeHelp<dimension>* = 0) // dummy parameter for vs6
238  {
239  for(int i=0; i<dimension; ++i)
240  {
241  LoCorner[i] = loCorner[i];
242  HiCorner[i] = hiCorner[i];
243  }
244  for(int i=dimension; i<(3-dimension); ++i)
245  {
246  LoCorner[i] = 0;
247  HiCorner[i] = 0;
248  }
249  }
250 
251 //*****************************************************************************
253 
255 template <typename T>
257  T *pArray,
258  const vtkAMRBox &arrayRegion,
259  const vtkAMRBox &destRegion,
260  T fillValue)
261 {
262  // Convert regions to array index space. VTK arrays
263  // always start with 0,0,0.
264  int ofs[3];
265  arrayRegion.GetLoCorner(ofs);
266  ofs[0]=-ofs[0];
267  ofs[1]=-ofs[1];
268  ofs[2]=-ofs[2];
269  vtkAMRBox arrayDims(arrayRegion);
270  arrayDims.Shift(ofs);
271  vtkAMRBox destDims(destRegion);
272  destDims.Shift(ofs);
273  // Quick sanity check.
274  if (!arrayRegion.Contains(destRegion))
275  {
276  vtkGenericWarningMacro(
277  << "ERROR: Array must enclose the destination region. "
278  << "Aborting the fill.");
279  }
280  // Get the bounds of the indices we fill.
281  int destLo[3];
282  destDims.GetLoCorner(destLo);
283  int destHi[3];
284  destDims.GetHiCorner(destHi);
285  // Get the array dimensions.
286  int arrayHi[3];
287  arrayDims.GetNumberOfCells(arrayHi);
288  // Fill.
289  for (int k=destLo[2]; k<=destHi[2]; ++k)
290  {
291  vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
292  for (int j=destLo[1]; j<=destHi[1]; ++j)
293  {
294  vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
295  for (int i=destLo[0]; i<=destHi[0]; ++i)
296  {
297  pArray[idx]=fillValue;
298  ++idx;
299  }
300  }
301  }
302 }
304 
308 void Split(const int N[3], const int minSide[3], vtkstd::vector<vtkAMRBox> &decomp);
309 
313 void Split(const int minSide[3], vtkstd::vector<vtkAMRBox> &decomp);
314 
315 #endif