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:
43 
45  vtkAMRBox(const vtkAMRBox &other);
46 
48 
50  int ilo,int jlo,int klo,
51  int ihi,int jhi,int khi);
53 
55 
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 
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 
115  void GetNumberOfCells(int num[3]) const;
117 
119 
121  void GetNumberOfNodes(int ext[3]) 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  {
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
vtkAMRBox
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:39
vtkgl::z
GLdouble GLdouble z
Definition: vtkgl.h:11754
vtkAMRBox::Coarsen
void Coarsen(int r)
vtkAMRBox::Intersect
bool Intersect(const vtkAMRBox &other)
vtkAMRBox::Contains
bool Contains(const int I[3]) const
vtkAMRBox::SetDimensions
void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID)
vtkgl::h
GLfloat GLfloat GLfloat GLfloat h
Definition: vtkgl.h:14364
vtkAMRBox::Print
ostream & Print(ostream &os) const
vtkAMRBox::DoesBoxIntersectAlongDimension
bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkCommonDataModelModule.h
vtkAMRBox::GetBounds
static void GetBounds(const vtkAMRBox &box, const double origin[3], const double spacing[3], double bounds[6])
vtkAMRBox::Deserialize
void Deserialize(unsigned char *buffer, const vtkIdType &bytesize)
vtkAMRBox::Shift
void Shift(const int I[3])
vtkAMRBox::EmptyDimension
bool EmptyDimension(int i) const
Definition: vtkAMRBox.h:91
vtkAMRBox::Grow
void Grow(int byN)
vtkAMRBox::vtkAMRBox
vtkAMRBox()
vtkAMRBox::vtkAMRBox
vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi)
vtkAMRBox::Serialize
void Serialize(int *buffer) const
vtkgl::x
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
vtkAMRBox::GetHiCorner
const int * GetHiCorner() const
Definition: vtkAMRBox.h:133
vtkAMRBox::vtkAMRBox
vtkAMRBox(const int lo[3], const int hi[3])
FillRegion
void FillRegion(T *pArray, const vtkAMRBox &arrayRegion, const vtkAMRBox &destRegion, T fillValue)
Definition: vtkAMRBox.h:288
vtkAMRBox::GetLoCorner
const int * GetLoCorner() const
Definition: vtkAMRBox.h:132
vtkAMRBox::Empty
bool Empty() const
Definition: vtkAMRBox.h:141
vtkAMRBox::GetNumberOfNodes
void GetNumberOfNodes(int ext[3]) const
vtkAMRBox::GetNumberOfNodes
vtkIdType GetNumberOfNodes() const
vtkAMRBox::vtkAMRBox
vtkAMRBox(const int dims[6])
vtkAMRBox::vtkAMRBox
vtkAMRBox(const double *origin, const int *dimensions, const double *spacing, const double *globalOrigin, int gridDescription=VTK_XYZ_GRID)
vtkAMRBox::Shift
void Shift(int i, int j, int k)
vtkAMRBox::~vtkAMRBox
virtual ~vtkAMRBox()
Definition: vtkAMRBox.h:78
vtkAMRBox::Contains
bool Contains(const vtkAMRBox &) const
vtkStructuredData.h
vtkAMRBox::operator==
bool operator==(const vtkAMRBox &other) const
vtkAMRBox::SetDimensions
void SetDimensions(const int dims[6], int desc=VTK_XYZ_GRID)
vtkAMRBox::Contains
bool Contains(int i, int j, int k) const
vtkAMRBox::GetNumberOfCells
vtkIdType GetNumberOfCells() const
VTK_XYZ_GRID
#define VTK_XYZ_GRID
Definition: vtkStructuredData.h:47
vtkgl::num
GLuint GLuint num
Definition: vtkgl.h:16907
vtkAMRBox::GetDimensions
void GetDimensions(int lo[3], int hi[3]) const
vtkAMRBox::GetBytesize
static vtkIdType GetBytesize()
Definition: vtkAMRBox.h:236
vtkAMRBox::vtkAMRBox
vtkAMRBox(const vtkAMRBox &other)
vtkAMRBox::RemoveGhosts
void RemoveGhosts(int r)
vtkAMRBox::GetBoxOrigin
static void GetBoxOrigin(const vtkAMRBox &box, const double X0[3], const double spacing[3], double x0[3])
vtkAMRBox::GetDimensions
void GetDimensions(int dims[6]) const
vtkAMRBox::Shrink
void Shrink(int byN)
vtkAMRBox::Refine
void Refine(int r)
vtkObject.h
vtkX3D::spacing
@ spacing
Definition: vtkX3D.h:481
vtkAMRBox::GetValidHiCorner
void GetValidHiCorner(int hi[3]) const
vtkgl::r
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
vtkgl::y
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
vtkgl::buffer
GLuint buffer
Definition: vtkgl.h:11839
vtkGenericWarningMacro
#define vtkGenericWarningMacro(x)
Definition: vtkSetGet.h:450
vtkAMRBox::IsInvalid
bool IsInvalid() const
Definition: vtkAMRBox.h:146
vtkAMRBox::Invalidate
void Invalidate()
Definition: vtkAMRBox.h:82
vtkAMRBox::DoesIntersect
bool DoesIntersect(const vtkAMRBox &other) const
vtkAMRBox::ComputeDimension
int ComputeDimension() const
vtkAMRBox::Serialize
void Serialize(unsigned char *&buffer, vtkIdType &bytesize)
VTKCOMMONDATAMODEL_EXPORT
#define VTKCOMMONDATAMODEL_EXPORT
Definition: vtkCommonDataModelModule.h:15
vtkAMRBox::GetNumberOfCells
void GetNumberOfCells(int num[3]) const
vtkAMRBox::Initialize
void Initialize()
vtkAMRBox::operator=
vtkAMRBox & operator=(const vtkAMRBox &other)
q
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
vtkAMRBox::HasPoint
static bool HasPoint(const vtkAMRBox &box, const double origin[3], const double spacing[3], double x, double y, double z)
vtkAMRBox::SetDimensions
void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID)
vtkAMRBox::operator!=
bool operator!=(const vtkAMRBox &other) const
Definition: vtkAMRBox.h:163
int
int
Definition: vtkVectorOperators.h:164
vtkAMRBox::IntersectBoxAlongDimension
bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q)
vtkAMRBox::GetCellLinearIndex
static int GetCellLinearIndex(const vtkAMRBox &box, const int i, const int j, const int k, int imageDimension[3])
vtkAMRBox::ComputeStructuredCoordinates
static int ComputeStructuredCoordinates(const vtkAMRBox &box, const double dataOrigin[3], const double h[3], const double x[3], int ijk[3], double pcoords[3])
vtkAMRBox::vtkAMRBox
vtkAMRBox(int ilo, int jlo, int ihi, int jhi)
vtkAMRBox::GetGhostVector
void GetGhostVector(int r, int nghost[6]) const