VTK  9.3.0
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
20#ifndef vtkStructuredData_h
21#define vtkStructuredData_h
22
23#include "vtkCommonDataModelModule.h" // For export macro
24#include "vtkObject.h"
25
26VTK_ABI_NAMESPACE_BEGIN
27class vtkIdList;
29
30#define VTK_UNCHANGED 0
31#define VTK_SINGLE_POINT 1
32#define VTK_X_LINE 2
33#define VTK_Y_LINE 3
34#define VTK_Z_LINE 4
35#define VTK_XY_PLANE 5
36#define VTK_YZ_PLANE 6
37#define VTK_XZ_PLANE 7
38#define VTK_XYZ_GRID 8
39#define VTK_EMPTY 9
40
41class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
42{
43public:
45 void PrintSelf(ostream& os, vtkIndent indent) override;
46
48
55 static int SetDimensions(VTK_FUTURE_CONST int inDim[3], int dim[3]);
56 static int SetExtent(VTK_FUTURE_CONST int inExt[6], int ext[6]);
58
60
64 static int GetDataDescription(int dims[3]);
65 static int GetDataDescriptionFromExtent(int ext[6]);
67
69
72 static int GetDataDimension(int dataDescription);
73 static int GetDataDimension(int ext[6]);
75
81 static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
82
88 static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
89
95 static void GetCellExtentFromPointExtent(
96 const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
97
102 static void GetDimensionsFromExtent(
103 const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
104
108 static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
109
113 static bool IsCellVisible(vtkIdType cellId, VTK_FUTURE_CONST int dimensions[3],
114 int dataDescription, vtkUnsignedCharArray* cellGhostArray,
115 vtkUnsignedCharArray* pointGhostArray = nullptr);
116
123 static void GetCellDimensionsFromExtent(
124 const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
125
131 static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
132
139 static void GetLocalStructuredCoordinates(
140 const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
141
147 static void GetGlobalStructuredCoordinates(
148 const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
149
153 static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
154
158 static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, VTK_FUTURE_CONST int dim[3]);
159
164 static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
165 static void GetCellNeighbors(
166 vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
167
173 static vtkIdType ComputePointIdForExtent(
174 const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
175
181 static vtkIdType ComputeCellIdForExtent(
182 const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
183
190 static vtkIdType ComputePointId(
191 const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
192
199 static vtkIdType ComputeCellId(
200 const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
201
208 static void ComputeCellStructuredCoordsForExtent(
209 vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
210
216 static void ComputeCellStructuredCoords(
217 vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
218
224 static void ComputePointStructuredCoordsForExtent(
225 vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
226
232 static void ComputePointStructuredCoords(
233 vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
234
235protected:
236 vtkStructuredData() = default;
237 ~vtkStructuredData() override = default;
238
246 static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
247 {
248 return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
249 }
250
252
259 const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
260 {
261 vtkIdType N12 = N1 * N2;
262 k = static_cast<int>(idx / N12);
263 j = static_cast<int>((idx - k * N12) / N1);
264 i = static_cast<int>(idx - k * N12 - j * N1);
265 }
267
268 // Want to avoid importing <algorithm> in the header...
269 template <typename T>
270 static T Max(const T& a, const T& b)
271 {
272 return (a > b) ? a : b;
273 }
274
275private:
276 vtkStructuredData(const vtkStructuredData&) = delete;
277 void operator=(const vtkStructuredData&) = delete;
278};
279
280//------------------------------------------------------------------------------
281inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
282{
283 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
284 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
285 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
286}
287
288//------------------------------------------------------------------------------
289inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
290{
291 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
292}
293
294//------------------------------------------------------------------------------
295inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
296{
297 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
298 vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
299}
300
301//------------------------------------------------------------------------------
303{
304 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
305 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
306}
307
308//------------------------------------------------------------------------------
310{
311 int cellDims[3];
313
314 // Replace 0's with 1's so we can just multiply them regardless of cell type.
315 cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
316 cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
317 cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
318
319 // Note, when we compute the result below, we statically cast to vtkIdType to
320 // ensure the compiler will generate a 32x32=64 instruction.
321 return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
322 static_cast<vtkIdType>(cellDims[2]);
323}
324
325//------------------------------------------------------------------------------
327 const int nodeExtent[6], int cellExtent[6], int)
328{
329 cellExtent[0] = nodeExtent[0];
330 cellExtent[2] = nodeExtent[2];
331 cellExtent[4] = nodeExtent[4];
332
333 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
334 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
335 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
336}
337
338//------------------------------------------------------------------------------
339inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
340{
341 dims[0] = ext[1] - ext[0] + 1;
342 dims[1] = ext[3] - ext[2] + 1;
343 dims[2] = ext[5] - ext[4] + 1;
344}
345
346//------------------------------------------------------------------------------
348 const int nodeDims[3], int cellDims[3])
349{
350 cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
351 cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
352 cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
353}
354
355//------------------------------------------------------------------------------
357 const int ijk[3], const int ext[6], int lijk[3], int)
358{
359 lijk[0] = ijk[0] - ext[0];
360 lijk[1] = ijk[1] - ext[2];
361 lijk[2] = ijk[2] - ext[4];
362}
363
364//------------------------------------------------------------------------------
366 const int lijk[3], const int ext[6], int ijk[3], int)
367{
368 ijk[0] = ext[0] + lijk[0];
369 ijk[1] = ext[2] + lijk[1];
370 ijk[2] = ext[4] + lijk[2];
371}
372
373//------------------------------------------------------------------------------
375 const int extent[6], const int ijk[3], int)
376{
377 int dims[3];
379
380 int lijk[3];
382
383 return vtkStructuredData::ComputePointId(dims, lijk);
384}
385
386//------------------------------------------------------------------------------
388 const int extent[6], const int ijk[3], int)
389{
390 int nodeDims[3];
392
393 int lijk[3];
395
396 return vtkStructuredData::ComputeCellId(nodeDims, lijk);
397}
398
399//------------------------------------------------------------------------------
401 vtkIdType cellId, const int dims[3], int ijk[3], int)
402{
404 cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
405}
406
407//------------------------------------------------------------------------------
409 vtkIdType cellIdx, const int ext[6], int ijk[3], int)
410{
411 int nodeDims[3];
413
414 int lijk[3];
415 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
416
418}
419
420//------------------------------------------------------------------------------
422 vtkIdType ptId, const int dim[3], int ijk[3], int)
423{
424 vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
425}
426
427//------------------------------------------------------------------------------
429 vtkIdType ptId, const int ext[6], int ijk[3], int)
430{
431 int nodeDims[3];
433
434 int lijk[3];
436
438}
439
440VTK_ABI_NAMESPACE_END
441#endif
list of point or cell ids
Definition vtkIdList.h:23
a simple class to control print indentation
Definition vtkIndent.h:29
abstract base class for most VTK objects
Definition vtkObject.h:49
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 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 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).
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
#define VTK_EMPTY
int vtkIdType
Definition vtkType.h:315