42 static RINGMesh2VTK tet_descriptor_vtk = { 10,
46 static RINGMesh2VTK hex_descriptor_vtk = { 12,
47 { 0, 4, 5, 1, 2, 6, 7, 3 }
50 static RINGMesh2VTK prism_descriptor_vtk = { 13,
54 static RINGMesh2VTK pyramid_descriptor_vtk = { 14,
58 static RINGMesh2VTK* cell_type_to_cell_descriptor_vtk[4] = {
59 &tet_descriptor_vtk, &hex_descriptor_vtk, &prism_descriptor_vtk,
60 &pyramid_descriptor_vtk };
62 class VTKIOHandler final:
public GeoModelIOHandler< 3 > {
64 void load(
const std::string& filename, GeoModel3D& geomodel )
final 68 throw RINGMeshException(
"I/O",
69 "Loading of a GeoModel from VTK not implemented yet" );
72 const GeoModel3D& geomodel,
73 const std::string& filename )
final 75 std::ofstream out( filename.c_str() );
78 out <<
"# vtk DataFile Version 2.0" <<
EOL;
79 out <<
"Unstructured Grid" <<
EOL;
80 out <<
"ASCII" <<
EOL;
81 out <<
"DATASET UNSTRUCTURED_GRID" <<
EOL;
83 const auto& mesh = geomodel.mesh;
84 out <<
"POINTS " << mesh.vertices.nb() <<
" double" <<
EOL;
85 for(
auto v : range( mesh.vertices.nb() ) ) {
86 out << mesh.vertices.vertex( v ) <<
EOL;
90 index_t total_corners = ( 4 + 1 ) * mesh.cells.nb_tet()
91 + ( 5 + 1 ) * mesh.cells.nb_pyramid()
92 + ( 6 + 1 ) * mesh.cells.nb_prism()
93 + ( 8 + 1 ) * mesh.cells.nb_hex();
94 out <<
"CELLS " << mesh.cells.nb_cells() <<
SPACE << total_corners
96 for(
auto c : range( mesh.cells.nb() ) ) {
97 out << mesh.cells.nb_vertices( c );
98 const auto& descriptor =
100 for(
auto v : range( mesh.cells.nb_vertices( c ) ) ) {
101 auto vertex_id = descriptor.vertices[v];
103 << mesh.cells.vertex( { c, vertex_id } );
108 out <<
"CELL_TYPES " << mesh.cells.nb() <<
EOL;
109 for(
auto c : range( mesh.cells.nb() ) ) {
110 const auto& descriptor =
112 out << descriptor.entity_type <<
EOL;
116 out <<
"CELL_DATA " << mesh.cells.nb() <<
EOL;
117 out <<
"SCALARS region int 1" <<
EOL;
118 out <<
"LOOKUP_TABLE default" <<
EOL;
119 for(
auto c : range( mesh.cells.nb() ) ) {
120 out << mesh.cells.region( c ) <<
EOL;
void ringmesh_unused(const T &)
auto to_underlying_type(Enum e) -> typename std::underlying_type< Enum >::type