VTK  9.5.20250806
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
82#ifndef vtkStructuredData_h
83#define vtkStructuredData_h
84
85#include "vtkCommonDataModelModule.h" // For export macro
86#include "vtkObject.h"
87#include "vtkSmartPointer.h" // For vtkSmartPointer
88
89VTK_ABI_NAMESPACE_BEGIN
90class vtkDataArray;
91class vtkIdList;
92class vtkPoints;
95
96template <typename T>
98template <typename Type>
100template <typename Type>
102
104{
105 VTK_UNCHANGED VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
106 0,
108 "Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 1,
109 VTK_X_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 2,
110 VTK_Y_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 3,
111 VTK_Z_LINE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 4,
112 VTK_XY_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
113 5,
114 VTK_YZ_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
115 6,
116 VTK_XZ_PLANE VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
117 7,
118 VTK_XYZ_GRID VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") =
119 8,
120 VTK_EMPTY VTK_DEPRECATED_IN_9_5_0("Use vtkStructuredData::VTK_STRUCTURED_* version instead") = 9
122
123class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
124{
125public:
127 void PrintSelf(ostream& os, vtkIndent indent) override;
128
135 {
136 VTK_STRUCTURED_INVALID = -1, // An invalid/unset/unitialized grid
137 VTK_STRUCTURED_UNCHANGED =
138 0, // Used by vtkStructuredData API to signify that the type of the grid was not changed
139 VTK_STRUCTURED_SINGLE_POINT = 1, // A single point, 0D
140 VTK_STRUCTURED_X_LINE = 2, // X aligned line, 1D
141 VTK_STRUCTURED_Y_LINE = 3, // Y aligned line, 1D
142 VTK_STRUCTURED_Z_LINE = 4, // Z aligned line, 1D
143 VTK_STRUCTURED_XY_PLANE = 5, // XY aligned plane, 2D
144 VTK_STRUCTURED_YZ_PLANE = 6, // XY aligned plane, 2D
145 VTK_STRUCTURED_XZ_PLANE = 7, // XY aligned plane, 2D
146 VTK_STRUCTURED_XYZ_GRID = 8, // XYZ grid, 3D
147 VTK_STRUCTURED_EMPTY = 9 // An empty grid
148 };
149
151
158 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
159 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
161
163
167 static int GetDataDescription(int dims[3]);
168 static int GetDataDescriptionFromExtent(int ext[6]);
170
172
175 static int GetDataDimension(int dataDescription);
176 static int GetDataDimension(int ext[6]);
178
184 static vtkIdType GetNumberOfPoints(
185 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
186
192 static vtkIdType GetNumberOfCells(
193 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
194
200 static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6],
201 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
202
207 static void GetDimensionsFromExtent(
208 const int ext[6], int dims[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
209
213 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
214
218 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
219 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
220 vtkUnsignedCharArray* pointGhostArray = nullptr);
221
228 static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3],
229 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
230
236 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
237
244 static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3],
245 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
246
252 static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3],
253 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
254
259 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
260
264 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
265
270 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
271 static void GetCellNeighbors(
272 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
273
279 static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3],
280 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
281
287 static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3],
288 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
289
296 static vtkIdType ComputePointId(const int dim[3], const int ijk[3],
297 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
298
305 static vtkIdType ComputeCellId(const int dim[3], const int ijk[3],
306 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
307
314 static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3],
315 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
316
322 static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3],
323 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
324
329 static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
330 int ijkMax[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
331
337 static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3],
338 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
339
345 static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3],
346 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
347
352 int extent[6], bool usePixelVoxelOrientation);
353
359 vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
360
365 int extent[6], bool usePixelVoxelOrientation);
366
367protected:
368 vtkStructuredData() = default;
369 ~vtkStructuredData() override = default;
370
378 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
379 {
380 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
381 }
382
384
391 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
392 {
393 vtkIdType N12 = N1 * N2;
394 k = static_cast<int>(idx / N12);
395 j = static_cast<int>((idx - k * N12) / N1);
396 i = static_cast<int>(idx - k * N12 - j * N1);
397 }
399
400 // Want to avoid importing <algorithm> in the header...
401 template <typename T>
402 static T Max(const T& a, const T& b)
403 {
404 return (a > b) ? a : b;
405 }
406
407private:
408 vtkStructuredData(const vtkStructuredData&) = delete;
409 void operator=(const vtkStructuredData&) = delete;
410};
411
412//------------------------------------------------------------------------------
413inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
414{
415 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
416 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
417 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
418}
419
420//------------------------------------------------------------------------------
421inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
422{
423 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
424}
425
426//------------------------------------------------------------------------------
427inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
428{
429 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
430 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
431}
432
433//------------------------------------------------------------------------------
435{
436 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
437 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
438}
439
440//------------------------------------------------------------------------------
442{
443 int dims[3];
445
446 // if any of the dimensions is 0, then there are no cells
447 const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
448 dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
449 dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
450
451 // Note, when we compute the result below, we statically cast to vtkIdType to
452 // ensure the compiler will generate a 32x32=64 instruction.
453 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
454 static_cast<vtkIdType>(cellDims[2]);
455}
456
457//------------------------------------------------------------------------------
459 const int nodeExtent[6], int cellExtent[6], int)
460{
461 cellExtent[0] = nodeExtent[0];
462 cellExtent[2] = nodeExtent[2];
463 cellExtent[4] = nodeExtent[4];
464
465 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
466 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
467 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
468}
469
470//------------------------------------------------------------------------------
471inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
472{
473 dims[0] = ext[1] - ext[0] + 1;
474 dims[1] = ext[3] - ext[2] + 1;
475 dims[2] = ext[5] - ext[4] + 1;
476}
477
478//------------------------------------------------------------------------------
480 const int nodeDims[3], int cellDims[3])
481{
482 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
483 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
484 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
485}
486
487//------------------------------------------------------------------------------
489 const int ijk[3], const int ext[6], int lijk[3], int)
490{
491 lijk[0] = ijk[0] - ext[0];
492 lijk[1] = ijk[1] - ext[2];
493 lijk[2] = ijk[2] - ext[4];
494}
495
496//------------------------------------------------------------------------------
498 const int lijk[3], const int ext[6], int ijk[3], int)
499{
500 ijk[0] = ext[0] + lijk[0];
501 ijk[1] = ext[2] + lijk[1];
502 ijk[2] = ext[4] + lijk[2];
503}
504
505//------------------------------------------------------------------------------
507 const int extent[6], const int ijk[3], int)
508{
509 int dims[3];
511
512 int lijk[3];
514
515 return vtkStructuredData::ComputePointId(dims, lijk);
516}
517
518//------------------------------------------------------------------------------
520 const int extent[6], const int ijk[3], int)
521{
522 int nodeDims[3];
524
525 int lijk[3];
527
528 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
529}
530
531//------------------------------------------------------------------------------
533 vtkIdType cellId, const int dims[3], int ijk[3], int)
534{
536 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
537}
538
539//------------------------------------------------------------------------------
541 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
542{
543 int nodeDims[3];
545
546 int lijk[3];
547 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
548
550}
551
552//------------------------------------------------------------------------------
554 vtkIdType ptId, const int dim[3], int ijk[3], int)
555{
556 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
557}
558
559//------------------------------------------------------------------------------
561 vtkIdType ptId, const int ext[6], int ijk[3], int)
562{
563 int nodeDims[3];
565
566 int lijk[3];
568
570}
571
572VTK_ABI_NAMESPACE_END
573#endif
abstract superclass for arrays of numeric data
list of point or cell ids
Definition vtkIdList.h:133
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:108
abstract base class for most VTK objects
Definition vtkObject.h:162
represent and manipulate 3D points
Definition vtkPoints.h:139
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 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).
~vtkStructuredData() override=default
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 VTK_DEPRECATED_IN_9_5_0(reason)
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:332
#define VTK_WRAPEXCLUDE