VTK  9.5.2
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
79#ifndef vtkStructuredData_h
80#define vtkStructuredData_h
81
82#include "vtkCommonDataModelModule.h" // For export macro
83#include "vtkObject.h"
84#include "vtkSmartPointer.h" // For vtkSmartPointer
85
86VTK_ABI_NAMESPACE_BEGIN
87class vtkDataArray;
88class vtkIdList;
89class vtkPoints;
92
93template <typename T>
95template <typename Type>
97template <typename Type>
99
100#define VTK_UNCHANGED 0
101#define VTK_SINGLE_POINT 1
102#define VTK_X_LINE 2
103#define VTK_Y_LINE 3
104#define VTK_Z_LINE 4
105#define VTK_XY_PLANE 5
106#define VTK_YZ_PLANE 6
107#define VTK_XZ_PLANE 7
108#define VTK_XYZ_GRID 8
109#define VTK_EMPTY 9
110
111class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
112{
113public:
115 void PrintSelf(ostream& os, vtkIndent indent) override;
116
118
125 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
126 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
128
130
134 static int GetDataDescription(int dims[3]);
135 static int GetDataDescriptionFromExtent(int ext[6]);
137
139
142 static int GetDataDimension(int dataDescription);
143 static int GetDataDimension(int ext[6]);
145
151 static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
152
158 static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
159
165 static void GetCellExtentFromPointExtent(
166 const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
167
172 static void GetDimensionsFromExtent(
173 const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
174
178 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
179
183 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
184 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
185 vtkUnsignedCharArray* pointGhostArray = nullptr);
186
193 static void GetCellDimensionsFromExtent(
194 const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
195
201 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
202
209 static void GetLocalStructuredCoordinates(
210 const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
211
217 static void GetGlobalStructuredCoordinates(
218 const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
219
223 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
224
228 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
229
234 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
235 static void GetCellNeighbors(
236 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
237
243 static vtkIdType ComputePointIdForExtent(
244 const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
245
251 static vtkIdType ComputeCellIdForExtent(
252 const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
253
260 static vtkIdType ComputePointId(
261 const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
262
269 static vtkIdType ComputeCellId(
270 const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
271
278 static void ComputeCellStructuredCoordsForExtent(
279 vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
280
286 static void ComputeCellStructuredCoords(
287 vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
288
293 static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
294 int ijkMax[3], int dataDescription = VTK_EMPTY);
295
301 static void ComputePointStructuredCoordsForExtent(
302 vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
303
309 static void ComputePointStructuredCoords(
310 vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
311
316 int extent[6], bool usePixelVoxelOrientation);
317
323 vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
324
329 int extent[6], bool usePixelVoxelOrientation);
330
331protected:
332 vtkStructuredData() = default;
333 ~vtkStructuredData() override = default;
334
342 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
343 {
344 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
345 }
346
348
355 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
356 {
357 vtkIdType N12 = N1 * N2;
358 k = static_cast<int>(idx / N12);
359 j = static_cast<int>((idx - k * N12) / N1);
360 i = static_cast<int>(idx - k * N12 - j * N1);
361 }
363
364 // Want to avoid importing <algorithm> in the header...
365 template <typename T>
366 static T Max(const T& a, const T& b)
367 {
368 return (a > b) ? a : b;
369 }
370
371private:
372 vtkStructuredData(const vtkStructuredData&) = delete;
373 void operator=(const vtkStructuredData&) = delete;
374};
375
376//------------------------------------------------------------------------------
377inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
378{
379 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
380 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
381 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
382}
383
384//------------------------------------------------------------------------------
385inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
386{
387 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
388}
389
390//------------------------------------------------------------------------------
391inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
392{
393 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
394 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
395}
396
397//------------------------------------------------------------------------------
399{
400 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
401 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
402}
403
404//------------------------------------------------------------------------------
406{
407 int dims[3];
409
410 // if any of the dimensions is 0, then there are no cells
411 const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
412 dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
413 dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
414
415 // Note, when we compute the result below, we statically cast to vtkIdType to
416 // ensure the compiler will generate a 32x32=64 instruction.
417 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
418 static_cast<vtkIdType>(cellDims[2]);
419}
420
421//------------------------------------------------------------------------------
423 const int nodeExtent[6], int cellExtent[6], int)
424{
425 cellExtent[0] = nodeExtent[0];
426 cellExtent[2] = nodeExtent[2];
427 cellExtent[4] = nodeExtent[4];
428
429 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
430 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
431 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
432}
433
434//------------------------------------------------------------------------------
435inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
436{
437 dims[0] = ext[1] - ext[0] + 1;
438 dims[1] = ext[3] - ext[2] + 1;
439 dims[2] = ext[5] - ext[4] + 1;
440}
441
442//------------------------------------------------------------------------------
444 const int nodeDims[3], int cellDims[3])
445{
446 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
447 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
448 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
449}
450
451//------------------------------------------------------------------------------
453 const int ijk[3], const int ext[6], int lijk[3], int)
454{
455 lijk[0] = ijk[0] - ext[0];
456 lijk[1] = ijk[1] - ext[2];
457 lijk[2] = ijk[2] - ext[4];
458}
459
460//------------------------------------------------------------------------------
462 const int lijk[3], const int ext[6], int ijk[3], int)
463{
464 ijk[0] = ext[0] + lijk[0];
465 ijk[1] = ext[2] + lijk[1];
466 ijk[2] = ext[4] + lijk[2];
467}
468
469//------------------------------------------------------------------------------
471 const int extent[6], const int ijk[3], int)
472{
473 int dims[3];
475
476 int lijk[3];
478
479 return vtkStructuredData::ComputePointId(dims, lijk);
480}
481
482//------------------------------------------------------------------------------
484 const int extent[6], const int ijk[3], int)
485{
486 int nodeDims[3];
488
489 int lijk[3];
491
492 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
493}
494
495//------------------------------------------------------------------------------
497 vtkIdType cellId, const int dims[3], int ijk[3], int)
498{
500 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
501}
502
503//------------------------------------------------------------------------------
505 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
506{
507 int nodeDims[3];
509
510 int lijk[3];
511 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
512
514}
515
516//------------------------------------------------------------------------------
518 vtkIdType ptId, const int dim[3], int ijk[3], int)
519{
520 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
521}
522
523//------------------------------------------------------------------------------
525 vtkIdType ptId, const int ext[6], int ijk[3], int)
526{
527 int nodeDims[3];
529
530 int lijk[3];
532
534}
535
536VTK_ABI_NAMESPACE_END
537#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 void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given a pointId and the grid extent ext, get the structured coordinates (i-j-k).
static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int dataDescription=VTK_EMPTY)
Returns the cell dimensions, i.e., the number of cells along the i,j,k for the grid with the given gr...
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 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=VTK_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 void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3], int dataDescription=VTK_EMPTY)
Given the global structured coordinates for a point or cell, ijk, w.r.t.
static void GetDimensionsFromExtent(const int ext[6], int dims[3], int dataDescription=VTK_EMPTY)
Computes the structured grid dimensions based on the given 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 void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY)
Given the point extent of a grid, this method computes the corresponding cell extent for the grid.
static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3], int ijkMax[3], int dataDescription=VTK_EMPTY)
Given a cellId and grid dimensions 'dim', get the min and max structured coordinates (i-j-k).
static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription=VTK_EMPTY)
Given the grid extent, this method returns the total number of cells within the extent.
vtkStructuredData()=default
static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6])
Specify the dimensions of a regular, rectangular dataset.
static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
Given a cellId and grid dimensions 'dim', get the structured coordinates (i-j-k).
static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given the global grid extent and the linear index of a cell within the grid extent,...
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 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.
~vtkStructuredData() override=default
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 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 ComputeCellIdForExtent(const int extent[6], const int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured 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 ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription=VTK_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=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the dimensions of the structured dataset,...
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 void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, VTK_FUTURE_CONST int dim[3])
Get the cells using a point.
static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given local structured coordinates, and the corresponding global sub-grid extent, this method compute...
static T Max(const T &a, const T &b)
static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription=VTK_EMPTY)
Given the grid extent, this method returns the total number of points within the extent.
static vtkIdType ComputeCellId(const int dim[3], const int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the dimensions of the structured dataset,...
dynamic, self-adjusting array of unsigned char
A utility structure serving as a backend for constant implicit arrays.
#define VTK_EMPTY
int vtkIdType
Definition vtkType.h:332
#define VTK_WRAPEXCLUDE