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 =========================================================================*/
31 #ifndef vtkStructuredData_h
32 #define vtkStructuredData_h
33 
34 #include "vtkCommonDataModelModule.h" // For export macro
35 #include "vtkObject.h"
36 
37 class vtkIdList;
38 
39 #define VTK_UNCHANGED 0
40 #define VTK_SINGLE_POINT 1
41 #define VTK_X_LINE 2
42 #define VTK_Y_LINE 3
43 #define VTK_Z_LINE 4
44 #define VTK_XY_PLANE 5
45 #define VTK_YZ_PLANE 6
46 #define VTK_XZ_PLANE 7
47 #define VTK_XYZ_GRID 8
48 #define VTK_EMPTY 9
49 
51 {
52 public:
54 
56 
61  static int SetDimensions(int inDim[3], int dim[3]);
62  static int SetExtent(int inExt[6], int ext[6]);
64 
66 
68  static int GetDataDescription(int dims[3]);
69  static int GetDataDescriptionFromExtent( int ext[6] );
71 
73 
74  static int GetDataDimension(int dataDescription);
75  static int GetDataDimension( int ext[6] );
77 
80  static vtkIdType GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY);
81 
84  static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY);
85 
87 
90  static void GetCellExtentFromPointExtent(
91  int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY );
93 
95 
97  static void GetDimensionsFromExtent(
98  int ext[6], int dims[3], int dataDescription=VTK_EMPTY );
100 
102 
105  static void GetCellDimensionsFromExtent(
106  int ext[6], int celldims[3], int dataDescription=VTK_EMPTY );
108 
110 
113  static void GetCellDimensionsFromPointDimensions(
114  int pntdims[3],int cellDims[3] );
116 
118 
122  static void GetLocalStructuredCoordinates(
123  int ijk[3], int ext[6], int lijk[3], int dataDescription=VTK_EMPTY );
125 
127 
130  static void GetGlobalStructuredCoordinates(
131  int lijk[3], int ext[6], int ijk[3], int dataDescription=VTK_EMPTY );
133 
135 
136  static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds,
137  int dataDescription, int dim[3]);
139 
141  static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3]);
142 
144 
146  static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
147  vtkIdList *cellIds, int dim[3]);
149 
151 
154  static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3],
155  int dataDescription=VTK_EMPTY );
157 
159 
162  static vtkIdType ComputeCellIdForExtent(
163  int extent[6], int ijk[3], int dataDescription=VTK_EMPTY );
165 
167 
171  static vtkIdType ComputePointId(
172  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
174 
176 
180  static vtkIdType ComputeCellId(
181  int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
183 
185 
189  static void ComputeCellStructuredCoordsForExtent(
190  const vtkIdType cellIdx, int ext[6], int ijk[3],
191  int dataDescription=VTK_EMPTY );
193 
195 
198  static void ComputeCellStructuredCoords(
199  const vtkIdType cellId, int dim[3], int ijk[3],
200  int dataDescription=VTK_EMPTY );
202 
204 
207  static void ComputePointStructuredCoordsForExtent(
208  const vtkIdType ptId, int ext[6], int ijk[3],
209  int dataDescription=VTK_EMPTY );
211 
213 
216  static void ComputePointStructuredCoords(
217  const vtkIdType ptId, int dim[3], int ijk[3],
218  int dataDescription=VTK_EMPTY );
220 
221 protected:
224 
226 
232  const int i, const int j, const int k, const int N1, const int N2 )
233  {
234  return( (static_cast<vtkIdType>(k)*N2+j)*N1+i );
235  }
237 
239 
244  const vtkIdType idx, const int N1, const int N2,int &i, int &j, int &k )
245  {
246  int N12 = N1*N2;
247  k = idx/N12;
248  j = (idx-k*N12)/N1;
249  i = idx-k*N12-j*N1;
250  }
252 
253  // Want to avoid importing <algorithm> in the header...
254  template <typename T>
255  static T Max(const T &a, const T &b)
256  {
257  return (a > b) ? a : b;
258  }
259 
260 private:
261  vtkStructuredData(const vtkStructuredData&); // Not implemented.
262  void operator=(const vtkStructuredData&); // Not implemented.
263 };
264 
265 //------------------------------------------------------------------------------
267  int ext[6], int celldims[3], int)
268 {
269  celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
270  celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
271  celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
272 }
273 
274 //------------------------------------------------------------------------------
275 inline vtkIdType vtkStructuredData::ComputePointId(int dims[3], int ijk[3], int)
276 {
277  return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
278  dims[0], dims[1]);
279 }
280 
281 //------------------------------------------------------------------------------
282 inline vtkIdType vtkStructuredData::ComputeCellId(int dims[3], int ijk[3], int)
283 {
285  ijk[0], ijk[1], ijk[2],
286  vtkStructuredData::Max(dims[0] - 1, 1),
287  vtkStructuredData::Max(dims[1] - 1, 1));
288 }
289 
290 //------------------------------------------------------------------------------
292 {
293  return static_cast<vtkIdType>(ext[1] - ext[0] + 1) *
294  static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
295  static_cast<vtkIdType>(ext[5] - ext[4] + 1);
296 }
297 
298 //------------------------------------------------------------------------------
300 {
301  int cellDims[3];
303 
304  // Replace 0's with 1's so we can just multiply them regardless of cell type.
305  cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
306  cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
307  cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
308 
309  // Note, when we compute the result below, we statically cast to vtkIdType to
310  // ensure the compiler will generate a 32x32=64 instruction.
311  return static_cast<vtkIdType>(cellDims[0]) *
312  static_cast<vtkIdType>(cellDims[1]) *
313  static_cast<vtkIdType>(cellDims[2]);
314 }
315 
316 //------------------------------------------------------------------------------
318  int nodeExtent[6], int cellExtent[6], int)
319 {
320  cellExtent[0] = nodeExtent[0];
321  cellExtent[2] = nodeExtent[2];
322  cellExtent[4] = nodeExtent[4];
323 
324  cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
325  cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
326  cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
327 }
328 
329 //------------------------------------------------------------------------------
330 inline void vtkStructuredData::GetDimensionsFromExtent(int ext[6], int dims[3],
331  int)
332 {
333  dims[0] = ext[1] - ext[0] + 1;
334  dims[1] = ext[3] - ext[2] + 1;
335  dims[2] = ext[5] - ext[4] + 1;
336 }
337 
338 //------------------------------------------------------------------------------
340  int nodeDims[3], int cellDims[3])
341 {
342  cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
343  cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
344  cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
345 }
346 
347 //------------------------------------------------------------------------------
349  int ijk[3], int ext[6], int lijk[3], int)
350 {
351  lijk[0] = ijk[0] - ext[0];
352  lijk[1] = ijk[1] - ext[2];
353  lijk[2] = ijk[2] - ext[4];
354 }
355 
356 //------------------------------------------------------------------------------
358  int lijk[3], int ext[6], int ijk[3], int)
359 {
360  ijk[0] = ext[0] + lijk[0];
361  ijk[1] = ext[2] + lijk[1];
362  ijk[2] = ext[4] + lijk[2];
363 }
364 
365 //------------------------------------------------------------------------------
367  int extent[6], int ijk[3], int)
368 {
369  int dims[3];
371 
372  int lijk[3];
374 
375  return vtkStructuredData::ComputePointId(dims, lijk);
376 }
377 
378 //------------------------------------------------------------------------------
380  int extent[6], int ijk[3], int)
381 {
382  int nodeDims[3];
384 
385  int lijk[3];
387 
388  return vtkStructuredData::ComputeCellId(nodeDims, lijk);
389 }
390 
391 //------------------------------------------------------------------------------
393  const vtkIdType cellId, int dims[3], int ijk[3], int)
394 {
396  dims[0] - 1, dims[1] - 1,
397  ijk[0], ijk[1], ijk[2]);
398 }
399 
400 //------------------------------------------------------------------------------
402  const vtkIdType cellIdx, int ext[6], int ijk[3], int)
403 {
404  int nodeDims[3];
406 
407  int lijk[3];
408  vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
409 
411 }
412 
413 //------------------------------------------------------------------------------
415  const vtkIdType ptId, int dim[3], int ijk[3], int)
416 {
417  vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1],
418  ijk[0], ijk[1], ijk[2]);
419 }
420 
421 //------------------------------------------------------------------------------
423  const vtkIdType ptId, int ext[6], int ijk[3], int)
424 {
425  int nodeDims[3];
427 
428  int lijk[3];
430 
432 }
433 
434 #endif
435 
436 // VTK-HeaderTest-Exclude: vtkStructuredData.h
static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY)
static void ComputePointStructuredCoordsForExtent(const vtkIdType ptId, int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
Singleton class for topologically regular data.
abstract base class for most VTK objects
Definition: vtkObject.h:61
#define N2
static T Max(const T &a, const T &b)
static vtkIdType ComputePointId(int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
int vtkIdType
Definition: vtkType.h:275
#define VTK_EMPTY
#define N1
static void GetGlobalStructuredCoordinates(int lijk[3], int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
static void GetCellDimensionsFromExtent(int ext[6], int celldims[3], int dataDescription=VTK_EMPTY)
static vtkIdType GetLinearIndex(const int i, const int j, const int k, const int N1, const int N2)
static void GetDimensionsFromExtent(int ext[6], int dims[3], int dataDescription=VTK_EMPTY)
static vtkIdType ComputeCellIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
list of point or cell ids
Definition: vtkIdList.h:35
static void GetLocalStructuredCoordinates(int ijk[3], int ext[6], int lijk[3], int dataDescription=VTK_EMPTY)
static void ComputeCellStructuredCoordsForExtent(const vtkIdType cellIdx, int ext[6], int ijk[3], int dataDescription=VTK_EMPTY)
static void GetCellDimensionsFromPointDimensions(int pntdims[3], int cellDims[3])
static vtkIdType ComputeCellId(int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3], int dataDescription=VTK_EMPTY)
static void ComputeCellStructuredCoords(const vtkIdType cellId, int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
static void ComputePointStructuredCoords(const vtkIdType ptId, int dim[3], int ijk[3], int dataDescription=VTK_EMPTY)
static void GetStructuredCoordinates(const vtkIdType idx, const int N1, const int N2, int &i, int &j, int &k)
static vtkIdType GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY)
static void GetCellExtentFromPointExtent(int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY)
#define VTKCOMMONDATAMODEL_EXPORT