RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel.h
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 
36 #pragma once
37 
38 #include <ringmesh/basic/common.h>
39 
40 #include <vector>
41 
47 
54 namespace RINGMesh
55 {
57  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelGeologicalEntity );
58  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelMeshEntity );
63  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelAccess );
64  FORWARD_DECLARATION_DIMENSION_STRUCT( EntityTypeManager );
65  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderTopologyBase );
66  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderTopology );
67  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderGeometryBase );
68  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderGeometry );
69  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderGeology );
70  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderRemovalBase );
71  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderRemoval );
72  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderRepair );
73  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderCopy );
74  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderInfo );
75  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderBase );
76  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilder );
77  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderGM );
78 
79  ALIAS_2D_AND_3D( GeoModelMeshEntity );
80  ALIAS_2D_AND_3D( Region );
81 } // namespace RINGMesh
82 
83 namespace RINGMesh
84 {
85  struct LineSide
86  {
87  LineSide() = default;
88  std::vector< index_t > lines_;
89  std::vector< bool > sides_;
90  };
91  struct SurfaceSide
92  {
93  SurfaceSide() = default;
94  std::vector< index_t > surfaces_;
95  std::vector< bool > sides_;
96  };
97 
98  template < index_t DIMENSION >
99  class RINGMESH_API GeoModelBase
100  {
103  friend class GeoModelAccess< DIMENSION >;
104 
105  public:
106  virtual ~GeoModelBase();
107 
111  const std::string& name() const
112  {
113  return geomodel_name_;
114  }
115 
120  {
121  return entity_type_manager_;
122  }
123 
129  virtual index_t nb_mesh_entities( const MeshEntityType& type ) const;
130 
136  index_t nb_geological_entities( const GeologicalEntityType& type ) const
137  {
138  return static_cast< index_t >( geological_entities( type ).size() );
139  }
140 
147  {
148  return entity_type_manager_.geological_entity_manager
149  .nb_geological_entity_types();
150  }
151 
153  index_t index ) const
154  {
155  return entity_type_manager_.geological_entity_manager
156  .geological_entity_type( index );
157  }
158 
166  gmge_id id ) const
167  {
168  return *geological_entities( id.type() )[id.index()];
169  }
170 
175  const GeologicalEntityType& entity_type,
176  index_t entity_index ) const
177  {
178  return geological_entity( gmge_id( entity_type, entity_index ) );
179  }
180 
185  virtual const GeoModelMeshEntity< DIMENSION >& mesh_entity(
186  const gmme_id& id ) const;
187 
192  const MeshEntityType& entity_type, index_t entity_index ) const
193  {
194  return mesh_entity( gmme_id( entity_type, entity_index ) );
195  }
196 
201  index_t nb_corners() const
202  {
203  return static_cast< index_t >( corners_.size() );
204  }
205  index_t nb_lines() const
206  {
207  return static_cast< index_t >( lines_.size() );
208  }
209  index_t nb_surfaces() const
210  {
211  return static_cast< index_t >( surfaces_.size() );
212  }
213 
214  const Corner< DIMENSION >& corner( index_t index ) const;
215  const Line< DIMENSION >& line( index_t index ) const;
216  const Surface< DIMENSION >& surface( index_t index ) const;
217 
218  double epsilon() const;
219 
220  double epsilon2() const
221  {
222  return epsilon() * epsilon();
223  }
224 
234  void set_wells( const WellGroup< DIMENSION >* wells );
236  {
237  return wells_;
238  }
239 
240  public:
242 
243  protected:
247  explicit GeoModelBase( GeoModel< DIMENSION >& geomodel );
252  const GeologicalEntityType& type ) const
253  {
254  return entity_type_manager_.geological_entity_manager
255  .geological_entity_type_index( type );
256  }
261  virtual const std::
262  vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >&
263  mesh_entities( const MeshEntityType& type ) const;
264 
269  const std::
270  vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > >&
272  {
273  index_t entity_index = geological_entity_type_index( type );
274  return geological_entities( entity_index );
275  }
276 
277  const std::
278  vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > >&
279  geological_entities( index_t geological_entity_type_index ) const
280  {
281  ringmesh_assert( geological_entity_type_index != NO_ID );
282  return geological_entities_[geological_entity_type_index];
283  }
284 
285  protected:
286  std::string geomodel_name_;
287  mutable double epsilon_{ -1 };
288 
290 
295  std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >
297  std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >
299  std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >
301 
306  std::vector< std::vector< std::
307  unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > >
309 
317  const WellGroup< DIMENSION >* wells_{ nullptr };
318  };
320 
321  template < index_t DIMENSION >
322  class RINGMESH_API GeoModel final : public GeoModelBase< DIMENSION >
323  {
324  friend class GeoModelAccess< DIMENSION >;
325 
326  public:
327  GeoModel();
328 
330  {
331  return corner_range< DIMENSION >( *this );
332  }
334  {
335  return line_range< DIMENSION >( *this );
336  }
338  {
339  return surface_range< DIMENSION >( *this );
340  }
342  const GeologicalEntityType& geol_type ) const
343  {
344  return geol_entity_range< DIMENSION >( *this, geol_type );
345  }
346  };
347 
348  template <>
349  class RINGMESH_API GeoModel< 3 > final : public GeoModelBase< 3 >
350  {
351  friend class GeoModelAccess< 3 >;
352 
353  public:
354  GeoModel();
355  ~GeoModel() override;
356 
358  {
359  return corner_range< 3 >( *this );
360  }
362  {
363  return line_range< 3 >( *this );
364  }
366  {
367  return surface_range< 3 >( *this );
368  }
370  {
371  return region_range< 3 >( *this );
372  }
374  const GeologicalEntityType& geol_type ) const
375  {
376  return geol_entity_range< 3 >( *this, geol_type );
377  }
378 
379  index_t nb_regions() const
380  {
381  return static_cast< index_t >( regions_.size() );
382  }
383 
384  const Region3D& region( index_t index ) const;
385 
386  const GeoModelMeshEntity3D& mesh_entity(
387  const MeshEntityType& entity_type, index_t entity_index ) const
388  {
389  return GeoModelBase3D::mesh_entity( entity_type, entity_index );
390  }
391 
392  const GeoModelMeshEntity3D& mesh_entity(
393  const gmme_id& id ) const override;
394 
395  index_t nb_mesh_entities( const MeshEntityType& type ) const override;
396 
397  double epsilon3() const
398  {
399  return epsilon2() * epsilon();
400  }
401  SurfaceSide voi_surfaces() const;
402 
403  private:
404  const std::vector< std::unique_ptr< GeoModelMeshEntity3D > >&
405  mesh_entities( const MeshEntityType& type ) const override;
406 
407  private:
408  std::vector< std::unique_ptr< GeoModelMeshEntity3D > > regions_;
409  };
410 
411  template <>
412  class GeoModel< 2 > final : public GeoModelBase< 2 >
413  {
414  friend class GeoModelAccess< 2 >;
415 
416  public:
417  GeoModel();
418  ~GeoModel() override;
419 
421  {
422  return corner_range< 2 >( *this );
423  }
425  {
426  return line_range< 2 >( *this );
427  }
429  {
430  return surface_range< 2 >( *this );
431  }
433  const GeologicalEntityType& geol_type ) const
434  {
435  return geol_entity_range< 2 >( *this, geol_type );
436  }
437  LineSide voi_lines() const;
438  };
439 
441 
442  template < index_t DIMENSION >
443  class RINGMESH_API GeoModelAccess
444  {
447  friend class GeoModelBuilderBase< DIMENSION >;
448  friend class GeoModelBuilder< DIMENSION >;
449  friend class GeoModelBuilderGM< DIMENSION >;
450  friend class GeoModelBuilderTopologyBase< DIMENSION >;
451  friend class GeoModelBuilderTopology< DIMENSION >;
452  friend class GeoModelBuilderGeometryBase< DIMENSION >;
453  friend class GeoModelBuilderGeometry< DIMENSION >;
454  friend class GeoModelBuilderGeology< DIMENSION >;
455  friend class GeoModelBuilderRemovalBase< DIMENSION >;
456  friend class GeoModelBuilderRemoval< DIMENSION >;
457  friend class GeoModelBuilderRepair< DIMENSION >;
458  friend class GeoModelBuilderCopy< DIMENSION >;
459  friend class GeoModelBuilderInfo< DIMENSION >;
460 
461  private:
462  explicit GeoModelAccess( GeoModel< DIMENSION >& geomodel )
463  : geomodel_( geomodel )
464  {
465  }
466  ~GeoModelAccess() = default;
467 
468  std::string& modifiable_name()
469  {
470  return geomodel_.geomodel_name_;
471  }
472 
474  {
475  return geomodel_.entity_type_manager_;
476  }
477 
478  std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > >&
480  {
481  return const_cast< std::vector< std::
482  unique_ptr< GeoModelMeshEntity< DIMENSION > > >& >(
483  geomodel_.mesh_entities( type ) );
484  }
485 
487  const gmme_id& id )
488  {
489  return *modifiable_mesh_entities( id.type() )[id.index()];
490  }
491 
492  std::vector< std::vector< std::
493  unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > >&
495  {
496  return geomodel_.geological_entities_;
497  }
498 
499  std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > >&
501  {
502  return const_cast< std::vector< std::
503  unique_ptr< GeoModelGeologicalEntity< DIMENSION > > >& >(
504  geomodel_.geological_entities( type ) );
505  }
506 
508  const gmge_id& id )
509  {
510  return *modifiable_geological_entities( id.type() )[id.index()];
511  }
512 
514  {
515  return geomodel_.epsilon_;
516  }
517 
518  private:
520  };
521 } // namespace RINGMesh
#define ringmesh_disable_copy_and_move(Class)
Definition: common.h:76
std::vector< std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > > & modifiable_geological_entities()
Definition: geomodel.h:494
GeoModelMesh< DIMENSION > mesh
Definition: geomodel.h:241
Abstract base class for GeoModelMeshEntity.
std::vector< bool > sides_
Definition: geomodel.h:95
std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > > corners_
Definition: geomodel.h:296
const EntityTypeManager< DIMENSION > & entity_type_manager() const
Gets the EntityTypeManager associated to the GeoModel.
Definition: geomodel.h:119
The GeologicalEntityType described the type of the Geological entities User can defined there own Geo...
Definition: entity_type.h:137
Base class to build or edit a GeoModel.
double epsilon2() const
Definition: geomodel.h:220
GeoModel< DIMENSION > & geomodel_
Definition: geomodel.h:519
geol_entity_range< 3 > geol_entities(const GeologicalEntityType &geol_type) const
Definition: geomodel.h:373
std::vector< bool > sides_
Definition: geomodel.h:89
std::string geomodel_name_
Definition: geomodel.h:286
geol_entity_range< 2 > geol_entities(const GeologicalEntityType &geol_type) const
Definition: geomodel.h:432
#define ringmesh_template_assert_2d_or_3d(type)
Definition: common.h:80
A GeoModelEntity of type CORNER.
corner_range< 2 > corners() const
Definition: geomodel.h:420
ALIAS_2D_AND_3D(Box)
EntityTypeManager< DIMENSION > & modifiable_entity_type_manager()
Definition: geomodel.h:473
index_t nb_geological_entity_types() const
Returns the index of the geological entity type storage.
Definition: geomodel.h:146
std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > > surfaces_
Definition: geomodel.h:300
const std::string & name() const
Gets the name of the GeoModel.
Definition: geomodel.h:111
geol_entity_range< DIMENSION > geol_entities(const GeologicalEntityType &geol_type) const
Definition: geomodel.h:341
region_range< 3 > regions() const
Definition: geomodel.h:369
FORWARD_DECLARATION_DIMENSION_STRUCT(EntityTypeManager)
index_t geological_entity_type_index(const GeologicalEntityType &type) const
Definition: geomodel.h:251
GeoModelMeshEntity< DIMENSION > & modifiable_mesh_entity(const gmme_id &id)
Definition: geomodel.h:486
line_range< 2 > lines() const
Definition: geomodel.h:424
line_range< 3 > lines() const
Definition: geomodel.h:361
const std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > & geological_entities(const GeologicalEntityType &type) const
Generic accessor to the storage of geological entities of the given type.
Definition: geomodel.h:271
surface_range< 3 > surfaces() const
Definition: geomodel.h:365
std::vector< index_t > surfaces_
Definition: geomodel.h:94
const GeologicalEntityType & geological_entity_type(index_t index) const
Definition: geomodel.h:152
index_t nb_regions() const
Definition: geomodel.h:379
EntityTypeManager< DIMENSION > entity_type_manager_
Definition: geomodel.h:289
Global entity manager which could be associated to a geomodel to give access to different manager to ...
std::vector< index_t > lines_
Definition: geomodel.h:88
const WellGroup< DIMENSION > * wells() const
Definition: geomodel.h:235
GeoModelAccess(GeoModel< DIMENSION > &geomodel)
Definition: geomodel.h:462
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
Builder tools to remove entities from a GeoModel.
corner_range< 3 > corners() const
Definition: geomodel.h:357
surface_range< 2 > surfaces() const
Definition: geomodel.h:428
#define ringmesh_assert(x)
const GeoModelMeshEntity3D & mesh_entity(const MeshEntityType &entity_type, index_t entity_index) const
Definition: geomodel.h:386
std::vector< std::unique_ptr< GeoModelMeshEntity3D > > regions_
Definition: geomodel.h:408
std::string & modifiable_name()
Definition: geomodel.h:468
index_t nb_surfaces() const
Definition: geomodel.h:209
double & modifiable_epsilon()
Definition: geomodel.h:513
std::vector< std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > > geological_entities_
Geological entities. They are optional. The EntityTypes are managed by the EntityTypeManager of the c...
Definition: geomodel.h:308
const GeoModelMeshEntity< DIMENSION > & mesh_entity(const MeshEntityType &entity_type, index_t entity_index) const
Definition: geomodel.h:191
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
corner_range< DIMENSION > corners() const
Definition: geomodel.h:329
const GeoModelGeologicalEntity< DIMENSION > & geological_entity(const GeologicalEntityType &entity_type, index_t entity_index) const
Definition: geomodel.h:174
std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > > lines_
Definition: geomodel.h:298
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
const GeoModelGeologicalEntity< DIMENSION > & geological_entity(gmge_id id) const
Returns a const reference the identified GeoModelGeologicalEntity.
Definition: geomodel.h:165
std::vector< std::unique_ptr< GeoModelMeshEntity< DIMENSION > > > & modifiable_mesh_entities(const MeshEntityType &type)
Definition: geomodel.h:479
Try repairing a supposedly invalid GeoModel.
double epsilon3() const
Definition: geomodel.h:397
const std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > & geological_entities(index_t geological_entity_type_index) const
Definition: geomodel.h:279
surface_range< DIMENSION > surfaces() const
Definition: geomodel.h:337
A GeoModelEntity of type LINE.
GeoModelGeologicalEntity< DIMENSION > & modifiable_geological_entity(const gmge_id &id)
Definition: geomodel.h:507
std::vector< std::unique_ptr< GeoModelGeologicalEntity< DIMENSION > > > & modifiable_geological_entities(const GeologicalEntityType &type)
Definition: geomodel.h:500
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
index_t nb_geological_entities(const GeologicalEntityType &type) const
Returns the number of geological entities of the given type.
Definition: geomodel.h:136
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)