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 =========================================================================*/
31 #ifndef vtkAMRBox_h
32 #define vtkAMRBox_h
33 
34 #include "vtkCommonDataModelModule.h" // For export macro
35 #include "vtkObject.h"
36 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
37 
39 {
40  public:
42  vtkAMRBox();
43 
45  vtkAMRBox(const vtkAMRBox &other);
46 
48 
49  vtkAMRBox(
50  int ilo,int jlo,int klo,
51  int ihi,int jhi,int khi);
53 
55 
56  vtkAMRBox(
57  int ilo,int jlo,
58  int ihi,int jhi);
60 
62 
65  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
66  const double* globalOrigin, int gridDescription=VTK_XYZ_GRID);
68 
70  vtkAMRBox(const int lo[3], const int hi[3]);
71 
72  vtkAMRBox(const int dims[6]);
73 
74 
76  vtkAMRBox &operator=(const vtkAMRBox &other);
77 
78  virtual ~vtkAMRBox(){}
79 
81 
82  void Invalidate()
83  {
84  this->LoCorner[0]=this->LoCorner[1]=this->LoCorner[2]=0;
85  this->HiCorner[0]=this->HiCorner[1]=this->HiCorner[2]=-2;
86  }
88 
91  bool EmptyDimension(int i) const{ return HiCorner[i]<=LoCorner[i]-1;}
92 
94 
95  void SetDimensions(
96  int ilo, int jlo, int klo,
97  int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID);
99 
101  void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID);
102 
104  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
105 
107  void GetDimensions(int lo[3], int hi[3]) const;
108 
110  void GetDimensions(int dims[6]) const;
111 
113 
114  vtkIdType GetNumberOfCells() const;
115  void GetNumberOfCells(int num[3]) const;
117 
119 
121  void GetNumberOfNodes(int ext[3]) const;
122  vtkIdType GetNumberOfNodes() const;
124 
128  int ComputeDimension() const;
129 
131 
132  const int *GetLoCorner() const { return this->LoCorner; }
133  const int *GetHiCorner() const { return this->HiCorner; }
135 
139  void GetValidHiCorner(int hi[3]) const;
140 
141  bool Empty() const
142  {return this->IsInvalid();}
143 
145 
146  bool IsInvalid() const
147  {
148  return ((this->HiCorner[0] < this->LoCorner[0]-1) ||
149  (this->HiCorner[1] < this->LoCorner[1]-1) ||
150  (this->HiCorner[2] < this->LoCorner[2]-1));
151  }
153 
157  bool operator==(const vtkAMRBox &other) const;
158 
160 
163  bool operator!=(const vtkAMRBox &other) const
164  { return( !(*this == other) ); }
166 
168  ostream &Print(ostream &os) const;
169 
171 
176  void Serialize( unsigned char*& buffer, vtkIdType &bytesize );
177  void Serialize(int* buffer) const;
179 
182  void Deserialize( unsigned char* buffer, const vtkIdType &bytesize );
183 
188  bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const;
189 
190  bool DoesIntersect(const vtkAMRBox &other) const;
191 
193  void Coarsen(int r);
194 
196  void Refine(int r);
197 
199 
200  void Grow(int byN);
201  void Shrink(int byN);
203 
205 
206  void Shift(int i, int j, int k);
207  void Shift(const int I[3]);
209 
213  bool Intersect(const vtkAMRBox &other);
214 
216 
217  bool Contains(int i,int j,int k) const;
218  bool Contains(const int I[3]) const;
220 
222  bool Contains(const vtkAMRBox&) const;
223 
227  void GetGhostVector(int r, int nghost[6]) const;
228 
230  void RemoveGhosts(int r);
231 
232  public:
236  static vtkIdType GetBytesize(){return 6*sizeof(int); };
237 
239  static int GetCellLinearIndex(const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3] );
240 
242  static void GetBounds(const vtkAMRBox& box, const double origin[3], const double spacing[3],double bounds[6]) ;
243 
246  static void GetBoxOrigin(const vtkAMRBox& box, const double X0[3], const double spacing[3],double x0[3]);
247 
250  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3], double x, double y, double z );
251 
253 
254  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
255  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
257 
258  protected:
260  void Initialize( );
261 
266  bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q);
267 
268  private:
269  int LoCorner[3]; // lo corner cell id.
270  int HiCorner[3]; // hi corner cell id.
271 
273 
276  void BuildAMRBox(
277  const int ilo, const int jlo, const int klo,
278  const int ihi, const int jhi, const int khi );
279 };
281 
282 
283 //*****************************************************************************
285 
287 template <typename T>
289  T *pArray,
290  const vtkAMRBox &arrayRegion,
291  const vtkAMRBox &destRegion,
292  T fillValue)
293 {
294  // Convert regions to array index space. VTK arrays
295  // always start with 0,0,0.
296  int ofs[3];
297  ofs[0]=-arrayRegion.GetLoCorner()[0];
298  ofs[1]=-arrayRegion.GetLoCorner()[1];
299  ofs[2]=-arrayRegion.GetLoCorner()[2];
300  vtkAMRBox arrayDims(arrayRegion);
301  arrayDims.Shift(ofs);
302  vtkAMRBox destDims(destRegion);
303  destDims.Shift(ofs);
304  // Quick sanity check.
305  if (!arrayRegion.Contains(destRegion))
306  {
307  vtkGenericWarningMacro(
308  << "ERROR: Array must enclose the destination region. "
309  << "Aborting the fill.");
310  }
311  // Get the bounds of the indices we fill.
312  const int* destLo = destDims.GetLoCorner();
313  int destHi[3];
314  destDims.GetValidHiCorner(destHi);
315  // Get the array dimensions.
316  int arrayHi[3];
317  arrayDims.GetNumberOfCells(arrayHi);
318  // Fill.
319  for (int k=destLo[2]; k<=destHi[2]; ++k)
320  {
321  vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
322  for (int j=destLo[1]; j<=destHi[1]; ++j)
323  {
324  vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
325  for (int i=destLo[0]; i<=destHi[0]; ++i)
326  {
327  pArray[idx]=fillValue;
328  ++idx;
329  }
330  }
331  }
333 
334 }
335 
336 #endif
337 // VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:38
void FillRegion(T *pArray, const vtkAMRBox &arrayRegion, const vtkAMRBox &destRegion, T fillValue)
Definition: vtkAMRBox.h:288
int vtkIdType
Definition: vtkType.h:275
void GetValidHiCorner(int hi[3]) const
void Shift(int i, int j, int k)
bool IsInvalid() const
Definition: vtkAMRBox.h:146
vtkIdType GetNumberOfCells() const
virtual ~vtkAMRBox()
Definition: vtkAMRBox.h:78
#define VTK_XYZ_GRID
const int * GetLoCorner() const
Definition: vtkAMRBox.h:132
static vtkIdType GetBytesize()
Definition: vtkAMRBox.h:236
bool EmptyDimension(int i) const
Definition: vtkAMRBox.h:91
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
const int * GetHiCorner() const
Definition: vtkAMRBox.h:133
bool Empty() const
Definition: vtkAMRBox.h:141
bool operator!=(const vtkAMRBox &other) const
Definition: vtkAMRBox.h:163
#define VTKCOMMONDATAMODEL_EXPORT
void Invalidate()
Definition: vtkAMRBox.h:82
bool Contains(int i, int j, int k) const