VTK  9.3.0
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
29#ifndef vtkAMRBox_h
30#define vtkAMRBox_h
31
32#include "vtkCommonDataModelModule.h" // For export macro
33#include "vtkObject.h"
34#include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
35
36VTK_ABI_NAMESPACE_BEGIN
37class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
38{
39public:
44
48 vtkAMRBox(const vtkAMRBox& other);
49
53 vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
54
59 vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
60 const double* globalOrigin, int gridDescription = VTK_XYZ_GRID);
61
65 vtkAMRBox(const int lo[3], const int hi[3]);
66
67 vtkAMRBox(const int dims[6]);
68
73
74 virtual ~vtkAMRBox() = default;
75
77
81 {
82 this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
83 this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
84 }
86
90 bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
91
95 void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc = VTK_XYZ_GRID);
96
100 void SetDimensions(const int lo[3], const int hi[3], int desc = VTK_XYZ_GRID);
101
105 void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
106
110 void GetDimensions(int lo[3], int hi[3]) const;
111
115 void GetDimensions(int dims[6]) const;
116
118
122 void GetNumberOfCells(int num[3]) const;
124
126
130 void GetNumberOfNodes(int ext[3]) const;
133
139 int ComputeDimension() const;
140
144 const int* GetLoCorner() const { return this->LoCorner; }
145 const int* GetHiCorner() const { return this->HiCorner; }
146
152 void GetValidHiCorner(int hi[3]) const;
153
154 bool Empty() const { return this->IsInvalid(); }
155
159 bool IsInvalid() const
160 {
161 return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
162 (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
163 }
164
170 bool operator==(const vtkAMRBox& other) const;
171
177 bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
178
182 ostream& Print(ostream& os) const;
183
185
196 void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
197 void Serialize(int* buffer) const;
199
206 void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
207
214 bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, int q) const;
215
216 bool DoesIntersect(const vtkAMRBox& other) const;
217
221 void Coarsen(int r);
222
226 void Refine(int r);
227
229
232 void Grow(int byN);
233 void Shrink(int byN);
235
237
240 void Shift(int i, int j, int k);
241 void Shift(const int I[3]);
243
249 bool Intersect(const vtkAMRBox& other);
250
252
255 bool Contains(int i, int j, int k) const;
256 bool Contains(const int I[3]) const;
258
262 bool Contains(const vtkAMRBox&) const;
263
269 void GetGhostVector(int r, int nghost[6]) const;
270
275 void RemoveGhosts(int r);
276
282 static vtkIdType GetBytesize() { return 6 * sizeof(int); }
283
287 static int GetCellLinearIndex(const vtkAMRBox& box, int i, int j, int k, int imageDimension[3]);
288
292 static void GetBounds(
293 const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
294
299 static void GetBoxOrigin(
300 const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
301
306 static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
307 double x, double y, double z);
308
312 static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
313 const double h[3], const double x[3], int ijk[3], double pcoords[3]);
314
315protected:
320
327 bool IntersectBoxAlongDimension(const vtkAMRBox& other, int q);
328
329private:
330 int LoCorner[3]; // lo corner cell id.
331 int HiCorner[3]; // hi corner cell id.
332
334
339 void BuildAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
341};
342
343//*****************************************************************************
345
349template <typename T>
350void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
351{
352 // Convert regions to array index space. VTK arrays
353 // always start with 0,0,0.
354 int ofs[3];
355 ofs[0] = -arrayRegion.GetLoCorner()[0];
356 ofs[1] = -arrayRegion.GetLoCorner()[1];
357 ofs[2] = -arrayRegion.GetLoCorner()[2];
358 vtkAMRBox arrayDims(arrayRegion);
359 arrayDims.Shift(ofs);
360 vtkAMRBox destDims(destRegion);
361 destDims.Shift(ofs);
362 // Quick sanity check.
363 if (!arrayRegion.Contains(destRegion))
364 {
365 vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
366 << "Aborting the fill.");
367 }
368 // Get the bounds of the indices we fill.
369 const int* destLo = destDims.GetLoCorner();
370 int destHi[3];
371 destDims.GetValidHiCorner(destHi);
372 // Get the array dimensions.
373 int arrayHi[3];
374 arrayDims.GetNumberOfCells(arrayHi);
375 // Fill.
376 for (int k = destLo[2]; k <= destHi[2]; ++k)
377 {
378 vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
379 for (int j = destLo[1]; j <= destHi[1]; ++j)
380 {
381 vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
382 for (int i = destLo[0]; i <= destHi[0]; ++i)
383 {
384 pArray[idx] = fillValue;
385 ++idx;
386 }
387 }
388 }
390}
391
392VTK_ABI_NAMESPACE_END
393#endif
394// VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition vtkAMRBox.h:38
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.
vtkAMRBox(const int dims[6])
vtkAMRBox(const vtkAMRBox &other)
Copy construct this box from another.
void Invalidate()
Set the box to be invalid;.
Definition vtkAMRBox.h:80
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:282
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.
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:90
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:154
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:177
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.
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:159
void Shrink(int byN)
Grows the box in all directions.
const int * GetLoCorner() const
Get the low corner index.
Definition vtkAMRBox.h:144
const int * GetHiCorner() const
Definition vtkAMRBox.h:145
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.
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:350
#define VTK_XYZ_GRID
int vtkIdType
Definition vtkType.h:315