VTK  9.2.6
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 =========================================================================*/
41 #ifndef vtkStructuredData_h
42 #define vtkStructuredData_h
43 
44 #include "vtkCommonDataModelModule.h" // For export macro
45 #include "vtkObject.h"
46 
47 class vtkIdList;
49 
50 #define VTK_UNCHANGED 0
51 #define VTK_SINGLE_POINT 1
52 #define VTK_X_LINE 2
53 #define VTK_Y_LINE 3
54 #define VTK_Z_LINE 4
55 #define VTK_XY_PLANE 5
56 #define VTK_YZ_PLANE 6
57 #define VTK_XZ_PLANE 7
58 #define VTK_XYZ_GRID 8
59 #define VTK_EMPTY 9
60 
61 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
62 {
63 public:
64  vtkTypeMacro(vtkStructuredData, vtkObject);
65  void PrintSelf(ostream& os, vtkIndent indent) override;
66 
68 
75  static int SetDimensions(int inDim[3], int dim[3]);
76  static int SetExtent(int inExt[6], int ext[6]);
78 
80 
84  static int GetDataDescription(int dims[3]);
85  static int GetDataDescriptionFromExtent(int ext[6]);
87 
89 
92  static int GetDataDimension(int dataDescription);
93  static int GetDataDimension(int ext[6]);
95 
101  static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
102 
108  static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
109 
115  static void GetCellExtentFromPointExtent(
116  const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
117 
122  static void GetDimensionsFromExtent(
123  const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
124 
128  static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
129 
133  static bool IsCellVisible(vtkIdType cellId, int dimensions[3], int dataDescription,
134  vtkUnsignedCharArray* cellGhostArray, vtkUnsignedCharArray* pointGhostArray = nullptr);
135 
142  static void GetCellDimensionsFromExtent(
143  const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
144 
150  static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
151 
158  static void GetLocalStructuredCoordinates(
159  const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
160 
166  static void GetGlobalStructuredCoordinates(
167  const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
168 
172  static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
173 
177  static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, int dim[3]);
178 
183  static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
184  static void GetCellNeighbors(
185  vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
186 
192  static vtkIdType ComputePointIdForExtent(
193  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
194 
200  static vtkIdType ComputeCellIdForExtent(
201  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
202 
209  static vtkIdType ComputePointId(
210  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
211 
218  static vtkIdType ComputeCellId(
219  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
220 
227  static void ComputeCellStructuredCoordsForExtent(
228  const vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
229 
235  static void ComputeCellStructuredCoords(
236  const vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
237 
243  static void ComputePointStructuredCoordsForExtent(
244  const vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
245 
251  static void ComputePointStructuredCoords(
252  const vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
253 
254 protected:
255  vtkStructuredData() = default;
256  ~vtkStructuredData() override = default;
257 
265  static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
266  {
267  return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
268  }
269 
271 
278  const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
279  {
280  vtkIdType N12 = N1 * N2;
281  k = static_cast<int>(idx / N12);
282  j = static_cast<int>((idx - k * N12) / N1);
283  i = static_cast<int>(idx - k * N12 - j * N1);
284  }
286 
287  // Want to avoid importing <algorithm> in the header...
288  template <typename T>
289  static T Max(const T& a, const T& b)
290  {
291  return (a > b) ? a : b;
292  }
293 
294 private:
295  vtkStructuredData(const vtkStructuredData&) = delete;
296  void operator=(const vtkStructuredData&) = delete;
297 };
298 
299 //------------------------------------------------------------------------------
300 inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
301 {
302  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
303  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
304  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
305 }
306 
307 //------------------------------------------------------------------------------
308 inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
309 {
310  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
311 }
312 
313 //------------------------------------------------------------------------------
314 inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
315 {
316  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
317  vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
318 }
319 
320 //------------------------------------------------------------------------------
321 inline vtkIdType vtkStructuredData::GetNumberOfPoints(const int ext[6], int)
322 {
323  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
324  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
325 }
326 
327 //------------------------------------------------------------------------------
328 inline vtkIdType vtkStructuredData::GetNumberOfCells(const int ext[6], int)
329 {
330  int cellDims[3];
332 
333  // Replace 0's with 1's so we can just multiply them regardless of cell type.
334  cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
335  cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
336  cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
337 
338  // Note, when we compute the result below, we statically cast to vtkIdType to
339  // ensure the compiler will generate a 32x32=64 instruction.
340  return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
341  static_cast<vtkIdType>(cellDims[2]);
342 }
343 
344 //------------------------------------------------------------------------------
346  const int nodeExtent[6], int cellExtent[6], int)
347 {
348  cellExtent[0] = nodeExtent[0];
349  cellExtent[2] = nodeExtent[2];
350  cellExtent[4] = nodeExtent[4];
351 
352  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
353  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
354  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
355 }
356 
357 //------------------------------------------------------------------------------
358 inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
359 {
360  dims[0] = ext[1] - ext[0] + 1;
361  dims[1] = ext[3] - ext[2] + 1;
362  dims[2] = ext[5] - ext[4] + 1;
363 }
364 
365 //------------------------------------------------------------------------------
367  const int nodeDims[3], int cellDims[3])
368 {
369  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
370  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
371  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
372 }
373 
374 //------------------------------------------------------------------------------
376  const int ijk[3], const int ext[6], int lijk[3], int)
377 {
378  lijk[0] = ijk[0] - ext[0];
379  lijk[1] = ijk[1] - ext[2];
380  lijk[2] = ijk[2] - ext[4];
381 }
382 
383 //------------------------------------------------------------------------------
385  const int lijk[3], const int ext[6], int ijk[3], int)
386 {
387  ijk[0] = ext[0] + lijk[0];
388  ijk[1] = ext[2] + lijk[1];
389  ijk[2] = ext[4] + lijk[2];
390 }
391 
392 //------------------------------------------------------------------------------
394  const int extent[6], const int ijk[3], int)
395 {
396  int dims[3];
398 
399  int lijk[3];
401 
402  return vtkStructuredData::ComputePointId(dims, lijk);
403 }
404 
405 //------------------------------------------------------------------------------
407  const int extent[6], const int ijk[3], int)
408 {
409  int nodeDims[3];
411 
412  int lijk[3];
414 
415  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
416 }
417 
418 //------------------------------------------------------------------------------
420  const vtkIdType cellId, const int dims[3], int ijk[3], int)
421 {
423  cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
424 }
425 
426 //------------------------------------------------------------------------------
428  const vtkIdType cellIdx, const int ext[6], int ijk[3], int)
429 {
430  int nodeDims[3];
432 
433  int lijk[3];
434  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
435 
437 }
438 
439 //------------------------------------------------------------------------------
441  const vtkIdType ptId, const int dim[3], int ijk[3], int)
442 {
443  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
444 }
445 
446 //------------------------------------------------------------------------------
448  const vtkIdType ptId, const int ext[6], int ijk[3], int)
449 {
450  int nodeDims[3];
452 
453  int lijk[3];
455 
457 }
458 
459 #endif
list of point or cell ids
Definition: vtkIdList.h:43
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
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