RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_builder_2d_from_3d.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 
37 
40 
41 namespace
42 {
43  using namespace RINGMesh;
44 
45  const MeshEntityType projectable_entity_types[3] = {
46  Corner3D::type_name_static(), Line3D::type_name_static(),
47  Surface3D::type_name_static()
48  };
49 
50  struct GeologicalEntityTypeMapFrom2DTo3DInitializer
51  {
52  static std::map< GeologicalEntityType, GeologicalEntityType >
53  initialize_map()
54  {
55  std::map< GeologicalEntityType, GeologicalEntityType > map;
56  map[Contact3D::type_name_static()] =
57  Interface2D::type_name_static();
58  map[Interface3D::type_name_static()] = Layer2D::type_name_static();
59  return map;
60  }
61  };
62 
63  template < typename U, typename T >
64  const T& mapped_value( const std::map< U, T >& map, const U& key )
65  {
66  return map.find( key )->second;
67  }
68 
69  const std::map< GeologicalEntityType, GeologicalEntityType >
70  geol_entity_type_2d_to_3d_map =
71  GeologicalEntityTypeMapFrom2DTo3DInitializer::initialize_map();
72 }
73 
74 namespace RINGMesh
75 {
77  {
78  copy_geomodel_3d_topology();
79  copy_geomodel_3d_geological_informations();
80  project_geomodel_3d_mesh_entities();
81  print_geomodel( geomodel_ );
82  }
83 
85  {
86  for( const auto& entity_type : projectable_entity_types )
87  {
88  topology.create_mesh_entities(
89  entity_type, geomodel3d_from_.nb_mesh_entities( entity_type ) );
90  }
91  for( const auto& entity_type : projectable_entity_types )
92  {
93  for( const auto entity_id :
94  range( geomodel3d_from_.nb_mesh_entities( entity_type ) ) )
95  {
96  const auto& entity =
97  geomodel3d_from_.mesh_entity( entity_type, entity_id );
98  for( const auto& boundary_id : range( entity.nb_boundaries() ) )
99  {
100  topology.add_mesh_entity_boundary_relation(
101  entity.gmme(), entity.boundary( boundary_id ).gmme() );
102  }
103  }
104  }
105  }
106 
108  {
109  for( const auto& geol_entity_id :
110  range( geomodel3d_from_.nb_geological_entity_types() ) )
111  {
112  const auto& cur_type =
113  geomodel3d_from_.geological_entity_type( geol_entity_id );
114  geology.create_geological_entities(
115  mapped_value( geol_entity_type_2d_to_3d_map, cur_type ),
116  geomodel3d_from_.nb_geological_entities( cur_type ) );
117  }
118  for( const auto& geol_entity_id :
119  range( geomodel3d_from_.nb_geological_entity_types() ) )
120  {
121  const auto& cur_type =
122  geomodel3d_from_.geological_entity_type( geol_entity_id );
123  for( const auto& cur_geol_entity :
124  geomodel3d_from_.geol_entities( cur_type ) )
125  {
126  for( const auto& child_id :
127  range( cur_geol_entity.nb_children() ) )
128  {
129  geology.add_parent_children_relation(
130  { mapped_value(
131  geol_entity_type_2d_to_3d_map, cur_type ),
132  cur_geol_entity.index() },
133  cur_geol_entity.child_gmme( child_id ) );
134  }
135  }
136  }
137  }
138 
140  {
141  for( const auto& corner : geomodel3d_from_.corners() )
142  {
143  auto projected_vertices = compute_projected_vertices( corner );
144  ringmesh_assert( projected_vertices.size() == 1 );
145  geometry.set_corner( corner.index(), projected_vertices.front() );
146  }
147 
148  for( const auto& line : geomodel3d_from_.lines() )
149  {
150  auto projected_vertices = compute_projected_vertices( line );
151  geometry.set_line( line.index(), projected_vertices );
152  }
153 
154  for( const auto& surface : geomodel3d_from_.surfaces() )
155  {
156  auto projected_vertices = compute_projected_vertices( surface );
157  std::vector< index_t > surface_polygons;
158  surface_polygons.reserve( 4 * surface.nb_mesh_elements() );
159  std::vector< index_t > surface_polygon_ptr( 1, 0 );
160  surface_polygon_ptr.reserve( surface.nb_mesh_elements() + 1 );
161  for( const auto& polygon_id : range( surface.nb_mesh_elements() ) )
162  {
163  for( const auto& v_id :
164  range( surface.nb_mesh_element_vertices( polygon_id ) ) )
165  {
166  surface_polygons.push_back(
167  surface.mesh_element_vertex_index(
168  { polygon_id, v_id } ) );
169  }
170  surface_polygon_ptr.push_back(
171  surface_polygon_ptr.back()
172  + surface.nb_mesh_element_vertices( polygon_id ) );
173  }
174  geometry.set_surface_geometry( surface.index(), projected_vertices,
175  surface_polygons, surface_polygon_ptr );
176  }
177  }
178 
180  const GeoModelMeshEntity3D& entity )
181  {
182  std::vector< vec2 > projected_vertices;
183  projected_vertices.reserve( entity.nb_vertices() );
184  for( const auto v : range( entity.nb_vertices() ) )
185  {
186  projected_vertices.push_back( get_2d_coord( entity.vertex( v ) ) );
187  }
188  return projected_vertices;
189  }
190 }
std::vector< vec2 > compute_projected_vertices(const GeoModelMeshEntity3D &entity)
void print_geomodel(const GeoModel< DIMENSION > &geomodel)
Print in the console the geomodel statistics.
#define ringmesh_assert(x)
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48