MOAB: Mesh Oriented datABase  (version 5.3.1)
VtkTypeInfo.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2005 Lawrence Livermore National Laboratory.  Under
00005     the terms of Contract B545069 with the University of Wisconsin --
00006     Madison, Lawrence Livermore National Laboratory retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 #include "VtkTypeInfo.hpp"
00028 #include "MsqError.hpp"
00029 #include <cassert>
00030 
00031 namespace MBMesquite
00032 {
00033 
00034 const unsigned vtk_pixel_order[] = { 0, 1, 3, 2 };
00035 
00036 const unsigned vtk_voxel_order[] = { 0, 1, 3, 2, 4, 5, 7, 6 };
00037 
00038 const unsigned vtk_wedge_order[] = { 0,  2,  1,     // bottom corners
00039                                      3,  5,  4,     // top corners
00040                                      8,  7,  6,     // bottom edges
00041                                      12, 14, 13,    // lateral edges
00042                                      11, 10, 9,     // top edges
00043                                      17, 16, 15 };  // quadrilateral faces
00044 
00045 const unsigned vtk_hex_order[] = { 0,  1,  2,  3,                   // corners (same)
00046                                    4,  5,  6,  7,  8,  9,  10, 11,  // mid-edge (top before lateral)
00047                                    16, 17, 18, 19, 12, 13, 14, 15,
00048                                    22, 21, 23, 20,  // mid-face (mixed up) & mid-region (same)
00049                                    24, 25, 26 };
00050 
00051 static const VtkTypeInfo typeInfoList[] = { { 0, 0, MIXED, 0, 0 },
00052                                             { "vertex", 1, MIXED, 1, 0 },
00053                                             { "polyvertex", 2, MIXED, 0, 0 },
00054                                             { "line", 3, MIXED, 2, 0 },
00055                                             { "polyline", 4, MIXED, 0, 0 },
00056                                             { "triangle", 5, TRIANGLE, 3, 0 },
00057                                             { "triangle strip", 6, MIXED, 0, 0 },
00058                                             { "polygon", 7, POLYGON, 0, 0 },
00059                                             { "pixel", 8, QUADRILATERAL, 4, vtk_pixel_order },
00060                                             { "quadrilateral", 9, QUADRILATERAL, 4, 0 },
00061                                             { "tetrahedron", 10, TETRAHEDRON, 4, 0 },
00062                                             { "voxel", 11, HEXAHEDRON, 8, vtk_voxel_order },
00063                                             { "hexahedron", 12, HEXAHEDRON, 8, 0 },
00064                                             { "wedge", 13, PRISM, 6, vtk_wedge_order },
00065                                             { "pyramid", 14, PYRAMID, 5, 0 },
00066                                             { "pentagonal prism", 15, MIXED, 10, 0 },  // not supported
00067                                             { "hexagonal prism", 16, MIXED, 12, 0 },   // not supported
00068                                             { "invalid (17)", 17, MIXED, 0, 0 },
00069                                             { "invalid (18)", 18, MIXED, 0, 0 },
00070                                             { "invalid (19)", 19, MIXED, 0, 0 },
00071                                             { "invalid (20)", 20, MIXED, 0, 0 },
00072                                             { "quadratic edge", 21, MIXED, 3, 0 },
00073                                             { "quadratic tri", 22, TRIANGLE, 6, 0 },
00074                                             { "quadratic quad", 23, QUADRILATERAL, 8, 0 },
00075                                             { "quadratic tet", 24, TETRAHEDRON, 10, 0 },
00076                                             { "quadratic hex", 25, HEXAHEDRON, 20, vtk_hex_order },
00077                                             { "quadratic wedge", 26, PRISM, 15, vtk_wedge_order },
00078                                             { "quadratic pyramid", 27, PYRAMID, 13, 0 },
00079                                             { "bi-quadratic quad", 28, QUADRILATERAL, 9, 0 },
00080                                             { "tri-quadratic hex", 29, HEXAHEDRON, 27, vtk_hex_order },
00081                                             { "quadratic-linear quad", 30, MIXED, 6, 0 },  // not supported
00082                                             { "quadratic-linear wedge", 31, MIXED, 12,
00083                                               vtk_wedge_order },                                       // not supported
00084                                             { "bi-quadratic wedge", 32, MIXED, 18, vtk_wedge_order },  // not supported
00085                                             { "bi-quadratic hex", 33, MIXED, 24, vtk_hex_order },      // not supported
00086                                             { 0, 34, MIXED, 0, 0 } };
00087 
00088 const unsigned typeInfoListLen = sizeof( typeInfoList ) / sizeof( typeInfoList[0] );
00089 
00090 const unsigned reverseIndexList[][3] = { { 0, 0, 0 },     // 0
00091                                          { 0, 0, 0 },     // 1
00092                                          { 0, 0, 0 },     // 2
00093                                          { 0, 0, 0 },     // 3
00094                                          { 0, 0, 0 },     // 4
00095                                          { 0, 0, 0 },     // 5
00096                                          { 0, 0, 0 },     // 6
00097                                          { 7, 0, 0 },     // POLYGON
00098                                          { 5, 22, 0 },    // TRIANGLE
00099                                          { 9, 23, 28 },   // QUADRILATERAL
00100                                          { 0, 0, 0 },     // POLYHEDRON
00101                                          { 10, 24, 0 },   // TETRAHEDRON
00102                                          { 12, 25, 29 },  // HEXAHEDRON
00103                                          { 13, 26, 0 },   // PRISM
00104                                          { 14, 27, 0 },   // PYRAMID
00105                                          { 0, 0, 0 },     // SEPTAHEDRON
00106                                          { 0, 0, 0 } };
00107 
00108 const VtkTypeInfo* VtkTypeInfo::find_type( unsigned vtk_type, MsqError& err )
00109 {
00110     if( vtk_type >= typeInfoListLen )
00111     {
00112         MSQ_SETERR( err )( "Type out of bounds", MsqError::INVALID_ARG );
00113         return 0;
00114     }
00115 
00116     return &typeInfoList[vtk_type];
00117 }
00118 
00119 const VtkTypeInfo* VtkTypeInfo::find_type( EntityTopology msq_type, unsigned num_nodes, MsqError& err )
00120 {
00121     if( typeInfoList[reverseIndexList[msq_type][0]].numNodes == num_nodes )
00122         return &typeInfoList[reverseIndexList[msq_type][0]];
00123     else if( typeInfoList[reverseIndexList[msq_type][1]].numNodes == num_nodes )
00124         return &typeInfoList[reverseIndexList[msq_type][1]];
00125     else if( typeInfoList[reverseIndexList[msq_type][2]].numNodes == num_nodes )
00126         return &typeInfoList[reverseIndexList[msq_type][2]];
00127 
00128     if( msq_type == POLYGON && num_nodes >= 3 && num_nodes <= 12 ) return &typeInfoList[reverseIndexList[msq_type][0]];
00129 
00130     MSQ_SETERR( err )
00131     ( MsqError::UNSUPPORTED_ELEMENT, "VTK file does not support element type %d with %u nodes", (int)msq_type,
00132       num_nodes );
00133     return 0;
00134 }
00135 
00136 void VtkTypeInfo::mesquiteToVtkOrder( std::vector< size_t >& conn_list ) const
00137 {
00138     assert( conn_list.size() == numNodes );
00139     if( vtkConnOrder )
00140     {
00141         std::vector< size_t > temp_list( numNodes );
00142         std::swap( temp_list, conn_list );
00143         for( size_t i = 0; i < numNodes; ++i )
00144             conn_list[vtkConnOrder[i]] = temp_list[i];
00145     }
00146 }
00147 
00148 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines