VTK  9.6.1
vtkAMRBox.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
19
20#ifndef vtkAMRBox_h
21#define vtkAMRBox_h
22
23#include "vtkCommonDataModelModule.h" // For export macro
24#include "vtkObject.h"
25#include "vtkStructuredData.h" // For vtkStructuredData::VTK_STRUCTURED_XYZ_GRID definition
26
27VTK_ABI_NAMESPACE_BEGIN
28class vtkUniformGrid;
29class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
30{
31public:
36
40 vtkAMRBox(const vtkAMRBox& other);
41
45 vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
46
51 vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
52 const double* globalOrigin, int gridDescription = vtkStructuredData::VTK_STRUCTURED_XYZ_GRID);
53
57 vtkAMRBox(const int lo[3], const int hi[3]);
58
59 vtkAMRBox(const int dims[6]);
60
65
66 virtual ~vtkAMRBox() = default;
67
69
73 {
74 this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
75 this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
76 }
77
78
82 bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
83
87 void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi,
89
94 const int lo[3], const int hi[3], int desc = vtkStructuredData::VTK_STRUCTURED_XYZ_GRID);
95
99 void SetDimensions(const int dims[6], int desc = vtkStructuredData::VTK_STRUCTURED_XYZ_GRID);
100
104 void GetDimensions(int lo[3], int hi[3]) const;
105
109 void GetDimensions(int dims[6]) const;
110
112
116 void GetNumberOfCells(int num[3]) const;
118
120
124 void GetNumberOfNodes(int ext[3]) const;
127
133 int ComputeDimension() const;
134
138 const int* GetLoCorner() const { return this->LoCorner; }
139 const int* GetHiCorner() const { return this->HiCorner; }
140
146 void GetValidHiCorner(int hi[3]) const;
147
148 bool Empty() const { return this->IsInvalid(); }
149
153 bool IsInvalid() const
154 {
155 return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
156 (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
157 }
158
164 bool operator==(const vtkAMRBox& other) const;
165
171 bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
172
176 ostream& Print(ostream& os) const;
177
179
190 void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
191 void Serialize(int* buffer) const;
193
200 void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
201
208 bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, int q) const;
209
210 bool DoesIntersect(const vtkAMRBox& other) const;
211
215 void Coarsen(int r);
216
220 void Refine(int r);
221
223
226 void Grow(int byN);
227 void Shrink(int byN);
229
231
234 void Shift(int i, int j, int k);
235 void Shift(const int I[3]);
237
243 bool Intersect(const vtkAMRBox& other);
244
246
249 bool Contains(int i, int j, int k) const;
250 bool Contains(const int I[3]) const;
252
256 bool Contains(const vtkAMRBox&) const;
257
263 void GetGhostVector(int r, int nghost[6]) const;
264
269 void RemoveGhosts(int r);
270
276 static vtkIdType GetBytesize() { return 6 * sizeof(int); }
277
281 static int GetCellLinearIndex(const vtkAMRBox& box, int i, int j, int k, int imageDimension[3]);
282
286 static void GetBounds(
287 const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
288
293 static void GetBoxOrigin(
294 const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
295
300 static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
301 double x, double y, double z);
302
306 static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
307 const double h[3], const double x[3], int ijk[3], double pcoords[3]);
308
315 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing) const;
316
324 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing, int nGhosts) const;
325
334 vtkUniformGrid* grid, double* origin, double* spacing, const int nGhosts[3]) const;
335
344 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing, int nGhostsI,
345 int nGhostsJ, int nGhostsK) const;
346
347protected:
352
359 bool IntersectBoxAlongDimension(const vtkAMRBox& other, int q);
360
361private:
362 int LoCorner[3]; // lo corner cell id.
363 int HiCorner[3]; // hi corner cell id.
364
366
371 void BuildAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
373};
374
375//*****************************************************************************
377
381template <typename T>
382void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
383{
384 // Convert regions to array index space. VTK arrays
385 // always start with 0,0,0.
386 int ofs[3];
387 ofs[0] = -arrayRegion.GetLoCorner()[0];
388 ofs[1] = -arrayRegion.GetLoCorner()[1];
389 ofs[2] = -arrayRegion.GetLoCorner()[2];
390 vtkAMRBox arrayDims(arrayRegion);
391 arrayDims.Shift(ofs);
392 vtkAMRBox destDims(destRegion);
393 destDims.Shift(ofs);
394 // Quick sanity check.
395 if (!arrayRegion.Contains(destRegion))
396 {
397 vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
398 << "Aborting the fill.");
399 }
400 // Get the bounds of the indices we fill.
401 const int* destLo = destDims.GetLoCorner();
402 int destHi[3];
403 destDims.GetValidHiCorner(destHi);
404 // Get the array dimensions.
405 int arrayHi[3];
406 arrayDims.GetNumberOfCells(arrayHi);
407 // Fill.
408 for (int k = destLo[2]; k <= destHi[2]; ++k)
409 {
410 vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
411 for (int j = destLo[1]; j <= destHi[1]; ++j)
412 {
413 vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
414 for (int i = destLo[0]; i <= destHi[0]; ++i)
415 {
416 pArray[idx] = fillValue;
417 ++idx;
418 }
419 }
420 }
422}
423
424VTK_ABI_NAMESPACE_END
425#endif
426// VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition vtkAMRBox.h:30
bool Contains(const vtkAMRBox &) const
Test to see if a given box is inside this box.
static int GetCellLinearIndex(const vtkAMRBox &box, int i, int j, int k, int imageDimension[3])
Returns the linear index of the given cell structured coordinates.
void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc=vtkStructuredData::VTK_STRUCTURED_XYZ_GRID)
Set the dimensions of the box.
vtkAMRBox(const int dims[6])
void SetDimensions(const int lo[3], const int hi[3], int desc=vtkStructuredData::VTK_STRUCTURED_XYZ_GRID)
Set the dimensions of the box.
vtkAMRBox(const vtkAMRBox &other)
Copy construct this box from another.
void Invalidate()
Set the box to be invalid;.
Definition vtkAMRBox.h:72
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.
bool IntersectBoxAlongDimension(const vtkAMRBox &other, int q)
Intersects this instance of vtkAMRbox with box passed through the argument list along the given dimen...
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.
ostream & Print(ostream &os) const
Send the box to a stream.
bool DoesBoxIntersectAlongDimension(const vtkAMRBox &other, int q) const
Checks if this instance of vtkAMRBox intersects with the box passed through the argument list along t...
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition vtkAMRBox.h:276
int InitializeGrid(vtkUniformGrid *grid, double *origin, double *spacing, const int nGhosts[3]) const
Initialize the provided grid from the definition in this box, with ghost cell arrays of the thickness...
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.
void Serialize(unsigned char *&buffer, vtkIdType &bytesize)
Serializes this object instance into a byte-stream.
bool EmptyDimension(int i) const
Whether dimension i is empty, e.g.
Definition vtkAMRBox.h:82
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.
vtkAMRBox & operator=(const vtkAMRBox &other)
Copy the other box to this 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:148
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.
int InitializeGrid(vtkUniformGrid *grid, double *origin, double *spacing, int nGhosts) const
Initialize the provided grid from the definition in this box, with ghost cell arrays nGhosts cells th...
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 SetDimensions(const int dims[6], int desc=vtkStructuredData::VTK_STRUCTURED_XYZ_GRID)
Set the dimensions of 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:171
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 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.
int InitializeGrid(vtkUniformGrid *grid, double *origin, double *spacing, int nGhostsI, int nGhostsJ, int nGhostsK) const
Initialize the provided grid, from the definition in this box, with ghost cell arrays of the thicknes...
int InitializeGrid(vtkUniformGrid *grid, double *origin, double *spacing) const
Initialize the provided grid with no ghost cell arrays, from the definition in this box.
bool IsInvalid() const
Check to see if the AMR box instance is invalid.
Definition vtkAMRBox.h:153
void Shrink(int byN)
Grows the box in all directions.
const int * GetLoCorner() const
Get the low corner index.
Definition vtkAMRBox.h:138
const int * GetHiCorner() const
Definition vtkAMRBox.h:139
vtkAMRBox(const double *origin, const int *dimensions, const double *spacing, const double *globalOrigin, int gridDescription=vtkStructuredData::VTK_STRUCTURED_XYZ_GRID)
Construct an AMR box from the description a vtkUniformGrid Note that the dimensions specify the node ...
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.
Deprecated vtkImageData.
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:382
int vtkIdType
Definition vtkType.h:368