RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel.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 
42 
43 #include <geogram/basic/command_line.h>
44 
47 
48 namespace
49 {
50  using namespace RINGMesh;
51 
52  template < index_t DIMENSION >
53  void compute_mesh_entity_bbox(
55  {
56  for( auto v : range( entity.nb_vertices() ) )
57  {
58  bbox.add_point( entity.vertex( v ) );
59  }
60  }
61 
62  template < index_t DIMENSION >
63  double compute_percentage_bbox_diagonal(
64  const GeoModelBase< DIMENSION >& gm )
65  {
66  Box< DIMENSION > bbox;
67  if( gm.nb_surfaces() > 0 )
68  {
69  for( auto s : range( gm.nb_surfaces() ) )
70  {
71  compute_mesh_entity_bbox( gm.surface( s ), bbox );
72  }
73  }
74  else if( gm.nb_lines() > 0 )
75  {
76  for( auto l : range( gm.nb_lines() ) )
77  {
78  compute_mesh_entity_bbox( gm.line( l ), bbox );
79  }
80  }
81  else
82  {
83  ringmesh_assert( gm.nb_corners() > 0 );
84  for( auto c : range( gm.nb_corners() ) )
85  {
86  bbox.add_point( gm.corner( c ).vertex( 0 ) );
87  }
88  }
89  return bbox.diagonal().length()
90  * GEO::CmdLine::get_arg_double( "epsilon" );
91  }
92 } // namespace
93 
94 namespace RINGMesh
95 {
96  template < index_t DIMENSION >
98  : mesh( geomodel )
99  {
100  }
101 
102  template < index_t DIMENSION >
104  {
105  }
106 
107  template < index_t DIMENSION >
109  const MeshEntityType& type ) const
110  {
111  const MeshEntityTypeManager< DIMENSION >& manager =
112  entity_type_manager().mesh_entity_manager;
113  if( manager.is_line( type ) )
114  {
115  return nb_lines();
116  }
117  if( manager.is_corner( type ) )
118  {
119  return nb_corners();
120  }
121  if( manager.is_surface( type ) )
122  {
123  return nb_surfaces();
124  }
126  return 0;
127  }
128 
129  template < index_t DIMENSION >
132  {
133  const MeshEntityTypeManager< DIMENSION >& manager =
134  entity_type_manager().mesh_entity_manager;
135  const MeshEntityType& type = id.type();
136  index_t index = id.index();
137  if( manager.is_line( type ) )
138  {
139  return line( index );
140  }
141  if( manager.is_corner( type ) )
142  {
143  return corner( index );
144  }
145  if( manager.is_surface( type ) )
146  {
147  return surface( index );
148  }
150  return surface( 0 );
151  }
152 
153  template < index_t DIMENSION >
154  const std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >&
156  const MeshEntityType& type ) const
157  {
158  const MeshEntityTypeManager< DIMENSION >& manager =
159  entity_type_manager().mesh_entity_manager;
160  if( manager.is_corner( type ) )
161  {
162  return corners_;
163  }
164  if( manager.is_line( type ) )
165  {
166  return lines_;
167  }
168  if( manager.is_surface( type ) )
169  {
170  return surfaces_;
171  }
173  return surfaces_;
174  }
175 
176  template < index_t DIMENSION >
178  index_t index ) const
179  {
180  ringmesh_assert( index < corners_.size() );
181  return *static_cast< const Corner< DIMENSION >* >(
182  corners_[index].get() );
183  }
184  template < index_t DIMENSION >
186  index_t index ) const
187  {
188  ringmesh_assert( index < lines_.size() );
189  return *static_cast< const Line< DIMENSION >* >( lines_[index].get() );
190  }
191  template < index_t DIMENSION >
193  index_t index ) const
194  {
195  ringmesh_assert( index < surfaces_.size() );
196  return *static_cast< const Surface< DIMENSION >* >(
197  surfaces_[index].get() );
198  }
199 
200  template < index_t DIMENSION >
202  const WellGroup< DIMENSION >* wells )
203  {
204  wells_ = wells;
205  }
206 
207  template < index_t DIMENSION >
209  {
210  if( epsilon_ == -1 )
211  {
212  epsilon_ = compute_percentage_bbox_diagonal( *this );
213  }
214  return epsilon_;
215  }
216 
217  template < index_t DIMENSION >
219  {
220  }
221 
223  {
224  }
225 
227  {
228  }
229 
231  {
232  }
233 
235  {
236  }
237 
238  const Region3D& GeoModel< 3 >::region( index_t index ) const
239  {
240  ringmesh_assert( index < regions_.size() );
241  return *static_cast< const Region3D* >( regions_[index].get() );
242  }
243 
244  const std::vector< std::unique_ptr< GeoModelMeshEntity3D > >&
246  {
247  if( entity_type_manager().mesh_entity_manager.is_region( type ) )
248  {
249  return regions_;
250  }
251  return GeoModelBase3D::mesh_entities( type );
252  }
253 
254  const GeoModelMeshEntity3D& GeoModel< 3 >::mesh_entity(
255  const gmme_id& id ) const
256  {
257  const MeshEntityType& type = id.type();
258  index_t index = id.index();
259  if( entity_type_manager().mesh_entity_manager.is_region( type ) )
260  {
261  return region( index );
262  }
263  return GeoModelBase3D::mesh_entity( id );
265  return surface( 0 );
266  }
267 
268  index_t GeoModel< 3 >::nb_mesh_entities( const MeshEntityType& type ) const
269  {
270  if( entity_type_manager().mesh_entity_manager.is_region( type ) )
271  {
272  return nb_regions();
273  }
274  return GeoModelBase3D::nb_mesh_entities( type );
275  }
276 
278  {
279  SurfaceSide surface_side;
280  auto& voi_surfaces = surface_side.surfaces_;
281  voi_surfaces.reserve( nb_surfaces() );
282  auto& voi_surface_region_side = surface_side.sides_;
283  voi_surface_region_side.reserve( nb_surfaces() );
284 
285  for( const auto& cur_surface : surfaces() )
286  {
287  if( cur_surface.is_on_voi() )
288  {
289  ringmesh_assert( cur_surface.nb_incident_entities() == 1 );
290  voi_surfaces.push_back( cur_surface.index() );
291  const auto& incident_region = cur_surface.incident_entity( 0 );
292 
293  index_t local_boundary_id{ NO_ID };
294  for( auto region_boundary_i :
295  range( incident_region.nb_boundaries() ) )
296  {
297  if( incident_region.boundary_gmme( region_boundary_i )
298  .index()
299  == cur_surface.index() )
300  {
301  local_boundary_id = region_boundary_i;
302  break;
303  }
304  }
305  ringmesh_assert( local_boundary_id != NO_ID );
306 
307  voi_surface_region_side.push_back(
308  incident_region.side( local_boundary_id ) );
309  }
310  }
311 
312  return surface_side;
313  }
314 
316  {
317  LineSide line_side;
318  auto& voi_lines = line_side.lines_;
319  voi_lines.reserve( nb_lines() );
320  auto& voi_line_surface_side = line_side.sides_;
321  voi_line_surface_side.reserve( nb_lines() );
322 
323  for( const auto& cur_line : lines() )
324  {
325  if( cur_line.is_on_voi() )
326  {
327  ringmesh_assert( cur_line.nb_incident_entities() == 1 );
328  voi_lines.push_back( cur_line.index() );
329  const auto& incident_surface = cur_line.incident_entity( 0 );
330 
331  index_t local_boundary_id{ NO_ID };
332  for( auto surface_boundary_i :
333  range( incident_surface.nb_boundaries() ) )
334  {
335  if( incident_surface.boundary_gmme( surface_boundary_i )
336  .index()
337  == cur_line.index() )
338  {
339  local_boundary_id = surface_boundary_i;
340  break;
341  }
342  }
343  ringmesh_assert( local_boundary_id != NO_ID );
344 
345  voi_line_surface_side.push_back(
346  incident_surface.side( local_boundary_id ) );
347  }
348  }
349 
350  return line_side;
351  }
352 
353  template class RINGMESH_API GeoModel< 2 >;
354  template class RINGMESH_API GeoModelBase< 2 >;
355  template class RINGMESH_API GeoModelAccess< 2 >;
356 
357  template class RINGMESH_API GeoModelBase< 3 >;
358  template class RINGMESH_API GeoModelAccess< 3 >;
359 
360 } // namespace RINGMesh
Abstract base class for GeoModelMeshEntity.
std::vector< bool > sides_
Definition: geomodel.h:95
const EntityTypeManager< DIMENSION > & entity_type_manager() const
Gets the EntityTypeManager associated to the GeoModel.
Definition: geomodel.h:119
const vecn< DIMENSION > & vertex(index_t vertex_index) const
Coordinates of the vertex_index.
virtual const GeoModelMeshEntity< DIMENSION > & mesh_entity(const gmme_id &id) const
Generic access to a meshed entity.
Definition: geomodel.cpp:131
GeoModelBase(GeoModel< DIMENSION > &geomodel)
Constructs an empty GeoModel.
Definition: geomodel.cpp:97
std::vector< bool > sides_
Definition: geomodel.h:89
A GeoModelEntity of type CORNER.
bool is_line(const MeshEntityType &type) const
const Corner< DIMENSION > & corner(index_t index) const
Definition: geomodel.cpp:177
bool is_surface(const MeshEntityType &type) const
void add_point(const vecn< DIMENSION > &p)
Definition: box.cpp:57
bool is_corner(const MeshEntityType &type) const
const Line< DIMENSION > & line(index_t index) const
Definition: geomodel.cpp:185
const Surface< DIMENSION > & surface(index_t index) const
Definition: geomodel.cpp:192
std::vector< index_t > surfaces_
Definition: geomodel.h:94
std::vector< index_t > lines_
Definition: geomodel.h:88
virtual const std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > > & mesh_entities(const MeshEntityType &type) const
Generic accessor to the storage of mesh entities of the given type.
Definition: geomodel.cpp:155
line_range< DIMENSION > lines() const
Definition: geomodel.h:333
index_t nb_corners() const
Definition: geomodel.h:201
index_t nb_lines() const
Definition: geomodel.h:205
#define ringmesh_assert(x)
index_t nb_surfaces() const
Definition: geomodel.h:209
vecn< DIMENSION > diagonal() const
Definition: box.h:76
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
surface_range< DIMENSION > surfaces() const
Definition: geomodel.h:337
A GeoModelEntity of type LINE.
virtual index_t nb_mesh_entities(const MeshEntityType &type) const
Returns the number of mesh entities of the given type.
Definition: geomodel.cpp:108
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
#define ringmesh_assert_not_reached