RINGMesh  Version 5.0.0
A programming library for geological model meshes
geomodel_builder_geometry.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 
42 
49 namespace RINGMesh
50 {
51  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilderBase );
52  FORWARD_DECLARATION_DIMENSION_CLASS( GeoModelBuilder );
53 
54  ALIAS_2D_AND_3D( GeoModelBuilder );
55 } // namespace RINGMesh
56 
57 namespace RINGMesh
58 {
59  template < index_t DIMENSION >
60  class RINGMESH_API GeoModelBuilderGeometryBase
61  {
64  friend class GeoModelBuilderBase< DIMENSION >;
65  friend class GeoModelBuilder< DIMENSION >;
66 
67  public:
68  virtual ~GeoModelBuilderGeometryBase() = default;
69 
70  void clear_geomodel_mesh();
78  const gmme_id& id, const MeshType type )
79  {
81  geomodel_access_.modifiable_mesh_entity( id ) );
82  gmme_access.change_mesh_data_structure( type );
83  }
84 
92  std::unique_ptr< PointSetMeshBuilder< DIMENSION > >
93  create_corner_builder( index_t corner_id )
94  {
97  geomodel_access_.modifiable_mesh_entity( id );
98  GeoModelMeshEntityAccess< DIMENSION > corner_access( corner );
99  auto& corner_mesh = dynamic_cast< PointSetMesh< DIMENSION >& >(
100  *corner_access.modifiable_mesh() );
102  corner_mesh );
103  }
104 
112  std::unique_ptr< LineMeshBuilder< DIMENSION > > create_line_builder(
113  index_t line_id )
114  {
117  geomodel_access_.modifiable_mesh_entity( id );
118  GeoModelMeshEntityAccess< DIMENSION > line_access( line );
119  auto& line_mesh = dynamic_cast< LineMesh< DIMENSION >& >(
120  *line_access.modifiable_mesh() );
122  }
123 
131  std::unique_ptr< SurfaceMeshBuilder< DIMENSION > >
132  create_surface_builder( index_t surface_id )
133  {
136  geomodel_access_.modifiable_mesh_entity( id );
137  GeoModelMeshEntityAccess< DIMENSION > surface_access( surface );
138  auto& surface_mesh = dynamic_cast< SurfaceMesh< DIMENSION >& >(
139  *surface_access.modifiable_mesh() );
141  surface_mesh );
142  }
143 
150  virtual void copy_meshes( const GeoModel< DIMENSION >& from );
151  void copy_meshes( const GeoModel< DIMENSION >& from,
152  const MeshEntityType& entity_type );
153  void copy_mesh(
154  const GeoModel< DIMENSION >& from, const gmme_id& mesh_entity );
155 
156  void assign_mesh_to_entity(
157  const MeshBase< DIMENSION >& mesh, const gmme_id& to );
158 
173  void set_mesh_entity_vertex( const gmme_id& entity_id,
174  index_t v,
175  const vecn< DIMENSION >& point,
176  bool update );
177 
185  void set_mesh_entity_vertices( const gmme_id& entity_id,
186  const std::vector< vecn< DIMENSION > >& points,
187  bool clear );
188 
194  void set_corner( index_t corner_id, const vecn< DIMENSION >& point );
202  void set_line(
203  index_t line_id, const std::vector< vecn< DIMENSION > >& vertices );
215  void set_surface_geometry( index_t surface_id,
216  const std::vector< vecn< DIMENSION > >& surface_vertices,
217  const std::vector< index_t >& surface_polygons,
218  const std::vector< index_t >& surface_polygon_ptr );
219 
234  void set_mesh_entity_vertex(
235  const gmme_id& entity_id, index_t v, index_t geomodel_vertex );
236 
245  void set_mesh_entity_vertices( const gmme_id& entity_id,
246  const std::vector< index_t >& geomodel_vertices,
247  bool clear );
248 
256  void set_corner( index_t corner_id, index_t geomodel_vertex_id );
257 
266  void set_line(
267  index_t line_id, const std::vector< index_t >& unique_vertices );
268 
282  void set_surface_geometry( index_t surface_id,
283  const std::vector< index_t >& polygons,
284  const std::vector< index_t >& polygon_ptr );
285 
286  void set_surface_element_geometry( index_t surface_id,
287  index_t polygon_id,
288  const std::vector< index_t >& corners );
289 
301  index_t create_mesh_entity_vertices(
302  const gmme_id& entity_id, index_t nb_vertices );
303 
304  index_t create_surface_polygon(
305  index_t surface_id, const std::vector< index_t >& vertex_indices );
306 
312  void delete_mesh_entity_mesh( const gmme_id& E_id );
313  virtual void delete_mesh_entity_isolated_vertices(
314  const gmme_id& E_id );
315  void delete_mesh_entity_vertices(
316  const gmme_id& E_id, const std::vector< bool >& to_delete );
317  void delete_corner_vertex( index_t corner_id );
318  void delete_line_edges( index_t line_id,
319  const std::vector< bool >& to_delete,
320  bool remove_isolated_vertices );
321  void delete_surface_polygons( index_t surface_id,
322  const std::vector< bool >& to_delete,
323  bool remove_isolated_vertices );
324 
330  void set_surface_element_adjacency( index_t surface_id,
331  index_t polygon_id,
332  const std::vector< index_t >& adjacents );
333 
346  void compute_surface_adjacencies(
347  index_t surface_id, bool recompute_adjacency = true );
348 
349  void cut_surfaces_by_internal_lines();
350 
358  void cut_surface_by_line( index_t surface_id, index_t line_id );
359 
360  protected:
362  GeoModel< DIMENSION >& geomodel );
363 
368  void duplicate_surface_vertices_along_line(
369  index_t surface_id, index_t line_id );
370  /*
371  * @brief Resets the adjacencies for all Surface polygons adjacent to
372  * the Line
373  * @return The number of disconnection done
374  * @pre All the edges of the Line are edges of at least one polygon of
375  * the Surface
376  */
377  index_t disconnect_surface_polygons_along_line_edges(
378  index_t surface_id, index_t line_id );
379 
380  void update_polygon_vertex( index_t surface_id,
381  const std::vector< index_t >& polygons,
382  index_t old_vertex,
383  index_t new_vertex );
384 
385  protected:
389  };
390 
392 
393  template < index_t DIMENSION >
394  class RINGMESH_API GeoModelBuilderGeometry final
395  : public GeoModelBuilderGeometryBase< DIMENSION >
396  {
397  friend class GeoModelBuilderBase< DIMENSION >;
398  friend class GeoModelBuilder< DIMENSION >;
399 
400  protected:
402  GeoModel< DIMENSION >& geomodel )
403  : GeoModelBuilderGeometryBase< DIMENSION >( builder, geomodel )
404  {
405  }
406  };
407 
408  template <>
409  class RINGMESH_API GeoModelBuilderGeometry< 3 > final
410  : public GeoModelBuilderGeometryBase< 3 >
411  {
412  friend class GeoModelBuilderBase< 3 >;
413  friend class GeoModelBuilder< 3 >;
414 
415  public:
423  std::unique_ptr< VolumeMeshBuilder3D > create_region_builder(
424  index_t region_id )
425  {
426  gmme_id id( Region3D::type_name_static(), region_id );
427  GeoModelMeshEntity3D& region =
428  geomodel_access_.modifiable_mesh_entity( id );
429  GeoModelMeshEntityAccess3D region_access( region );
430  VolumeMesh3D& region_mesh = dynamic_cast< VolumeMesh3D& >(
431  *region_access.modifiable_mesh() );
432  return VolumeMeshBuilder3D::create_builder( region_mesh );
433  }
434 
435  void copy_meshes( const GeoModel3D& geomodel ) override;
436 
437  void set_region_element_geometry( index_t region_id,
438  index_t cell_id,
439  const std::vector< index_t >& corners );
440 
448  void set_region_geometry( index_t region_id,
449  const std::vector< vec3 >& points,
450  const std::vector< index_t >& tetras );
451 
452  index_t create_region_cell( index_t region_id,
453  CellType type,
454  const std::vector< index_t >& vertex_indices );
455 
463  index_t create_region_cells(
464  index_t region_id, CellType type, index_t nb_cells );
465 
466  void delete_region_cells( index_t region_id,
467  const std::vector< bool >& to_delete,
468  bool remove_isolated_vertices );
469 
480  void compute_region_adjacencies(
481  index_t region_id, bool recompute_adjacency = true );
482 
483  void cut_regions_by_internal_surfaces();
484 
485  void cut_region_by_surface( index_t region_id, index_t surface_id );
486 
487  void delete_mesh_entity_isolated_vertices(
488  const gmme_id& E_id ) override;
489 
490  protected:
492  GeoModelBuilder3D& builder, GeoModel3D& geomodel )
493  : GeoModelBuilderGeometryBase< 3 >( builder, geomodel )
494  {
495  }
496 
497  void assign_region_tet_mesh(
498  index_t region_id, const std::vector< index_t >& tet_vertices );
499 
500  void update_cell_vertex( index_t region_id,
501  const std::vector< index_t >& cells,
502  index_t old_vertex,
503  index_t new_vertex );
504 
505  void duplicate_region_vertices_along_surface(
506  index_t region_id, index_t surface_id );
507 
508  index_t disconnect_region_cells_along_surface_polygons(
509  index_t region_id, index_t surface_id );
510  };
511 } // namespace RINGMesh
#define ringmesh_disable_copy_and_move(Class)
Definition: common.h:76
void change_mesh_data_structure(const gmme_id &id, const MeshType type)
Transfer general mesh information from one mesh data structure to another one.
Abstract base class for GeoModelMeshEntity.
GEO::vecng< DIMENSION, double > vecn
Definition: types.h:74
static std::unique_ptr< LineMeshBuilder > create_builder(LineMesh< DIMENSION > &mesh)
static std::unique_ptr< PointSetMeshBuilder< DIMENSION > > create_builder(PointSetMesh< DIMENSION > &mesh)
std::unique_ptr< SurfaceMeshBuilder< DIMENSION > > create_surface_builder(index_t surface_id)
Create a Mesh2DBuilder for a given surface.
Base class to build or edit a GeoModel.
#define ringmesh_template_assert_2d_or_3d(type)
Definition: common.h:80
A GeoModelEntity of type CORNER.
ALIAS_2D_AND_3D(Box)
void change_mesh_data_structure(const MeshType &type)
static std::unique_ptr< VolumeMeshBuilder< DIMENSION > > create_builder(VolumeMesh< DIMENSION > &mesh)
CellType
Definition: types.h:89
std::string MeshType
Definition: mesh.h:69
encapsulate adimensional mesh functionalities in order to provide an API on which we base the RINGMes...
Definition: mesh.h:138
std::unique_ptr< PointSetMeshBuilder< DIMENSION > > create_corner_builder(index_t corner_id)
Create a PointMeshBuilder for a given corner.
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
A GeoModelEntity of type LINE.
std::unique_ptr< LineMeshBuilder< DIMENSION > > create_line_builder(index_t line_id)
Create a LineMeshBuilder for a given line.
GeoModelBuilderGeometry(GeoModelBuilder3D &builder, GeoModel3D &geomodel)
static std::unique_ptr< SurfaceMeshBuilder< DIMENSION > > create_builder(SurfaceMesh< DIMENSION > &mesh)
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
std::unique_ptr< VolumeMeshBuilder3D > create_region_builder(index_t region_id)
Create a Mesh3DBuilder for a given region.
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
GeoModelBuilderGeometry(GeoModelBuilder< DIMENSION > &builder, GeoModel< DIMENSION > &geomodel)
std::shared_ptr< MeshBase< DIMENSION > > & modifiable_mesh()