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 =========================================================================*/
32 #ifndef vtkAMRBox_h
33 #define vtkAMRBox_h
34 
35 #include "vtkCommonDataModelModule.h" // For export macro
36 #include "vtkObject.h"
37 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
38 
39 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
40 {
41  public:
45  vtkAMRBox();
46 
50  vtkAMRBox(const vtkAMRBox &other);
51 
55  vtkAMRBox(
56  int ilo,int jlo,int klo,
57  int ihi,int jhi,int khi);
58 
63  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
64  const double* globalOrigin, int gridDescription=VTK_XYZ_GRID);
65 
69  vtkAMRBox(const int lo[3], const int hi[3]);
70 
71  vtkAMRBox(const int dims[6]);
72 
73 
77  vtkAMRBox &operator=(const vtkAMRBox &other);
78 
79  virtual ~vtkAMRBox(){}
80 
82 
85  void Invalidate()
86  {
87  this->LoCorner[0]=this->LoCorner[1]=this->LoCorner[2]=0;
88  this->HiCorner[0]=this->HiCorner[1]=this->HiCorner[2]=-2;
89  }
91 
95  bool EmptyDimension(int i) const{ return HiCorner[i]<=LoCorner[i]-1;}
96 
100  void SetDimensions(
101  int ilo, int jlo, int klo,
102  int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID);
103 
107  void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID);
108 
112  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
113 
117  void GetDimensions(int lo[3], int hi[3]) const;
118 
122  void GetDimensions(int dims[6]) const;
123 
125 
128  vtkIdType GetNumberOfCells() const;
129  void GetNumberOfCells(int num[3]) const;
131 
133 
137  void GetNumberOfNodes(int ext[3]) const;
138  vtkIdType GetNumberOfNodes() const;
140 
146  int ComputeDimension() const;
147 
151  const int *GetLoCorner() const { return this->LoCorner; }
152  const int *GetHiCorner() const { return this->HiCorner; }
153 
159  void GetValidHiCorner(int hi[3]) const;
160 
161  bool Empty() const
162  {return this->IsInvalid();}
163 
167  bool IsInvalid() const
168  {
169  return ((this->HiCorner[0] < this->LoCorner[0]-1) ||
170  (this->HiCorner[1] < this->LoCorner[1]-1) ||
171  (this->HiCorner[2] < this->LoCorner[2]-1));
172  }
173 
179  bool operator==(const vtkAMRBox &other) const;
180 
186  bool operator!=(const vtkAMRBox &other) const
187  { return( !(*this == other) ); }
188 
192  ostream &Print(ostream &os) const;
193 
195 
206  void Serialize( unsigned char*& buffer, vtkIdType &bytesize );
207  void Serialize(int* buffer) const;
209 
216  void Deserialize( unsigned char* buffer, const vtkIdType &bytesize );
217 
224  bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const;
225 
226  bool DoesIntersect(const vtkAMRBox &other) const;
227 
231  void Coarsen(int r);
232 
236  void Refine(int r);
237 
239 
242  void Grow(int byN);
243  void Shrink(int byN);
245 
247 
250  void Shift(int i, int j, int k);
251  void Shift(const int I[3]);
253 
259  bool Intersect(const vtkAMRBox &other);
260 
262 
265  bool Contains(int i,int j,int k) const;
266  bool Contains(const int I[3]) const;
268 
272  bool Contains(const vtkAMRBox&) const;
273 
279  void GetGhostVector(int r, int nghost[6]) const;
280 
285  void RemoveGhosts(int r);
286 
287  public:
293  static vtkIdType GetBytesize(){return 6*sizeof(int); };
294 
298  static int GetCellLinearIndex(const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3] );
299 
303  static void GetBounds(const vtkAMRBox& box, const double origin[3], const double spacing[3],double bounds[6]) ;
304 
309  static void GetBoxOrigin(const vtkAMRBox& box, const double X0[3], const double spacing[3],double x0[3]);
310 
315  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3], double x, double y, double z );
316 
320  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
321  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
322 
323  protected:
327  void Initialize( );
328 
335  bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q);
336 
337  private:
338  int LoCorner[3]; // lo corner cell id.
339  int HiCorner[3]; // hi corner cell id.
340 
342 
347  void BuildAMRBox(
348  const int ilo, const int jlo, const int klo,
349  const int ihi, const int jhi, const int khi );
350 };
352 
353 
354 //*****************************************************************************
356 
360 template <typename T>
362  T *pArray,
363  const vtkAMRBox &arrayRegion,
364  const vtkAMRBox &destRegion,
365  T fillValue)
366 {
367  // Convert regions to array index space. VTK arrays
368  // always start with 0,0,0.
369  int ofs[3];
370  ofs[0]=-arrayRegion.GetLoCorner()[0];
371  ofs[1]=-arrayRegion.GetLoCorner()[1];
372  ofs[2]=-arrayRegion.GetLoCorner()[2];
373  vtkAMRBox arrayDims(arrayRegion);
374  arrayDims.Shift(ofs);
375  vtkAMRBox destDims(destRegion);
376  destDims.Shift(ofs);
377  // Quick sanity check.
378  if (!arrayRegion.Contains(destRegion))
379  {
380  vtkGenericWarningMacro(
381  << "ERROR: Array must enclose the destination region. "
382  << "Aborting the fill.");
383  }
384  // Get the bounds of the indices we fill.
385  const int* destLo = destDims.GetLoCorner();
386  int destHi[3];
387  destDims.GetValidHiCorner(destHi);
388  // Get the array dimensions.
389  int arrayHi[3];
390  arrayDims.GetNumberOfCells(arrayHi);
391  // Fill.
392  for (int k=destLo[2]; k<=destHi[2]; ++k)
393  {
394  vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
395  for (int j=destLo[1]; j<=destHi[1]; ++j)
396  {
397  vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
398  for (int i=destLo[0]; i<=destHi[0]; ++i)
399  {
400  pArray[idx]=fillValue;
401  ++idx;
402  }
403  }
404  }
406 
407 }
408 
409 #endif
410 // VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:39
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:361
int vtkIdType
Definition: vtkType.h:287
void GetValidHiCorner(int hi[3]) const
Return a high corner.
void Shift(int i, int j, int k)
Shifts the box in index space.
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition: vtkAMRBox.h:167
vtkIdType GetNumberOfCells() const
Gets the number of cells enclosed by the box.
virtual ~vtkAMRBox()
Definition: vtkAMRBox.h:79
#define VTK_XYZ_GRID
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:151
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:293
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition: vtkAMRBox.h:95
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
const int * GetHiCorner() const
Definition: vtkAMRBox.h:152
bool Empty() const
Definition: vtkAMRBox.h:161
bool operator!=(const vtkAMRBox &other) const
Test if this box is NOT equal with the box instance on the rhs.
Definition: vtkAMRBox.h:186
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:85
bool Contains(int i, int j, int k) const
Test to see if a given cell index is inside this box.