VTK  9.7.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
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 
31 VTK_ABI_NAMESPACE_BEGIN
32 class vtkDataArray;
33 class vtkIdList;
34 class vtkPoints;
37 template <typename T>
38 class vtkConstantArray;
39 
40 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
41 {
42 public:
43  vtkTypeMacro(vtkStructuredData, vtkObject);
44  void PrintSelf(ostream& os, vtkIndent indent) override;
45 
52  {
53  VTK_STRUCTURED_INVALID = -1, // An invalid/unset/unitialized grid
54  VTK_STRUCTURED_UNCHANGED =
55  0, // Used by vtkStructuredData API to signify that the type of the grid was not changed
56  VTK_STRUCTURED_SINGLE_POINT = 1, // A single point, 0D
57  VTK_STRUCTURED_X_LINE = 2, // X aligned line, 1D
58  VTK_STRUCTURED_Y_LINE = 3, // Y aligned line, 1D
59  VTK_STRUCTURED_Z_LINE = 4, // Z aligned line, 1D
60  VTK_STRUCTURED_XY_PLANE = 5, // XY aligned plane, 2D
61  VTK_STRUCTURED_YZ_PLANE = 6, // XY aligned plane, 2D
62  VTK_STRUCTURED_XZ_PLANE = 7, // XY aligned plane, 2D
63  VTK_STRUCTURED_XYZ_GRID = 8, // XYZ grid, 3D
64  VTK_STRUCTURED_EMPTY = 9 // An empty grid
65  };
66 
68 
75  static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
76  static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
78 
80 
84  static int GetDataDescription(int dims[3]);
85  static int GetDataDescriptionFromExtent(VTK_FUTURE_CONST int ext[6]);
87 
89 
92  static int GetDataDimension(int dataDescription);
93  static int GetDataDimension(int ext[6]);
95 
101  static vtkIdType GetNumberOfPoints(
102  const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
103 
109  static vtkIdType GetNumberOfCells(
110  const int ext[6], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
111 
117  static void GetCellExtentFromPointExtent(const int pntExtent[6], int cellExtent[6],
118  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
119 
124  static inline void GetDimensionsFromExtent(
125  const int ext[6], int dims[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
126 
130  static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
131 
135  static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
136  int dataDescription, vtkUnsignedCharArray* cellGhostArray,
137  vtkUnsignedCharArray* pointGhostArray = nullptr);
138 
145  static void GetCellDimensionsFromExtent(const int ext[6], int celldims[3],
146  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
147 
153  static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
154 
161  static void GetLocalStructuredCoordinates(const int ijk[3], const int ext[6], int lijk[3],
162  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
163 
169  static void GetGlobalStructuredCoordinates(const int lijk[3], const int ext[6], int ijk[3],
170  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
171 
176  static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
177 
181  static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
182 
187  static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
188  static void GetCellNeighbors(
189  vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
190 
196  static vtkIdType ComputePointIdForExtent(const int extent[6], const int ijk[3],
197  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
198 
204  static vtkIdType ComputeCellIdForExtent(const int extent[6], const int ijk[3],
205  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
206 
213  static vtkIdType ComputePointId(const int dim[3], const int ijk[3],
214  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
215 
222  static vtkIdType ComputeCellId(const int dim[3], const int ijk[3],
223  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
224 
231  static void ComputeCellStructuredCoordsForExtent(vtkIdType cellIdx, const int ext[6], int ijk[3],
232  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
233 
239  static void ComputeCellStructuredCoords(vtkIdType cellId, const int dim[3], int ijk[3],
240  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
241 
246  static void ComputeCellStructuredMinMaxCoords(vtkIdType cellId, const int dim[3], int ijkMin[3],
247  int ijkMax[3], int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
248 
254  static void ComputePointStructuredCoordsForExtent(vtkIdType ptId, const int ext[6], int ijk[3],
255  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
256 
262  static void ComputePointStructuredCoords(vtkIdType ptId, const int dim[3], int ijk[3],
263  int dataDescription = vtkStructuredData::VTK_STRUCTURED_EMPTY);
264 
268  static vtkSmartPointer<vtkStructuredCellArray> GetCellArray(
269  int extent[6], bool usePixelVoxelOrientation);
270 
275  static vtkSmartPointer<vtkPoints> GetPoints(vtkDataArray* xCoords, vtkDataArray* yCoords,
276  vtkDataArray* zCoords, int extent[6], double dirMatrix[9]);
277 
279 
283  int extent[6], bool usePixelVoxelOrientation);
285  "Use vtkSmartPointer<vtkConstantArray<unsigned char>> GetCellTypes(extent, "
286  "usePixelVoxelOrientation) instead")
287  VTK_WRAPEXCLUDE static vtkSmartPointer<vtkConstantArray<int>> GetCellTypesArray(
288  int extent[6], bool usePixelVoxelOrientation);
290 
291 protected:
292  vtkStructuredData() = default;
293  ~vtkStructuredData() override = default;
294 
302  static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
303  {
304  return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
305  }
306 
308 
315  const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
316  {
317  vtkIdType N12 = N1 * N2;
318  k = static_cast<int>(idx / N12);
319  j = static_cast<int>((idx - k * N12) / N1);
320  i = static_cast<int>(idx - k * N12 - j * N1);
321  }
323 
324  // Want to avoid importing <algorithm> in the header...
325  template <typename T>
326  static T Max(const T& a, const T& b)
327  {
328  return (a > b) ? a : b;
329  }
330 
331 private:
332  vtkStructuredData(const vtkStructuredData&) = delete;
333  void operator=(const vtkStructuredData&) = delete;
334 };
335 
336 //------------------------------------------------------------------------------
337 inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
338 {
339  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
340  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
341  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
342 }
343 
344 //------------------------------------------------------------------------------
345 inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
346 {
347  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
348 }
349 
350 //------------------------------------------------------------------------------
351 inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
352 {
353  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
354  vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
355 }
356 
357 //------------------------------------------------------------------------------
358 inline vtkIdType vtkStructuredData::GetNumberOfPoints(const int ext[6], int)
359 {
360  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
361  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
362 }
363 
364 //------------------------------------------------------------------------------
365 inline vtkIdType vtkStructuredData::GetNumberOfCells(const int ext[6], int)
366 {
367  int dims[3];
369 
370  // if any of the dimensions is 0, then there are no cells
371  const int cellDims[3] = { dims[0] != 0 ? vtkStructuredData::Max(dims[0] - 1, 1) : 0,
372  dims[1] != 0 ? vtkStructuredData::Max(dims[1] - 1, 1) : 0,
373  dims[2] != 0 ? vtkStructuredData::Max(dims[2] - 1, 1) : 0 };
374 
375  // Note, when we compute the result below, we statically cast to vtkIdType to
376  // ensure the compiler will generate a 32x32=64 instruction.
377  return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
378  static_cast<vtkIdType>(cellDims[2]);
379 }
380 
381 //------------------------------------------------------------------------------
383  const int nodeExtent[6], int cellExtent[6], int)
384 {
385  cellExtent[0] = nodeExtent[0];
386  cellExtent[2] = nodeExtent[2];
387  cellExtent[4] = nodeExtent[4];
388 
389  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
390  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
391  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
392 }
393 
394 //------------------------------------------------------------------------------
395 void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
396 {
397  dims[0] = ext[1] - ext[0] + 1;
398  dims[1] = ext[3] - ext[2] + 1;
399  dims[2] = ext[5] - ext[4] + 1;
400 }
401 
402 //------------------------------------------------------------------------------
404  const int nodeDims[3], int cellDims[3])
405 {
406  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
407  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
408  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
409 }
410 
411 //------------------------------------------------------------------------------
413  const int ijk[3], const int ext[6], int lijk[3], int)
414 {
415  lijk[0] = ijk[0] - ext[0];
416  lijk[1] = ijk[1] - ext[2];
417  lijk[2] = ijk[2] - ext[4];
418 }
419 
420 //------------------------------------------------------------------------------
422  const int lijk[3], const int ext[6], int ijk[3], int)
423 {
424  ijk[0] = ext[0] + lijk[0];
425  ijk[1] = ext[2] + lijk[1];
426  ijk[2] = ext[4] + lijk[2];
427 }
428 
429 //------------------------------------------------------------------------------
431  const int extent[6], const int ijk[3], int)
432 {
433  int dims[3];
435 
436  int lijk[3];
438 
439  return vtkStructuredData::ComputePointId(dims, lijk);
440 }
441 
442 //------------------------------------------------------------------------------
444  const int extent[6], const int ijk[3], int)
445 {
446  int nodeDims[3];
448 
449  int lijk[3];
451 
452  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
453 }
454 
455 //------------------------------------------------------------------------------
457  vtkIdType cellId, const int dims[3], int ijk[3], int)
458 {
460  cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
461 }
462 
463 //------------------------------------------------------------------------------
465  vtkIdType cellIdx, const int ext[6], int ijk[3], int)
466 {
467  int nodeDims[3];
469 
470  int lijk[3];
471  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
472 
474 }
475 
476 //------------------------------------------------------------------------------
478  vtkIdType ptId, const int dim[3], int ijk[3], int)
479 {
480  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
481 }
482 
483 //------------------------------------------------------------------------------
485  vtkIdType ptId, const int ext[6], int ijk[3], int)
486 {
487  int nodeDims[3];
489 
490  int lijk[3];
492 
494 }
495 
496 VTK_ABI_NAMESPACE_END
497 #endif
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, this method computes the corresponding structured coordinates of the given cell.
Singleton class for topologically regular data.
abstract base class for most VTK objects
Definition: vtkObject.h:52
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 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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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...
A utility array for wrapping constant functions in implicit arrays.
implicit object to represent cell connectivity
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 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 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 T Max(const T &a, const T &b)
int vtkIdType
Definition: vtkType.h:363
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 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...
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 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.
#define VTK_DEPRECATED_IN_9_6_0(reason)
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 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...
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:25
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkStructuredDataType
An enum to describe the different types of vtkStructuredData XXX: This should be an enum class...
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...
dynamic, self-adjusting array of unsigned char
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 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 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...
#define VTK_WRAPEXCLUDE
represent and manipulate 3D points
Definition: vtkPoints.h:30
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).