Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
VtkUtil.cpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #include "moab/VtkUtil.hpp"
17 
18 namespace moab
19 {
20 
21 const char* VtkUtil::vtkTypeNames[] = {
22  "unsigned_char", // MB_TYPE_OPAQUE
23  "int", // MB_TYPE_INTEGER
24  "double", // MB_TYPE_DOUBLE
25  "bit", // MB_TYPE_BIT
26  "unsigned_long", // MB_TYPE_HANDLE
27 };
28 
29 /*
30 const unsigned VtkUtil::typeSizes[] = {
31  1, // MB_TYPE_OPAQUE
32  sizeof(int), // MB_TYPE_INTEGER
33  sizeof(double), // MB_TYPE_DOUBLE
34  1, // MB_TYPE_BIT
35  sizeof(EntityHandle), // MB_TYPE_HANDLE
36 };
37 */
38 
39 // Define node ordering for those types for which
40 // the VTK and MOAB ordering doesn't match. The values
41 // contained in the array are MOAB connectivity indices,
42 // and the values used to index the arrays are VTK
43 // connectivity indices.
44 const unsigned pixel[] = { 0, 1, 3, 2 };
45 const unsigned voxel[] = { 0, 1, 3, 2, 4, 5, 7, 6 };
46 const unsigned wedge[] = { 0, 2, 1, // bottom corners
47  3, 5, 4, // top corners
48  8, 7, 6, // bottom edges
49  14, 13, 12, // top edges
50  9, 11, 10, // lateral edges
51  17, 16, 15 }; // quadrilateral faces
52 const unsigned qhex[] = { 0, 1, 2, 3, // corners (same)
53  4, 5, 6, 7, 8, 9, 10, 11, // mid-edge (top before lateral)
54  16, 17, 18, 19, 12, 13, 14, 15, 23, 21, 20, 22, // mid-face (mixed up) & mid-region (same)
55  24, 25, 26 };
56 
57 // List of VtkElemType structs, indexed by the VTK type number.
58 const VtkElemType VtkUtil::vtkElemTypes[] = {
59  { 0, 0, MBMAXTYPE, 0, 0 },
60  { "vertex", 1, MBVERTEX, 1, 0 },
61  { "polyvertex", 2, MBMAXTYPE, 0, 0 },
62  { "line", 3, MBEDGE, 2, 0 },
63  { "polyline", 4, MBMAXTYPE, 0, 0 },
64  { "triangle", 5, MBTRI, 3, 0 },
65  { "triangle strip", 6, MBMAXTYPE, 0, 0 },
66  { "polygon", 7, MBPOLYGON, 0, 0 },
67  { "pixel", 8, MBQUAD, 4, pixel },
68  { "quadrilateral", 9, MBQUAD, 4, 0 },
69  { "tetrahedron", 10, MBTET, 4, 0 },
70  { "voxel", 11, MBHEX, 8, voxel },
71  { "hexahedron", 12, MBHEX, 8, 0 },
72  { "wedge", 13, MBPRISM, 6, wedge },
73  { "pyramid", 14, MBPYRAMID, 5, 0 },
74  { "pentagonal prism", 15, MBMAXTYPE, 10, 0 }, // not supported
75  { "hexagonal prism", 16, MBMAXTYPE, 12, 0 }, // not supported
76  { 0, 17, MBMAXTYPE, 0, 0 },
77  { 0, 18, MBMAXTYPE, 0, 0 },
78  { 0, 19, MBMAXTYPE, 0, 0 },
79  { 0, 20, MBMAXTYPE, 0, 0 },
80  { "quadratic edge", 21, MBEDGE, 3, 0 },
81  { "quadratic tri", 22, MBTRI, 6, 0 },
82  { "quadratic quad", 23, MBQUAD, 8, 0 },
83  { "quadratic tet", 24, MBTET, 10, 0 },
84  { "quadratic hex", 25, MBHEX, 20, qhex },
85  { "quadratic wedge", 26, MBPRISM, 15, wedge },
86  { "quadratic pyramid", 27, MBPYRAMID, 13, 0 },
87  { "bi-quadratic quad", 28, MBQUAD, 9, 0 },
88  { "tri-quadratic hex", 29, MBHEX, 27, qhex },
89  { "quadratic-linear quad", 30, MBMAXTYPE, 6, 0 }, // not supported
90  { "quadratic-linear wedge", 31, MBMAXTYPE, 12, wedge }, // not supported
91  { "bi-quadratic wedge", 32, MBMAXTYPE, 18, wedge }, // not supported
92  { "bi-quadratic hex", 33, MBMAXTYPE, 24, qhex }, // not supported
93  { "bi-quadratic triangle", 34, MBMAXTYPE, 0, 0 },
94  { "cubic line", 35, MBMAXTYPE, 0, 0 }, // VTK_CUBIC_LINE not supported
95  { 0, 36, MBMAXTYPE, 0, 0 },
96  { 0, 37, MBMAXTYPE, 0, 0 },
97  { 0, 38, MBMAXTYPE, 0, 0 },
98  { 0, 39, MBMAXTYPE, 0, 0 },
99  { 0, 40, MBMAXTYPE, 0, 0 },
100  { "convex point set", 41, MBMAXTYPE, 0, 0 }, // VTK_CONVEX_POINT_SET = 41, not supported
101  { "polyhedron", 42, MBPOLYHEDRON, 0, 0 } //
102 };
103 
104 const unsigned VtkUtil::numVtkElemType = sizeof( VtkUtil::vtkElemTypes ) / sizeof( VtkUtil::vtkElemTypes[0] );
105 
106 // Define an array, indexed by EntityType containing the corresponding
107 // VTK element type numbers for the linear, quadratic (mid-edge),
108 // and full (mid-face & mid-region node) elements.
109 // Zero is used to indicate an invalid type (not supported by VTK.) The
110 // VTK element type number may be used as an index into vtkElemTypes[].
111 const int mb_to_vtk_type[][3] = { { 1, 0, 0 }, // MBVERTEX
112  { 3, 21, 0 }, // MBEDGE
113  { 5, 22, 0 }, // MBTRI
114  { 9, 23, 28 }, // MBQUAD
115  { 7, 0, 0 }, // MBPOLYGON
116  { 10, 24, 0 }, // MBTET
117  { 14, 27, 0 }, // MBPYRAMID
118  { 13, 26, 0 }, // MBWEDGE
119  { 0, 0, 0 }, // MBKNIFE
120  { 12, 25, 29 }, // MBHEX
121  { 42, 0, 0 }, // MBPOLYHEDRON
122  { 0, 0, 0 }, // MBENTITYSET
123  { 0, 0, 0 } }; // MBMAXTYPE
124 
125 const VtkElemType* VtkUtil::get_vtk_type( EntityType type, unsigned num_nodes )
126 {
127  const int i = mb_to_vtk_type[type][0]; // Index for linear type
128  const int j = mb_to_vtk_type[type][1]; // Index for quadratic type
129  const int k = mb_to_vtk_type[type][2]; // Index for full quadratic type
130  if( i ) // If element type is supported at all (if not linear then not quadratic either)
131  {
132  // If the linear type is requested (all polygons are linear
133  // irrespective of the number of nodes), return that.
134  if( type == MBPOLYGON || type == MBPOLYHEDRON || vtkElemTypes[i].num_nodes == num_nodes )
135  return vtkElemTypes + i;
136  // Otherwise if there is a quadratic type and the number of
137  // nodes specified corresponds to the quadratic type, return that.
138  else if( j && vtkElemTypes[j].num_nodes == num_nodes )
139  return vtkElemTypes + j;
140  // Otherwise if there is a full quadratic type and the number of
141  // nodes specified corresponds to the quadratic type, return that.
142  else if( k && vtkElemTypes[k].num_nodes == num_nodes )
143  return vtkElemTypes + k;
144  }
145 
146  return 0;
147 }
148 
149 } // namespace moab