VTK  9.1.0
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=========================================================================*/
35#ifndef vtkAMRBox_h
36#define vtkAMRBox_h
37
38#include "vtkCommonDataModelModule.h" // For export macro
39#include "vtkObject.h"
40#include "vtkStructuredData.h" // For VTK_XYZ_GRID definition
41
42class VTKCOMMONDATAMODEL_EXPORT vtkAMRBox
43{
44public:
49
53 vtkAMRBox(const vtkAMRBox& other);
54
58 vtkAMRBox(int ilo, int jlo, int klo, int ihi, int jhi, int khi);
59
64 vtkAMRBox(const double* origin, const int* dimensions, const double* spacing,
65 const double* globalOrigin, int gridDescription = VTK_XYZ_GRID);
66
70 vtkAMRBox(const int lo[3], const int hi[3]);
71
72 vtkAMRBox(const int dims[6]);
73
78
79 virtual ~vtkAMRBox() = default;
80
82
86 {
87 this->LoCorner[0] = this->LoCorner[1] = this->LoCorner[2] = 0;
88 this->HiCorner[0] = this->HiCorner[1] = this->HiCorner[2] = -2;
89 }
91
95 bool EmptyDimension(int i) const { return HiCorner[i] <= LoCorner[i] - 1; }
96
100 void SetDimensions(int ilo, int jlo, int klo, int ihi, int jhi, int khi, int desc = VTK_XYZ_GRID);
101
105 void SetDimensions(const int lo[3], const int hi[3], int desc = VTK_XYZ_GRID);
106
110 void SetDimensions(const int dims[6], int desc = VTK_XYZ_GRID);
111
115 void GetDimensions(int lo[3], int hi[3]) const;
116
120 void GetDimensions(int dims[6]) const;
121
123
127 void GetNumberOfCells(int num[3]) const;
129
131
135 void GetNumberOfNodes(int ext[3]) const;
138
144 int ComputeDimension() const;
145
149 const int* GetLoCorner() const { return this->LoCorner; }
150 const int* GetHiCorner() const { return this->HiCorner; }
151
157 void GetValidHiCorner(int hi[3]) const;
158
159 bool Empty() const { return this->IsInvalid(); }
160
164 bool IsInvalid() const
165 {
166 return ((this->HiCorner[0] < this->LoCorner[0] - 1) ||
167 (this->HiCorner[1] < this->LoCorner[1] - 1) || (this->HiCorner[2] < this->LoCorner[2] - 1));
168 }
169
175 bool operator==(const vtkAMRBox& other) const;
176
182 bool operator!=(const vtkAMRBox& other) const { return (!(*this == other)); }
183
187 ostream& Print(ostream& os) const;
188
190
201 void Serialize(unsigned char*& buffer, vtkIdType& bytesize);
202 void Serialize(int* buffer) const;
204
211 void Deserialize(unsigned char* buffer, const vtkIdType& bytesize);
212
219 bool DoesBoxIntersectAlongDimension(const vtkAMRBox& other, const int q) const;
220
221 bool DoesIntersect(const vtkAMRBox& other) const;
222
226 void Coarsen(int r);
227
231 void Refine(int r);
232
234
237 void Grow(int byN);
238 void Shrink(int byN);
240
242
245 void Shift(int i, int j, int k);
246 void Shift(const int I[3]);
248
254 bool Intersect(const vtkAMRBox& other);
255
257
260 bool Contains(int i, int j, int k) const;
261 bool Contains(const int I[3]) const;
263
267 bool Contains(const vtkAMRBox&) const;
268
274 void GetGhostVector(int r, int nghost[6]) const;
275
280 void RemoveGhosts(int r);
281
282public:
288 static vtkIdType GetBytesize() { return 6 * sizeof(int); }
289
294 const vtkAMRBox& box, const int i, const int j, const int k, int imageDimension[3]);
295
299 static void GetBounds(
300 const vtkAMRBox& box, const double origin[3], const double spacing[3], double bounds[6]);
301
306 static void GetBoxOrigin(
307 const vtkAMRBox& box, const double X0[3], const double spacing[3], double x0[3]);
308
313 static bool HasPoint(const vtkAMRBox& box, const double origin[3], const double spacing[3],
314 double x, double y, double z);
315
319 static int ComputeStructuredCoordinates(const vtkAMRBox& box, const double dataOrigin[3],
320 const double h[3], const double x[3], int ijk[3], double pcoords[3]);
321
322protected:
327
334 bool IntersectBoxAlongDimension(const vtkAMRBox& other, const int q);
335
336private:
337 int LoCorner[3]; // lo corner cell id.
338 int HiCorner[3]; // hi corner cell id.
339
341
346 void BuildAMRBox(
347 const int ilo, const int jlo, const int klo, const int ihi, const int jhi, const int khi);
349};
350
351//*****************************************************************************
353
357template <typename T>
358void FillRegion(T* pArray, const vtkAMRBox& arrayRegion, const vtkAMRBox& destRegion, T fillValue)
359{
360 // Convert regions to array index space. VTK arrays
361 // always start with 0,0,0.
362 int ofs[3];
363 ofs[0] = -arrayRegion.GetLoCorner()[0];
364 ofs[1] = -arrayRegion.GetLoCorner()[1];
365 ofs[2] = -arrayRegion.GetLoCorner()[2];
366 vtkAMRBox arrayDims(arrayRegion);
367 arrayDims.Shift(ofs);
368 vtkAMRBox destDims(destRegion);
369 destDims.Shift(ofs);
370 // Quick sanity check.
371 if (!arrayRegion.Contains(destRegion))
372 {
373 vtkGenericWarningMacro(<< "ERROR: Array must enclose the destination region. "
374 << "Aborting the fill.");
375 }
376 // Get the bounds of the indices we fill.
377 const int* destLo = destDims.GetLoCorner();
378 int destHi[3];
379 destDims.GetValidHiCorner(destHi);
380 // Get the array dimensions.
381 int arrayHi[3];
382 arrayDims.GetNumberOfCells(arrayHi);
383 // Fill.
384 for (int k = destLo[2]; k <= destHi[2]; ++k)
385 {
386 vtkIdType kOfs = k * arrayHi[0] * arrayHi[1];
387 for (int j = destLo[1]; j <= destHi[1]; ++j)
388 {
389 vtkIdType idx = kOfs + j * arrayHi[0] + destLo[0];
390 for (int i = destLo[0]; i <= destHi[0]; ++i)
391 {
392 pArray[idx] = fillValue;
393 ++idx;
394 }
395 }
396 }
398}
399
400#endif
401// VTK-HeaderTest-Exclude: vtkAMRBox.h
Encloses a rectangular region of voxel like cells.
Definition: vtkAMRBox.h:43
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(const vtkAMRBox &other)
Copy construct this box from another.
void Invalidate()
Set the box to be invalid;.
Definition: vtkAMRBox.h:85
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.
ostream & Print(ostream &os) const
Send the box to a stream.
static vtkIdType GetBytesize()
Returns the number of bytes allocated by this instance.
Definition: vtkAMRBox.h:288
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.
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:95
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:159
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:182
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.
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:164
void Shrink(int byN)
Grows the box in all directions.
const int * GetLoCorner() const
Get the low corner index.
Definition: vtkAMRBox.h:149
const int * GetHiCorner() const
Definition: vtkAMRBox.h:150
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
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
@ 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:358
#define VTK_XYZ_GRID
int vtkIdType
Definition: vtkType.h:332