VTK  9.7.20260718
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 "vtkObject.h"
87#include "vtkSmartPointer.h" // For vtkSmartPointer
88
89VTK_ABI_NAMESPACE_BEGIN
90class vtkDataArray;
91class vtkIdList;
92class vtkPoints;
95template <typename T>
97
98class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
99{
100public:
102 void PrintSelf(ostream& os, vtkIndent indent) override;
103
110 {
111 VTK_STRUCTURED_INVALID = -1, // An invalid/unset/unitialized grid
113 0, // Used by vtkStructuredData API to signify that the type of the grid was not changed
114 VTK_STRUCTURED_SINGLE_POINT = 1, // A single point, 0D
115 VTK_STRUCTURED_X_LINE = 2, // X aligned line, 1D
116 VTK_STRUCTURED_Y_LINE = 3, // Y aligned line, 1D
117 VTK_STRUCTURED_Z_LINE = 4, // Z aligned line, 1D
118 VTK_STRUCTURED_XY_PLANE = 5, // XY aligned plane, 2D
119 VTK_STRUCTURED_YZ_PLANE = 6, // XY aligned plane, 2D
120 VTK_STRUCTURED_XZ_PLANE = 7, // XY aligned plane, 2D
121 VTK_STRUCTURED_XYZ_GRID = 8, // XYZ grid, 3D
122 VTK_STRUCTURED_EMPTY = 9 // An empty grid
123 };
124
126
133 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
134 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
136
138
142 static int GetDataDescription(int dims[3]);
143 static int GetDataDescriptionFromExtent(VTK_FUTURE_CONST int ext[6]);
145
147
150 static int GetDataDimension(int dataDescription);
151 static int GetDataDimension(int ext[6]);
153
160 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
161
168 const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
169
175 static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6],
176 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
177
182 static inline void GetDimensionsFromExtent(
183 const int ext[6], int dims[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
184
188 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
189
193 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
194 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
195 vtkUnsignedCharArray* pointGhostArray = nullptr);
196
203 static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3],
204 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
205
211 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
212
219 static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3],
220 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
221
227 static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3],
228 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
229
234 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
235
239 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
240
245 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
246 static void GetCellNeighbors(
247 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
248
254 static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3],
255 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
256
262 static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3],
263 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
264
271 static vtkIdType ComputePointId(const int dim[3], const int ijk[3],
272 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
273
280 static vtkIdType ComputeCellId(const int dim[3], const int ijk[3],
281 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
282
289 static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3],
290 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
291
297 static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3],
298 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
299
304 static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
305 int ijkMax[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
306
312 static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3],
313 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
314
320 static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3],
321 int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
322
327 int extent[6], bool usePixelVoxelOrientation);
328
334 vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
335
340 int extent[6], bool usePixelVoxelOrientation);
341
342protected:
343 vtkStructuredData() = default;
344 ~vtkStructuredData() override = default;
345
353 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
354 {
355 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
356 }
357
359
366 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
367 {
368 vtkIdType N12 = N1 * N2;
369 k = static_cast<int>(idx / N12);
370 j = static_cast<int>((idx - k * N12) / N1);
371 i = static_cast<int>(idx - k * N12 - j * N1);
372 }
373
374
375 // Want to avoid importing <algorithm> in the header...
376 template <typename T>
377 static T Max(const T& a, const T& b)
378 {
379 return (a > b) ? a : b;
380 }
381
382private:
383 vtkStructuredData(const vtkStructuredData&) = delete;
384 void operator=(const vtkStructuredData&) = delete;
385};
386
387//------------------------------------------------------------------------------
388inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
389{
390 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
391 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
392 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
393}
394
395//------------------------------------------------------------------------------
396inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
397{
398 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
399}
400
401//------------------------------------------------------------------------------
402inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
403{
404 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
405 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
406}
407
408//------------------------------------------------------------------------------
410{
411 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
412 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
413}
414
415//------------------------------------------------------------------------------
417{
418 int dims[3];
420
421 // if any of the dimensions is 0, then there are no cells
422 const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
423 dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
424 dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
425
426 // Note, when we compute the result below, we statically cast to vtkIdType to
427 // ensure the compiler will generate a 32x32=64 instruction.
428 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
429 static_cast<vtkIdType>(cellDims[2]);
430}
431
432//------------------------------------------------------------------------------
434 const int nodeExtent[6], int cellExtent[6], int)
435{
436 cellExtent[0] = nodeExtent[0];
437 cellExtent[2] = nodeExtent[2];
438 cellExtent[4] = nodeExtent[4];
439
440 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
441 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
442 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
443}
444
445//------------------------------------------------------------------------------
446void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
447{
448 dims[0] = ext[1] - ext[0] + 1;
449 dims[1] = ext[3] - ext[2] + 1;
450 dims[2] = ext[5] - ext[4] + 1;
451}
452
453//------------------------------------------------------------------------------
455 const int nodeDims[3], int cellDims[3])
456{
457 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
458 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
459 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
460}
461
462//------------------------------------------------------------------------------
464 const int ijk[3], const int ext[6], int lijk[3], int)
465{
466 lijk[0] = ijk[0] - ext[0];
467 lijk[1] = ijk[1] - ext[2];
468 lijk[2] = ijk[2] - ext[4];
469}
470
471//------------------------------------------------------------------------------
473 const int lijk[3], const int ext[6], int ijk[3], int)
474{
475 ijk[0] = ext[0] + lijk[0];
476 ijk[1] = ext[2] + lijk[1];
477 ijk[2] = ext[4] + lijk[2];
478}
479
480//------------------------------------------------------------------------------
482 const int extent[6], const int ijk[3], int)
483{
484 int dims[3];
486
487 int lijk[3];
489
490 return vtkStructuredData::ComputePointId(dims, lijk);
491}
492
493//------------------------------------------------------------------------------
495 const int extent[6], const int ijk[3], int)
496{
497 int nodeDims[3];
499
500 int lijk[3];
502
503 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
504}
505
506//------------------------------------------------------------------------------
508 vtkIdType cellId, const int dims[3], int ijk[3], int)
509{
511 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
512}
513
514//------------------------------------------------------------------------------
516 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
517{
518 int nodeDims[3];
520
521 int lijk[3];
522 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
523
525}
526
527//------------------------------------------------------------------------------
529 vtkIdType ptId, const int dim[3], int ijk[3], int)
530{
531 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
532}
533
534//------------------------------------------------------------------------------
536 vtkIdType ptId, const int ext[6], int ijk[3], int)
537{
538 int nodeDims[3];
540
541 int lijk[3];
543
545}
546
547VTK_ABI_NAMESPACE_END
548#endif
A utility array for wrapping constant functions in implicit arrays.
list of point or cell ids
Definition vtkIdList.h:135
a simple class to control print indentation
Definition vtkIndent.h:108
represent and manipulate 3D points
Definition vtkPoints.h:140
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 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< 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).
~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 int GetDataDescriptionFromExtent(VTK_FUTURE_CONST int ext[6])
Returns the data description given the dimensions (eg.
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
#define vtkDataArray
int vtkIdType
Definition vtkType.h:363
#define VTK_WRAPEXCLUDE