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 =========================================================================*/
32 #ifndef vtkStructuredData_h
33 #define vtkStructuredData_h
34 
35 #include "vtkCommonDataModelModule.h" // For export macro
36 #include "vtkObject.h"
37 
38 class vtkIdList;
40 
41 #define VTK_UNCHANGED 0
42 #define VTK_SINGLE_POINT 1
43 #define VTK_X_LINE 2
44 #define VTK_Y_LINE 3
45 #define VTK_Z_LINE 4
46 #define VTK_XY_PLANE 5
47 #define VTK_YZ_PLANE 6
48 #define VTK_XZ_PLANE 7
49 #define VTK_XYZ_GRID 8
50 #define VTK_EMPTY 9
51 
52 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
53 {
54 public:
55  vtkTypeMacro(vtkStructuredData, vtkObject);
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
59 
66  static int SetDimensions(int inDim[3], int dim[3]);
67  static int SetExtent(int inExt[6], int ext[6]);
69 
71 
75  static int GetDataDescription(int dims[3]);
76  static int GetDataDescriptionFromExtent(int ext[6]);
78 
80 
83  static int GetDataDimension(int dataDescription);
84  static int GetDataDimension(int ext[6]);
86 
92  static vtkIdType GetNumberOfPoints(const int ext[6], int dataDescription = VTK_EMPTY);
93 
99  static vtkIdType GetNumberOfCells(const int ext[6], int dataDescription = VTK_EMPTY);
100 
106  static void GetCellExtentFromPointExtent(
107  const int pntExtent[6], int cellExtent[6], int dataDescription = VTK_EMPTY);
108 
113  static void GetDimensionsFromExtent(
114  const int ext[6], int dims[3], int dataDescription = VTK_EMPTY);
115 
119  static bool IsPointVisible(vtkIdType cellId, vtkUnsignedCharArray* ghosts);
120 
124  static bool IsCellVisible(vtkIdType cellId, int dimensions[3], int dataDescription,
125  vtkUnsignedCharArray* cellGhostArray, vtkUnsignedCharArray* pointGhostArray = nullptr);
126 
133  static void GetCellDimensionsFromExtent(
134  const int ext[6], int celldims[3], int dataDescription = VTK_EMPTY);
135 
141  static void GetCellDimensionsFromPointDimensions(const int pntdims[3], int cellDims[3]);
142 
149  static void GetLocalStructuredCoordinates(
150  const int ijk[3], const int ext[6], int lijk[3], int dataDescription = VTK_EMPTY);
151 
157  static void GetGlobalStructuredCoordinates(
158  const int lijk[3], const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
159 
163  static void GetCellPoints(vtkIdType cellId, vtkIdList* ptIds, int dataDescription, int dim[3]);
164 
168  static void GetPointCells(vtkIdType ptId, vtkIdList* cellIds, int dim[3]);
169 
174  static void GetCellNeighbors(vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3]);
175  static void GetCellNeighbors(
176  vtkIdType cellId, vtkIdList* ptIds, vtkIdList* cellIds, int dim[3], int seedLoc[3]);
177 
183  static vtkIdType ComputePointIdForExtent(
184  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
185 
191  static vtkIdType ComputeCellIdForExtent(
192  const int extent[6], const int ijk[3], int dataDescription = VTK_EMPTY);
193 
200  static vtkIdType ComputePointId(
201  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
202 
209  static vtkIdType ComputeCellId(
210  const int dim[3], const int ijk[3], int dataDescription = VTK_EMPTY);
211 
218  static void ComputeCellStructuredCoordsForExtent(
219  const vtkIdType cellIdx, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
220 
226  static void ComputeCellStructuredCoords(
227  const vtkIdType cellId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
228 
234  static void ComputePointStructuredCoordsForExtent(
235  const vtkIdType ptId, const int ext[6], int ijk[3], int dataDescription = VTK_EMPTY);
236 
242  static void ComputePointStructuredCoords(
243  const vtkIdType ptId, const int dim[3], int ijk[3], int dataDescription = VTK_EMPTY);
244 
245 protected:
246  vtkStructuredData() = default;
247  ~vtkStructuredData() override = default;
248 
256  static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
257  {
258  return ((static_cast<vtkIdType>(k) * N2 + j) * N1 + i);
259  }
260 
262 
269  const vtkIdType idx, const int N1, const int N2, int& i, int& j, int& k)
270  {
271  vtkIdType N12 = N1 * N2;
272  k = static_cast<int>(idx / N12);
273  j = static_cast<int>((idx - k * N12) / N1);
274  i = static_cast<int>(idx - k * N12 - j * N1);
275  }
277 
278  // Want to avoid importing <algorithm> in the header...
279  template <typename T>
280  static T Max(const T& a, const T& b)
281  {
282  return (a > b) ? a : b;
283  }
284 
285 private:
286  vtkStructuredData(const vtkStructuredData&) = delete;
287  void operator=(const vtkStructuredData&) = delete;
288 };
289 
290 //------------------------------------------------------------------------------
291 inline void vtkStructuredData::GetCellDimensionsFromExtent(const int ext[6], int celldims[3], int)
292 {
293  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
294  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
295  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
296 }
297 
298 //------------------------------------------------------------------------------
299 inline vtkIdType vtkStructuredData::ComputePointId(const int dims[3], const int ijk[3], int)
300 {
301  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2], dims[0], dims[1]);
302 }
303 
304 //------------------------------------------------------------------------------
305 inline vtkIdType vtkStructuredData::ComputeCellId(const int dims[3], const int ijk[3], int)
306 {
307  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
308  vtkStructuredData::Max(dims[0] - 1, 1), vtkStructuredData::Max(dims[1] - 1, 1));
309 }
310 
311 //------------------------------------------------------------------------------
312 inline vtkIdType vtkStructuredData::GetNumberOfPoints(const int ext[6], int)
313 {
314  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) * static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
315  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
316 }
317 
318 //------------------------------------------------------------------------------
319 inline vtkIdType vtkStructuredData::GetNumberOfCells(const int ext[6], int)
320 {
321  int cellDims[3];
323 
324  // Replace 0's with 1's so we can just multiply them regardless of cell type.
325  cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
326  cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
327  cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
328 
329  // Note, when we compute the result below, we statically cast to vtkIdType to
330  // ensure the compiler will generate a 32x32=64 instruction.
331  return static_cast<vtkIdType>(cellDims[0]) * static_cast<vtkIdType>(cellDims[1]) *
332  static_cast<vtkIdType>(cellDims[2]);
333 }
334 
335 //------------------------------------------------------------------------------
337  const int nodeExtent[6], int cellExtent[6], int)
338 {
339  cellExtent[0] = nodeExtent[0];
340  cellExtent[2] = nodeExtent[2];
341  cellExtent[4] = nodeExtent[4];
342 
343  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
344  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
345  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
346 }
347 
348 //------------------------------------------------------------------------------
349 inline void vtkStructuredData::GetDimensionsFromExtent(const int ext[6], int dims[3], int)
350 {
351  dims[0] = ext[1] - ext[0] + 1;
352  dims[1] = ext[3] - ext[2] + 1;
353  dims[2] = ext[5] - ext[4] + 1;
354 }
355 
356 //------------------------------------------------------------------------------
358  const int nodeDims[3], int cellDims[3])
359 {
360  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
361  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
362  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
363 }
364 
365 //------------------------------------------------------------------------------
367  const int ijk[3], const int ext[6], int lijk[3], int)
368 {
369  lijk[0] = ijk[0] - ext[0];
370  lijk[1] = ijk[1] - ext[2];
371  lijk[2] = ijk[2] - ext[4];
372 }
373 
374 //------------------------------------------------------------------------------
376  const int lijk[3], const int ext[6], int ijk[3], int)
377 {
378  ijk[0] = ext[0] + lijk[0];
379  ijk[1] = ext[2] + lijk[1];
380  ijk[2] = ext[4] + lijk[2];
381 }
382 
383 //------------------------------------------------------------------------------
385  const int extent[6], const int ijk[3], int)
386 {
387  int dims[3];
389 
390  int lijk[3];
392 
393  return vtkStructuredData::ComputePointId(dims, lijk);
394 }
395 
396 //------------------------------------------------------------------------------
398  const int extent[6], const int ijk[3], int)
399 {
400  int nodeDims[3];
402 
403  int lijk[3];
405 
406  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
407 }
408 
409 //------------------------------------------------------------------------------
411  const vtkIdType cellId, const int dims[3], int ijk[3], int)
412 {
414  cellId, dims[0] - 1, dims[1] - 1, ijk[0], ijk[1], ijk[2]);
415 }
416 
417 //------------------------------------------------------------------------------
419  const vtkIdType cellIdx, const int ext[6], int ijk[3], int)
420 {
421  int nodeDims[3];
423 
424  int lijk[3];
425  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
426 
428 }
429 
430 //------------------------------------------------------------------------------
432  const vtkIdType ptId, const int dim[3], int ijk[3], int)
433 {
434  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1], ijk[0], ijk[1], ijk[2]);
435 }
436 
437 //------------------------------------------------------------------------------
439  const vtkIdType ptId, const int ext[6], int ijk[3], int)
440 {
441  int nodeDims[3];
443 
444  int lijk[3];
446 
448 }
449 
450 #endif
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, this method computes the corresponding structured coordinates of the given cell.
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 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.
Singleton class for topologically regular data.
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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.
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 void GetDimensionsFromExtent(const int ext[6], int dims[3], int dataDescription=VTK_EMPTY)
Computes the structured grid dimensions based on the given extent.
static T Max(const T &a, const T &b)
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).
int vtkIdType
Definition: vtkType.h:332
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...
#define VTK_EMPTY
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 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 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...
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:33
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.
dynamic, self-adjusting array of unsigned char
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 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...
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 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 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...