MOAB: Mesh Oriented datABase  (version 5.4.1)
CellTypeToType.h
Go to the documentation of this file.
00001 #ifndef __smoab_detail_CellTypeToType_h
00002 #define __smoab_detail_CellTypeToType_h
00003 
00004 #include "vtkCellType.h"
00005 #include <algorithm>
00006 
00007 namespace smoab
00008 {
00009 namespace detail
00010 {
00011 
00012     template < int N >
00013     struct QuadratricOrdering
00014     {
00015     };
00016 
00017     template <>
00018     struct QuadratricOrdering< VTK_QUADRATIC_WEDGE >
00019     {
00020         static const int NUM_VERTS = 15;
00021         void reorder( vtkIdType* connectivity ) const
00022         {
00023             std::swap_ranges( connectivity + 9, connectivity + 12, connectivity + 12 );
00024         }
00025     };
00026 
00027     template <>
00028     struct QuadratricOrdering< VTK_TRIQUADRATIC_HEXAHEDRON >
00029     {
00030         static const int NUM_VERTS = 27;
00031         void reorder( vtkIdType* connectivity ) const
00032         {
00033             std::swap_ranges( connectivity + 12, connectivity + 16, connectivity + 16 );
00034 
00035             //move 20 to 22
00036             //move 22 to 23
00037             //move 23 to 20
00038 
00039             //swap 20 with 22
00040             std::swap( connectivity[20], connectivity[23] );
00041 
00042             //swap 22 with 23
00043             std::swap( connectivity[22], connectivity[23] );
00044         }
00045     };
00046 
00047     template < typename QuadraticOrdering >
00048     void FixQuadraticIdOrdering( vtkIdType* connectivity, vtkIdType numCells, QuadraticOrdering& ordering )
00049     {
00050         //skip the first index that holds the length of the cells
00051         //if we skip it once here, and than properly increment it makes the code
00052         //far easier
00053         connectivity += 1;
00054         for( vtkIdType i = 0; i < numCells; ++i )
00055         {
00056             ordering.reorder( connectivity );
00057             connectivity += ordering.NUM_VERTS + 1;
00058         }
00059     }
00060 
00061     int vtkCellType( moab::EntityType t, int& num_connect )
00062     {
00063         int ctype = -1;
00064         switch( t )
00065         {
00066             case moab::MBEDGE:
00067                 if( num_connect == 2 )
00068                     ctype = VTK_LINE;
00069                 else if( num_connect == 3 )
00070                     ctype = VTK_QUADRATIC_EDGE;
00071                 break;
00072             case moab::MBTRI:
00073                 if( num_connect == 3 )
00074                     ctype = VTK_TRIANGLE;
00075                 else if( num_connect == 6 )
00076                     ctype = VTK_QUADRATIC_TRIANGLE;
00077                 else if( num_connect == 7 )
00078                     ctype = VTK_BIQUADRATIC_TRIANGLE;
00079                 break;
00080             case moab::MBQUAD:
00081                 if( num_connect == 4 )
00082                     ctype = VTK_QUAD;
00083                 else if( num_connect == 8 )
00084                     ctype = VTK_QUADRATIC_QUAD;
00085                 else if( num_connect == 9 )
00086                     ctype = VTK_BIQUADRATIC_QUAD;
00087                 break;
00088             case moab::MBPOLYGON:
00089                 if( num_connect == 4 ) ctype = VTK_POLYGON;
00090                 break;
00091             case moab::MBTET:
00092                 if( num_connect == 4 )
00093                     ctype = VTK_TETRA;
00094                 else if( num_connect == 10 )
00095                     ctype = VTK_QUADRATIC_TETRA;
00096                 break;
00097             case moab::MBPYRAMID:
00098                 if( num_connect == 5 )
00099                     ctype = VTK_PYRAMID;
00100                 else if( num_connect == 13 )
00101                     ctype = VTK_QUADRATIC_PYRAMID;
00102                 break;
00103             case moab::MBPRISM:
00104                 if( num_connect == 6 )
00105                     ctype = VTK_WEDGE;
00106                 else if( num_connect == 15 )
00107                     ctype = VTK_QUADRATIC_WEDGE;
00108                 break;
00109             case moab::MBHEX:
00110                 if( num_connect == 8 )
00111                     ctype = VTK_HEXAHEDRON;
00112                 else if( num_connect == 20 )
00113                     ctype = VTK_QUADRATIC_HEXAHEDRON;
00114                 else if( num_connect == 21 )
00115                     ctype = VTK_QUADRATIC_HEXAHEDRON, num_connect = 20;
00116                 else if( num_connect == 27 )
00117                     ctype = VTK_TRIQUADRATIC_HEXAHEDRON;
00118                 break;
00119             default:
00120                 ctype = -1;
00121                 break;
00122         }
00123         return ctype;
00124     }
00125 
00126     int vtkLinearCellType( moab::EntityType t, int& num_connect )
00127     {
00128         int ctype = -1;
00129         switch( t )
00130         {
00131             case moab::MBEDGE:
00132                 ctype       = VTK_LINE;
00133                 num_connect = 2;
00134                 break;
00135             case moab::MBTRI:
00136                 ctype       = VTK_TRIANGLE;
00137                 num_connect = 3;
00138                 break;
00139             case moab::MBQUAD:
00140                 ctype       = VTK_QUAD;
00141                 num_connect = 4;
00142                 break;
00143             case moab::MBPOLYGON:
00144                 ctype       = VTK_POLYGON;
00145                 num_connect = 4;
00146                 break;
00147             case moab::MBTET:
00148                 ctype       = VTK_TETRA;
00149                 num_connect = 4;
00150                 break;
00151             case moab::MBPYRAMID:
00152                 ctype       = VTK_PYRAMID;
00153                 num_connect = 5;
00154                 break;
00155             case moab::MBPRISM:
00156                 ctype       = VTK_WEDGE;
00157                 num_connect = 6;
00158                 break;
00159             case moab::MBHEX:
00160                 ctype       = VTK_HEXAHEDRON;
00161                 num_connect = 8;
00162                 break;
00163             default:
00164                 break;
00165         }
00166         return ctype;
00167     }
00168 
00169 }  // namespace detail
00170 }  // namespace smoab
00171 
00172 #endif  // CELLTYPETOTYPE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines