VTK  9.6.20260703
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
58
59#ifndef vtkAMRBox_h
60#define vtkAMRBox_h
61
62#include "vtkCommonDataModelModule.h" // For export macro
63#include "vtkObject.h"
64#include "vtkStructuredData.h" // For vtkStructuredData::VTK_STRUCTURED_XYZ_GRID definition
65
66VTK_ABI_NAMESPACE_BEGIN
67class vtkUniformGrid;
68class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
69{
70public:
75
79 vtkAMRBox(const vtkAMRBox& other);
80
84 vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
85
90 vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
91 const double* globalOrigin, int gridDescription = vtkStructuredData::VTK_STRUCTURED_XYZ_GRID);
92
96 vtkAMRBox(const int lo[3], const int hi[3]);
97
98 vtkAMRBox(const int dims[6]);
99
104
105 virtual ~vtkAMRBox() = default;
106
108
112 {
113 this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
114 this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
115 }
116
117
121 bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
122
126 void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi,
128
133 const int lo[3], const int hi[3], int desc = vtkStructuredData::VTK_STRUCTURED_XYZ_GRID);
134
139
143 void GetDimensions(int lo[3], int hi[3]) const;
144
148 void GetDimensions(int dims[6]) const;
149
151
155 void GetNumberOfCells(int num[3]) const;
157
159
163 void GetNumberOfNodes(int ext[3]) const;
166
172 int ComputeDimension() const;
173
177 const int* GetLoCorner() const { return this->LoCorner; }
178 const int* GetHiCorner() const { return this->HiCorner; }
179
185 void GetValidHiCorner(int hi[3]) const;
186
187 bool Empty() const { return this->IsInvalid(); }
188
192 bool IsInvalid() const
193 {
194 return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
195 (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
196 }
197
203 bool operator==(const vtkAMRBox& other) const;
204
210 bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
211
215 ostream& Print(ostream& os) const;
216
218
229 void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
230 void Serialize(int* buffer) const;
232
239 void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
240
247 bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, int q) const;
248
249 bool DoesIntersect(const vtkAMRBox& other) const;
250
254 void Coarsen(int r);
255
259 void Refine(int r);
260
262
265 void Grow(int byN);
266 void Shrink(int byN);
268
270
273 void Shift(int i, int j, int k);
274 void Shift(const int I[3]);
276
278
281 void Add(int i, int j, int k);
282 void Add(const int ijk[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
323 static vtkIdType GetBytesize() { return 6 * sizeof(int); }
324
328 static int GetCellLinearIndex(const vtkAMRBox& box, int i, int j, int k, int imageDimension[3]);
329
333 static void GetBounds(
334 const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
335
340 static void GetBoxOrigin(
341 const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
342
347 static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
348 double x, double y, double z);
349
353 static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
354 const double h[3], const double x[3], int ijk[3], double pcoords[3]);
355
362 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing) const;
363
371 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing, int nGhosts) const;
372
381 vtkUniformGrid* grid, double* origin, double* spacing, const int nGhosts[3]) const;
382
391 int InitializeGrid(vtkUniformGrid* grid, double* origin, double* spacing, int nGhostsI,
392 int nGhostsJ, int nGhostsK) const;
393
394protected:
399
406 bool IntersectBoxAlongDimension(const vtkAMRBox& other, int q);
407
408private:
409 int LoCorner[3]; // lo corner cell id.
410 int HiCorner[3]; // hi corner cell id.
411
413
418 void BuildAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
420};
421
422//*****************************************************************************
424
428template <typename T>
429void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
430{
431 // Convert regions to array index space. VTK arrays
432 // always start with 0,0,0.
433 int ofs[3];
434 ofs[0] = -arrayRegion.GetLoCorner()[0];
435 ofs[1] = -arrayRegion.GetLoCorner()[1];
436 ofs[2] = -arrayRegion.GetLoCorner()[2];
437 vtkAMRBox arrayDims(arrayRegion);
438 arrayDims.Shift(ofs);
439 vtkAMRBox destDims(destRegion);
440 destDims.Shift(ofs);
441 // Quick sanity check.
442 if (!arrayRegion.Contains(destRegion))
443 {
444 vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
445 << "Aborting the fill.");
446 }
447 // Get the bounds of the indices we fill.
448 const int* destLo = destDims.GetLoCorner();
449 int destHi[3];
450 destDims.GetValidHiCorner(destHi);
451 // Get the array dimensions.
452 int arrayHi[3];
453 arrayDims.GetNumberOfCells(arrayHi);
454 // Fill.
455 for (int k = destLo[2]; k <= destHi[2]; ++k)
456 {
457 vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
458 for (int j = destLo[1]; j <= destHi[1]; ++j)
459 {
460 vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
461 for (int i = destLo[0]; i <= destHi[0]; ++i)
462 {
463 pArray[idx] = fillValue;
464 ++idx;
465 }
466 }
467 }
469}
470
471VTK_ABI_NAMESPACE_END
472#endif
473// VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition vtkAMRBox.h:69
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:111
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:323
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:121
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 Add(int i, int j, int k)
Grow the box so it contains the provided coordinates.
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:187
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 Add(const int ijk[3])
Grow the box so it contains the provided coordinates.
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:210
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:192
void Shrink(int byN)
Grows the box in all directions.
const int * GetLoCorner() const
Get the low corner index.
Definition vtkAMRBox.h:177
const int * GetHiCorner() const
Definition vtkAMRBox.h:178
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:429
int vtkIdType
Definition vtkType.h:363