RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_builder_remove.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 
39 
46 namespace RINGMesh
47 {
48  template < index_t DIMENSION >
51  : builder_( builder ),
52  geomodel_( geomodel ),
53  geomodel_access_( geomodel )
54  {
55  nb_mesh_entity_types_ = geomodel_.entity_type_manager()
56  .mesh_entity_manager.nb_mesh_entity_types();
57  nb_geological_entity_types_ = geomodel_.nb_geological_entity_types();
58  nb_entity_types_ = nb_geological_entity_types_ + nb_mesh_entity_types_;
59  }
60 
61  template < index_t DIMENSION >
63  const std::set< gmme_id >& entities )
64  {
65  if( entities.empty() )
66  {
67  return;
68  }
69  initialize_for_removal( entities );
70  do_delete_flagged_mesh_entities();
71  geomodel_.mesh.vertices.clear();
72  update_mesh_entity_connectivity();
73  flag_geological_entities_without_children();
74  do_delete_flagged_geological_entities();
75  update_geological_entity_connectivity();
76  }
77 
78  template < index_t DIMENSION >
80  const std::set< gmge_id >& entities )
81  {
82  std::set< gmme_id > mesh_entities;
83  for( const gmge_id& it : entities )
84  {
86  geomodel_.geological_entity( it );
87  for( auto i : range( cur_gmge.nb_children() ) )
88  {
89  mesh_entities.insert( cur_gmge.child( i ).gmme() );
90  }
91  }
92  remove_mesh_entities( mesh_entities );
93  }
94 
95  template < index_t DIMENSION >
98  {
99  for( auto i : range( nb_geological_entity_types_ ) )
100  {
101  const GeologicalEntityType& entity_type =
102  index_to_geological_entity_type( i );
103  for( auto j :
104  range( geomodel_.nb_geological_entities( entity_type ) ) )
105  {
106  if( old_2_new_geological_entity_[i][j] == NO_ID )
107  {
108  builder_.geology.delete_geological_entity( entity_type, j );
109  }
110  }
111  clear_null_geological_entities( i );
112  }
113  }
114 
115  template < index_t DIMENSION >
117  index_t type, index_t index )
118  {
119  const MeshEntityType& type_name = index_to_mesh_entity_type( type );
120  gmme_id id( type_name, index );
121  builder_.topology.delete_mesh_entity( type_name, index );
122  }
123 
124  template < index_t DIMENSION >
125  index_t
128  {
129  const GeologicalEntityType& type = E.type_name();
130  return geological_entity_type_to_index( type );
131  }
132 
133  template < index_t DIMENSION >
135  GeoModelMeshEntity< DIMENSION >& E, index_t new_index_in_geomodel )
136  {
138  dynamic_cast< GeoModelMeshEntity< DIMENSION >& >( E ) );
139  gmme_access.modifiable_index() = new_index_in_geomodel;
140  }
141 
142  template < index_t DIMENSION >
145  index_t new_index_in_geomodel )
146  {
148  dynamic_cast< GeoModelGeologicalEntity< DIMENSION >& >( E ) );
149  gmge_access.modifiable_index() = new_index_in_geomodel;
150  }
151 
152  template < index_t DIMENSION >
155  {
156  index_t old_id = ME.index();
157  index_t type = mesh_entity_type_index( ME );
158  index_t new_id = old_2_new_mesh_entity_[type][old_id];
159  ringmesh_assert( new_id != NO_ID );
160  set_mesh_entity_index( ME, new_id );
161  }
162 
163  template < index_t DIMENSION >
164  void
167  {
168  index_t old_id = GE.index();
169  index_t type = geological_entity_type_index( GE );
170  index_t new_id = old_2_new_geological_entity_[type][old_id];
171  ringmesh_assert( new_id != NO_ID );
172  set_geological_entity_index( GE, new_id );
173  }
174 
175  template < index_t DIMENSION >
178  {
179  index_t type_index = boundary_type_index( ME.mesh_entity_type() );
180  if( type_index == NO_ID )
181  {
182  return;
183  }
184  for( auto i : range( ME.nb_boundaries() ) )
185  {
186  index_t old_boundary = ME.boundary_gmme( i ).index();
187  index_t new_boundary =
188  old_2_new_mesh_entity_[type_index][old_boundary];
189  builder_.topology.set_mesh_entity_boundary(
190  ME.gmme(), i, new_boundary );
191  }
192  }
193 
194  template < index_t DIMENSION >
197  {
198  const MeshEntityTypeManager< DIMENSION >& manager =
199  geomodel_.entity_type_manager().mesh_entity_manager;
200  const MeshEntityType& incident_entity_type =
201  manager.incident_entity_type( E.mesh_entity_type() );
202  bool valid_type = manager.is_valid_type( incident_entity_type );
203  if( !valid_type )
204  {
205  return;
206  }
207  index_t incident_entity_type_index =
208  mesh_entity_type_to_index( incident_entity_type );
209  for( auto i : range( E.nb_incident_entities() ) )
210  {
211  index_t old_id = E.incident_entity_gmme( i ).index();
212  index_t new_id =
213  old_2_new_mesh_entity_[incident_entity_type_index][old_id];
214  builder_.topology.set_mesh_entity_incident_entity(
215  E.gmme(), i, new_id );
216  }
217  }
218 
219  template < index_t DIMENSION >
222  {
223  gmme_id id = E.gmme();
224  for( auto p : range( E.nb_parents() ) )
225  {
226  const GeologicalEntityType& parent_type = E.parent_gmge( p ).type();
227  index_t parent_type_index =
228  geological_entity_type_to_index( parent_type );
229 
230  index_t old_id = E.parent_gmge( p ).index();
231  index_t new_id =
232  old_2_new_geological_entity_[parent_type_index][old_id];
233  builder_.geology.set_mesh_entity_parent(
234  id, p, gmge_id( parent_type, new_id ) );
235  }
236  }
237 
238  template < index_t DIMENSION >
242  {
243  if( E.nb_children() > 0 )
244  {
245  index_t child_type = children_type_index( E.entity_type() );
246  for( auto i : range( E.nb_children() ) )
247  {
248  index_t old_id = E.child_gmme( i ).index();
249  index_t new_id = old_2_new_mesh_entity_[child_type][old_id];
250  builder_.geology.set_geological_entity_child(
251  E.gmge(), i, new_id );
252  }
253  }
254  }
255 
256  template < index_t DIMENSION >
258  {
259  for( auto i : range( nb_childs_.size() ) )
260  {
261  for( auto j : range( nb_childs_[i].size() ) )
262  {
263  nb_childs_[i][j] =
264  geomodel_
265  .geological_entity(
266  index_to_geological_entity_type( i ), j )
267  .nb_children();
268  }
269  }
270  }
271 
272  template < index_t DIMENSION >
275  : GeoModelBuilderRemovalBase< DIMENSION >( builder, geomodel )
276  {
277  }
278 
280  GeoModelBuilder3D& builder, GeoModel3D& geomodel )
281  : GeoModelBuilderRemovalBase< 3 >( builder, geomodel )
282  {
283  }
284 
286  GeoModelMeshEntity3D& ME )
287  {
288  GeoModelBuilderRemovalBase3D::update_mesh_entity( ME );
289 
290  if( ME.mesh_entity_type() == Region3D::type_name_static() )
291  {
292  auto& R = dynamic_cast< Region3D& >( ME );
293  update_region_boundary_signs( R );
294  delete_invalid_signs( R );
295  }
296  }
297 
298  template class RINGMESH_API GeoModelBuilderRemovalBase< 2 >;
299  template class RINGMESH_API GeoModelBuilderRemoval< 2 >;
300 
301  template class RINGMESH_API GeoModelBuilderRemovalBase< 3 >;
302 } // namespace RINGMesh
const GeoModelMeshEntity< DIMENSION > & child(index_t x) const
Abstract base class for GeoModelMeshEntity.
virtual GeologicalEntityType type_name() const
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
const gmme_id & boundary_gmme(index_t x) const
GeoModelBuilderRemovalBase(GeoModelBuilder< DIMENSION > &builder, GeoModel< DIMENSION > &geomodel)
virtual void update_mesh_entity(GeoModelMeshEntity< DIMENSION > &ME)
const gmge_id & parent_gmge(index_t id) const
const gmme_id & incident_entity_gmme(index_t x) const
const gmme_id & child_gmme(index_t x) const
bool is_valid_type(const MeshEntityType &type) const
Builder tools to remove entities from a GeoModel.
#define ringmesh_assert(x)
GeoModelBuilderRemoval(GeoModelBuilder< DIMENSION > &builder, GeoModel< DIMENSION > &geomodel)
const MeshEntityType & incident_entity_type(const MeshEntityType &mesh_entity_type) const
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
This template is a specialization of a gme_id to the GeoModelGeologicalEntity.
Definition: entity_type.h:262
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
MeshEntityType mesh_entity_type() const