36 #include <geologyjs/main_export.h> 40 class HTMLIOHandler final:
public GeoModelIOHandler< 3 > {
42 void load(
const std::string& filename, GeoModel& geomodel )
final 44 throw RINGMeshException(
"I/O",
45 "Geological model loading of a from HTML mesh not yet implemented" );
49 void save(
const GeoModel& geomodel,
const std::string& filename )
final 51 GEOLOGYJS::JSWriter js( filename );
52 js.build_js_gui_ =
true;
54 save_all_lines( geomodel, js );
55 save_interfaces( geomodel, js );
58 std::string error_message;
59 if( js.check_validity( error_message ) ) {
62 throw RINGMeshException(
"I/O", error_message );
68 const GeoModel& geomodel,
69 GEOLOGYJS::JSWriter& js )
const 71 std::vector< std::vector< double > > xyz;
72 xyz.resize( geomodel.nb_lines() );
73 for(
const auto& line : geomodel.lines() ) {
74 index_t line_id = line.index();
75 xyz[line_id].reserve( 3 * line.nb_vertices() );
76 for(
auto v_itr : range( line.nb_vertices() ) ) {
77 xyz[line_id].push_back( line.vertex( v_itr ).x );
78 xyz[line_id].push_back( line.vertex( v_itr ).y );
79 xyz[line_id].push_back( line.vertex( v_itr ).z );
82 js.add_lines(
"all_lines", xyz );
87 const GeoModel& geomodel,
88 GEOLOGYJS::JSWriter& js )
const 90 for(
auto& cur_interface : geomodel.geol_entities(
91 Interface::type_name_static() ) ) {
92 if( !GeoModelGeologicalEntity::is_stratigraphic_limit(
93 cur_interface.geological_feature() )
94 && !GeoModelGeologicalEntity::is_fault(
95 cur_interface.geological_feature() ) ) {
99 index_t nb_vertices = 0;
100 index_t nb_triangles = 0;
101 for(
auto surf_itr : range( cur_interface.nb_children() ) ) {
102 const Surface& cur_surface = geomodel.surface(
103 cur_interface.child( surf_itr ).index() );
104 nb_vertices += cur_surface.nb_vertices();
105 nb_triangles += cur_surface.nb_mesh_elements();
108 std::vector< double > xyz;
109 xyz.reserve( 3 * nb_vertices );
110 std::vector< index_t > indices;
111 indices.reserve( 3 * nb_triangles );
113 index_t vertex_count = 0;
114 for(
auto surf_itr : range( cur_interface.nb_children() ) ) {
115 const Surface& cur_surface = geomodel.surface(
116 cur_interface.child( surf_itr ).index() );
118 for(
auto v_itr : range( cur_surface.nb_vertices() ) ) {
119 xyz.push_back( cur_surface.vertex( v_itr ).x );
120 xyz.push_back( cur_surface.vertex( v_itr ).y );
121 xyz.push_back( cur_surface.vertex( v_itr ).z );
124 for(
auto p_itr : range( cur_surface.nb_mesh_elements() ) ) {
125 for(
auto v_itr : range( 3 ) ) {
128 + cur_surface.mesh_element_vertex_index( p_itr,
133 vertex_count += cur_surface.nb_vertices();
135 js.add_surface( cur_interface.name(), xyz, indices );