VTK
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;
36 
37 #define VTK_UNCHANGED 0
38 #define VTK_SINGLE_POINT 1
39 #define VTK_X_LINE 2
40 #define VTK_Y_LINE 3
41 #define VTK_Z_LINE 4
42 #define VTK_XY_PLANE 5
43 #define VTK_YZ_PLANE 6
44 #define VTK_XZ_PLANE 7
45 #define VTK_XYZ_GRID 8
46 #define VTK_EMPTY 9
47 
48 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
49 {
50 public:
52 
54 
61  static int SetDimensions(int inDim[3], int dim[3]);
62  static int SetExtent(int inExt[6], int ext[6]);
64 
66 
70  static int GetDataDescription(int dims[3]);
71  static int GetDataDescriptionFromExtent( int ext[6] );
73 
75 
78  static int GetDataDimension(int dataDescription);
79  static int GetDataDimension( int ext[6] );
81 
87  static vtkIdType GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY);
88 
94  static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY);
95 
101  static void GetCellExtentFromPointExtent(
102  int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY );
103 
108  static void GetDimensionsFromExtent(
109  int ext[6], int dims[3], int dataDescription=VTK_EMPTY );
110 
117  static void GetCellDimensionsFromExtent(
118  int ext[6], int celldims[3], int dataDescription=VTK_EMPTY );
119 
125  static void GetCellDimensionsFromPointDimensions(
126  int pntdims[3],int cellDims[3] );
127 
134  static void GetLocalStructuredCoordinates(
135  int ijk[3], int ext[6], int lijk[3], int dataDescription=VTK_EMPTY );
136 
142  static void GetGlobalStructuredCoordinates(
143  int lijk[3], int ext[6], int ijk[3], int dataDescription=VTK_EMPTY );
144 
148  static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds,
149  int dataDescription, int dim[3]);
150 
154  static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3]);
155 
160  static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
161  vtkIdList *cellIds, int dim[3]);
162  static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
163  vtkIdList *cellIds, int dim[3], int seedLoc[3]);
164 
170  static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3],
171  int dataDescription=VTK_EMPTY );
172 
178  static vtkIdType ComputeCellIdForExtent(
179  int extent[6], int ijk[3], int dataDescription=VTK_EMPTY );
180 
187  static vtkIdType ComputePointId(
188  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
189 
196  static vtkIdType ComputeCellId(
197  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
198 
205  static void ComputeCellStructuredCoordsForExtent(
206  const vtkIdType cellIdx, int ext[6], int ijk[3],
207  int dataDescription=VTK_EMPTY );
208 
214  static void ComputeCellStructuredCoords(
215  const vtkIdType cellId, int dim[3], int ijk[3],
216  int dataDescription=VTK_EMPTY );
217 
223  static void ComputePointStructuredCoordsForExtent(
224  const vtkIdType ptId, int ext[6], int ijk[3],
225  int dataDescription=VTK_EMPTY );
226 
232  static void ComputePointStructuredCoords(
233  const vtkIdType ptId, int dim[3], int ijk[3],
234  int dataDescription=VTK_EMPTY );
235 
236 protected:
238  ~vtkStructuredData() override {}
239 
248  const int i, const int j, const int k, const int N1, const int N2 )
249  {
250  return( (static_cast<vtkIdType>(k)*N2+j)*N1+i );
251  }
252 
254 
261  const vtkIdType idx, const int N1, const int N2,int &i, int &j, int &k )
262  {
263  int N12 = N1*N2;
264  k = idx/N12;
265  j = (idx-k*N12)/N1;
266  i = idx-k*N12-j*N1;
267  }
269 
270  // Want to avoid importing <algorithm> in the header...
271  template <typename T>
272  static T Max(const T &a, const T &b)
273  {
274  return (a > b) ? a : b;
275  }
276 
277 private:
278  vtkStructuredData(const vtkStructuredData&) = delete;
279  void operator=(const vtkStructuredData&) = delete;
280 };
281 
282 //------------------------------------------------------------------------------
284  int ext[6], int celldims[3], int)
285 {
286  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
287  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
288  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
289 }
290 
291 //------------------------------------------------------------------------------
292 inline vtkIdType vtkStructuredData::ComputePointId(int dims[3], int ijk[3], int)
293 {
294  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
295  dims[0], dims[1]);
296 }
297 
298 //------------------------------------------------------------------------------
299 inline vtkIdType vtkStructuredData::ComputeCellId(int dims[3], int ijk[3], int)
300 {
302  ijk[0], ijk[1], ijk[2],
303  vtkStructuredData::Max(dims[0] - 1, 1),
304  vtkStructuredData::Max(dims[1] - 1, 1));
305 }
306 
307 //------------------------------------------------------------------------------
309 {
310  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) *
311  static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
312  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
313 }
314 
315 //------------------------------------------------------------------------------
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]) *
329  static_cast<vtkIdType>(cellDims[1]) *
330  static_cast<vtkIdType>(cellDims[2]);
331 }
332 
333 //------------------------------------------------------------------------------
335  int nodeExtent[6], int cellExtent[6], int)
336 {
337  cellExtent[0] = nodeExtent[0];
338  cellExtent[2] = nodeExtent[2];
339  cellExtent[4] = nodeExtent[4];
340 
341  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
342  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
343  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
344 }
345 
346 //------------------------------------------------------------------------------
347 inline void vtkStructuredData::GetDimensionsFromExtent(int ext[6], int dims[3],
348  int)
349 {
350  dims[0] = ext[1] - ext[0] + 1;
351  dims[1] = ext[3] - ext[2] + 1;
352  dims[2] = ext[5] - ext[4] + 1;
353 }
354 
355 //------------------------------------------------------------------------------
357  int nodeDims[3], int cellDims[3])
358 {
359  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
360  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
361  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
362 }
363 
364 //------------------------------------------------------------------------------
366  int ijk[3], int ext[6], int lijk[3], int)
367 {
368  lijk[0] = ijk[0] - ext[0];
369  lijk[1] = ijk[1] - ext[2];
370  lijk[2] = ijk[2] - ext[4];
371 }
372 
373 //------------------------------------------------------------------------------
375  int lijk[3], int ext[6], int ijk[3], int)
376 {
377  ijk[0] = ext[0] + lijk[0];
378  ijk[1] = ext[2] + lijk[1];
379  ijk[2] = ext[4] + lijk[2];
380 }
381 
382 //------------------------------------------------------------------------------
384  int extent[6], int ijk[3], int)
385 {
386  int dims[3];
388 
389  int lijk[3];
391 
392  return vtkStructuredData::ComputePointId(dims, lijk);
393 }
394 
395 //------------------------------------------------------------------------------
397  int extent[6], int ijk[3], int)
398 {
399  int nodeDims[3];
401 
402  int lijk[3];
404 
405  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
406 }
407 
408 //------------------------------------------------------------------------------
410  const vtkIdType cellId, int dims[3], int ijk[3], int)
411 {
413  dims[0] - 1, dims[1] - 1,
414  ijk[0], ijk[1], ijk[2]);
415 }
416 
417 //------------------------------------------------------------------------------
419  const vtkIdType cellIdx, 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, int dim[3], int ijk[3], int)
433 {
434  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1],
435  ijk[0], ijk[1], ijk[2]);
436 }
437 
438 //------------------------------------------------------------------------------
440  const vtkIdType ptId, int ext[6], int ijk[3], int)
441 {
442  int nodeDims[3];
444 
445  int lijk[3];
447 
449 }
450 
451 #endif
452 
453 // VTK-HeaderTest-Exclude: vtkStructuredData.h
static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY)
Given the grid extent, this method returns the total number of cells within the extent.
static void ComputePointStructuredCoordsForExtent(const vtkIdType ptId, 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).
Singleton class for topologically regular data.
abstract base class for most VTK objects
Definition: vtkObject.h:53
#define N2
static T Max(const T &a, const T &b)
static vtkIdType ComputePointId(int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the dimensions of the structured dataset,...
int vtkIdType
Definition: vtkType.h:345
~vtkStructuredData() override
#define VTK_EMPTY
#define N1
static void GetGlobalStructuredCoordinates(int lijk[3], 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 void GetCellDimensionsFromExtent(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 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 GetDimensionsFromExtent(int ext[6], int dims[3], int dataDescription=VTK_EMPTY)
Computes the structured grid dimensions based on the given extent.
static vtkIdType ComputeCellIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
Given a location in structured coordinates (i-j-k), and the extent of the structured dataset,...
list of point or cell ids
Definition: vtkIdList.h:30
static void GetLocalStructuredCoordinates(int ijk[3], 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 ComputeCellStructuredCoordsForExtent(const vtkIdType cellIdx, 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 void GetCellDimensionsFromPointDimensions(int pntdims[3], int cellDims[3])
Given the dimensions of the grid, in pntdims, this method returns the corresponding cell dimensions f...
static vtkIdType ComputeCellId(int dim[3], 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(int extent[6], 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 ComputeCellStructuredCoords(const vtkIdType cellId, 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 ComputePointStructuredCoords(const vtkIdType ptId, 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 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 GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY)
Given the grid extent, this method returns the total number of points within the extent.
static void GetCellExtentFromPointExtent(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.