RINGMesh  Version 5.0.0
A programming library for geological model meshes
geogram_mesh.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 <memory>
41 
42 #include <geogram/mesh/mesh.h>
43 #include <geogram/mesh/mesh_io.h>
44 
46 
47 #include <ringmesh/mesh/mesh.h>
48 
49 namespace RINGMesh
50 {
51  FORWARD_DECLARATION_DIMENSION_CLASS( GeogramPointSetMeshBuilder );
52  FORWARD_DECLARATION_DIMENSION_CLASS( GeogramLineMeshBuilder );
53  FORWARD_DECLARATION_DIMENSION_CLASS( GeogramSurfaceMeshBuilder );
54  FORWARD_DECLARATION_DIMENSION_CLASS( GeogramVolumeMeshBuilder );
55 } // namespace RINGMesh
56 
57 namespace RINGMesh
58 {
59 #define COMMON_GEOGRAM_MESH_IMPLEMENTATION( Class ) \
60  friend class Class##Builder< DIMENSION >; \
61  \
62 public: \
63  Class() : mesh_( new GEO::Mesh( DIMENSION, false ) ) \
64  { \
65  } \
66  static MeshType type_name_static() \
67  { \
68  return #Class; \
69  } \
70  void save_mesh( const std::string& filename ) const override \
71  { \
72  GEO::mesh_save( *mesh_, filename, GEO::MeshIOFlags() ); \
73  } \
74  const GEO::Mesh& gfx_mesh() const \
75  { \
76  return *mesh_; \
77  } \
78  void print_mesh_bounded_attributes() const override \
79  { \
80  print_bounded_attributes( *mesh_ ); \
81  } \
82  GEO::AttributesManager& vertex_attribute_manager() const override \
83  { \
84  return mesh_->vertices.attributes(); \
85  } \
86  MeshType type_name() const override \
87  { \
88  return type_name_static(); \
89  } \
90  static std::string default_extension_static() \
91  { \
92  return "geogram"; \
93  } \
94  std::string default_extension() const override \
95  { \
96  return default_extension_static(); \
97  } \
98  const vecn< DIMENSION >& vertex( index_t v_id ) const override \
99  { \
100  ringmesh_assert( v_id < nb_vertices() ); \
101  double* vertex_ptr = mesh_->vertices.point_ptr( v_id ); \
102  return *(vecn< DIMENSION >*) ( vertex_ptr ); \
103  } \
104  index_t nb_vertices() const override \
105  { \
106  return mesh_->vertices.nb(); \
107  } \
108  \
109 private: \
110  vecn< DIMENSION >& ref_vertex( index_t v_id ) \
111  { \
112  ringmesh_assert( v_id < nb_vertices() ); \
113  double* vertex_ptr = mesh_->vertices.point_ptr( v_id ); \
114  return *(vecn< DIMENSION >*) ( vertex_ptr ); \
115  } \
116  \
117 protected: \
118  std::unique_ptr< GEO::Mesh > mesh_
119 
120  template < index_t DIMENSION >
121  class GeogramPointSetMesh : public PointSetMesh< DIMENSION >
122  {
124  };
125 
127 
128  template < index_t DIMENSION >
129  class GeogramLineMesh : public LineMesh< DIMENSION >
130  {
132 
133  public:
134  index_t edge_vertex(
135  const ElementLocalVertex& edge_local_vertex ) const override
136  {
137  return mesh_->edges.vertex( edge_local_vertex.element_id_,
138  edge_local_vertex.local_vertex_id_ );
139  }
140 
141  index_t nb_edges() const override
142  {
143  return mesh_->edges.nb();
144  }
145 
146  GEO::AttributesManager& edge_attribute_manager() const override
147  {
148  return mesh_->edges.attributes();
149  }
150  };
151 
153 
154  template < index_t DIMENSION >
155  class GeogramSurfaceMesh : public SurfaceMesh< DIMENSION >
156  {
158 
159  public:
160  index_t polygon_vertex(
161  const ElementLocalVertex& polygon_local_vertex ) const override
162  {
163  return mesh_->facets.vertex( polygon_local_vertex.element_id_,
164  polygon_local_vertex.local_vertex_id_ );
165  }
166 
167  index_t nb_polygons() const override
168  {
169  return mesh_->facets.nb();
170  }
171 
172  index_t nb_polygon_vertices( index_t polygon_id ) const override
173  {
174  return mesh_->facets.nb_vertices( polygon_id );
175  }
176 
178  const PolygonLocalEdge& polygon_local_edge ) const override
179  {
180  return mesh_->facets.adjacent( polygon_local_edge.polygon_id_,
181  polygon_local_edge.local_edge_id_ );
182  }
183 
184  GEO::AttributesManager& polygon_attribute_manager() const override
185  {
186  return mesh_->facets.attributes();
187  }
188 
189  bool polygons_are_simplicies() const override
190  {
191  return mesh_->facets.are_simplices();
192  }
193  };
194 
196 
197  template < index_t DIMENSION >
198  class GeogramVolumeMesh : public VolumeMesh< DIMENSION >
199  {
201 
202  public:
203  index_t cell_vertex(
204  const ElementLocalVertex& cell_local_vertex ) const override
205  {
206  return mesh_->cells.vertex( cell_local_vertex.element_id_,
207  cell_local_vertex.local_vertex_id_ );
208  }
209 
211  index_t cell_id, index_t edge_id, index_t vertex_id ) const override
212  {
213  return mesh_->cells.edge_vertex( cell_id, edge_id, vertex_id );
214  }
215 
216  index_t cell_facet_vertex( const CellLocalFacet& cell_local_facet,
217  index_t vertex_id ) const override
218  {
219  return mesh_->cells.facet_vertex( cell_local_facet.cell_id_,
220  cell_local_facet.local_facet_id_, vertex_id );
221  }
222 
223  index_t cell_facet(
224  const CellLocalFacet& cell_local_facet ) const override
225  {
226  return mesh_->cells.facet(
227  cell_local_facet.cell_id_, cell_local_facet.local_facet_id_ );
228  }
229 
230  index_t nb_cell_facets( index_t cell_id ) const override
231  {
232  return mesh_->cells.nb_facets( cell_id );
233  }
234 
235  index_t nb_cell_facets() const override
236  {
237  return mesh_->cell_facets.nb();
238  }
239 
240  index_t nb_cell_edges( index_t cell_id ) const override
241  {
242  return mesh_->cells.nb_edges( cell_id );
243  }
244 
246  const CellLocalFacet& cell_local_facet ) const override
247  {
248  return mesh_->cells.facet_nb_vertices(
249  cell_local_facet.cell_id_, cell_local_facet.local_facet_id_ );
250  }
251 
252  index_t nb_cell_vertices( index_t cell_id ) const override
253  {
254  return mesh_->cells.nb_vertices( cell_id );
255  }
256 
257  index_t nb_cells() const override
258  {
259  return mesh_->cells.nb();
260  }
261 
262  index_t cell_begin( index_t cell_id ) const override
263  {
264  return mesh_->cells.corners_begin( cell_id );
265  }
266 
267  index_t cell_end( index_t cell_id ) const override
268  {
269  return mesh_->cells.corners_end( cell_id );
270  }
271 
272  index_t cell_adjacent(
273  const CellLocalFacet& cell_local_facet ) const override
274  {
275  return mesh_->cells.adjacent(
276  cell_local_facet.cell_id_, cell_local_facet.local_facet_id_ );
277  }
278 
279  GEO::AttributesManager& cell_attribute_manager() const override
280  {
281  return mesh_->cells.attributes();
282  }
283 
284  GEO::AttributesManager& cell_facet_attribute_manager() const override
285  {
286  return mesh_->cell_facets.attributes();
287  }
288 
289  CellType cell_type( index_t cell_id ) const override
290  {
291  return static_cast< CellType >( mesh_->cells.type( cell_id ) );
292  }
293 
294  bool cells_are_simplicies() const override
295  {
296  return mesh_->cells.are_simplices();
297  }
298 
299  double cell_volume( index_t cell_id ) const override
300  {
301  return RINGMesh::mesh_cell_volume( *mesh_, cell_id );
302  }
303  };
304 
306 
307  void register_geogram_mesh();
308 } // namespace RINGMesh
index_t nb_cell_vertices(index_t cell_id) const override
Gets the number of vertices of a cell.
Definition: geogram_mesh.h:252
index_t cell_facet_vertex(const CellLocalFacet &cell_local_facet, index_t vertex_id) const override
Gets a vertex by cell facet and local vertex index.
Definition: geogram_mesh.h:216
index_t edge_vertex(const ElementLocalVertex &edge_local_vertex) const override
Definition: geogram_mesh.h:134
index_t nb_cell_edges(index_t cell_id) const override
Gets the number of edges in a cell.
Definition: geogram_mesh.h:240
index_t polygon_adjacent(const PolygonLocalEdge &polygon_local_edge) const override
Gets an adjacent polygon index by polygon index and local edge index.
Definition: geogram_mesh.h:177
index_t nb_edges() const override
Gets the number of all the edges in the whole Mesh.
Definition: geogram_mesh.h:141
index_t cell_begin(index_t cell_id) const override
Definition: geogram_mesh.h:262
index_t nb_cell_facets(index_t cell_id) const override
Gets the number of facet in a cell.
Definition: geogram_mesh.h:230
GEO::AttributesManager & cell_facet_attribute_manager() const override
Definition: geogram_mesh.h:284
GEO::AttributesManager & edge_attribute_manager() const override
Definition: geogram_mesh.h:146
bool cells_are_simplicies() const override
Tests whether all the cells are tetrahedra. When all the cells are tetrahedra, storage and access is ...
Definition: geogram_mesh.h:294
ALIAS_2D_AND_3D(Box)
index_t cell_vertex(const ElementLocalVertex &cell_local_vertex) const override
Gets a vertex index by cell and local vertex index.
Definition: geogram_mesh.h:203
index_t nb_polygons() const override
Gets the number of all polygons in the whole Mesh.
Definition: geogram_mesh.h:167
bool polygons_are_simplicies() const override
Tests whether all the polygons are triangles. when all the polygons are triangles, storage and access is optimized.
Definition: geogram_mesh.h:189
GEO::AttributesManager & cell_attribute_manager() const override
Definition: geogram_mesh.h:279
CellType
Definition: types.h:89
void register_geogram_mesh()
GEO::AttributesManager & polygon_attribute_manager() const override
Definition: geogram_mesh.h:184
index_t nb_cell_facets() const override
Gets the total number of facet in a all cells.
Definition: geogram_mesh.h:235
double RINGMESH_API mesh_cell_volume(const GEO::Mesh &M, index_t c)
index_t cell_end(index_t cell_id) const override
Definition: geogram_mesh.h:267
index_t nb_cell_facet_vertices(const CellLocalFacet &cell_local_facet) const override
Gets the number of vertices of a facet in a cell.
Definition: geogram_mesh.h:245
COMMON_GEOGRAM_MESH_IMPLEMENTATION(GeogramPointSetMesh)
index_t nb_cells() const override
Gets the number of cells in the Mesh.
Definition: geogram_mesh.h:257
double cell_volume(index_t cell_id) const override
compute the volume of the cell
Definition: geogram_mesh.h:299
index_t cell_adjacent(const CellLocalFacet &cell_local_facet) const override
Definition: geogram_mesh.h:272
index_t nb_polygon_vertices(index_t polygon_id) const override
Gets the number of vertices in the polygon.
Definition: geogram_mesh.h:172
CellType cell_type(index_t cell_id) const override
Gets the type of a cell.
Definition: geogram_mesh.h:289
index_t cell_facet(const CellLocalFacet &cell_local_facet) const override
Gets a facet index by cell and local facet index.
Definition: geogram_mesh.h:223
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
index_t polygon_vertex(const ElementLocalVertex &polygon_local_vertex) const override
Gets the vertex index by polygon index and local vertex index.
Definition: geogram_mesh.h:160
index_t cell_edge_vertex(index_t cell_id, index_t edge_id, index_t vertex_id) const override
Gets a vertex index by cell and local edge and local vertex index.
Definition: geogram_mesh.h:210
FORWARD_DECLARATION_DIMENSION_CLASS(GeoModelMeshEntityAccess)
index_t local_facet_id_
Definition: mesh.h:127