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
38class 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
51class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
52{
53public:
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
171 static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3],
172 int dataDescription=VTK_EMPTY );
173
179 static vtkIdType ComputeCellIdForExtent(
180 int extent[6], int ijk[3], int dataDescription=VTK_EMPTY );
181
188 static vtkIdType ComputePointId(
189 int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
190
197 static vtkIdType ComputeCellId(
198 int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
199
206 static void ComputeCellStructuredCoordsForExtent(
207 const vtkIdType cellIdx, int ext[6], int ijk[3],
208 int dataDescription=VTK_EMPTY );
209
215 static void ComputeCellStructuredCoords(
216 const vtkIdType cellId, int dim[3], int ijk[3],
217 int dataDescription=VTK_EMPTY );
218
224 static void ComputePointStructuredCoordsForExtent(
225 const vtkIdType ptId, int ext[6], int ijk[3],
226 int dataDescription=VTK_EMPTY );
227
233 static void ComputePointStructuredCoords(
234 const vtkIdType ptId, int dim[3], int ijk[3],
235 int dataDescription=VTK_EMPTY );
236
237protected:
239 ~vtkStructuredData() VTK_OVERRIDE {}
240
249 const int i, const int j, const int k, const int N1, const int N2 )
250 {
251 return( (static_cast<vtkIdType>(k)*N2+j)*N1+i );
252 }
253
255
262 const vtkIdType idx, const int N1, const int N2,int &i, int &j, int &k )
263 {
264 int N12 = N1*N2;
265 k = idx/N12;
266 j = (idx-k*N12)/N1;
267 i = idx-k*N12-j*N1;
268 }
270
271 // Want to avoid importing <algorithm> in the header...
272 template <typename T>
273 static T Max(const T &a, const T &b)
274 {
275 return (a > b) ? a : b;
276 }
277
278private:
279 vtkStructuredData(const vtkStructuredData&) VTK_DELETE_FUNCTION;
280 void operator=(const vtkStructuredData&) VTK_DELETE_FUNCTION;
281};
282
283//------------------------------------------------------------------------------
285 int ext[6], int celldims[3], int)
286{
287 celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
288 celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
289 celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
290}
291
292//------------------------------------------------------------------------------
293inline vtkIdType vtkStructuredData::ComputePointId(int dims[3], int ijk[3], int)
294{
295 return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
296 dims[0], dims[1]);
297}
298
299//------------------------------------------------------------------------------
300inline vtkIdType vtkStructuredData::ComputeCellId(int dims[3], int ijk[3], int)
301{
303 ijk[0], ijk[1], ijk[2],
304 vtkStructuredData::Max(dims[0] - 1, 1),
305 vtkStructuredData::Max(dims[1] - 1, 1));
306}
307
308//------------------------------------------------------------------------------
310{
311 return static_cast<vtkIdType>(ext[1] - ext[0] + 1) *
312 static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
313 static_cast<vtkIdType>(ext[5] - ext[4] + 1);
314}
315
316//------------------------------------------------------------------------------
318{
319 int cellDims[3];
321
322 // Replace 0's with 1's so we can just multiply them regardless of cell type.
323 cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
324 cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
325 cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
326
327 // Note, when we compute the result below, we statically cast to vtkIdType to
328 // ensure the compiler will generate a 32x32=64 instruction.
329 return static_cast<vtkIdType>(cellDims[0]) *
330 static_cast<vtkIdType>(cellDims[1]) *
331 static_cast<vtkIdType>(cellDims[2]);
332}
333
334//------------------------------------------------------------------------------
336 int nodeExtent[6], int cellExtent[6], int)
337{
338 cellExtent[0] = nodeExtent[0];
339 cellExtent[2] = nodeExtent[2];
340 cellExtent[4] = nodeExtent[4];
341
342 cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
343 cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
344 cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
345}
346
347//------------------------------------------------------------------------------
348inline void vtkStructuredData::GetDimensionsFromExtent(int ext[6], int dims[3],
349 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 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 int ijk[3], 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 int lijk[3], 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 int extent[6], 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 int extent[6], 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, int dims[3], int ijk[3], int)
412{
414 dims[0] - 1, dims[1] - 1,
415 ijk[0], ijk[1], ijk[2]);
416}
417
418//------------------------------------------------------------------------------
420 const vtkIdType cellIdx, int ext[6], int ijk[3], int)
421{
422 int nodeDims[3];
424
425 int lijk[3];
426 vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
427
429}
430
431//------------------------------------------------------------------------------
433 const vtkIdType ptId, int dim[3], int ijk[3], int)
434{
436 ijk[0], ijk[1], ijk[2]);
437}
438
439//------------------------------------------------------------------------------
441 const vtkIdType ptId, int ext[6], int ijk[3], int)
442{
443 int nodeDims[3];
445
446 int lijk[3];
448
450}
451
452#endif
453
454// VTK-HeaderTest-Exclude: vtkStructuredData.h
list of point or cell ids
Definition: vtkIdList.h:37
abstract base class for most VTK objects
Definition: vtkObject.h:60
Singleton class for topologically regular data.
static int GetDataDescription(int dims[3])
Returns the data description given the dimensions (eg.
static int GetDataDimension(int ext[6])
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 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 int SetExtent(int inExt[6], int ext[6])
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).
static int GetDataDescriptionFromExtent(int ext[6])
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,...
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 GetCellPoints(vtkIdType cellId, vtkIdList *ptIds, int dataDescription, int dim[3])
Get the points defining a cell.
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 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 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.
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,...
~vtkStructuredData() override
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 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 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 int GetDataDimension(int dataDescription)
Return the topological dimension of the data (e.g., 0, 1, 2, or 3D).
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 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 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 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 GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3])
Get the cells using a point.
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 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 GetDimensionsFromExtent(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)
@ extent
Definition: vtkX3D.h:345
#define VTK_EMPTY
#define N1
#define N2
int vtkIdType
Definition: vtkType.h:287