VTK  9.2.20220703
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 =========================================================================*/
71 #ifndef vtkAMRBox_h
72 #define vtkAMRBox_h
73 
74 #include "vtkCommonDataModelModule.h" // For export macro
75 #include "vtkObject.h"
76 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
77 
78 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
79 {
80 public:
85 
89  vtkAMRBox(const vtkAMRBox& other);
90 
94  vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
95 
100  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
101  const double* globalOrigin, int gridDescription = VTK_XYZ_GRID);
102 
106  vtkAMRBox(const int lo[3], const int hi[3]);
107 
108  vtkAMRBox(const int dims[6]);
109 
113  vtkAMRBox& operator=(const vtkAMRBox& other);
114 
115  virtual ~vtkAMRBox() = default;
116 
118 
121  void Invalidate()
122  {
123  this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
124  this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
125  }
127 
131  bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
132 
136  void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc = VTK_XYZ_GRID);
137 
141  void SetDimensions(const int lo[3], const int hi[3], int desc = VTK_XYZ_GRID);
142 
146  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
147 
151  void GetDimensions(int lo[3], int hi[3]) const;
152 
156  void GetDimensions(int dims[6]) const;
157 
159 
163  void GetNumberOfCells(int num[3]) const;
165 
167 
171  void GetNumberOfNodes(int ext[3]) const;
174 
180  int ComputeDimension() const;
181 
185  const int* GetLoCorner() const { return this->LoCorner; }
186  const int* GetHiCorner() const { return this->HiCorner; }
187 
193  void GetValidHiCorner(int hi[3]) const;
194 
195  bool Empty() const { return this->IsInvalid(); }
196 
200  bool IsInvalid() const
201  {
202  return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
203  (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
204  }
205 
211  bool operator==(const vtkAMRBox& other) const;
212 
218  bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
219 
223  ostream& Print(ostream& os) const;
224 
226 
237  void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
238  void Serialize(int* buffer) const;
240 
247  void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
248 
255  bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, const int q) const;
256 
257  bool DoesIntersect(const vtkAMRBox& other) const;
258 
262  void Coarsen(int r);
263 
267  void Refine(int r);
268 
270 
273  void Grow(int byN);
274  void Shrink(int byN);
276 
278 
281  void Shift(int i, int j, int k);
282  void Shift(const int I[3]);
284 
290  bool Intersect(const vtkAMRBox& other);
291 
293 
296  bool Contains(int i, int j, int k) const;
297  bool Contains(const int I[3]) const;
299 
303  bool Contains(const vtkAMRBox&) const;
304 
310  void GetGhostVector(int r, int nghost[6]) const;
311 
316  void RemoveGhosts(int r);
317 
318 public:
324  static vtkIdType GetBytesize() { return 6 * sizeof(int); }
325 
329  static int GetCellLinearIndex(
330  const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3]);
331 
335  static void GetBounds(
336  const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
337 
342  static void GetBoxOrigin(
343  const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
344 
349  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
350  double x, double y, double z);
351 
355  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
356  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
357 
358 protected:
362  void Initialize();
363 
370  bool IntersectBoxAlongDimension(const vtkAMRBox& other, const int q);
371 
372 private:
373  int LoCorner[3]; // lo corner cell id.
374  int HiCorner[3]; // hi corner cell id.
375 
377 
382  void BuildAMRBox(
383  const int ilo, const int jlo, const int klo, const int ihi, const int jhi, const int khi);
385 };
386 
387 //*****************************************************************************
389 
393 template <typename T>
394 void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
395 {
396  // Convert regions to array index space. VTK arrays
397  // always start with 0,0,0.
398  int ofs[3];
399  ofs[0] = -arrayRegion.GetLoCorner()[0];
400  ofs[1] = -arrayRegion.GetLoCorner()[1];
401  ofs[2] = -arrayRegion.GetLoCorner()[2];
402  vtkAMRBox arrayDims(arrayRegion);
403  arrayDims.Shift(ofs);
404  vtkAMRBox destDims(destRegion);
405  destDims.Shift(ofs);
406  // Quick sanity check.
407  if (!arrayRegion.Contains(destRegion))
408  {
409  vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
410  << "Aborting the fill.");
411  }
412  // Get the bounds of the indices we fill.
413  const int* destLo = destDims.GetLoCorner();
414  int destHi[3];
415  destDims.GetValidHiCorner(destHi);
416  // Get the array dimensions.
417  int arrayHi[3];
418  arrayDims.GetNumberOfCells(arrayHi);
419  // Fill.
420  for (int k = destLo[2]; k <= destHi[2]; ++k)
421  {
422  vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
423  for (int j = destLo[1]; j <= destHi[1]; ++j)
424  {
425  vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
426  for (int i = destLo[0]; i <= destHi[0]; ++i)
427  {
428  pArray[idx] = fillValue;
429  ++idx;
430  }
431  }
432  }
434 }
435 
436 #endif
437 // VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:79
bool Contains(const vtkAMRBox &) const
Test to see if a given box is inside this box.
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(const int dims[6])
vtkAMRBox & operator=(const vtkAMRBox &other)
Copy the other box to this box.
vtkAMRBox(const vtkAMRBox &other)
Copy construct this box from another.
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:121
void Serialize(int *buffer) const
Serializes this object instance into a byte-stream.
void Grow(int byN)
Grows the box in all directions.
int ComputeDimension() const
Determines the dimension of the AMR box given the box indices.
void Shift(const int I[3])
Shifts the box in index space.
void Refine(int r)
Refine the box.
bool Contains(const int I[3]) const
Test to see if a given cell index is inside this box.
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:324
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.
bool operator==(const vtkAMRBox &other) const
Test if this box is equal with the box instance on the rhs.
void GetValidHiCorner(int hi[3]) const
Return a high corner.
ostream & Print(ostream &os) const
Send the box to a stream.
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:185
void Serialize(unsigned char *&buffer, vtkIdType &bytesize)
Serializes this object instance into a byte-stream.
void SetDimensions(const int lo[3], const int hi[3], int desc=VTK_XYZ_GRID)
Set the dimensions of the box.
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition: vtkAMRBox.h:131
static void GetBounds(const vtkAMRBox &box, const double origin[3], const double spacing[3], double bounds[6])
Get the bounds of this box.
vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi)
Construct a specific 3D box.
bool DoesIntersect(const vtkAMRBox &other) const
void Shift(int i, int j, int k)
Shifts the box in index space.
void GetDimensions(int lo[3], int hi[3]) const
Get the dimensions of this box.
bool Empty() const
Definition: vtkAMRBox.h:195
bool Contains(int i, int j, int k) const
Test to see if a given cell index is inside this box.
void Deserialize(unsigned char *buffer, const vtkIdType &bytesize)
Deserializes this object instance from the given byte-stream.
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.
void Coarsen(int r)
Coarsen the box.
void Initialize()
Initializes this box instance.
vtkAMRBox(const int lo[3], const int hi[3])
Construct a specific box.
bool Intersect(const vtkAMRBox &other)
Intersect this box with another box in place.
vtkAMRBox()
Construct the empty box.
void RemoveGhosts(int r)
Given an AMR box and the refinement ratio, r, this shrinks the AMRBox.
void GetNumberOfNodes(int ext[3]) const
Gets the number of nodes required to construct a physical representation of the box.
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.
void GetDimensions(int dims[6]) const
Get the dimensions of this box.
bool operator!=(const vtkAMRBox &other) const
Test if this box is NOT equal with the box instance on the rhs.
Definition: vtkAMRBox.h:218
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.
vtkIdType GetNumberOfNodes() const
Gets the number of nodes required to construct a physical representation of the box.
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.
void SetDimensions(const int dims[6], int desc=VTK_XYZ_GRID)
Set the dimensions of the box.
void GetNumberOfCells(int num[3]) const
Gets the number of cells enclosed by the box.
vtkIdType GetNumberOfCells() const
Gets the number of cells enclosed by the box.
const int * GetHiCorner() const
Definition: vtkAMRBox.h:186
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...
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 ...
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition: vtkAMRBox.h:200
void Shrink(int byN)
Grows the box in all directions.
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...
virtual ~vtkAMRBox()=default
Computes the portion of a dataset which is inside a selection.
@ spacing
Definition: vtkX3D.h:487
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:394
#define VTK_XYZ_GRID
int vtkIdType
Definition: vtkType.h:325