VTK  9.2.6
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 =========================================================================*/
32 #ifndef vtkAMRBox_h
33 #define vtkAMRBox_h
34 
35 #include "vtkCommonDataModelModule.h" // For export macro
36 #include "vtkObject.h"
37 #include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
38 
39 class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
40 {
41 public:
45  vtkAMRBox();
46 
50  vtkAMRBox(const vtkAMRBox& other);
51 
55  vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
56 
61  vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
62  const double* globalOrigin, int gridDescription = VTK_XYZ_GRID);
63 
67  vtkAMRBox(const int lo[3], const int hi[3]);
68 
69  vtkAMRBox(const int dims[6]);
70 
74  vtkAMRBox& operator=(const vtkAMRBox& other);
75 
76  virtual ~vtkAMRBox() = default;
77 
79 
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 
92  bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
93 
97  void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc = VTK_XYZ_GRID);
98 
102  void SetDimensions(const int lo[3], const int hi[3], int desc = VTK_XYZ_GRID);
103 
107  void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
108 
112  void GetDimensions(int lo[3], int hi[3]) const;
113 
117  void GetDimensions(int dims[6]) const;
118 
120 
123  vtkIdType GetNumberOfCells() const;
124  void GetNumberOfCells(int num[3]) const;
126 
128 
132  void GetNumberOfNodes(int ext[3]) const;
133  vtkIdType GetNumberOfNodes() const;
135 
141  int ComputeDimension() const;
142 
146  const int* GetLoCorner() const { return this->LoCorner; }
147  const int* GetHiCorner() const { return this->HiCorner; }
148 
154  void GetValidHiCorner(int hi[3]) const;
155 
156  bool Empty() const { return this->IsInvalid(); }
157 
161  bool IsInvalid() const
162  {
163  return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
164  (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
165  }
166 
172  bool operator==(const vtkAMRBox& other) const;
173 
179  bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
180 
184  ostream& Print(ostream& os) const;
185 
187 
198  void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
199  void Serialize(int* buffer) const;
201 
208  void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
209 
216  bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, const int q) const;
217 
218  bool DoesIntersect(const vtkAMRBox& other) const;
219 
223  void Coarsen(int r);
224 
228  void Refine(int r);
229 
231 
234  void Grow(int byN);
235  void Shrink(int byN);
237 
239 
242  void Shift(int i, int j, int k);
243  void Shift(const int I[3]);
245 
251  bool Intersect(const vtkAMRBox& other);
252 
254 
257  bool Contains(int i, int j, int k) const;
258  bool Contains(const int I[3]) const;
260 
264  bool Contains(const vtkAMRBox&) const;
265 
271  void GetGhostVector(int r, int nghost[6]) const;
272 
277  void RemoveGhosts(int r);
278 
279 public:
285  static vtkIdType GetBytesize() { return 6 * sizeof(int); }
286 
290  static int GetCellLinearIndex(
291  const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3]);
292 
296  static void GetBounds(
297  const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
298 
303  static void GetBoxOrigin(
304  const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
305 
310  static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
311  double x, double y, double z);
312 
316  static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
317  const double h[3], const double x[3], int ijk[3], double pcoords[3]);
318 
319 protected:
323  void Initialize();
324 
331  bool IntersectBoxAlongDimension(const vtkAMRBox& other, const int q);
332 
333 private:
334  int LoCorner[3]; // lo corner cell id.
335  int HiCorner[3]; // hi corner cell id.
336 
338 
343  void BuildAMRBox(
344  const int ilo, const int jlo, const int klo, const int ihi, const int jhi, const int khi);
346 };
347 
348 //*****************************************************************************
350 
354 template <typename T>
355 void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
356 {
357  // Convert regions to array index space. VTK arrays
358  // always start with 0,0,0.
359  int ofs[3];
360  ofs[0] = -arrayRegion.GetLoCorner()[0];
361  ofs[1] = -arrayRegion.GetLoCorner()[1];
362  ofs[2] = -arrayRegion.GetLoCorner()[2];
363  vtkAMRBox arrayDims(arrayRegion);
364  arrayDims.Shift(ofs);
365  vtkAMRBox destDims(destRegion);
366  destDims.Shift(ofs);
367  // Quick sanity check.
368  if (!arrayRegion.Contains(destRegion))
369  {
370  vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
371  << "Aborting the fill.");
372  }
373  // Get the bounds of the indices we fill.
374  const int* destLo = destDims.GetLoCorner();
375  int destHi[3];
376  destDims.GetValidHiCorner(destHi);
377  // Get the array dimensions.
378  int arrayHi[3];
379  arrayDims.GetNumberOfCells(arrayHi);
380  // Fill.
381  for (int k = destLo[2]; k <= destHi[2]; ++k)
382  {
383  vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
384  for (int j = destLo[1]; j <= destHi[1]; ++j)
385  {
386  vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
387  for (int i = destLo[0]; i <= destHi[0]; ++i)
388  {
389  pArray[idx] = fillValue;
390  ++idx;
391  }
392  }
393  }
395 }
396 
397 #endif
398 // VTK-HeaderTest-Exclude: vtkAMRBox.h
void GetBounds(T a, double bds[6])
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:39
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:355
void Print(const std::vector< T > &input, const std::string &name)
Print a vector with an associated name.
int vtkIdType
Definition: vtkType.h:332
void GetValidHiCorner(int hi[3]) const
Return a high corner.
void Shift(int i, int j, int k)
Shifts the box in index space.
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition: vtkAMRBox.h:161
vtkIdType GetNumberOfCells() const
Gets the number of cells enclosed by the box.
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
#define VTK_XYZ_GRID
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:146
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:285
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition: vtkAMRBox.h:92
const int * GetHiCorner() const
Definition: vtkAMRBox.h:147
bool Empty() const
Definition: vtkAMRBox.h:156
bool operator!=(const vtkAMRBox &other) const
Test if this box is NOT equal with the box instance on the rhs.
Definition: vtkAMRBox.h:179
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:82
bool Contains(int i, int j, int k) const
Test to see if a given cell index is inside this box.