VTK  9.6.20260201
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
81
82#ifndef vtkStructuredData_h
83#define vtkStructuredData_h
84
85#include "vtkCommonDataModelModule.h" // For export macro
86#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
87#include "vtkObject.h"
88#include "vtkSmartPointer.h" // For vtkSmartPointer
89
90VTK_ABI_NAMESPACE_BEGIN
91class vtkDataArray;
92class vtkIdList;
93class vtkPoints;
96
97template <typename T, int ArrayType>
99template <typename Type>
101template <typename Type>
104
105class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
106{
107public:
109 void PrintSelf(ostream& os, vtkIndent indent) override;
110
117 {
118 VTK_STRUCTURED_INVALID = -1, // An invalid/unset/unitialized grid
120 0, // Used by vtkStructuredData API to signify that the type of the grid was not changed
121 VTK_STRUCTURED_SINGLE_POINT = 1, // A single point, 0D
122 VTK_STRUCTURED_X_LINE = 2, // X aligned line, 1D
123 VTK_STRUCTURED_Y_LINE = 3, // Y aligned line, 1D
124 VTK_STRUCTURED_Z_LINE = 4, // Z aligned line, 1D
125 VTK_STRUCTURED_XY_PLANE = 5, // XY aligned plane, 2D
126 VTK_STRUCTURED_YZ_PLANE = 6, // XY aligned plane, 2D
127 VTK_STRUCTURED_XZ_PLANE = 7, // XY aligned plane, 2D
128 VTK_STRUCTURED_XYZ_GRID = 8, // XYZ grid, 3D
129 VTK_STRUCTURED_EMPTY = 9 // An empty grid
130 };
131
133
140 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
141 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
143
145
149 static int GetDataDescription(int dims[3]);
150 static int GetDataDescriptionFromExtent(int ext[6]);
152
154
157 static int GetDataDimension(int dataDescription);
158 static int GetDataDimension(int ext[6]);
160
167 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
168
175 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
176
182 static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6],
183 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
184
189 static inline void GetDimensionsFromExtent(
190 const int ext[6], int dims[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
191
195 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
196
200 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
201 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
202 vtkUnsignedCharArray* pointGhostArray = nullptr);
203
210 static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3],
211 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
212
218 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
219
226 static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3],
227 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
228
234 static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3],
235 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
236
241 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
242
246 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
247
252 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
253 static void GetCellNeighbors(
254 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
255
261 static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3],
262 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
263
269 static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3],
270 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
271
278 static vtkIdType ComputePointId(const int dim[3], const int ijk[3],
279 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
280
287 static vtkIdType ComputeCellId(const int dim[3], const int ijk[3],
288 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
289
296 static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3],
297 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
298
304 static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3],
305 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
306
311 static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
312 int ijkMax[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
313
319 static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3],
320 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
321
327 static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3],
328 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
329
334 int extent[6], bool usePixelVoxelOrientation);
335
341 vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
342
344
348 int extent[6], bool usePixelVoxelOrientation);
350 "Use vtkSmartPointer<vtkConstantArray<unsigned char>> GetCellTypes(extent, "
351 "usePixelVoxelOrientation) instead")
353 int extent[6], bool usePixelVoxelOrientation);
355
356protected:
357 vtkStructuredData() = default;
358 ~vtkStructuredData() override = default;
359
367 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
368 {
369 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
370 }
371
373
380 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
381 {
382 vtkIdType N12 = N1 * N2;
383 k = static_cast<int>(idx / N12);
384 j = static_cast<int>((idx - k * N12) / N1);
385 i = static_cast<int>(idx - k * N12 - j * N1);
386 }
387
388
389 // Want to avoid importing <algorithm> in the header...
390 template <typename T>
391 static T Max(const T& a, const T& b)
392 {
393 return (a > b) ? a : b;
394 }
395
396private:
397 vtkStructuredData(const vtkStructuredData&) = delete;
398 void operator=(const vtkStructuredData&) = delete;
399};
400
401//------------------------------------------------------------------------------
402inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
403{
404 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
405 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
406 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
407}
408
409//------------------------------------------------------------------------------
410inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
411{
412 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
413}
414
415//------------------------------------------------------------------------------
416inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
417{
418 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
419 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
420}
421
422//------------------------------------------------------------------------------
424{
425 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
426 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
427}
428
429//------------------------------------------------------------------------------
431{
432 int dims[3];
434
435 // if any of the dimensions is 0, then there are no cells
436 const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
437 dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
438 dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
439
440 // Note, when we compute the result below, we statically cast to vtkIdType to
441 // ensure the compiler will generate a 32x32=64 instruction.
442 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
443 static_cast<vtkIdType>(cellDims[2]);
444}
445
446//------------------------------------------------------------------------------
448 const int nodeExtent[6], int cellExtent[6], int)
449{
450 cellExtent[0] = nodeExtent[0];
451 cellExtent[2] = nodeExtent[2];
452 cellExtent[4] = nodeExtent[4];
453
454 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
455 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
456 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
457}
458
459//------------------------------------------------------------------------------
460void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
461{
462 dims[0] = ext[1] - ext[0] + 1;
463 dims[1] = ext[3] - ext[2] + 1;
464 dims[2] = ext[5] - ext[4] + 1;
465}
466
467//------------------------------------------------------------------------------
469 const int nodeDims[3], int cellDims[3])
470{
471 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
472 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
473 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
474}
475
476//------------------------------------------------------------------------------
478 const int ijk[3], const int ext[6], int lijk[3], int)
479{
480 lijk[0] = ijk[0] - ext[0];
481 lijk[1] = ijk[1] - ext[2];
482 lijk[2] = ijk[2] - ext[4];
483}
484
485//------------------------------------------------------------------------------
487 const int lijk[3], const int ext[6], int ijk[3], int)
488{
489 ijk[0] = ext[0] + lijk[0];
490 ijk[1] = ext[2] + lijk[1];
491 ijk[2] = ext[4] + lijk[2];
492}
493
494//------------------------------------------------------------------------------
496 const int extent[6], const int ijk[3], int)
497{
498 int dims[3];
500
501 int lijk[3];
503
504 return vtkStructuredData::ComputePointId(dims, lijk);
505}
506
507//------------------------------------------------------------------------------
509 const int extent[6], const int ijk[3], int)
510{
511 int nodeDims[3];
513
514 int lijk[3];
516
517 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
518}
519
520//------------------------------------------------------------------------------
522 vtkIdType cellId, const int dims[3], int ijk[3], int)
523{
525 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
526}
527
528//------------------------------------------------------------------------------
530 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
531{
532 int nodeDims[3];
534
535 int lijk[3];
536 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
537
539}
540
541//------------------------------------------------------------------------------
543 vtkIdType ptId, const int dim[3], int ijk[3], int)
544{
545 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
546}
547
548//------------------------------------------------------------------------------
550 vtkIdType ptId, const int ext[6], int ijk[3], int)
551{
552 int nodeDims[3];
554
555 int lijk[3];
557
559}
560
561VTK_ABI_NAMESPACE_END
562#endif
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
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 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)
vtkImplicitArray< vtkConstantImplicitBackend< Type >, vtkArrayTypes::VTK_CONSTANT_ARRAY > vtkConstantArray
int vtkIdType
Definition vtkType.h:354
@ VTK_CONSTANT_ARRAY
Definition vtkType.h:84
#define VTK_WRAPEXCLUDE