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 
58  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
59  const double* globalOrigin, int gridDescription=VTK_XYZ_GRID);
61 
63  vtkAMRBox(const int lo[3], const int hi[3]);
64 
65  vtkAMRBox(const int dims[6]);
66 
67 
69  vtkAMRBox &operator=(const vtkAMRBox &other);
70 
71  virtual ~vtkAMRBox(){}
72 
74 
75  void Invalidate()
76  {
77  this->LoCorner[0]=this->LoCorner[1]=this->LoCorner[2]=0;
78  this->HiCorner[0]=this->HiCorner[1]=this->HiCorner[2]=-2;
79  }
81 
84  bool EmptyDimension(int i) const{ return HiCorner[i]<=LoCorner[i]-1;}
85 
87 
88  void SetDimensions(
89  int ilo, int jlo, int klo,
90  int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID);
92 
94  void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID);
95 
97  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
98 
100  void GetDimensions(int lo[3], int hi[3]) const;
101 
103  void GetDimensions(int dims[6]) const;
104 
106 
107  vtkIdType GetNumberOfCells() const;
108  void GetNumberOfCells(int num[3]) const;
110 
112 
114  void GetNumberOfNodes(int ext[3]) const;
115  vtkIdType GetNumberOfNodes() const;
117 
121  int ComputeDimension() const;
122 
124 
125  const int *GetLoCorner() const { return this->LoCorner; }
126  const int *GetHiCorner() const { return this->HiCorner; }
128 
132  void GetValidHiCorner(int hi[3]) const;
133 
134  bool Empty() const
135  {return this->IsInvalid();}
136 
138 
139  bool IsInvalid() const
140  {
141  return ((this->HiCorner[0] < this->LoCorner[0]-1) ||
142  (this->HiCorner[1] < this->LoCorner[1]-1) ||
143  (this->HiCorner[2] < this->LoCorner[2]-1));
144  }
146 
150  bool operator==(const vtkAMRBox &other) const;
151 
153 
156  bool operator!=(const vtkAMRBox &other) const
157  { return( !(*this == other) ); }
159 
161  ostream &Print(ostream &os) const;
162 
164 
169  void Serialize( unsigned char*& buffer, vtkIdType &bytesize );
170  void Serialize(int* buffer) const;
172 
175  void Deserialize( unsigned char* buffer, const vtkIdType &bytesize );
176 
181  bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const;
182 
183  bool DoesIntersect(const vtkAMRBox &other) const;
184 
186  void Coarsen(int r);
187 
189  void Refine(int r);
190 
192 
193  void Grow(int byN);
194  void Shrink(int byN);
196 
198 
199  void Shift(int i, int j, int k);
200  void Shift(const int I[3]);
202 
206  bool Intersect(const vtkAMRBox &other);
207 
209 
210  bool Contains(int i,int j,int k) const;
211  bool Contains(const int I[3]) const;
213 
215  bool Contains(const vtkAMRBox&) const;
216 
220  void GetGhostVector(int r, int nghost[6]) const;
221 
223  void RemoveGhosts(int r);
224 
225  public:
229  static vtkIdType GetBytesize(){return 6*sizeof(int); };
230 
232  static int GetCellLinearIndex(const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3] );
233 
235  static void GetBounds(const vtkAMRBox& box, const double origin[3], const double spacing[3],double bounds[6]) ;
236 
239  static void GetBoxOrigin(const vtkAMRBox& box, const double X0[3], const double spacing[3],double x0[3]);
240 
243  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3], double x, double y, double z );
244 
246 
247  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
248  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
250 
251  protected:
253  void Initialize( );
254 
259  bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q);
260 
261  private:
262  int LoCorner[3]; // lo corner cell id.
263  int HiCorner[3]; // hi corner cell id.
264 
266 
269  void BuildAMRBox(
270  const int ilo, const int jlo, const int klo,
271  const int ihi, const int jhi, const int khi );
272 };
274 
275 
276 //*****************************************************************************
278 
280 template <typename T>
282  T *pArray,
283  const vtkAMRBox &arrayRegion,
284  const vtkAMRBox &destRegion,
285  T fillValue)
286 {
287  // Convert regions to array index space. VTK arrays
288  // always start with 0,0,0.
289  int ofs[3];
290  ofs[0]=-arrayRegion.GetLoCorner()[0];
291  ofs[1]=-arrayRegion.GetLoCorner()[1];
292  ofs[2]=-arrayRegion.GetLoCorner()[2];
293  vtkAMRBox arrayDims(arrayRegion);
294  arrayDims.Shift(ofs);
295  vtkAMRBox destDims(destRegion);
296  destDims.Shift(ofs);
297  // Quick sanity check.
298  if (!arrayRegion.Contains(destRegion))
299  {
300  vtkGenericWarningMacro(
301  << "ERROR: Array must enclose the destination region. "
302  << "Aborting the fill.");
303  }
304  // Get the bounds of the indices we fill.
305  const int* destLo = destDims.GetLoCorner();
306  int destHi[3];
307  destDims.GetValidHiCorner(destHi);
308  // Get the array dimensions.
309  int arrayHi[3];
310  arrayDims.GetNumberOfCells(arrayHi);
311  // Fill.
312  for (int k=destLo[2]; k<=destHi[2]; ++k)
313  {
314  vtkIdType kOfs=k*arrayHi[0]*arrayHi[1];
315  for (int j=destLo[1]; j<=destHi[1]; ++j)
316  {
317  vtkIdType idx=kOfs+j*arrayHi[0]+destLo[0];
318  for (int i=destLo[0]; i<=destHi[0]; ++i)
319  {
320  pArray[idx]=fillValue;
321  ++idx;
322  }
323  }
324  }
326 
327 }
328 
329 #endif
330 // 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:281
int vtkIdType
Definition: vtkType.h:247
void GetValidHiCorner(int hi[3]) const
void Shift(int i, int j, int k)
bool IsInvalid() const
Definition: vtkAMRBox.h:139
vtkIdType GetNumberOfCells() const
virtual ~vtkAMRBox()
Definition: vtkAMRBox.h:71
#define VTK_XYZ_GRID
const int * GetLoCorner() const
Definition: vtkAMRBox.h:125
static vtkIdType GetBytesize()
Definition: vtkAMRBox.h:229
bool EmptyDimension(int i) const
Definition: vtkAMRBox.h:84
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:126
bool Empty() const
Definition: vtkAMRBox.h:134
bool operator!=(const vtkAMRBox &other) const
Definition: vtkAMRBox.h:156
#define VTKCOMMONDATAMODEL_EXPORT
void Invalidate()
Definition: vtkAMRBox.h:75
bool Contains(int i, int j, int k) const