VTK  9.1.0
vtkStructuredData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkStructuredData.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
58 #ifndef vtkStructuredData_h
59 #define vtkStructuredData_h
60 
61 #include "vtkCommonDataModelModule.h" // For export macro
62 #include "vtkObject.h"
63 
64 class vtkIdList;
66 
67 #define VTK_UNCHANGED 0
68 #define VTK_SINGLE_POINT 1
69 #define VTK_X_LINE 2
70 #define VTK_Y_LINE 3
71 #define VTK_Z_LINE 4
72 #define VTK_XY_PLANE 5
73 #define VTK_YZ_PLANE 6
74 #define VTK_XZ_PLANE 7
75 #define VTK_XYZ_GRID 8
76 #define VTK_EMPTY 9
77 
78 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
79 {
80 public:
81  vtkTypeMacro(vtkStructuredData, vtkObject);
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
85 
92  static int SetDimensions(int inDim[3], int dim[3]);
93  static int SetExtent(int inExt[6], int ext[6]);
95 
97 
101  static int GetDataDescription(int dims[3]);
102  static int GetDataDescriptionFromExtent(int ext[6]);
104 
106 
109  static int GetDataDimension(int dataDescription);
110  static int GetDataDimension(int ext[6]);
112 
118  static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
119 
125  static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
126 
132  static void GetCellExtentFromPointExtent(
133  const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
134 
139  static void GetDimensionsFromExtent(
140  const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
141 
145  static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
146 
150  static bool IsCellVisible(vtkIdType cellId, int dimensions[3], int dataDescription,
151  vtkUnsignedCharArray* cellGhostArray, vtkUnsignedCharArray* pointGhostArray = nullptr);
152 
159  static void GetCellDimensionsFromExtent(
160  const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
161 
167  static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
168 
175  static void GetLocalStructuredCoordinates(
176  const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
177 
183  static void GetGlobalStructuredCoordinates(
184  const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
185 
189  static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
190 
194  static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, int dim[3]);
195 
200  static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
201  static void GetCellNeighbors(
202  vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
203 
209  static vtkIdType ComputePointIdForExtent(
210  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
211 
217  static vtkIdType ComputeCellIdForExtent(
218  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
219 
226  static vtkIdType ComputePointId(
227  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
228 
235  static vtkIdType ComputeCellId(
236  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
237 
244  static void ComputeCellStructuredCoordsForExtent(
245  const vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
246 
252  static void ComputeCellStructuredCoords(
253  const vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
254 
260  static void ComputePointStructuredCoordsForExtent(
261  const vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
262 
268  static void ComputePointStructuredCoords(
269  const vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
270 
271 protected:
272  vtkStructuredData() = default;
273  ~vtkStructuredData() override = default;
274 
282  static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
283  {
284  return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
285  }
286 
288 
295  const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
296  {
297  vtkIdType N12 = N1 * N2;
298  k = static_cast<int>(idx / N12);
299  j = static_cast<int>((idx - k * N12) / N1);
300  i = static_cast<int>(idx - k * N12 - j * N1);
301  }
303 
304  // Want to avoid importing <algorithm> in the header...
305  template <typename T>
306  static T Max(const T& a, const T& b)
307  {
308  return (a > b) ? a : b;
309  }
310 
311 private:
312  vtkStructuredData(const vtkStructuredData&) = delete;
313  void operator=(const vtkStructuredData&) = delete;
314 };
315 
316 //------------------------------------------------------------------------------
317 inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
318 {
319  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
320  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
321  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
322 }
323 
324 //------------------------------------------------------------------------------
325 inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
326 {
327  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
328 }
329 
330 //------------------------------------------------------------------------------
331 inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
332 {
333  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
334  vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
335 }
336 
337 //------------------------------------------------------------------------------
338 inline vtkIdType vtkStructuredData::GetNumberOfPoints(const int ext[6], int)
339 {
340  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
341  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
342 }
343 
344 //------------------------------------------------------------------------------
345 inline vtkIdType vtkStructuredData::GetNumberOfCells(const int ext[6], int)
346 {
347  int cellDims[3];
349 
350  // Replace 0's with 1's so we can just multiply them regardless of cell type.
351  cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
352  cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
353  cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
354 
355  // Note, when we compute the result below, we statically cast to vtkIdType to
356  // ensure the compiler will generate a 32x32=64 instruction.
357  return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
358  static_cast<vtkIdType>(cellDims[2]);
359 }
360 
361 //------------------------------------------------------------------------------
363  const int nodeExtent[6], int cellExtent[6], int)
364 {
365  cellExtent[0] = nodeExtent[0];
366  cellExtent[2] = nodeExtent[2];
367  cellExtent[4] = nodeExtent[4];
368 
369  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
370  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
371  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
372 }
373 
374 //------------------------------------------------------------------------------
375 inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
376 {
377  dims[0] = ext[1] - ext[0] + 1;
378  dims[1] = ext[3] - ext[2] + 1;
379  dims[2] = ext[5] - ext[4] + 1;
380 }
381 
382 //------------------------------------------------------------------------------
384  const int nodeDims[3], int cellDims[3])
385 {
386  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
387  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
388  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
389 }
390 
391 //------------------------------------------------------------------------------
393  const int ijk[3], const int ext[6], int lijk[3], int)
394 {
395  lijk[0] = ijk[0] - ext[0];
396  lijk[1] = ijk[1] - ext[2];
397  lijk[2] = ijk[2] - ext[4];
398 }
399 
400 //------------------------------------------------------------------------------
402  const int lijk[3], const int ext[6], int ijk[3], int)
403 {
404  ijk[0] = ext[0] + lijk[0];
405  ijk[1] = ext[2] + lijk[1];
406  ijk[2] = ext[4] + lijk[2];
407 }
408 
409 //------------------------------------------------------------------------------
411  const int extent[6], const int ijk[3], int)
412 {
413  int dims[3];
415 
416  int lijk[3];
418 
419  return vtkStructuredData::ComputePointId(dims, lijk);
420 }
421 
422 //------------------------------------------------------------------------------
424  const int extent[6], const int ijk[3], int)
425 {
426  int nodeDims[3];
428 
429  int lijk[3];
431 
432  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
433 }
434 
435 //------------------------------------------------------------------------------
437  const vtkIdType cellId, const int dims[3], int ijk[3], int)
438 {
440  cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
441 }
442 
443 //------------------------------------------------------------------------------
445  const vtkIdType cellIdx, const int ext[6], int ijk[3], int)
446 {
447  int nodeDims[3];
449 
450  int lijk[3];
451  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
452 
454 }
455 
456 //------------------------------------------------------------------------------
458  const vtkIdType ptId, const int dim[3], int ijk[3], int)
459 {
460  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
461 }
462 
463 //------------------------------------------------------------------------------
465  const vtkIdType ptId, const int ext[6], int ijk[3], int)
466 {
467  int nodeDims[3];
469 
470  int lijk[3];
472 
474 }
475 
476 #endif
vtkStructuredData::GetDataDimension
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
vtkStructuredData::GetLocalStructuredCoordinates
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.
Definition: vtkStructuredData.h:392
vtkStructuredData::GetCellExtentFromPointExtent
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.
Definition: vtkStructuredData.h:362
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkStructuredData::GetCellDimensionsFromExtent
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...
Definition: vtkStructuredData.h:317
vtkStructuredData::ComputeCellStructuredCoords
static void ComputeCellStructuredCoords(const 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).
Definition: vtkStructuredData.h:436
vtkStructuredData::GetDataDescription
static int GetDataDescription(int dims[3])
Returns the data description given the dimensions (eg.
vtkStructuredData::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:145
vtkStructuredData::ComputePointStructuredCoordsForExtent
static void ComputePointStructuredCoordsForExtent(const 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).
Definition: vtkStructuredData.h:464
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkStructuredData::GetDimensionsFromExtent
static void GetDimensionsFromExtent(const int ext[6], int dims[3], int dataDescription=VTK_EMPTY)
Computes the structured grid dimensions based on the given extent.
Definition: vtkStructuredData.h:375
vtkStructuredData::GetCellDimensionsFromPointDimensions
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...
Definition: vtkStructuredData.h:383
vtkStructuredData::GetLinearIndex
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...
Definition: vtkStructuredData.h:282
vtkStructuredData::GetNumberOfCells
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.
Definition: vtkStructuredData.h:345
vtkStructuredData::GetDataDescriptionFromExtent
static int GetDataDescriptionFromExtent(int ext[6])
Returns the data description given the dimensions (eg.
vtkStructuredData::SetDimensions
static int SetDimensions(int inDim[3], int dim[3])
Specify the dimensions of a regular, rectangular dataset.
vtkStructuredData::vtkStructuredData
vtkStructuredData()=default
vtkStructuredData::GetDataDimension
static int GetDataDimension(int ext[6])
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
vtkStructuredData::GetGlobalStructuredCoordinates
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...
Definition: vtkStructuredData.h:401
vtkStructuredData::Max
static T Max(const T &a, const T &b)
Definition: vtkStructuredData.h:306
vtkStructuredData::IsPointVisible
static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray *ghosts)
Return non-zero value if specified point is visible.
vtkStructuredData::GetCellPoints
static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
vtkStructuredData::GetCellNeighbors
static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds, int dim[3])
Get the cells using the points ptIds, exclusive of the cell cellId.
vtkStructuredData::ComputePointId
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,...
Definition: vtkStructuredData.h:325
vtkStructuredData::GetPointCells
static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkStructuredData
Singleton class for topologically regular data.
Definition: vtkStructuredData.h:79
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:140
vtkStructuredData::GetNumberOfPoints
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.
Definition: vtkStructuredData.h:338
vtkStructuredData::SetExtent
static int SetExtent(int inExt[6], int ext[6])
Specify the dimensions of a regular, rectangular dataset.
vtkStructuredData::GetCellNeighbors
static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds, vtkIdList *cellIds, int dim[3], int seedLoc[3])
vtkObject.h
vtkStructuredData::IsCellVisible
static bool IsCellVisible(vtkIdType cellId, int dimensions[3], int dataDescription, vtkUnsignedCharArray *cellGhostArray, vtkUnsignedCharArray *pointGhostArray=nullptr)
Return non-zero value if specified cell is visible.
vtkStructuredData::~vtkStructuredData
~vtkStructuredData() override=default
vtkStructuredData::ComputePointStructuredCoords
static void ComputePointStructuredCoords(const 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).
Definition: vtkStructuredData.h:457
vtkStructuredData::ComputeCellStructuredCoordsForExtent
static void ComputeCellStructuredCoordsForExtent(const 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,...
Definition: vtkStructuredData.h:444
vtkX3D::extent
@ extent
Definition: vtkX3D.h:351
vtkStructuredData::ComputeCellId
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,...
Definition: vtkStructuredData.h:331
vtkStructuredData::GetStructuredCoordinates
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...
Definition: vtkStructuredData.h:294
vtkStructuredData::ComputeCellIdForExtent
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,...
Definition: vtkStructuredData.h:423
VTK_EMPTY
#define VTK_EMPTY
Definition: vtkStructuredData.h:76
vtkStructuredData::ComputePointIdForExtent
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,...
Definition: vtkStructuredData.h:410