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 =========================================================================*/
26 #ifndef vtkAMRBox_h
27 #define vtkAMRBox_h
28 
29 #include "vtkCommonDataModelModule.h" // For export macro
30 #include "vtkObject.h"
31 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
32 
33 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
34 {
35  public:
39  vtkAMRBox();
40 
44  vtkAMRBox(const vtkAMRBox &other);
45 
49  vtkAMRBox(
50  int ilo,int jlo,int klo,
51  int ihi,int jhi,int khi);
52 
57  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
58  const double* globalOrigin, int gridDescription=VTK_XYZ_GRID);
59 
63  vtkAMRBox(const int lo[3], const int hi[3]);
64 
65  vtkAMRBox(const int dims[6]);
66 
67 
71  vtkAMRBox &operator=(const vtkAMRBox &other);
72 
73  virtual ~vtkAMRBox(){}
74 
76 
79  void Invalidate()
80  {
81  this->LoCorner[0]=this->LoCorner[1]=this->LoCorner[2]=0;
82  this->HiCorner[0]=this->HiCorner[1]=this->HiCorner[2]=-2;
83  }
85 
89  bool EmptyDimension(int i) const{ return HiCorner[i]<=LoCorner[i]-1;}
90 
94  void SetDimensions(
95  int ilo, int jlo, int klo,
96  int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID);
97 
101  void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID);
102 
106  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
107 
111  void GetDimensions(int lo[3], int hi[3]) const;
112 
116  void GetDimensions(int dims[6]) const;
117 
119 
122  vtkIdType GetNumberOfCells() const;
123  void GetNumberOfCells(int num[3]) const;
125 
127 
131  void GetNumberOfNodes(int ext[3]) const;
132  vtkIdType GetNumberOfNodes() const;
134 
140  int ComputeDimension() const;
141 
145  const int *GetLoCorner() const { return this->LoCorner; }
146  const int *GetHiCorner() const { return this->HiCorner; }
147 
153  void GetValidHiCorner(int hi[3]) const;
154 
155  bool Empty() const
156  {return this->IsInvalid();}
157 
161  bool IsInvalid() const
162  {
163  return ((this->HiCorner[0] < this->LoCorner[0]-1) ||
164  (this->HiCorner[1] < this->LoCorner[1]-1) ||
165  (this->HiCorner[2] < this->LoCorner[2]-1));
166  }
167 
173  bool operator==(const vtkAMRBox &other) const;
174 
180  bool operator!=(const vtkAMRBox &other) const
181  { return( !(*this == other) ); }
182 
186  ostream &Print(ostream &os) const;
187 
189 
200  void Serialize( unsigned char*& buffer, vtkIdType &bytesize );
201  void Serialize(int* buffer) const;
203 
210  void Deserialize( unsigned char* buffer, const vtkIdType &bytesize );
211 
218  bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const;
219 
220  bool DoesIntersect(const vtkAMRBox &other) const;
221 
225  void Coarsen(int r);
226 
230  void Refine(int r);
231 
233 
236  void Grow(int byN);
237  void Shrink(int byN);
239 
241 
244  void Shift(int i, int j, int k);
245  void Shift(const int I[3]);
247 
253  bool Intersect(const vtkAMRBox &other);
254 
256 
259  bool Contains(int i,int j,int k) const;
260  bool Contains(const int I[3]) const;
262 
266  bool Contains(const vtkAMRBox&) const;
267 
273  void GetGhostVector(int r, int nghost[6]) const;
274 
279  void RemoveGhosts(int r);
280 
281  public:
287  static vtkIdType GetBytesize(){return 6*sizeof(int); };
288 
292  static int GetCellLinearIndex(const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3] );
293 
297  static void GetBounds(const vtkAMRBox& box, const double origin[3], const double spacing[3],double bounds[6]) ;
298 
303  static void GetBoxOrigin(const vtkAMRBox& box, const double X0[3], const double spacing[3],double x0[3]);
304 
309  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3], double x, double y, double z );
310 
314  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
315  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
316 
317  protected:
321  void Initialize( );
322 
329  bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q);
330 
331  private:
332  int LoCorner[3]; // lo corner cell id.
333  int HiCorner[3]; // hi corner cell id.
334 
336 
341  void BuildAMRBox(
342  const int ilo, const int jlo, const int klo,
343  const int ihi, const int jhi, const int khi );
344 };
346 
347 
348 //*****************************************************************************
350 
354 template <typename T>
356  T *pArray,
357  const vtkAMRBox &arrayRegion,
358  const vtkAMRBox &destRegion,
359  T fillValue)
360 {
361  // Convert regions to array index space. VTK arrays
362  // always start with 0,0,0.
363  int ofs[3];
364  ofs[0]=-arrayRegion.GetLoCorner()[0];
365  ofs[1]=-arrayRegion.GetLoCorner()[1];
366  ofs[2]=-arrayRegion.GetLoCorner()[2];
367  vtkAMRBox arrayDims(arrayRegion);
368  arrayDims.Shift(ofs);
369  vtkAMRBox destDims(destRegion);
370  destDims.Shift(ofs);
371  // Quick sanity check.
372  if (!arrayRegion.Contains(destRegion))
373  {
374  vtkGenericWarningMacro(
375  << "ERROR: Array must enclose the destination region. "
376  << "Aborting the fill.");
377  }
378  // Get the bounds of the indices we fill.
379  const int* destLo = destDims.GetLoCorner();
380  int destHi[3];
381  destDims.GetValidHiCorner(destHi);
382  // Get the array dimensions.
383  int arrayHi[3];
384  arrayDims.GetNumberOfCells(arrayHi);
385  // Fill.
386  for (int k=destLo[2]; k<=destHi[2]; ++k)
387  {
388  vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
389  for (int j=destLo[1]; j<=destHi[1]; ++j)
390  {
391  vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
392  for (int i=destLo[0]; i<=destHi[0]; ++i)
393  {
394  pArray[idx]=fillValue;
395  ++idx;
396  }
397  }
398  }
400 
401 }
402 
403 #endif
404 // VTK-HeaderTest-Exclude: vtkAMRBox.h
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition: vtkAMRBox.h:89
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:145
bool Empty() const
Definition: vtkAMRBox.h:155
bool Contains(int i, int j, int k) const
Test to see if a given cell index is inside this box.
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:33
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition: vtkAMRBox.h:161
void FillRegion(T *pArray, const vtkAMRBox &arrayRegion, const vtkAMRBox &destRegion, T fillValue)
Fill the region of "pArray" enclosed by "destRegion" with "fillValue" "pArray" is defined on "arrayRe...
Definition: vtkAMRBox.h:355
int vtkIdType
Definition: vtkType.h:345
void Shift(int i, int j, int k)
Shifts the box in index space.
vtkIdType GetNumberOfCells() const
Gets the number of cells enclosed by the box.
void GetValidHiCorner(int hi[3]) const
Return a high corner.
const int * GetHiCorner() const
Definition: vtkAMRBox.h:146
bool operator!=(const vtkAMRBox &other) const
Test if this box is NOT equal with the box instance on the rhs.
Definition: vtkAMRBox.h:180
virtual ~vtkAMRBox()
Definition: vtkAMRBox.h:73
#define VTK_XYZ_GRID
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:287
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:79