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 =========================================================================*/
32 #ifndef vtkStructuredData_h
33 #define vtkStructuredData_h
34 
35 #include "vtkCommonDataModelModule.h" // For export macro
36 #include "vtkObject.h"
37 
38 class vtkIdList;
39 
40 #define VTK_UNCHANGED 0
41 #define VTK_SINGLE_POINT 1
42 #define VTK_X_LINE 2
43 #define VTK_Y_LINE 3
44 #define VTK_Z_LINE 4
45 #define VTK_XY_PLANE 5
46 #define VTK_YZ_PLANE 6
47 #define VTK_XZ_PLANE 7
48 #define VTK_XYZ_GRID 8
49 #define VTK_EMPTY 9
50 
51 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
52 {
53 public:
55 
57 
64  static int SetDimensions(int inDim[3], int dim[3]);
65  static int SetExtent(int inExt[6], int ext[6]);
67 
69 
73  static int GetDataDescription(int dims[3]);
74  static int GetDataDescriptionFromExtent( int ext[6] );
76 
78 
81  static int GetDataDimension(int dataDescription);
82  static int GetDataDimension( int ext[6] );
84 
90  static vtkIdType GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY);
91 
97  static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY);
98 
104  static void GetCellExtentFromPointExtent(
105  int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY );
106 
111  static void GetDimensionsFromExtent(
112  int ext[6], int dims[3], int dataDescription=VTK_EMPTY );
113 
120  static void GetCellDimensionsFromExtent(
121  int ext[6], int celldims[3], int dataDescription=VTK_EMPTY );
122 
128  static void GetCellDimensionsFromPointDimensions(
129  int pntdims[3],int cellDims[3] );
130 
137  static void GetLocalStructuredCoordinates(
138  int ijk[3], int ext[6], int lijk[3], int dataDescription=VTK_EMPTY );
139 
145  static void GetGlobalStructuredCoordinates(
146  int lijk[3], int ext[6], int ijk[3], int dataDescription=VTK_EMPTY );
147 
151  static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds,
152  int dataDescription, int dim[3]);
153 
157  static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3]);
158 
163  static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
164  vtkIdList *cellIds, int dim[3]);
165  static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
166  vtkIdList *cellIds, int dim[3], int seedLoc[3]);
167 
173  static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3],
174  int dataDescription=VTK_EMPTY );
175 
181  static vtkIdType ComputeCellIdForExtent(
182  int extent[6], int ijk[3], int dataDescription=VTK_EMPTY );
183 
190  static vtkIdType ComputePointId(
191  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
192 
199  static vtkIdType ComputeCellId(
200  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
201 
208  static void ComputeCellStructuredCoordsForExtent(
209  const vtkIdType cellIdx, int ext[6], int ijk[3],
210  int dataDescription=VTK_EMPTY );
211 
217  static void ComputeCellStructuredCoords(
218  const vtkIdType cellId, int dim[3], int ijk[3],
219  int dataDescription=VTK_EMPTY );
220 
226  static void ComputePointStructuredCoordsForExtent(
227  const vtkIdType ptId, int ext[6], int ijk[3],
228  int dataDescription=VTK_EMPTY );
229 
235  static void ComputePointStructuredCoords(
236  const vtkIdType ptId, int dim[3], int ijk[3],
237  int dataDescription=VTK_EMPTY );
238 
239 protected:
241  ~vtkStructuredData() override {}
242 
251  const int i, const int j, const int k, const int N1, const int N2 )
252  {
253  return( (static_cast<vtkIdType>(k)*N2+j)*N1+i );
254  }
255 
257 
264  const vtkIdType idx, const int N1, const int N2,int &i, int &j, int &k )
265  {
266  int N12 = N1*N2;
267  k = idx/N12;
268  j = (idx-k*N12)/N1;
269  i = idx-k*N12-j*N1;
270  }
272 
273  // Want to avoid importing <algorithm> in the header...
274  template <typename T>
275  static T Max(const T &a, const T &b)
276  {
277  return (a > b) ? a : b;
278  }
279 
280 private:
281  vtkStructuredData(const vtkStructuredData&) = delete;
282  void operator=(const vtkStructuredData&) = delete;
283 };
284 
285 //------------------------------------------------------------------------------
287  int ext[6], int celldims[3], int)
288 {
289  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
290  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
291  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
292 }
293 
294 //------------------------------------------------------------------------------
295 inline vtkIdType vtkStructuredData::ComputePointId(int dims[3], int ijk[3], int)
296 {
297  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
298  dims[0], dims[1]);
299 }
300 
301 //------------------------------------------------------------------------------
302 inline vtkIdType vtkStructuredData::ComputeCellId(int dims[3], int ijk[3], int)
303 {
305  ijk[0], ijk[1], ijk[2],
306  vtkStructuredData::Max(dims[0] - 1, 1),
307  vtkStructuredData::Max(dims[1] - 1, 1));
308 }
309 
310 //------------------------------------------------------------------------------
312 {
313  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) *
314  static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
315  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
316 }
317 
318 //------------------------------------------------------------------------------
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]) *
332  static_cast<vtkIdType>(cellDims[1]) *
333  static_cast<vtkIdType>(cellDims[2]);
334 }
335 
336 //------------------------------------------------------------------------------
338  int nodeExtent[6], int cellExtent[6], int)
339 {
340  cellExtent[0] = nodeExtent[0];
341  cellExtent[2] = nodeExtent[2];
342  cellExtent[4] = nodeExtent[4];
343 
344  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
345  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
346  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
347 }
348 
349 //------------------------------------------------------------------------------
350 inline void vtkStructuredData::GetDimensionsFromExtent(int ext[6], int dims[3],
351  int)
352 {
353  dims[0] = ext[1] - ext[0] + 1;
354  dims[1] = ext[3] - ext[2] + 1;
355  dims[2] = ext[5] - ext[4] + 1;
356 }
357 
358 //------------------------------------------------------------------------------
360  int nodeDims[3], int cellDims[3])
361 {
362  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
363  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
364  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
365 }
366 
367 //------------------------------------------------------------------------------
369  int ijk[3], int ext[6], int lijk[3], int)
370 {
371  lijk[0] = ijk[0] - ext[0];
372  lijk[1] = ijk[1] - ext[2];
373  lijk[2] = ijk[2] - ext[4];
374 }
375 
376 //------------------------------------------------------------------------------
378  int lijk[3], int ext[6], int ijk[3], int)
379 {
380  ijk[0] = ext[0] + lijk[0];
381  ijk[1] = ext[2] + lijk[1];
382  ijk[2] = ext[4] + lijk[2];
383 }
384 
385 //------------------------------------------------------------------------------
387  int extent[6], int ijk[3], int)
388 {
389  int dims[3];
391 
392  int lijk[3];
394 
395  return vtkStructuredData::ComputePointId(dims, lijk);
396 }
397 
398 //------------------------------------------------------------------------------
400  int extent[6], int ijk[3], int)
401 {
402  int nodeDims[3];
404 
405  int lijk[3];
407 
408  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
409 }
410 
411 //------------------------------------------------------------------------------
413  const vtkIdType cellId, int dims[3], int ijk[3], int)
414 {
416  dims[0] - 1, dims[1] - 1,
417  ijk[0], ijk[1], ijk[2]);
418 }
419 
420 //------------------------------------------------------------------------------
422  const vtkIdType cellIdx, int ext[6], int ijk[3], int)
423 {
424  int nodeDims[3];
426 
427  int lijk[3];
428  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
429 
431 }
432 
433 //------------------------------------------------------------------------------
435  const vtkIdType ptId, int dim[3], int ijk[3], int)
436 {
437  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1],
438  ijk[0], ijk[1], ijk[2]);
439 }
440 
441 //------------------------------------------------------------------------------
443  const vtkIdType ptId, int ext[6], int ijk[3], int)
444 {
445  int nodeDims[3];
447 
448  int lijk[3];
450 
452 }
453 
454 #endif
455 
456 // 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:59
#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:347
~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:36
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, this method computes the corresponding structured coordinates of the given cell.
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 &#39;dim&#39;, 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 &#39;dim&#39;, 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...