VTK
/Users/kitware/Dashboards/MyTests/VTK_BLD_Release_docs/Utilities/Doxygen/dox/Common/DataModel/vtkStructuredData.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkStructuredData.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00031 #ifndef vtkStructuredData_h
00032 #define vtkStructuredData_h
00033 
00034 #include "vtkCommonDataModelModule.h" // For export macro
00035 #include "vtkObject.h"
00036 
00037 class vtkIdList;
00038 
00039 #define VTK_UNCHANGED 0
00040 #define VTK_SINGLE_POINT 1
00041 #define VTK_X_LINE 2
00042 #define VTK_Y_LINE 3
00043 #define VTK_Z_LINE 4
00044 #define VTK_XY_PLANE 5
00045 #define VTK_YZ_PLANE 6
00046 #define VTK_XZ_PLANE 7
00047 #define VTK_XYZ_GRID 8
00048 #define VTK_EMPTY 9
00049 
00050 class VTKCOMMONDATAMODEL_EXPORT vtkStructuredData : public vtkObject
00051 {
00052 public:
00053   vtkTypeMacro(vtkStructuredData,vtkObject);
00054 
00056 
00061   static int SetDimensions(int inDim[3], int dim[3]);
00062   static int SetExtent(int inExt[6], int ext[6]);
00064 
00066 
00068   static int GetDataDescription(int dims[3]);
00069   static int GetDataDescriptionFromExtent( int ext[6] );
00071 
00073 
00074   static int GetDataDimension(int dataDescription);
00075   static int GetDataDimension( int ext[6] );
00077 
00080   static vtkIdType GetNumberOfPoints(int ext[6], int dataDescription=VTK_EMPTY);
00081 
00084   static vtkIdType GetNumberOfCells(int ext[6], int dataDescription=VTK_EMPTY);
00085 
00087 
00090   static void GetCellExtentFromPointExtent(
00091       int pntExtent[6], int cellExtent[6], int dataDescription=VTK_EMPTY );
00093 
00095 
00097   static void GetDimensionsFromExtent(
00098       int ext[6], int dims[3], int dataDescription=VTK_EMPTY );
00100 
00102 
00105   static void GetCellDimensionsFromExtent(
00106       int ext[6], int celldims[3], int dataDescription=VTK_EMPTY );
00108 
00110 
00113   static void GetCellDimensionsFromPointDimensions(
00114       int pntdims[3],int cellDims[3] );
00116 
00118 
00122   static void GetLocalStructuredCoordinates(
00123       int ijk[3], int ext[6], int lijk[3], int dataDescription=VTK_EMPTY );
00125 
00127 
00130   static void GetGlobalStructuredCoordinates(
00131       int lijk[3], int ext[6], int ijk[3], int dataDescription=VTK_EMPTY );
00133 
00135 
00136   static void GetCellPoints(vtkIdType cellId, vtkIdList *ptIds,
00137                             int dataDescription, int dim[3]);
00139 
00141   static void GetPointCells(vtkIdType ptId, vtkIdList *cellIds, int dim[3]);
00142 
00144 
00146   static void GetCellNeighbors(vtkIdType cellId, vtkIdList *ptIds,
00147                                vtkIdList *cellIds, int dim[3]);
00149 
00151 
00154   static vtkIdType ComputePointIdForExtent(int extent[6], int ijk[3],
00155                                            int dataDescription=VTK_EMPTY );
00157 
00159 
00162   static vtkIdType ComputeCellIdForExtent(
00163       int extent[6], int ijk[3], int dataDescription=VTK_EMPTY );
00165 
00167 
00171   static vtkIdType ComputePointId(
00172       int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
00174 
00176 
00180   static vtkIdType ComputeCellId(
00181       int dim[3], int ijk[3], int dataDescription=VTK_EMPTY );
00183 
00185 
00189   static void ComputeCellStructuredCoordsForExtent(
00190       const vtkIdType cellIdx, int ext[6], int ijk[3],
00191       int dataDescription=VTK_EMPTY );
00193 
00195 
00198   static void ComputeCellStructuredCoords(
00199       const vtkIdType cellId, int dim[3], int ijk[3],
00200       int dataDescription=VTK_EMPTY );
00202 
00204 
00207   static void ComputePointStructuredCoordsForExtent(
00208       const vtkIdType ptId, int ext[6], int ijk[3],
00209       int dataDescription=VTK_EMPTY );
00211 
00213 
00216   static void ComputePointStructuredCoords(
00217       const vtkIdType ptId, int dim[3], int ijk[3],
00218       int dataDescription=VTK_EMPTY );
00220 
00221 protected:
00222   vtkStructuredData() {}
00223   ~vtkStructuredData() {}
00224 
00226 
00231   static vtkIdType GetLinearIndex(
00232       const int i, const int j, const int k, const int N1, const int N2 )
00233     {
00234       return( (static_cast<vtkIdType>(k)*N2+j)*N1+i );
00235     }
00237 
00239 
00243   static void GetStructuredCoordinates(
00244       const vtkIdType idx, const int N1, const int N2,int &i, int &j, int &k )
00245     {
00246       int N12 = N1*N2;
00247       k = idx/N12;
00248       j = (idx-k*N12)/N1;
00249       i = idx-k*N12-j*N1;
00250     }
00252 
00253   // Want to avoid importing <algorithm> in the header...
00254   template <typename T>
00255   static T Max(const T &a, const T &b)
00256   {
00257     return (a > b) ? a : b;
00258   }
00259 
00260 private:
00261   vtkStructuredData(const vtkStructuredData&);  // Not implemented.
00262   void operator=(const vtkStructuredData&);  // Not implemented.
00263 };
00264 
00265 //------------------------------------------------------------------------------
00266 inline void vtkStructuredData::GetCellDimensionsFromExtent(
00267     int ext[6], int celldims[3], int)
00268 {
00269   celldims[0] = vtkStructuredData::Max(ext[1] - ext[0], 0);
00270   celldims[1] = vtkStructuredData::Max(ext[3] - ext[2], 0);
00271   celldims[2] = vtkStructuredData::Max(ext[5] - ext[4], 0);
00272 }
00273 
00274 //------------------------------------------------------------------------------
00275 inline vtkIdType vtkStructuredData::ComputePointId(int dims[3], int ijk[3], int)
00276 {
00277   return vtkStructuredData::GetLinearIndex(ijk[0], ijk[1], ijk[2],
00278                                            dims[0], dims[1]);
00279 }
00280 
00281 //------------------------------------------------------------------------------
00282 inline vtkIdType vtkStructuredData::ComputeCellId(int dims[3], int ijk[3], int)
00283 {
00284   return vtkStructuredData::GetLinearIndex(
00285         ijk[0], ijk[1], ijk[2],
00286         vtkStructuredData::Max(dims[0] - 1, 1),
00287         vtkStructuredData::Max(dims[1] - 1, 1));
00288 }
00289 
00290 //------------------------------------------------------------------------------
00291 inline vtkIdType vtkStructuredData::GetNumberOfPoints(int ext[6], int)
00292 {
00293   return static_cast<vtkIdType>(ext[1] - ext[0] + 1) *
00294          static_cast<vtkIdType>(ext[3] - ext[2] + 1) *
00295          static_cast<vtkIdType>(ext[5] - ext[4] + 1);
00296 }
00297 
00298 //------------------------------------------------------------------------------
00299 inline vtkIdType vtkStructuredData::GetNumberOfCells(int ext[6], int)
00300 {
00301   int cellDims[3];
00302   vtkStructuredData::GetCellDimensionsFromExtent(ext,cellDims);
00303 
00304   // Replace 0's with 1's so we can just multiply them regardless of cell type.
00305   cellDims[0] = vtkStructuredData::Max(cellDims[0], 1);
00306   cellDims[1] = vtkStructuredData::Max(cellDims[1], 1);
00307   cellDims[2] = vtkStructuredData::Max(cellDims[2], 1);
00308 
00309   // Note, when we compute the result below, we statically cast to vtkIdType to
00310   // ensure the compiler will generate a 32x32=64 instruction.
00311   return static_cast<vtkIdType>(cellDims[0]) *
00312          static_cast<vtkIdType>(cellDims[1]) *
00313          static_cast<vtkIdType>(cellDims[2]);
00314 }
00315 
00316 //------------------------------------------------------------------------------
00317 inline void vtkStructuredData::GetCellExtentFromPointExtent(
00318     int nodeExtent[6], int cellExtent[6], int)
00319 {
00320   cellExtent[0] = nodeExtent[0];
00321   cellExtent[2] = nodeExtent[2];
00322   cellExtent[4] = nodeExtent[4];
00323 
00324   cellExtent[1] = vtkStructuredData::Max(nodeExtent[0], nodeExtent[1] - 1);
00325   cellExtent[3] = vtkStructuredData::Max(nodeExtent[2], nodeExtent[3] - 1);
00326   cellExtent[5] = vtkStructuredData::Max(nodeExtent[4], nodeExtent[5] - 1);
00327 }
00328 
00329 //------------------------------------------------------------------------------
00330 inline void vtkStructuredData::GetDimensionsFromExtent(int ext[6], int dims[3],
00331                                                        int)
00332 {
00333   dims[0] = ext[1] - ext[0] + 1;
00334   dims[1] = ext[3] - ext[2] + 1;
00335   dims[2] = ext[5] - ext[4] + 1;
00336 }
00337 
00338 //------------------------------------------------------------------------------
00339 inline void vtkStructuredData::GetCellDimensionsFromPointDimensions(
00340     int nodeDims[3], int cellDims[3])
00341 {
00342   cellDims[0] = vtkStructuredData::Max(nodeDims[0] - 1, 0);
00343   cellDims[1] = vtkStructuredData::Max(nodeDims[1] - 1, 0);
00344   cellDims[2] = vtkStructuredData::Max(nodeDims[2] - 1, 0);
00345 }
00346 
00347 //------------------------------------------------------------------------------
00348 inline void vtkStructuredData::GetLocalStructuredCoordinates(
00349     int ijk[3], int ext[6], int lijk[3], int)
00350 {
00351   lijk[0] = ijk[0] - ext[0];
00352   lijk[1] = ijk[1] - ext[2];
00353   lijk[2] = ijk[2] - ext[4];
00354 }
00355 
00356 //------------------------------------------------------------------------------
00357 inline void vtkStructuredData::GetGlobalStructuredCoordinates(
00358     int lijk[3], int ext[6], int ijk[3], int)
00359 {
00360   ijk[0] = ext[0] + lijk[0];
00361   ijk[1] = ext[2] + lijk[1];
00362   ijk[2] = ext[4] + lijk[2];
00363 }
00364 
00365 //------------------------------------------------------------------------------
00366 inline vtkIdType vtkStructuredData::ComputePointIdForExtent(
00367     int extent[6], int ijk[3], int)
00368 {
00369   int dims[3];
00370   vtkStructuredData::GetDimensionsFromExtent(extent, dims);
00371 
00372   int lijk[3];
00373   vtkStructuredData::GetLocalStructuredCoordinates(ijk, extent, lijk);
00374 
00375   return vtkStructuredData::ComputePointId(dims, lijk);
00376 }
00377 
00378 //------------------------------------------------------------------------------
00379 inline vtkIdType vtkStructuredData::ComputeCellIdForExtent(
00380     int extent[6], int ijk[3], int)
00381 {
00382   int nodeDims[3];
00383   vtkStructuredData::GetDimensionsFromExtent(extent, nodeDims);
00384 
00385   int lijk[3];
00386   vtkStructuredData::GetLocalStructuredCoordinates(ijk, extent, lijk);
00387 
00388   return vtkStructuredData::ComputeCellId(nodeDims, lijk);
00389 }
00390 
00391 //------------------------------------------------------------------------------
00392 inline void vtkStructuredData::ComputeCellStructuredCoords(
00393     const vtkIdType cellId, int dims[3], int ijk[3], int)
00394 {
00395   vtkStructuredData::GetStructuredCoordinates(cellId,
00396                                               dims[0] - 1, dims[1] - 1,
00397                                               ijk[0], ijk[1], ijk[2]);
00398 }
00399 
00400 //------------------------------------------------------------------------------
00401 inline void vtkStructuredData::ComputeCellStructuredCoordsForExtent(
00402     const vtkIdType cellIdx, int ext[6], int ijk[3], int)
00403 {
00404   int nodeDims[3];
00405   vtkStructuredData::GetDimensionsFromExtent(ext, nodeDims);
00406 
00407   int lijk[3];
00408   vtkStructuredData::ComputeCellStructuredCoords(cellIdx, nodeDims, lijk);
00409 
00410   vtkStructuredData::GetGlobalStructuredCoordinates(lijk, ext, ijk);
00411 }
00412 
00413 //------------------------------------------------------------------------------
00414 inline void vtkStructuredData::ComputePointStructuredCoords(
00415     const vtkIdType ptId, int dim[3], int ijk[3], int)
00416 {
00417   vtkStructuredData::GetStructuredCoordinates(ptId, dim[0], dim[1],
00418                                               ijk[0], ijk[1], ijk[2]);
00419 }
00420 
00421 //------------------------------------------------------------------------------
00422 inline void vtkStructuredData::ComputePointStructuredCoordsForExtent(
00423     const vtkIdType ptId, int ext[6], int ijk[3], int)
00424 {
00425   int nodeDims[3];
00426   vtkStructuredData::GetDimensionsFromExtent(ext, nodeDims);
00427 
00428   int lijk[3];
00429   vtkStructuredData::ComputePointStructuredCoords(ptId, nodeDims, lijk);
00430 
00431   vtkStructuredData::GetGlobalStructuredCoordinates(lijk, ext, ijk);
00432 }
00433 
00434 #endif
00435 
00436 // VTK-HeaderTest-Exclude: vtkStructuredData.h