VTK  9.6.1
vtkStructuredData.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
22
23#ifndef vtkStructuredData_h
24#define vtkStructuredData_h
25
26#include "vtkCommonDataModelModule.h" // For export macro
27#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
28#include "vtkObject.h"
29#include "vtkSmartPointer.h" // For vtkSmartPointer
30
31VTK_ABI_NAMESPACE_BEGIN
32class vtkDataArray;
33class vtkIdList;
34class vtkPoints;
37
38template <typename T, int ArrayType>
40template <typename Type>
42template <typename Type>
45
47{
48 VTK_UNCHANGED VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
49 0,
51 "Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 1,
52 VTK_X_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 2,
53 VTK_Y_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 3,
54 VTK_Z_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 4,
55 VTK_XY_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
56 5,
57 VTK_YZ_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
58 6,
59 VTK_XZ_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
60 7,
61 VTK_XYZ_GRID VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
62 8,
63 VTK_EMPTY VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 9
64};
65
66class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
67{
68public:
70 void PrintSelf(ostream& os, vtkIndent indent) override;
71
78 {
79 VTK_STRUCTURED_INVALID = -1, // An invalid/unset/unitialized grid
81 0, // Used by vtkStructuredData API to signify that the type of the grid was not changed
82 VTK_STRUCTURED_SINGLE_POINT = 1, // A single point, 0D
83 VTK_STRUCTURED_X_LINE = 2, // X aligned line, 1D
84 VTK_STRUCTURED_Y_LINE = 3, // Y aligned line, 1D
85 VTK_STRUCTURED_Z_LINE = 4, // Z aligned line, 1D
86 VTK_STRUCTURED_XY_PLANE = 5, // XY aligned plane, 2D
87 VTK_STRUCTURED_YZ_PLANE = 6, // XY aligned plane, 2D
88 VTK_STRUCTURED_XZ_PLANE = 7, // XY aligned plane, 2D
89 VTK_STRUCTURED_XYZ_GRID = 8, // XYZ grid, 3D
90 VTK_STRUCTURED_EMPTY = 9 // An empty grid
91 };
92
94
101 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
102 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
104
106
110 static int GetDataDescription(int dims[3]);
111 static int GetDataDescriptionFromExtent(int ext[6]);
113
115
118 static int GetDataDimension(int dataDescription);
119 static int GetDataDimension(int ext[6]);
121
128 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
129
136 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
137
143 static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6],
144 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
145
150 static void GetDimensionsFromExtent(
151 const int ext[6], int dims[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
152
156 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
157
161 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
162 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
163 vtkUnsignedCharArray* pointGhostArray = nullptr);
164
171 static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3],
172 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
173
179 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
180
187 static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3],
188 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
189
195 static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3],
196 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
197
202 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
203
207 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
208
213 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
214 static void GetCellNeighbors(
215 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
216
222 static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3],
223 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
224
230 static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3],
231 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
232
239 static vtkIdType ComputePointId(const int dim[3], const int ijk[3],
240 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
241
248 static vtkIdType ComputeCellId(const int dim[3], const int ijk[3],
249 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
250
257 static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3],
258 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
259
265 static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3],
266 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
267
272 static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
273 int ijkMax[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
274
280 static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3],
281 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
282
288 static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3],
289 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
290
295 int extent[6], bool usePixelVoxelOrientation);
296
302 vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
303
305
309 int extent[6], bool usePixelVoxelOrientation);
311 "Use vtkSmartPointer<vtkConstantArray<unsigned char>> GetCellTypes(extent, "
312 "usePixelVoxelOrientation) instead")
314 int extent[6], bool usePixelVoxelOrientation);
316
317protected:
318 vtkStructuredData() = default;
319 ~vtkStructuredData() override = default;
320
328 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
329 {
330 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
331 }
332
334
341 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
342 {
343 vtkIdType N12 = N1 * N2;
344 k = static_cast<int>(idx / N12);
345 j = static_cast<int>((idx - k * N12) / N1);
346 i = static_cast<int>(idx - k * N12 - j * N1);
347 }
348
349
350 // Want to avoid importing <algorithm> in the header...
351 template <typename T>
352 static T Max(const T& a, const T& b)
353 {
354 return (a > b) ? a : b;
355 }
356
357private:
358 vtkStructuredData(const vtkStructuredData&) = delete;
359 void operator=(const vtkStructuredData&) = delete;
360};
361
362//------------------------------------------------------------------------------
363inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
364{
365 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
366 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
367 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
368}
369
370//------------------------------------------------------------------------------
371inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
372{
373 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
374}
375
376//------------------------------------------------------------------------------
377inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
378{
379 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
380 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
381}
382
383//------------------------------------------------------------------------------
385{
386 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
387 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
388}
389
390//------------------------------------------------------------------------------
392{
393 int dims[3];
395
396 // if any of the dimensions is 0, then there are no cells
397 const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
398 dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
399 dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
400
401 // Note, when we compute the result below, we statically cast to vtkIdType to
402 // ensure the compiler will generate a 32x32=64 instruction.
403 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
404 static_cast<vtkIdType>(cellDims[2]);
405}
406
407//------------------------------------------------------------------------------
409 const int nodeExtent[6], int cellExtent[6], int)
410{
411 cellExtent[0] = nodeExtent[0];
412 cellExtent[2] = nodeExtent[2];
413 cellExtent[4] = nodeExtent[4];
414
415 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
416 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
417 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
418}
419
420//------------------------------------------------------------------------------
421inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
422{
423 dims[0] = ext[1] - ext[0] + 1;
424 dims[1] = ext[3] - ext[2] + 1;
425 dims[2] = ext[5] - ext[4] + 1;
426}
427
428//------------------------------------------------------------------------------
430 const int nodeDims[3], int cellDims[3])
431{
432 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
433 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
434 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
435}
436
437//------------------------------------------------------------------------------
439 const int ijk[3], const int ext[6], int lijk[3], int)
440{
441 lijk[0] = ijk[0] - ext[0];
442 lijk[1] = ijk[1] - ext[2];
443 lijk[2] = ijk[2] - ext[4];
444}
445
446//------------------------------------------------------------------------------
448 const int lijk[3], const int ext[6], int ijk[3], int)
449{
450 ijk[0] = ext[0] + lijk[0];
451 ijk[1] = ext[2] + lijk[1];
452 ijk[2] = ext[4] + lijk[2];
453}
454
455//------------------------------------------------------------------------------
457 const int extent[6], const int ijk[3], int)
458{
459 int dims[3];
461
462 int lijk[3];
464
465 return vtkStructuredData::ComputePointId(dims, lijk);
466}
467
468//------------------------------------------------------------------------------
470 const int extent[6], const int ijk[3], int)
471{
472 int nodeDims[3];
474
475 int lijk[3];
477
478 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
479}
480
481//------------------------------------------------------------------------------
483 vtkIdType cellId, const int dims[3], int ijk[3], int)
484{
486 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
487}
488
489//------------------------------------------------------------------------------
491 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
492{
493 int nodeDims[3];
495
496 int lijk[3];
497 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
498
500}
501
502//------------------------------------------------------------------------------
504 vtkIdType ptId, const int dim[3], int ijk[3], int)
505{
506 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
507}
508
509//------------------------------------------------------------------------------
511 vtkIdType ptId, const int ext[6], int ijk[3], int)
512{
513 int nodeDims[3];
515
516 int lijk[3];
518
520}
521
522VTK_ABI_NAMESPACE_END
523#endif
list of point or cell ids
Definition vtkIdList.h:24
A read only array class that wraps an implicit function from integers to any value type supported by ...
a simple class to control print indentation
Definition vtkIndent.h:29
represent and manipulate 3D points
Definition vtkPoints.h:30
Hold a reference to a vtkObjectBase instance.
implicit object to represent cell connectivity
Singleton class for topologically regular data.
static int GetDataDescription(int dims[3])
Returns the data description given the dimensions (eg.
static int GetDataDimension(int ext[6])
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Returns the cell dimensions, i.e., the number of cells along the i,j,k for the grid with the given gr...
static void GetStructuredCoordinates(const vtkIdType idx, const int N1, const int N2, int &i, int &j, int &k)
Returns the structured coordinates (i,j,k) for the given linear index of a grid with N1 and N2 dimens...
static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset,...
static int GetDataDescriptionFromExtent(int ext[6])
Returns the data description given the dimensions (eg.
static vtkSmartPointer< vtkStructuredCellArray > GetCellArray(int extent[6], bool usePixelVoxelOrientation)
Get the implicit cell array for structured data.
static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given the grid extent, this method returns the total number of cells within the extent.
static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds, int dim[3], int seedLoc[3])
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray *ghosts)
Return non-zero value if specified point is visible.
static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset,...
vtkStructuredData()=default
static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6])
Specify the dimensions of a regular, rectangular dataset.
static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given local structured coordinates, and the corresponding global sub-grid extent, this method compute...
static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a pointId and grid dimensions 'dim', get the structured coordinates (i-j-k).
static vtkIdType ComputePointId(const int dim[3], const int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a location in structured coordinates (i-j-k), and the dimensions of the structured dataset,...
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
static VTK_WRAPEXCLUDE vtkSmartPointer< vtkConstantArray< int > > GetCellTypesArray(int extent[6], bool usePixelVoxelOrientation)
Get the implicit cell array types for structured data.
static VTK_WRAPEXCLUDE vtkSmartPointer< vtkConstantArray< unsigned char > > GetCellTypes(int extent[6], bool usePixelVoxelOrientation)
Get the implicit cell array types for structured data.
static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3], int ijkMax[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a cellId and grid dimensions 'dim', get the min and max structured coordinates (i-j-k).
static vtkSmartPointer< vtkPoints > GetPoints(vtkDataArray *xCoords, vtkDataArray *yCoords, vtkDataArray *zCoords, int extent[6], double dirMatrix[9])
Given 3 arrays describing the xCoords, yCoords, and zCoords, the extent, and the direction matrix,...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a cellId and grid dimensions 'dim', get the structured coordinates (i-j-k).
static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given the global structured coordinates for a point or cell, ijk, w.r.t.
static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3])
Given the dimensions of the grid, in pntdims, this method returns the corresponding cell dimensions f...
static void GetDimensionsFromExtent(const int ext[6], int dims[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Computes the structured grid dimensions based on the given extent.
static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds, int dim[3])
Get the cells using the points ptIds, exclusive of the cell cellId.
static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3])
Specify the dimensions of a regular, rectangular dataset.
static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
Computes the linear index for the given i-j-k structured of a grid with of N1 and N2 dimensions along...
static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given the global grid extent and the linear index of a cell within the grid extent,...
static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given the grid extent, this method returns the total number of points within the extent.
static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3], int dataDescription, vtkUnsignedCharArray *cellGhostArray, vtkUnsignedCharArray *pointGhostArray=nullptr)
Return non-zero value if specified cell is visible.
static vtkIdType ComputeCellId(const int dim[3], const int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a location in structured coordinates (i-j-k), and the dimensions of the structured dataset,...
static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given a pointId and the grid extent ext, get the structured coordinates (i-j-k).
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, VTK_FUTURE_CONST int dim[3])
Get the cells using a point.
static T Max(const T &a, const T &b)
static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6], int dataDescription=vtkStructuredData::VTK_STRUCTURED_EMPTY)
Given the point extent of a grid, this method computes the corresponding cell extent for the grid.
vtkStructuredDataType
An enum to describe the different types of vtkStructuredData XXX: This should be an enum class,...
dynamic, self-adjusting array of unsigned char
A utility structure serving as a backend for constant implicit arrays.
#define vtkDataArray
vtkImplicitArray< vtkConstantImplicitBackend< T >, vtkArrayTypes::VTK_CONSTANT_ARRAY > vtkConstantArray
A utility alias for wrapping constant functions in implicit arrays.
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_DEPRECATED_IN_9_5_0(reason)
virtual int GetNumberOfPoints()=0
Return the number of corner points that compose the cell.
vtkImplicitArray< vtkConstantImplicitBackend< Type >, vtkArrayTypes::VTK_CONSTANT_ARRAY > vtkConstantArray
vtkStructuredDataType
@ VTK_YZ_PLANE
@ VTK_XYZ_GRID
@ VTK_XY_PLANE
@ VTK_Y_LINE
@ VTK_Z_LINE
@ VTK_XZ_PLANE
@ VTK_X_LINE
@ VTK_SINGLE_POINT
@ VTK_EMPTY
@ VTK_UNCHANGED
int vtkIdType
Definition vtkType.h:368
@ VTK_CONSTANT_ARRAY
Definition vtkType.h:93
#define VTK_WRAPEXCLUDE