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