moab
VtkUtil.cpp
Go to the documentation of this file.
00001 
00016 #include "VtkUtil.hpp"
00017 
00018 namespace moab {
00019 
00020 
00021 const char* VtkUtil::vtkTypeNames[] = {
00022  "unsigned_char", // MB_TYPE_OPAQUE
00023  "int",           // MB_TYPE_INTEGER
00024  "double",        // MB_TYPE_DOUBLE
00025  "bit",           // MB_TYPE_BIT
00026  "unsigned_long", // MB_TYPE_HANDLE
00027 };
00028 
00029 /*
00030 const unsigned VtkUtil::typeSizes[] = {
00031  1,                      // MB_TYPE_OPAQUE
00032  sizeof(int),            // MB_TYPE_INTEGER
00033  sizeof(double),         // MB_TYPE_DOUBLE
00034  1,                      // MB_TYPE_BIT
00035  sizeof(EntityHandle), // MB_TYPE_HANDLE
00036 };
00037 */
00038 
00039 // Define node ordering for those types for which
00040 // the VTK and MOAB ordering doesn't match.  The values
00041 // contained in the array are MOAB connectivity indices,
00042 // and the values used to index the arrays are VTK 
00043 // connectivity indices.
00044 const unsigned pixel[] = { 0, 1, 3, 2 };
00045 const unsigned voxel[] = { 0, 1, 3, 2, 4, 5, 7, 6 };
00046 const unsigned wedge[] = { 0, 2, 1,   // bottom corners
00047                            3, 5, 4,   // top corners
00048                            8, 7, 6,   // bottom edges
00049                           14,13,12,   // top edges
00050                            9,11,10,   // lateral edges
00051                           17,16,15 }; // quadrilateral faces
00052 const unsigned  qhex[] = {  0,  1,  2,  3, // corners (same)
00053                             4,  5,  6,  7, 
00054                             8,  9, 10, 11, // mid-edge (top before lateral)
00055                            16, 17, 18, 19,
00056                            12, 13, 14, 15,
00057                            23, 21, 20, 22, // mid-face (mixed up) & mid-region (same)
00058                            24, 25, 26 };
00059 
00060 // List of VtkElemType structs, indexed by the VTK type number.
00061 const VtkElemType VtkUtil::vtkElemTypes[] = {
00062       { 0,                         0, MBMAXTYPE, 0, 0 },
00063       { "vertex",                  1, MBMAXTYPE, 1, 0 },
00064       { "polyvertex",              2, MBMAXTYPE, 0, 0 },
00065       { "line",                    3, MBEDGE,    2, 0 },
00066       { "polyline",                4, MBMAXTYPE, 0, 0 },
00067       { "triangle",                5, MBTRI,     3, 0 },
00068       { "triangle strip",          6, MBMAXTYPE, 0, 0 },
00069       { "polygon",                 7, MBPOLYGON, 0, 0 },
00070       { "pixel",                   8, MBQUAD,    4, pixel },
00071       { "quadrilateral",           9, MBQUAD,    4, 0 }, 
00072       { "tetrahedron",            10, MBTET,     4, 0 }, 
00073       { "voxel",                  11, MBHEX,     8, voxel }, 
00074       { "hexahedron",             12, MBHEX,     8, 0 }, 
00075       { "wedge",                  13, MBPRISM,   6, wedge }, 
00076       { "pyramid",                14, MBPYRAMID, 5, 0 },
00077       { "pentagonal prism",       15, MBMAXTYPE,10, 0 }, // not supported
00078       { "hexagonal prism",        16, MBMAXTYPE,12, 0 }, // not supported
00079       { 0,                        17, MBMAXTYPE, 0, 0 },
00080       { 0,                        18, MBMAXTYPE, 0, 0 },
00081       { 0,                        19, MBMAXTYPE, 0, 0 },
00082       { 0,                        20, MBMAXTYPE, 0, 0 },
00083       { "quadratic edge",         21, MBEDGE,    3, 0 },
00084       { "quadratic tri",          22, MBTRI,     6, 0 },
00085       { "quadratic quad",         23, MBQUAD,    8, 0 },
00086       { "quadratic tet",          24, MBTET,    10, 0 },
00087       { "quadratic hex",          25, MBHEX,    20, qhex },
00088       { "quadratic wedge",        26, MBPRISM,  15, wedge },
00089       { "quadratic pyramid",      27, MBPYRAMID,13, 0 },
00090       { "bi-quadratic quad",      28, MBQUAD,    9, 0 },
00091       { "tri-quadratic hex",      29, MBHEX,    27, qhex },
00092       { "quadratic-linear quad",  30, MBMAXTYPE, 6, 0 },     // not supported
00093       { "quadratic-linear wedge", 31, MBMAXTYPE,12, wedge }, // not supported
00094       { "bi-quadratic wedge",     32, MBMAXTYPE,18, wedge }, // not supported
00095       { "bi-quadratic hex",       33, MBMAXTYPE,24, qhex },  // not supported
00096       { 0,                        34, MBMAXTYPE, 0, 0 }
00097     };
00098 
00099 const unsigned VtkUtil::numVtkElemType = sizeof(VtkUtil::vtkElemTypes) / sizeof(VtkUtil::vtkElemTypes[0]);
00100 
00101 // Define an array, indexed by EntityType containing the corresponding 
00102 // VTK element type numbers for the linear, quadratic (mid-edge),
00103 // and full (mid-face & mid-region node) elements.
00104 // Zero is used to indicate an invalid type (not supported by VTK.)  The
00105 // VTK element type number may be used as an index into vtkElemTypes[].
00106 const int mb_to_vtk_type[][3] = {
00107   {  1,  0,  0 },  // MBVERTEX
00108   {  3, 21,  0 },  // MBEDGE
00109   {  5, 22,  0 },  // MBTRI
00110   {  9, 23, 28 },  // MBQUAD
00111   {  7,  0,  0 },  // MBPOLYGON
00112   { 10, 24,  0 },  // MBTET
00113   { 14, 27,  0 },  // MBPYRAMID
00114   { 13, 26,  0 },  // MBWEDGE
00115   {  0,  0,  0 },  // MBKNIFE
00116   { 12, 25, 29 },  // MBHEX
00117   {  0,  0,  0 },  // MBPOLYHEDRON
00118   {  0,  0,  0 },  // MBENTITYSET
00119   {  0,  0,  0 } };// MBMAXTYPE
00120 
00121 const VtkElemType* VtkUtil::get_vtk_type( EntityType type, unsigned num_nodes )
00122 {
00123   const int i = mb_to_vtk_type[type][0]; // Index for linear type
00124   const int j = mb_to_vtk_type[type][1]; // Index for quadratic type
00125   const int k = mb_to_vtk_type[type][2]; // Index for full quadratic type
00126   if (i) // If element type is supported at all (if not linear then not quadratic either)
00127   {
00128       // If the linear type is requested (all polygons are linear
00129       // irrespective of the number of nodes), return that.
00130     if (type == MBPOLYGON || vtkElemTypes[i].num_nodes == num_nodes)
00131       return vtkElemTypes + i;
00132       // Otherwise if there is a quadratic type and the number of
00133       // nodes specified corresponds to the quadratic type, return that.
00134     else if (j && vtkElemTypes[j].num_nodes == num_nodes)
00135       return vtkElemTypes + j;
00136       // Otherwise if there is a full quadratic type and the number of
00137       // nodes specified corresponds to the quadratic type, return that.
00138     else if (k && vtkElemTypes[k].num_nodes == num_nodes)
00139       return vtkElemTypes + k;
00140   }
00141   
00142   return 0;
00143 }
00144 
00145 } // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines