VTK  9.1.0
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 =========================================================================*/
65 #ifndef vtkAMRBox_h
66 #define vtkAMRBox_h
67 
68 #include "vtkCommonDataModelModule.h" // For export macro
69 #include "vtkObject.h"
70 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
71 
72 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
73 {
74 public:
79 
83  vtkAMRBox(const vtkAMRBox& other);
84 
88  vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
89 
94  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
95  const double* globalOrigin, int gridDescription = VTK_XYZ_GRID);
96 
100  vtkAMRBox(const int lo[3], const int hi[3]);
101 
102  vtkAMRBox(const int dims[6]);
103 
107  vtkAMRBox& operator=(const vtkAMRBox& other);
108 
109  virtual ~vtkAMRBox() = default;
110 
112 
115  void Invalidate()
116  {
117  this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
118  this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
119  }
121 
125  bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
126 
130  void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc = VTK_XYZ_GRID);
131 
135  void SetDimensions(const int lo[3], const int hi[3], int desc = VTK_XYZ_GRID);
136 
140  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
141 
145  void GetDimensions(int lo[3], int hi[3]) const;
146 
150  void GetDimensions(int dims[6]) const;
151 
153 
157  void GetNumberOfCells(int num[3]) const;
159 
161 
165  void GetNumberOfNodes(int ext[3]) const;
168 
174  int ComputeDimension() const;
175 
179  const int* GetLoCorner() const { return this->LoCorner; }
180  const int* GetHiCorner() const { return this->HiCorner; }
181 
187  void GetValidHiCorner(int hi[3]) const;
188 
189  bool Empty() const { return this->IsInvalid(); }
190 
194  bool IsInvalid() const
195  {
196  return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
197  (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
198  }
199 
205  bool operator==(const vtkAMRBox& other) const;
206 
212  bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
213 
217  ostream& Print(ostream& os) const;
218 
220 
231  void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
232  void Serialize(int* buffer) const;
234 
241  void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
242 
249  bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, const int q) const;
250 
251  bool DoesIntersect(const vtkAMRBox& other) const;
252 
256  void Coarsen(int r);
257 
261  void Refine(int r);
262 
264 
267  void Grow(int byN);
268  void Shrink(int byN);
270 
272 
275  void Shift(int i, int j, int k);
276  void Shift(const int I[3]);
278 
284  bool Intersect(const vtkAMRBox& other);
285 
287 
290  bool Contains(int i, int j, int k) const;
291  bool Contains(const int I[3]) const;
293 
297  bool Contains(const vtkAMRBox&) const;
298 
304  void GetGhostVector(int r, int nghost[6]) const;
305 
310  void RemoveGhosts(int r);
311 
312 public:
318  static vtkIdType GetBytesize() { return 6 * sizeof(int); }
319 
323  static int GetCellLinearIndex(
324  const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3]);
325 
329  static void GetBounds(
330  const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
331 
336  static void GetBoxOrigin(
337  const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
338 
343  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
344  double x, double y, double z);
345 
349  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
350  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
351 
352 protected:
356  void Initialize();
357 
364  bool IntersectBoxAlongDimension(const vtkAMRBox& other, const int q);
365 
366 private:
367  int LoCorner[3]; // lo corner cell id.
368  int HiCorner[3]; // hi corner cell id.
369 
371 
376  void BuildAMRBox(
377  const int ilo, const int jlo, const int klo, const int ihi, const int jhi, const int khi);
379 };
380 
381 //*****************************************************************************
383 
387 template <typename T>
388 void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
389 {
390  // Convert regions to array index space. VTK arrays
391  // always start with 0,0,0.
392  int ofs[3];
393  ofs[0] = -arrayRegion.GetLoCorner()[0];
394  ofs[1] = -arrayRegion.GetLoCorner()[1];
395  ofs[2] = -arrayRegion.GetLoCorner()[2];
396  vtkAMRBox arrayDims(arrayRegion);
397  arrayDims.Shift(ofs);
398  vtkAMRBox destDims(destRegion);
399  destDims.Shift(ofs);
400  // Quick sanity check.
401  if (!arrayRegion.Contains(destRegion))
402  {
403  vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
404  << "Aborting the fill.");
405  }
406  // Get the bounds of the indices we fill.
407  const int* destLo = destDims.GetLoCorner();
408  int destHi[3];
409  destDims.GetValidHiCorner(destHi);
410  // Get the array dimensions.
411  int arrayHi[3];
412  arrayDims.GetNumberOfCells(arrayHi);
413  // Fill.
414  for (int k = destLo[2]; k <= destHi[2]; ++k)
415  {
416  vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
417  for (int j = destLo[1]; j <= destHi[1]; ++j)
418  {
419  vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
420  for (int i = destLo[0]; i <= destHi[0]; ++i)
421  {
422  pArray[idx] = fillValue;
423  ++idx;
424  }
425  }
426  }
428 }
429 
430 #endif
431 // VTK-HeaderTest-Exclude: vtkAMRBox.h
vtkAMRBox
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:73
vtkAMRBox::Coarsen
void Coarsen(int r)
Coarsen the box.
vtkAMRBox::Intersect
bool Intersect(const vtkAMRBox &other)
Intersect this box with another box in place.
vtkAMRBox::Contains
bool Contains(const int I[3]) const
Test to see if a given cell index is inside this box.
vtkAMRBox::SetDimensions
void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc=VTK_XYZ_GRID)
Set the dimensions of the box.
vtkAMRBox::Print
ostream & Print(ostream &os) const
Send the box to a stream.
vtkAMRBox::DoesBoxIntersectAlongDimension
bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, const int q) const
Checks if this instance of vtkAMRBox intersects with the box passed through the argument list along t...
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkAMRBox::GetBounds
static void GetBounds(const vtkAMRBox &box, const double origin[3], const double spacing[3], double bounds[6])
Get the bounds of this box.
vtkAMRBox::Deserialize
void Deserialize(unsigned char *buffer, const vtkIdType &bytesize)
Deserializes this object instance from the given byte-stream.
vtkAMRBox::Shift
void Shift(const int I[3])
Shifts the box in index space.
vtkAMRBox::EmptyDimension
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition: vtkAMRBox.h:125
vtkAMRBox::Grow
void Grow(int byN)
Grows the box in all directions.
vtkAMRBox::vtkAMRBox
vtkAMRBox()
Construct the empty box.
vtkAMRBox::vtkAMRBox
vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi)
Construct a specific 3D box.
vtkAMRBox::Serialize
void Serialize(int *buffer) const
Serializes this object instance into a byte-stream.
vtkAMRBox::GetHiCorner
const int * GetHiCorner() const
Definition: vtkAMRBox.h:180
vtkAMRBox::vtkAMRBox
vtkAMRBox(const int lo[3], const int hi[3])
Construct a specific box.
FillRegion
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:388
vtkAMRBox::GetLoCorner
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:179
vtkAMRBox::Empty
bool Empty() const
Definition: vtkAMRBox.h:189
vtkAMRBox::GetNumberOfNodes
void GetNumberOfNodes(int ext[3]) const
Gets the number of nodes required to construct a physical representation of the box.
vtkAMRBox::GetNumberOfNodes
vtkIdType GetNumberOfNodes() const
Gets the number of nodes required to construct a physical representation of the box.
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)
Construct an AMR box from the description a vtkUniformGrid Note that the dimensions specify the node ...
vtkAMRBox::Shift
void Shift(int i, int j, int k)
Shifts the box in index space.
vtkAMRBox::Contains
bool Contains(const vtkAMRBox &) const
Test to see if a given box is inside this box.
vtkStructuredData.h
vtkAMRBox::operator==
bool operator==(const vtkAMRBox &other) const
Test if this box is equal with the box instance on the rhs.
vtkAMRBox::SetDimensions
void SetDimensions(const int dims[6], int desc=VTK_XYZ_GRID)
Set the dimensions of the box.
vtkAMRBox::Contains
bool Contains(int i, int j, int k) const
Test to see if a given cell index is inside this box.
vtkAMRBox::GetNumberOfCells
vtkIdType GetNumberOfCells() const
Gets the number of cells enclosed by the box.
VTK_XYZ_GRID
#define VTK_XYZ_GRID
Definition: vtkStructuredData.h:75
vtkAMRBox::GetDimensions
void GetDimensions(int lo[3], int hi[3]) const
Get the dimensions of this box.
vtkAMRBox::GetBytesize
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:318
vtkAMRBox::vtkAMRBox
vtkAMRBox(const vtkAMRBox &other)
Copy construct this box from another.
vtkAMRBox::RemoveGhosts
void RemoveGhosts(int r)
Given an AMR box and the refinement ratio, r, this shrinks the AMRBox.
vtkAMRBox::GetBoxOrigin
static void GetBoxOrigin(const vtkAMRBox &box, const double X0[3], const double spacing[3], double x0[3])
Get the world space origin of this box.
vtkAMRBox::GetDimensions
void GetDimensions(int dims[6]) const
Get the dimensions of this box.
vtkAMRBox::Shrink
void Shrink(int byN)
Grows the box in all directions.
vtkAMRBox::Refine
void Refine(int r)
Refine the box.
vtkObject.h
vtkX3D::spacing
@ spacing
Definition: vtkX3D.h:487
vtkAMRBox::GetValidHiCorner
void GetValidHiCorner(int hi[3]) const
Return a high corner.
vtkAMRBox::IsInvalid
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition: vtkAMRBox.h:194
vtkAMRBox::Invalidate
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:115
vtkAMRBox::DoesIntersect
bool DoesIntersect(const vtkAMRBox &other) const
vtkAMRBox::ComputeDimension
int ComputeDimension() const
Determines the dimension of the AMR box given the box indices.
vtkAMRBox::Serialize
void Serialize(unsigned char *&buffer, vtkIdType &bytesize)
Serializes this object instance into a byte-stream.
vtkAMRBox::GetNumberOfCells
void GetNumberOfCells(int num[3]) const
Gets the number of cells enclosed by the box.
vtkAMRBox::Initialize
void Initialize()
Initializes this box instance.
vtkAMRBox::~vtkAMRBox
virtual ~vtkAMRBox()=default
vtkAMRBox::operator=
vtkAMRBox & operator=(const vtkAMRBox &other)
Copy the other box to this box.
vtkAMRBox::HasPoint
static bool HasPoint(const vtkAMRBox &box, const double origin[3], const double spacing[3], double x, double y, double z)
Checks if the point is inside this AMRBox instance.
vtkAMRBox::SetDimensions
void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID)
Set the dimensions of the box.
vtkAMRBox::operator!=
bool operator!=(const vtkAMRBox &other) const
Test if this box is NOT equal with the box instance on the rhs.
Definition: vtkAMRBox.h:212
h
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
vtkAMRBox::IntersectBoxAlongDimension
bool IntersectBoxAlongDimension(const vtkAMRBox &other, const int q)
Intersects this instance of vtkAMRbox with box passed through the argument list along the given dimen...
vtkAMRBox::GetCellLinearIndex
static int GetCellLinearIndex(const vtkAMRBox &box, const int i, const int j, const int k, int imageDimension[3])
Returns the linear index of the given cell structured coordinates.
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])
Compute structured coordinates.
vtkAMRBox::GetGhostVector
void GetGhostVector(int r, int nghost[6]) const
Given an AMR box and the refinement ratio, r, this method computes the number of ghost layers in each...