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 =========================================================================*/
29 #ifndef vtkStructuredData_h
30 #define vtkStructuredData_h
31 
32 #include "vtkCommonDataModelModule.h" // For export macro
33 #include "vtkObject.h"
34 
35 class vtkIdList;
37 
38 #define VTK_UNCHANGED 0
39 #define VTK_SINGLE_POINT 1
40 #define VTK_X_LINE 2
41 #define VTK_Y_LINE 3
42 #define VTK_Z_LINE 4
43 #define VTK_XY_PLANE 5
44 #define VTK_YZ_PLANE 6
45 #define VTK_XZ_PLANE 7
46 #define VTK_XYZ_GRID 8
47 #define VTK_EMPTY 9
48 
49 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
50 {
51 public:
52  vtkTypeMacro(vtkStructuredData, vtkObject);
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
56 
63  static int SetDimensions(int inDim[3], int dim[3]);
64  static int SetExtent(int inExt[6], int ext[6]);
66 
68 
72  static int GetDataDescription(int dims[3]);
73  static int GetDataDescriptionFromExtent(int ext[6]);
75 
77 
80  static int GetDataDimension(int dataDescription);
81  static int GetDataDimension(int ext[6]);
83 
89  static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
90 
96  static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
97 
103  static void GetCellExtentFromPointExtent(
104  const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
105 
110  static void GetDimensionsFromExtent(
111  const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
112 
116  static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
117 
121  static bool IsCellVisible(vtkIdType cellId, int dimensions[3], int dataDescription,
122  vtkUnsignedCharArray* cellGhostArray, vtkUnsignedCharArray* pointGhostArray = nullptr);
123 
130  static void GetCellDimensionsFromExtent(
131  const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
132 
138  static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
139 
146  static void GetLocalStructuredCoordinates(
147  const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
148 
154  static void GetGlobalStructuredCoordinates(
155  const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
156 
160  static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
161 
165  static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, int dim[3]);
166 
171  static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
172  static void GetCellNeighbors(
173  vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
174 
180  static vtkIdType ComputePointIdForExtent(
181  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
182 
188  static vtkIdType ComputeCellIdForExtent(
189  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
190 
197  static vtkIdType ComputePointId(
198  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
199 
206  static vtkIdType ComputeCellId(
207  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
208 
215  static void ComputeCellStructuredCoordsForExtent(
216  const vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
217 
223  static void ComputeCellStructuredCoords(
224  const vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
225 
231  static void ComputePointStructuredCoordsForExtent(
232  const vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
233 
239  static void ComputePointStructuredCoords(
240  const vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
241 
242 protected:
243  vtkStructuredData() = default;
244  ~vtkStructuredData() override = default;
245 
253  static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
254  {
255  return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
256  }
257 
259 
266  const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
267  {
268  vtkIdType N12 = N1 * N2;
269  k = static_cast<int>(idx / N12);
270  j = static_cast<int>((idx - k * N12) / N1);
271  i = static_cast<int>(idx - k * N12 - j * N1);
272  }
274 
275  // Want to avoid importing <algorithm> in the header...
276  template <typename T>
277  static T Max(const T& a, const T& b)
278  {
279  return (a > b) ? a : b;
280  }
281 
282 private:
283  vtkStructuredData(const vtkStructuredData&) = delete;
284  void operator=(const vtkStructuredData&) = delete;
285 };
286 
287 //------------------------------------------------------------------------------
288 inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
289 {
290  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
291  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
292  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
293 }
294 
295 //------------------------------------------------------------------------------
296 inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
297 {
298  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
299 }
300 
301 //------------------------------------------------------------------------------
302 inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
303 {
304  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
305  vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
306 }
307 
308 //------------------------------------------------------------------------------
309 inline vtkIdType vtkStructuredData::GetNumberOfPoints(const int ext[6], int)
310 {
311  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
312  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
313 }
314 
315 //------------------------------------------------------------------------------
316 inline vtkIdType vtkStructuredData::GetNumberOfCells(const int ext[6], int)
317 {
318  int cellDims[3];
320 
321  // Replace 0's with 1's so we can just multiply them regardless of cell type.
322  cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
323  cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
324  cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
325 
326  // Note, when we compute the result below, we statically cast to vtkIdType to
327  // ensure the compiler will generate a 32x32=64 instruction.
328  return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
329  static_cast<vtkIdType>(cellDims[2]);
330 }
331 
332 //------------------------------------------------------------------------------
334  const int nodeExtent[6], int cellExtent[6], int)
335 {
336  cellExtent[0] = nodeExtent[0];
337  cellExtent[2] = nodeExtent[2];
338  cellExtent[4] = nodeExtent[4];
339 
340  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
341  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
342  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
343 }
344 
345 //------------------------------------------------------------------------------
346 inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
347 {
348  dims[0] = ext[1] - ext[0] + 1;
349  dims[1] = ext[3] - ext[2] + 1;
350  dims[2] = ext[5] - ext[4] + 1;
351 }
352 
353 //------------------------------------------------------------------------------
355  const int nodeDims[3], int cellDims[3])
356 {
357  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
358  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
359  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
360 }
361 
362 //------------------------------------------------------------------------------
364  const int ijk[3], const int ext[6], int lijk[3], int)
365 {
366  lijk[0] = ijk[0] - ext[0];
367  lijk[1] = ijk[1] - ext[2];
368  lijk[2] = ijk[2] - ext[4];
369 }
370 
371 //------------------------------------------------------------------------------
373  const int lijk[3], const int ext[6], int ijk[3], int)
374 {
375  ijk[0] = ext[0] + lijk[0];
376  ijk[1] = ext[2] + lijk[1];
377  ijk[2] = ext[4] + lijk[2];
378 }
379 
380 //------------------------------------------------------------------------------
382  const int extent[6], const int ijk[3], int)
383 {
384  int dims[3];
386 
387  int lijk[3];
389 
390  return vtkStructuredData::ComputePointId(dims, lijk);
391 }
392 
393 //------------------------------------------------------------------------------
395  const int extent[6], const int ijk[3], int)
396 {
397  int nodeDims[3];
399 
400  int lijk[3];
402 
403  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
404 }
405 
406 //------------------------------------------------------------------------------
408  const vtkIdType cellId, const int dims[3], int ijk[3], int)
409 {
411  cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
412 }
413 
414 //------------------------------------------------------------------------------
416  const vtkIdType cellIdx, const int ext[6], int ijk[3], int)
417 {
418  int nodeDims[3];
420 
421  int lijk[3];
422  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
423 
425 }
426 
427 //------------------------------------------------------------------------------
429  const vtkIdType ptId, const int dim[3], int ijk[3], int)
430 {
431  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
432 }
433 
434 //------------------------------------------------------------------------------
436  const vtkIdType ptId, const int ext[6], int ijk[3], int)
437 {
438  int nodeDims[3];
440 
441  int lijk[3];
443 
445 }
446 
447 #endif
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
Singleton class for topologically regular data.
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 int SetDimensions(int inDim[3], int dim[3])
Specify the dimensions of a regular, rectangular dataset.
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).
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 SetExtent(int inExt[6], int ext[6])
Specify the dimensions of a regular, rectangular 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 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,...
static int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
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).
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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() 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 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).
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 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 void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, 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
@ extent
Definition: vtkX3D.h:351
#define VTK_EMPTY
int vtkIdType
Definition: vtkType.h:332