RINGMesh  Version 5.0.0
A programming library for geological model meshes
io_stradivarius.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2017, Association Scientifique pour la Geologie et ses
3  * Applications (ASGA). All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ASGA nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * http://www.ring-team.org
28  *
29  * RING Project
30  * Ecole Nationale Superieure de Geologie - GeoRessources
31  * 2 Rue du Doyen Marcel Roubault - TSA 70605
32  * 54518 VANDOEUVRE-LES-NANCY
33  * FRANCE
34  */
35 
40 namespace {
41 
45  class StradivariusBuilder final: public GeoModelBuilderFile< 2 > {
46  public:
47  StradivariusBuilder( GeoModel2D& geomodel, std::string filename )
48  : GeoModelBuilderFile< 2 >( geomodel, std::move( filename ) )
49  {
50  }
51 
52  private:
53  void load_file() override
54  {
55  load_points();
56  load_interfaces();
57  load_media();
58 
59  horizon_m0_.emplace( Surface2D::type_name_static(), index_t( 0 ) );
60  removal.remove_mesh_entities( horizon_m0_ );
61  build_corners_from_lines();
62  }
63 
64  void load_points()
65  {
66  GEO::LineInput file{ filename_ };
67  move_to( file, "liste des points\n" );
68  file.get_line();
69  file.get_fields();
70  auto nb_points = file.field_as_uint( 0 );
71  points_.resize( nb_points );
72  for( auto p : range( nb_points ) ) {
73  file.get_line();
74  file.get_fields();
75  // convert coordinates from depth to elevation
76  points_[p] = {file.field_as_double( 1 ), - file.field_as_double( 2 )};
77  }
78  }
79 
80  void load_interfaces() {
81  GEO::LineInput file{ filename_ };
82  move_to( file, "liste des horizons\n" );
83  file.get_line();
84  file.get_fields();
85  auto nb_horizons = file.field_as_uint( 0 );
86  topology.create_mesh_entities( Line2D::type_name_static(), nb_horizons );
87 
88  for( auto horizon_id : range( nb_horizons ) ) {
89  file.get_line();
90  file.get_fields();
91 
92  gmme_id horizon{ Line2D::type_name_static(), horizon_id };
93  int medium_1 {file.field_as_int( 0 )};
94  int medium_2 {file.field_as_int( 1 )};
95  auto nb_points = file.field_as_uint( 2 );
96  info.set_mesh_entity_name(horizon, file.field( 4 ));
97 
98  std::vector<vec2> vertices(nb_points);
99  for(auto point_i : range( nb_points )) {
100  file.get_line();
101  file.get_fields();
102  auto point_id = file.field_as_uint( 0 );
103  vertices[point_i] = points_[point_id];
104  }
105  geometry.set_line(horizon_id, vertices);
106 
107  if (((medium_1 == 0 && (medium_2 == -1))) || ((medium_1 == -1 && (medium_2 == 0)))) {
108  horizon_m0_.insert(horizon);
109  }
110  }
111  }
112 
113  void load_media() {
114  GEO::LineInput file{ filename_ };
115  move_to(file, "liste des milieux\n");
116  file.get_line();
117  file.get_fields();
118  auto nb_media = file.field_as_uint( 0 );
119  topology.create_mesh_entities( Surface2D::type_name_static(), nb_media + 1 );
120 
121  for( const auto& horizon : horizon_m0_ ) {
122  topology.add_mesh_entity_boundary_relation(
123  { Surface2D::type_name_static(), index_t( 0 )}, horizon,
124  true );
125  }
126 
127  for (auto milieu_i : range( nb_media )) {
128  file.get_line();
129  file.get_fields();
130  auto nb_interfaces = file.field_as_uint( 1 );
131  for (auto interface_i : range( nb_interfaces )) {
132  ringmesh_unused( interface_i );
133  file.get_line();
134  file.get_fields();
135  auto interface_id = file.field_as_uint( 0 );
136  gmme_id horizon{ Line2D::type_name_static(), interface_id };
137  topology.add_mesh_entity_boundary_relation(
138  { Surface2D ::type_name_static(), milieu_i + 1}, horizon,
139  true );
140  }
141  }
142  }
143 
144  bool move_to(GEO::LineInput& file, std::string selector) {
145  while (!file.eof() && file.get_line()) {
146  if (selector.compare(file.current_line()) == 0) {
147  return true;
148  }
149  }
150  return false;
151  }
152 
153  private:
154  std::vector< vec2 > points_;
155  std::set< gmme_id > horizon_m0_;
156  };
157 
161  class StradivariusIOHandler final: public GeoModelIOHandler< 2 > {
162  public:
163  void load( const std::string& filename, GeoModel2D& geomodel ) final
164  {
165  StradivariusBuilder builder{ geomodel, filename };
166  builder.build_geomodel();
167  }
168  void save( const GeoModel2D& geomodel, const std::string& filename ) final
169  {
170  throw RINGMeshException( "I/O",
171  "Cannot save a GeoModel for Stradivarius" );
172  }
173  };
174 
175 }
176 
void ringmesh_unused(const T &)
Definition: common.h:105