RINGMesh  Version 5.0.0
A programming library for geological model meshes
test-geomodel-vertices.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 
36 #include <ringmesh/ringmesh_tests_config.h>
37 
38 #include <vector>
39 
41 
44 
45 #include <ringmesh/io/io.h>
46 
47 using namespace RINGMesh;
48 
49 void error( index_t vertex_id_in_mesh_entity,
50  index_t vertex_id_in_geomodel_mesh,
51  const gmme_id& mesh_entity_gmme_id )
52 {
53  throw RINGMeshException( "TEST", "Vertex ", vertex_id_in_mesh_entity,
54  " in entity ", mesh_entity_gmme_id.type().string(),
55  mesh_entity_gmme_id.index(),
56  " has not the same coordinates than its equivalent vertex ",
57  vertex_id_in_geomodel_mesh, " in the GeoModelMesh" );
58 }
59 void test_geomodel_vertices( const GeoModel3D& geomodel )
60 {
61  const GeoModelMeshVertices3D& geomodel_mesh_vertices =
62  geomodel.mesh.vertices;
63  for( const MeshEntityType& mesh_entity_type :
64  geomodel.entity_type_manager().mesh_entity_manager.mesh_entity_types() )
65  {
66  for( index_t mesh_entity_id :
67  range( geomodel.nb_mesh_entities( mesh_entity_type ) ) )
68  {
69  const GeoModelMeshEntity3D& cur_geomodel_mesh_entity =
70  geomodel.mesh_entity(
71  gmme_id( mesh_entity_type, mesh_entity_id ) );
72  for( index_t vertex_id_in_mesh_entity :
73  range( cur_geomodel_mesh_entity.nb_vertices() ) )
74  {
75  index_t vertex_id_in_geomodel_mesh =
76  geomodel_mesh_vertices.geomodel_vertex_id(
77  cur_geomodel_mesh_entity.gmme(),
78  vertex_id_in_mesh_entity );
79  if( geomodel_mesh_vertices.vertex( vertex_id_in_geomodel_mesh )
80  != cur_geomodel_mesh_entity.vertex(
81  vertex_id_in_mesh_entity ) )
82  {
83  error( vertex_id_in_mesh_entity, vertex_id_in_geomodel_mesh,
84  cur_geomodel_mesh_entity.gmme() );
85  }
86  }
87  }
88  }
89 }
90 
91 void test_GMEVertex( const GeoModel3D& geomodel )
92 {
93  const GeoModelMeshVertices3D& geomodel_mesh_vertices =
94  geomodel.mesh.vertices;
95 
96  for( index_t vertex_id_in_geomodel_mesh :
97  range( geomodel_mesh_vertices.nb() ) )
98  {
99  std::vector< GMEVertex > vertices_on_geomodel_mesh_entity =
100  geomodel_mesh_vertices.gme_vertices( vertex_id_in_geomodel_mesh );
101  for( const GMEVertex& cur_vertex_on_geomodel :
102  vertices_on_geomodel_mesh_entity )
103  {
104  const GeoModelMeshEntity3D& cur_geomodel_mesh_entity =
105  geomodel.mesh_entity( cur_vertex_on_geomodel.gmme );
106  index_t vertex_id_in_mesh_entity = cur_vertex_on_geomodel.v_index;
107  if( geomodel_mesh_vertices.vertex( vertex_id_in_geomodel_mesh )
108  != cur_geomodel_mesh_entity.vertex( vertex_id_in_mesh_entity ) )
109  {
110  error( vertex_id_in_mesh_entity, vertex_id_in_geomodel_mesh,
111  cur_geomodel_mesh_entity.gmme() );
112  }
113  }
114  }
115 }
116 
117 int main()
118 {
119  using namespace RINGMesh;
120 
121  try
122  {
124  Logger::out( "TEST", "Test GeoModelMeshVertices" );
125 
126  std::string input_model_file_name =
127  ringmesh_test_data_path + "unit_cube_volume_meshed.gm";
128 
129  GeoModel3D in;
130  bool loaded_model_is_valid = geomodel_load( in, input_model_file_name );
131 
132  if( !loaded_model_is_valid )
133  {
134  throw RINGMeshException(
135  "RINGMesh Test", "Failed when loading model ", in.name() );
136  }
138  test_GMEVertex( in );
139  }
140  catch( const RINGMeshException& e )
141  {
142  Logger::err( e.category(), e.what() );
143  return 1;
144  }
145  catch( const std::exception& e )
146  {
147  Logger::err( "Exception", e.what() );
148  return 1;
149  }
150  Logger::out( "TEST", "SUCCESS" );
151  return 0;
152 }
Entity_type_template type() const
Definition: entity_type.h:202
bool geomodel_load(GeoModel< DIMENSION > &geomodel, const std::string &filename)
Definition: io.cpp:131
static void err(const std::string &feature, const Args &... args)
Definition: logger.h:68
static void out(const std::string &feature, const Args &... args)
Definition: logger.h:61
void test_GMEVertex(const GeoModel3D &geomodel)
Vertex in a GeoModelEntity.
const std::string & category() const
Definition: common.h:165
The MeshEntityType described the type of the meshed entities There are 4 MeshEntityTypes correspondin...
Definition: entity_type.h:117
void test_geomodel_vertices(const GeoModel3D &geomodel)
Classes to build GeoModel from various inputs.
Definition: algorithm.h:48
index_t index() const
Definition: entity_type.h:197
void error(index_t vertex_id_in_mesh_entity, index_t vertex_id_in_geomodel_mesh, const gmme_id &mesh_entity_gmme_id)
This template is a specialization of a gme_id to the GeoModelMeshEntity.
Definition: entity_type.h:285
void RINGMESH_API default_configure()
Definition: common.cpp:99
const std::string & string() const
Definition: entity_type.h:81