From b7a3941251e6d9caa09cd0e67999ec120a9c27d7 Mon Sep 17 00:00:00 2001 From: Date: Mon, 1 Apr 2019 18:14:55 +0200 Subject: [PATCH 01/24] comments to set up the project of emna --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index ea2f9d263..7992b8b34 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -275,6 +275,7 @@ namespace * @param index Index of this PolygonToSort in * GeoModelRegionFromSurfaces * @param surface_index Index of the Surface + * @param normal normal to the polygon - normalized vector * @param p0 point of the polygon * @param p1 point of the polygon */ @@ -1120,6 +1121,11 @@ namespace RINGMesh return surface_ids_[0] == NO_ID || surface_ids_[1] == NO_ID; } + bool is_internal_line() const { + //TODO to be implement by EMNA + return false; + } + index_t plus_surface_index() const { return surface_ids_[0]; @@ -1290,6 +1296,11 @@ namespace RINGMesh line_indicent_surfaces, const index_t nb_found_surfaces ) const { + //THIS is test that detect holes in surfaces. + //TODO EMNA should process particular step if we have internal inclusion or boundaries + // 1 - iterates on the line_indicent_surfaces + // 2 - compare couple minus,plus if all minus are associated with the same plus it means that they are the same surfaces + // 3 - in this case unpade minus and plus to the same index. desable polygone build for on of the surfaces. std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { @@ -1355,7 +1366,7 @@ namespace RINGMesh polygon_vertices, polygon_corners, polygon_vertex_ptr ); } } - + // TODO :: TO be removed by emna because the universe will not be created anymore. void find_exterior_and_remove_it( GeoModelBuilder2D& builder, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const From 6b44ab461261e40bc8f262345ad84b1d68a1e8d9 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Mon, 1 Apr 2019 16:19:10 +0000 Subject: [PATCH 02/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.cpp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 7992b8b34..a7acb8bce 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -275,7 +275,7 @@ namespace * @param index Index of this PolygonToSort in * GeoModelRegionFromSurfaces * @param surface_index Index of the Surface - * @param normal normal to the polygon - normalized vector + * @param normal normal to the polygon - normalized vector * @param p0 point of the polygon * @param p1 point of the polygon */ @@ -1121,10 +1121,11 @@ namespace RINGMesh return surface_ids_[0] == NO_ID || surface_ids_[1] == NO_ID; } - bool is_internal_line() const { - //TODO to be implement by EMNA - return false; - } + bool is_internal_line() const + { + // TODO to be implement by EMNA + return false; + } index_t plus_surface_index() const { @@ -1296,11 +1297,14 @@ namespace RINGMesh line_indicent_surfaces, const index_t nb_found_surfaces ) const { - //THIS is test that detect holes in surfaces. - //TODO EMNA should process particular step if we have internal inclusion or boundaries - // 1 - iterates on the line_indicent_surfaces - // 2 - compare couple minus,plus if all minus are associated with the same plus it means that they are the same surfaces - // 3 - in this case unpade minus and plus to the same index. desable polygone build for on of the surfaces. + // THIS is test that detect holes in surfaces. + // TODO EMNA should process particular step if we have internal + // inclusion or boundaries + // 1 - iterates on the line_indicent_surfaces + // 2 - compare couple minus,plus if all minus are associated with + // the same plus it means that they are the same surfaces 3 - in + // this case unpade minus and plus to the same index. desable + // polygone build for on of the surfaces. std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { @@ -1366,7 +1370,8 @@ namespace RINGMesh polygon_vertices, polygon_corners, polygon_vertex_ptr ); } } - // TODO :: TO be removed by emna because the universe will not be created anymore. + // TODO :: TO be removed by emna because the universe will not be + // created anymore. void find_exterior_and_remove_it( GeoModelBuilder2D& builder, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const From c08b2abcdfe9e6fae3b01cbd945f7081a899459d Mon Sep 17 00:00:00 2001 From: Date: Tue, 2 Apr 2019 10:23:58 +0200 Subject: [PATCH 03/24] change comments for EMNA --- .../geomodel/builder/geomodel_builder.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 7992b8b34..e1eeeb658 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1121,11 +1121,6 @@ namespace RINGMesh return surface_ids_[0] == NO_ID || surface_ids_[1] == NO_ID; } - bool is_internal_line() const { - //TODO to be implement by EMNA - return false; - } - index_t plus_surface_index() const { return surface_ids_[0]; @@ -1291,17 +1286,12 @@ namespace RINGMesh } } - void check_internal_floating_lines( + void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - const index_t nb_found_surfaces ) const + std::vector< std::vector< Impl::OrientedLine > >& surface_boundary_lines) const { - //THIS is test that detect holes in surfaces. - //TODO EMNA should process particular step if we have internal inclusion or boundaries - // 1 - iterates on the line_indicent_surfaces - // 2 - compare couple minus,plus if all minus are associated with the same plus it means that they are the same surfaces - // 3 - in this case unpade minus and plus to the same index. desable polygone build for on of the surfaces. - std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); + std::vector< bool > are_surfaces_hole(surface_boundary_lines.size(), true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { if( line_indicent_surfaces[line_id].plus_surface_index() @@ -1317,6 +1307,13 @@ namespace RINGMesh are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; if( nb_pb_surfaces > 0 ) { + //TODO by EMNA + // 1 - check if is it internal boundary + // * do not create surface inside by removing the corresponding oriented line in the surface_boundary_lines vector + // * associate a particular feature + // 2 - check if it is inclusions + // * create the inclusion surface + // * associate a particlar feature throw RINGMeshException( "Surface2D", "During surface from corners " " and lines build, ", @@ -1436,8 +1433,8 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); - impl_->check_internal_floating_lines( line_incident_surfaces, - static_cast< index_t >( surface_boundary_lines.size() ) ); + impl_->check_internal_intrusion_or_boundaries( line_incident_surfaces, + surface_boundary_lines); // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); From 0f27f129d8a9623539bd94d0b0371a726293a244 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 2 Apr 2019 09:04:35 +0000 Subject: [PATCH 04/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.cpp | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index c54818d0b..1081a1ae7 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1289,9 +1289,11 @@ namespace RINGMesh void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - std::vector< std::vector< Impl::OrientedLine > >& surface_boundary_lines) const + std::vector< std::vector< Impl::OrientedLine > >& + surface_boundary_lines ) const { - std::vector< bool > are_surfaces_hole(surface_boundary_lines.size(), true ); + std::vector< bool > are_surfaces_hole( + surface_boundary_lines.size(), true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { @@ -1308,13 +1310,15 @@ namespace RINGMesh are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; if( nb_pb_surfaces > 0 ) { - //TODO by EMNA - // 1 - check if is it internal boundary - // * do not create surface inside by removing the corresponding oriented line in the surface_boundary_lines vector - // * associate a particular feature - // 2 - check if it is inclusions - // * create the inclusion surface - // * associate a particlar feature + // TODO by EMNA + // 1 - check if is it internal boundary + // * do not create surface inside by removing the + // corresponding oriented line in the surface_boundary_lines + // vector + // * associate a particular feature + // 2 - check if it is inclusions + // * create the inclusion surface + // * associate a particlar feature throw RINGMeshException( "Surface2D", "During surface from corners " " and lines build, ", @@ -1435,8 +1439,8 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); - impl_->check_internal_intrusion_or_boundaries( line_incident_surfaces, - surface_boundary_lines); + impl_->check_internal_intrusion_or_boundaries( + line_incident_surfaces, surface_boundary_lines ); // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); From bb5fbfd5b26731448d43cf0f839c11499d69c4ea Mon Sep 17 00:00:00 2001 From: Date: Tue, 9 Apr 2019 13:45:40 +0200 Subject: [PATCH 05/24] new functions to implement --- .../geomodel/builder/geomodel_builder.cpp | 75 ++++++++++++++----- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 1081a1ae7..21a1f5fd8 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1286,6 +1286,36 @@ namespace RINGMesh } } + /*! + * This function implement a geometric test to find the englobing surface index for the current line + * @param line_id index of the current line + * @return the englobing surface index + * @note you may need other inputs. + */ + index_t find_englobing_surface(index_t line_id) const { + // implement geometrical test to detect the index of the surface that englobe the line + return 0; + } + + std::set get_line_boundary_indices(index_t surface_id) const{ + return std::set(); + } + + void manage_intrusion_surface() const{ + //iterate on every surfaces + index_t surface_id; + std::set line_boundary_indices = get_line_boundary_indices(surface_id); + //interates on every other surfaces + index_t upper_surface_id; + std::set upper_line_boundary_indices = get_line_boundary_indices(upper_surface_id); + //compare the two sets: line_boundary_indices and upper_line_boundary_indices + //if equal do: + // find englobing_surface_index for upper_line_boundary_indices + // set line_indicent_surfaces corresponding to every upper_line_boundary_indices to + //englobing_surface_index (be careful it correspond to eitehr plus or minus side) + return; + } + void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, @@ -1305,28 +1335,33 @@ namespace RINGMesh are_surfaces_hole[line_indicent_surfaces[line_id] .minus_surface_index()] = false; } + else { // if a line have the same minus and plus surface index this line is an internal boundary. + //TODO by Emna + // find the englobing surface for the current line + //implement the following function + index_t englobing_surface_id = find_englobing_surface(line_id); + // reset the index of line incident surfaces to englobing_surface_id + //(line_indicent_surfaces[line_id].plus_surface_index() & line_indicent_surfaces[line_id].minus_surface_index()) + } } - index_t nb_pb_surfaces{ static_cast< index_t >( std::count( + index_t nb_floating_set_of_lines{ static_cast< index_t >( std::count( are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; - if( nb_pb_surfaces > 0 ) - { - // TODO by EMNA - // 1 - check if is it internal boundary - // * do not create surface inside by removing the - // corresponding oriented line in the surface_boundary_lines - // vector - // * associate a particular feature - // 2 - check if it is inclusions - // * create the inclusion surface - // * associate a particlar feature - throw RINGMeshException( "Surface2D", - "During surface from corners " - " and lines build, ", - nb_pb_surfaces, - " group(s) of lines are " - "floating inside a surface. This is not yet handled by the " - "algorithm. Aborting..." ); - } + if (nb_floating_set_of_lines > 0) + { + //TODO by EMNA + // update message to say that we have taken into account the internal boundary. + // remove exception + throw RINGMeshException("Surface2D", + "During surface from corners " + " and lines build, ", + nb_floating_set_of_lines, + " group(s) of lines are " + "floating inside a surface. This is not yet handled by the " + "algorithm. Aborting..."); + } + //TODO Manage intrusions surfaces + //manage_intrusion_surface(); + } std::vector< vec2 > get_surface_polygon_vertices( From 962228be89e5dd88ef61cc3248a880afadc4852f Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 9 Apr 2019 11:47:49 +0000 Subject: [PATCH 06/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.cpp | 127 ++++++++++-------- 1 file changed, 71 insertions(+), 56 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 21a1f5fd8..524d10244 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1286,36 +1286,46 @@ namespace RINGMesh } } - /*! - * This function implement a geometric test to find the englobing surface index for the current line - * @param line_id index of the current line - * @return the englobing surface index - * @note you may need other inputs. - */ - index_t find_englobing_surface(index_t line_id) const { - // implement geometrical test to detect the index of the surface that englobe the line - return 0; - } - - std::set get_line_boundary_indices(index_t surface_id) const{ - return std::set(); - } - - void manage_intrusion_surface() const{ - //iterate on every surfaces - index_t surface_id; - std::set line_boundary_indices = get_line_boundary_indices(surface_id); - //interates on every other surfaces - index_t upper_surface_id; - std::set upper_line_boundary_indices = get_line_boundary_indices(upper_surface_id); - //compare the two sets: line_boundary_indices and upper_line_boundary_indices - //if equal do: - // find englobing_surface_index for upper_line_boundary_indices - // set line_indicent_surfaces corresponding to every upper_line_boundary_indices to - //englobing_surface_index (be careful it correspond to eitehr plus or minus side) - return; - } - + /*! + * This function implement a geometric test to find the englobing + * surface index for the current line + * @param line_id index of the current line + * @return the englobing surface index + * @note you may need other inputs. + */ + index_t find_englobing_surface( index_t line_id ) const + { + // implement geometrical test to detect the index of the surface + // that englobe the line + return 0; + } + + std::set< index_t > get_line_boundary_indices( + index_t surface_id ) const + { + return std::set< index_t >(); + } + + void manage_intrusion_surface() const + { + // iterate on every surfaces + index_t surface_id; + std::set< index_t > line_boundary_indices = + get_line_boundary_indices( surface_id ); + // interates on every other surfaces + index_t upper_surface_id; + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( upper_surface_id ); + // compare the two sets: line_boundary_indices and + // upper_line_boundary_indices if equal do: + // find englobing_surface_index for upper_line_boundary_indices + // set line_indicent_surfaces corresponding to every + // upper_line_boundary_indices to + // englobing_surface_index (be careful it correspond to eitehr plus + // or minus side) + return; + } + void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, @@ -1335,33 +1345,38 @@ namespace RINGMesh are_surfaces_hole[line_indicent_surfaces[line_id] .minus_surface_index()] = false; } - else { // if a line have the same minus and plus surface index this line is an internal boundary. - //TODO by Emna - // find the englobing surface for the current line - //implement the following function - index_t englobing_surface_id = find_englobing_surface(line_id); - // reset the index of line incident surfaces to englobing_surface_id - //(line_indicent_surfaces[line_id].plus_surface_index() & line_indicent_surfaces[line_id].minus_surface_index()) - } + else + { // if a line have the same minus and plus surface index this + // line is an internal boundary. + // TODO by Emna + // find the englobing surface for the current line + // implement the following function + index_t englobing_surface_id = + find_englobing_surface( line_id ); + // reset the index of line incident surfaces to + // englobing_surface_id + //(line_indicent_surfaces[line_id].plus_surface_index() & + //line_indicent_surfaces[line_id].minus_surface_index()) + } } - index_t nb_floating_set_of_lines{ static_cast< index_t >( std::count( - are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; - if (nb_floating_set_of_lines > 0) - { - //TODO by EMNA - // update message to say that we have taken into account the internal boundary. - // remove exception - throw RINGMeshException("Surface2D", - "During surface from corners " - " and lines build, ", - nb_floating_set_of_lines, - " group(s) of lines are " - "floating inside a surface. This is not yet handled by the " - "algorithm. Aborting..."); - } - //TODO Manage intrusions surfaces - //manage_intrusion_surface(); - + index_t nb_floating_set_of_lines{ static_cast< index_t >( + std::count( are_surfaces_hole.begin(), are_surfaces_hole.end(), + true ) ) }; + if( nb_floating_set_of_lines > 0 ) + { + // TODO by EMNA + // update message to say that we have taken into account the + // internal boundary. remove exception + throw RINGMeshException( "Surface2D", + "During surface from corners " + " and lines build, ", + nb_floating_set_of_lines, + " group(s) of lines are " + "floating inside a surface. This is not yet handled by the " + "algorithm. Aborting..." ); + } + // TODO Manage intrusions surfaces + // manage_intrusion_surface(); } std::vector< vec2 > get_surface_polygon_vertices( From 48d7063e5ec1749900d7deeb62e0b234a5c529ac Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 9 Apr 2019 11:49:28 +0000 Subject: [PATCH 07/24] Travis CI format update --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 524d10244..f6bdc939b 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1356,7 +1356,7 @@ namespace RINGMesh // reset the index of line incident surfaces to // englobing_surface_id //(line_indicent_surfaces[line_id].plus_surface_index() & - //line_indicent_surfaces[line_id].minus_surface_index()) + // line_indicent_surfaces[line_id].minus_surface_index()) } } index_t nb_floating_set_of_lines{ static_cast< index_t >( From a2e850f48ea7ffbd7f0f0ffe4dbb55f35d786457 Mon Sep 17 00:00:00 2001 From: Date: Tue, 9 Apr 2019 14:13:33 +0200 Subject: [PATCH 08/24] add comments and a function to manage internal boundary --- .../geomodel/builder/geomodel_builder.cpp | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 21a1f5fd8..686197068 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1297,7 +1297,43 @@ namespace RINGMesh return 0; } + /*! + * This function iterates on lines and manage internal boundaries. + * @param line_indicent_surfaces vector of lines and incident surfaces to manage. + * @return the number of intenal boundaries. + */ + index_t manage_internal_boundary ( + const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + const index_t nb_found_surfaces + ) const { + std::vector< bool > are_surfaces_hole(nb_found_surfaces, true); + for (auto line_id : range(geomodel_.nb_lines())) + { + if (line_indicent_surfaces[line_id].plus_surface_index() + != line_indicent_surfaces[line_id].minus_surface_index()) + { + are_surfaces_hole[line_indicent_surfaces[line_id].plus_surface_index()] = false; + are_surfaces_hole[line_indicent_surfaces[line_id].minus_surface_index()] = false; + } + else { // if a line have the same minus and plus surface index this line is an internal boundary. + //TODO by Emna + // find the englobing surface for the current line + //implement the following function + index_t englobing_surface_id = find_englobing_surface(line_id); + // reset the index of line incident surfaces to englobing_surface_id + //(line_indicent_surfaces[line_id].plus_surface_index() & line_indicent_surfaces[line_id].minus_surface_index()) + } + } + return{ static_cast(std::count( + are_surfaces_hole.begin(), are_surfaces_hole.end(), true)) }; + } + /*! + * This function find all line boundary indices associated to a surface + * @param surface_id index of the current surface + * @return a set of line index that are either the minus or the plus boundary. + */ std::set get_line_boundary_indices(index_t surface_id) const{ + //Todo implement it return std::set(); } @@ -1319,33 +1355,9 @@ namespace RINGMesh void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - std::vector< std::vector< Impl::OrientedLine > >& - surface_boundary_lines ) const + const index_t nb_found_surfaces) const { - std::vector< bool > are_surfaces_hole( - surface_boundary_lines.size(), true ); - - for( auto line_id : range( geomodel_.nb_lines() ) ) - { - if( line_indicent_surfaces[line_id].plus_surface_index() - != line_indicent_surfaces[line_id].minus_surface_index() ) - { - are_surfaces_hole[line_indicent_surfaces[line_id] - .plus_surface_index()] = false; - are_surfaces_hole[line_indicent_surfaces[line_id] - .minus_surface_index()] = false; - } - else { // if a line have the same minus and plus surface index this line is an internal boundary. - //TODO by Emna - // find the englobing surface for the current line - //implement the following function - index_t englobing_surface_id = find_englobing_surface(line_id); - // reset the index of line incident surfaces to englobing_surface_id - //(line_indicent_surfaces[line_id].plus_surface_index() & line_indicent_surfaces[line_id].minus_surface_index()) - } - } - index_t nb_floating_set_of_lines{ static_cast< index_t >( std::count( - are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; + index_t nb_floating_set_of_lines = manage_internal_boundary(line_indicent_surfaces, nb_found_surfaces); if (nb_floating_set_of_lines > 0) { //TODO by EMNA @@ -1358,9 +1370,9 @@ namespace RINGMesh " group(s) of lines are " "floating inside a surface. This is not yet handled by the " "algorithm. Aborting..."); - } - //TODO Manage intrusions surfaces - //manage_intrusion_surface(); + } + //TODO Manage intrusions surfaces + manage_intrusion_surface(); } @@ -1474,8 +1486,8 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); - impl_->check_internal_intrusion_or_boundaries( - line_incident_surfaces, surface_boundary_lines ); + impl_->check_internal_intrusion_or_boundaries(line_incident_surfaces, + static_cast< index_t >(surface_boundary_lines.size())); // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); From 6c603e37106ad7cbfad2d6fce2661bd705446b38 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 9 Apr 2019 12:15:58 +0000 Subject: [PATCH 09/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.cpp | 189 ++++++++++-------- 1 file changed, 105 insertions(+), 84 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 4052d2d99..00bdafdbb 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1287,71 +1287,91 @@ namespace RINGMesh } <<<<<<< HEAD - /*! - * This function implement a geometric test to find the englobing surface index for the current line - * @param line_id index of the current line - * @return the englobing surface index - * @note you may need other inputs. - */ - index_t find_englobing_surface(index_t line_id) const { - // implement geometrical test to detect the index of the surface that englobe the line - return 0; - } - - /*! - * This function iterates on lines and manage internal boundaries. - * @param line_indicent_surfaces vector of lines and incident surfaces to manage. - * @return the number of intenal boundaries. - */ - index_t manage_internal_boundary ( - const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - const index_t nb_found_surfaces - ) const { - std::vector< bool > are_surfaces_hole(nb_found_surfaces, true); - for (auto line_id : range(geomodel_.nb_lines())) - { - if (line_indicent_surfaces[line_id].plus_surface_index() - != line_indicent_surfaces[line_id].minus_surface_index()) - { - are_surfaces_hole[line_indicent_surfaces[line_id].plus_surface_index()] = false; - are_surfaces_hole[line_indicent_surfaces[line_id].minus_surface_index()] = false; - } - else { // if a line have the same minus and plus surface index this line is an internal boundary. - //TODO by Emna - // find the englobing surface for the current line - //implement the following function - index_t englobing_surface_id = find_englobing_surface(line_id); - // reset the index of line incident surfaces to englobing_surface_id - //(line_indicent_surfaces[line_id].plus_surface_index() & line_indicent_surfaces[line_id].minus_surface_index()) - } - } - return{ static_cast(std::count( - are_surfaces_hole.begin(), are_surfaces_hole.end(), true)) }; - } - /*! - * This function find all line boundary indices associated to a surface - * @param surface_id index of the current surface - * @return a set of line index that are either the minus or the plus boundary. - */ - std::set get_line_boundary_indices(index_t surface_id) const{ - //Todo implement it - return std::set(); - } - - void manage_intrusion_surface() const{ - //iterate on every surfaces - index_t surface_id; - std::set line_boundary_indices = get_line_boundary_indices(surface_id); - //interates on every other surfaces - index_t upper_surface_id; - std::set upper_line_boundary_indices = get_line_boundary_indices(upper_surface_id); - //compare the two sets: line_boundary_indices and upper_line_boundary_indices - //if equal do: - // find englobing_surface_index for upper_line_boundary_indices - // set line_indicent_surfaces corresponding to every upper_line_boundary_indices to - //englobing_surface_index (be careful it correspond to eitehr plus or minus side) - return; - } + /*! + * This function implement a geometric test to find the englobing + * surface index for the current line + * @param line_id index of the current line + * @return the englobing surface index + * @note you may need other inputs. + */ + index_t find_englobing_surface( index_t line_id ) const + { + // implement geometrical test to detect the index of the surface + // that englobe the line + return 0; + } + + /*! + * This function iterates on lines and manage internal boundaries. + * @param line_indicent_surfaces vector of lines and incident surfaces + * to manage. + * @return the number of intenal boundaries. + */ + index_t manage_internal_boundary( + const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, + const index_t nb_found_surfaces ) const + { + std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); + for( auto line_id : range( geomodel_.nb_lines() ) ) + { + if( line_indicent_surfaces[line_id].plus_surface_index() + != line_indicent_surfaces[line_id].minus_surface_index() ) + { + are_surfaces_hole[line_indicent_surfaces[line_id] + .plus_surface_index()] = false; + are_surfaces_hole[line_indicent_surfaces[line_id] + .minus_surface_index()] = false; + } + else + { // if a line have the same minus and plus surface index this + // line is an internal boundary. + // TODO by Emna + // find the englobing surface for the current line + // implement the following function + index_t englobing_surface_id = + find_englobing_surface( line_id ); + // reset the index of line incident surfaces to + // englobing_surface_id + //(line_indicent_surfaces[line_id].plus_surface_index() & + //line_indicent_surfaces[line_id].minus_surface_index()) + } + } + return { static_cast< index_t >( std::count( + are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; + } + /*! + * This function find all line boundary indices associated to a surface + * @param surface_id index of the current surface + * @return a set of line index that are either the minus or the plus + * boundary. + */ + std::set< index_t > get_line_boundary_indices( + index_t surface_id ) const + { + // Todo implement it + return std::set< index_t >(); + } + + void manage_intrusion_surface() const + { + // iterate on every surfaces + index_t surface_id; + std::set< index_t > line_boundary_indices = + get_line_boundary_indices( surface_id ); + // interates on every other surfaces + index_t upper_surface_id; + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( upper_surface_id ); + // compare the two sets: line_boundary_indices and + // upper_line_boundary_indices if equal do: + // find englobing_surface_index for upper_line_boundary_indices + // set line_indicent_surfaces corresponding to every + // upper_line_boundary_indices to + // englobing_surface_index (be careful it correspond to eitehr plus + // or minus side) + return; + } ======= /*! @@ -1398,25 +1418,26 @@ namespace RINGMesh void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - const index_t nb_found_surfaces) const + const index_t nb_found_surfaces ) const { <<<<<<< HEAD - index_t nb_floating_set_of_lines = manage_internal_boundary(line_indicent_surfaces, nb_found_surfaces); - if (nb_floating_set_of_lines > 0) - { - //TODO by EMNA - // update message to say that we have taken into account the internal boundary. - // remove exception - throw RINGMeshException("Surface2D", - "During surface from corners " - " and lines build, ", - nb_floating_set_of_lines, - " group(s) of lines are " - "floating inside a surface. This is not yet handled by the " - "algorithm. Aborting..."); - } - //TODO Manage intrusions surfaces - manage_intrusion_surface(); + index_t nb_floating_set_of_lines = manage_internal_boundary( + line_indicent_surfaces, nb_found_surfaces ); + if( nb_floating_set_of_lines > 0 ) + { + // TODO by EMNA + // update message to say that we have taken into account the + // internal boundary. remove exception + throw RINGMeshException( "Surface2D", + "During surface from corners " + " and lines build, ", + nb_floating_set_of_lines, + " group(s) of lines are " + "floating inside a surface. This is not yet handled by the " + "algorithm. Aborting..." ); + } + // TODO Manage intrusions surfaces + manage_intrusion_surface(); ======= std::vector< bool > are_surfaces_hole( @@ -1577,8 +1598,8 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); - impl_->check_internal_intrusion_or_boundaries(line_incident_surfaces, - static_cast< index_t >(surface_boundary_lines.size())); + impl_->check_internal_intrusion_or_boundaries( line_incident_surfaces, + static_cast< index_t >( surface_boundary_lines.size() ) ); // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); From 8a9d8e6f247c88e8be24d9eacd5246c790489773 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 9 Apr 2019 12:17:58 +0000 Subject: [PATCH 10/24] Travis CI format update --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 00bdafdbb..14bdad92b 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1334,7 +1334,7 @@ namespace RINGMesh // reset the index of line incident surfaces to // englobing_surface_id //(line_indicent_surfaces[line_id].plus_surface_index() & - //line_indicent_surfaces[line_id].minus_surface_index()) + // line_indicent_surfaces[line_id].minus_surface_index()) } } return { static_cast< index_t >( std::count( From b2e08039daead114f147cafbb221ad6b24bec425 Mon Sep 17 00:00:00 2001 From: Date: Tue, 9 Apr 2019 14:18:25 +0200 Subject: [PATCH 11/24] real merge --- .../geomodel/builder/geomodel_builder.cpp | 90 ------------------- 1 file changed, 90 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 4052d2d99..0cff49ec3 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1353,48 +1353,6 @@ namespace RINGMesh return; } -======= - /*! - * This function implement a geometric test to find the englobing - * surface index for the current line - * @param line_id index of the current line - * @return the englobing surface index - * @note you may need other inputs. - */ - index_t find_englobing_surface( index_t line_id ) const - { - // implement geometrical test to detect the index of the surface - // that englobe the line - return 0; - } - - std::set< index_t > get_line_boundary_indices( - index_t surface_id ) const - { - return std::set< index_t >(); - } - - void manage_intrusion_surface() const - { - // iterate on every surfaces - index_t surface_id; - std::set< index_t > line_boundary_indices = - get_line_boundary_indices( surface_id ); - // interates on every other surfaces - index_t upper_surface_id; - std::set< index_t > upper_line_boundary_indices = - get_line_boundary_indices( upper_surface_id ); - // compare the two sets: line_boundary_indices and - // upper_line_boundary_indices if equal do: - // find englobing_surface_index for upper_line_boundary_indices - // set line_indicent_surfaces corresponding to every - // upper_line_boundary_indices to - // englobing_surface_index (be careful it correspond to eitehr plus - // or minus side) - return; - } - ->>>>>>> 48d7063e5ec1749900d7deeb62e0b234a5c529ac void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, @@ -1417,54 +1375,6 @@ namespace RINGMesh } //TODO Manage intrusions surfaces manage_intrusion_surface(); - -======= - std::vector< bool > are_surfaces_hole( - surface_boundary_lines.size(), true ); - - for( auto line_id : range( geomodel_.nb_lines() ) ) - { - if( line_indicent_surfaces[line_id].plus_surface_index() - != line_indicent_surfaces[line_id].minus_surface_index() ) - { - are_surfaces_hole[line_indicent_surfaces[line_id] - .plus_surface_index()] = false; - are_surfaces_hole[line_indicent_surfaces[line_id] - .minus_surface_index()] = false; - } - else - { // if a line have the same minus and plus surface index this - // line is an internal boundary. - // TODO by Emna - // find the englobing surface for the current line - // implement the following function - index_t englobing_surface_id = - find_englobing_surface( line_id ); - // reset the index of line incident surfaces to - // englobing_surface_id - //(line_indicent_surfaces[line_id].plus_surface_index() & - // line_indicent_surfaces[line_id].minus_surface_index()) - } - } - index_t nb_floating_set_of_lines{ static_cast< index_t >( - std::count( are_surfaces_hole.begin(), are_surfaces_hole.end(), - true ) ) }; - if( nb_floating_set_of_lines > 0 ) - { - // TODO by EMNA - // update message to say that we have taken into account the - // internal boundary. remove exception - throw RINGMeshException( "Surface2D", - "During surface from corners " - " and lines build, ", - nb_floating_set_of_lines, - " group(s) of lines are " - "floating inside a surface. This is not yet handled by the " - "algorithm. Aborting..." ); - } - // TODO Manage intrusions surfaces - // manage_intrusion_surface(); ->>>>>>> 48d7063e5ec1749900d7deeb62e0b234a5c529ac } std::vector< vec2 > get_surface_polygon_vertices( From 3e61071dd29bff0bbd6aa618e3f2c24d8e479d28 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 9 Apr 2019 12:30:50 +0000 Subject: [PATCH 12/24] Travis CI format update --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 6b6e0c3b2..527d32b51 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1371,7 +1371,7 @@ namespace RINGMesh // or minus side) return; } - + void check_internal_intrusion_or_boundaries( const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, From 04b6dc8e3c02890f7a8d0bd054e2edeb45166f38 Mon Sep 17 00:00:00 2001 From: Date: Wed, 10 Apr 2019 11:22:14 +0200 Subject: [PATCH 13/24] update comments --- .../geomodel/builder/geomodel_builder.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 527d32b51..9537c1bde 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1287,7 +1287,7 @@ namespace RINGMesh } /*! - * This function implement a geometric test to find the englobing + * This function implements a geometric test to find the englobing * surface index for the current line * @param line_id index of the current line * @return the englobing surface index @@ -1301,10 +1301,11 @@ namespace RINGMesh } /*! - * This function iterates on lines and manage internal boundaries. - * @param line_indicent_surfaces vector of lines and incident surfaces - * to manage. - * @return the number of intenal boundaries. + * This function iterates on lines and manages internal boundaries. + * @param line_indicent_surfaces for each line, a pair of incident + * surfaces is given (corresponding to plus and minus sides). + * @note internal boundaries corresponds to lines having the same plus and minus. + * @return the number of connected set of intenal boundaries. */ index_t manage_internal_boundary( const std::vector< LineIncidentSurfacePair >& @@ -1340,7 +1341,7 @@ namespace RINGMesh are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; } /*! - * This function find all line boundary indices associated to a surface + * This function finds all line boundary indices associated to a surface * @param surface_id index of the current surface * @return a set of line index that are either the minus or the plus * boundary. @@ -1352,6 +1353,9 @@ namespace RINGMesh return std::set< index_t >(); } + /*! + * TODO by Emna + */ void manage_intrusion_surface() const { // iterate on every surfaces @@ -1435,9 +1439,8 @@ namespace RINGMesh polygon_vertices, polygon_corners, polygon_vertex_ptr ); } } - // TODO :: TO be removed by emna because the universe will not be - // created anymore. - void find_exterior_and_remove_it( GeoModelBuilder2D& builder, + + void find_exterior_and_remove_it( GeoModelBuilder2D& builder, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const { From 283b42e058a2e81dfbbcdeb7c8881d2cbda14614 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Wed, 10 Apr 2019 09:24:03 +0000 Subject: [PATCH 14/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 9537c1bde..b8af17279 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1302,9 +1302,10 @@ namespace RINGMesh /*! * This function iterates on lines and manages internal boundaries. - * @param line_indicent_surfaces for each line, a pair of incident - * surfaces is given (corresponding to plus and minus sides). - * @note internal boundaries corresponds to lines having the same plus and minus. + * @param line_indicent_surfaces for each line, a pair of incident + * surfaces is given (corresponding to plus and minus sides). + * @note internal boundaries corresponds to lines having the same plus + * and minus. * @return the number of connected set of intenal boundaries. */ index_t manage_internal_boundary( @@ -1353,9 +1354,9 @@ namespace RINGMesh return std::set< index_t >(); } - /*! - * TODO by Emna - */ + /*! + * TODO by Emna + */ void manage_intrusion_surface() const { // iterate on every surfaces @@ -1440,7 +1441,7 @@ namespace RINGMesh } } - void find_exterior_and_remove_it( GeoModelBuilder2D& builder, + void find_exterior_and_remove_it( GeoModelBuilder2D& builder, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const { From b4b139ad035563d1325a95c12f61e14cf8b05b3a Mon Sep 17 00:00:00 2001 From: Date: Fri, 12 Apr 2019 17:55:28 +0200 Subject: [PATCH 15/24] fix tests --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index b8af17279..1a7d40716 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1398,7 +1398,7 @@ namespace RINGMesh "algorithm. Aborting..." ); } // TODO Manage intrusions surfaces - manage_intrusion_surface(); + //manage_intrusion_surface(); } std::vector< vec2 > get_surface_polygon_vertices( From 7a3b4171586a4bc527253faa36bd26b38266158f Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Fri, 12 Apr 2019 15:57:42 +0000 Subject: [PATCH 16/24] Travis CI format update --- src/ringmesh/geomodel/builder/geomodel_builder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 1a7d40716..0c5a58da7 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1398,7 +1398,7 @@ namespace RINGMesh "algorithm. Aborting..." ); } // TODO Manage intrusions surfaces - //manage_intrusion_surface(); + // manage_intrusion_surface(); } std::vector< vec2 > get_surface_polygon_vertices( From 11bcf84a529627e4ccc6dce3d05e42dd4c1de98f Mon Sep 17 00:00:00 2001 From: Pierre Anquez Date: Fri, 19 Apr 2019 15:53:44 +0200 Subject: [PATCH 17/24] add the test for Emna's work --- tests/geomodel/builder/CMakeLists.txt | 3 +- ...ild-2d-geomodel-with-internal-features.cpp | 116 ++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp diff --git a/tests/geomodel/builder/CMakeLists.txt b/tests/geomodel/builder/CMakeLists.txt index 95517766f..b224dedd6 100644 --- a/tests/geomodel/builder/CMakeLists.txt +++ b/tests/geomodel/builder/CMakeLists.txt @@ -31,4 +31,5 @@ # 54518 VANDOEUVRE-LES-NANCY # FRANCE -add_ringmesh_test(test-build-2d-geomodels-from-3d.cpp geomodel_tools io) \ No newline at end of file +add_ringmesh_test(test-build-2d-geomodels-from-3d.cpp geomodel_tools io) +add_ringmesh_test(test-build-2d-geomodel-with-internal-features.cpp geomodel_tools io) diff --git a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp new file mode 100644 index 000000000..36300e60c --- /dev/null +++ b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp @@ -0,0 +1,116 @@ +/* * Copyright (c) 2012-2019, Association Scientifique pour la Geologie et ses + * Applications (ASGA). All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of ASGA nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASGA BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://www.ring-team.org + * + * RING Project + * Ecole Nationale Superieure de Geologie - GeoRessources + * 2 Rue du Doyen Marcel Roubault - TSA 70605 + * 54518 VANDOEUVRE-LES-NANCY + * FRANCE + */ + +#include + +#include + +#include +#include +#include +#include + +/*! + * @file Test GeoModel loading + * @author Pierre Anquez + */ + +using namespace RINGMesh; + +const std::string ringmesh_test_load_path = + ringmesh_test_path + "io/data/load/"; + +void throw_error( const std::string& feature ) +{ + throw RINGMeshException( "RINGMesh Test", "Failed when loading model: ", + "the loaded model as not the correct number of ", feature ); +} + +void check_geomodel( const GeoModel2D& geomodel ) +{ + if( geomodel.nb_corners() != 38 ) + { + throw_error( "corners" ); + } + + if( geomodel.nb_lines() != 36 ) + { + throw_error( "lines" ); + } + + if( geomodel.nb_surfaces() != 6 ) + { + throw_error( "surfaces" ); + } + + index_t max_boundaries{ 0 }; + for( const auto& surface : geomodel.surfaces() ) + { + max_boundaries = std::max( max_boundaries, surface.nb_boundaries() ); + } + + if( max_boundaries != 34 ) + { + throw_error( "number of boundaries" ); + } +} + +void test_geomodel_2D_with_internal_features() +{ + Logger::out( "TEST", "Load GeoModel2D with internal features" ); + GeoModel2D geomodel; + geomodel_load( geomodel, ringmesh_test_data_path + "model_with_internal_features.gm" ); + check_geomodel( geomodel ); +} + +int main() +{ + try + { + Logger::out( "TEST", "Import GeoModel files" ); + test_geomodel_2D_with_internal_features(); + } + catch( const RINGMeshException& e ) + { + Logger::err( e.category(), e.what() ); + return 1; + } + catch( const std::exception& e ) + { + Logger::err( "Exception", e.what() ); + return 1; + } + Logger::out( "TEST", "SUCCESS" ); + return 0; +} From 34bbf9a2ccc105cfe908b83d1d6abbe0c5ff8e13 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Fri, 19 Apr 2019 13:55:39 +0000 Subject: [PATCH 18/24] Travis CI format update --- .../builder/test-build-2d-geomodel-with-internal-features.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp index 36300e60c..d6c90b15f 100644 --- a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp +++ b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp @@ -90,7 +90,8 @@ void test_geomodel_2D_with_internal_features() { Logger::out( "TEST", "Load GeoModel2D with internal features" ); GeoModel2D geomodel; - geomodel_load( geomodel, ringmesh_test_data_path + "model_with_internal_features.gm" ); + geomodel_load( + geomodel, ringmesh_test_data_path + "model_with_internal_features.gm" ); check_geomodel( geomodel ); } From ee0365dcfe9da226c854ad93b80721000c31f727 Mon Sep 17 00:00:00 2001 From: emnabelazi Date: Fri, 26 Apr 2019 11:39:21 +0200 Subject: [PATCH 19/24] start iplementation of internal_boundaries and manage_intrusions --- .../geomodel/builder/geomodel_builder.cpp | 120 +++++++++++++----- 1 file changed, 85 insertions(+), 35 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index 0c5a58da7..f3b048408 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1297,6 +1297,16 @@ namespace RINGMesh { // implement geometrical test to detect the index of the surface // that englobe the line + + //for (index_t surface_id; surface_id <= geomodel_.nb_surfaces;++ surface_id) + //{ + + + + + //} + + return 0; } @@ -1306,10 +1316,10 @@ namespace RINGMesh * surfaces is given (corresponding to plus and minus sides). * @note internal boundaries corresponds to lines having the same plus * and minus. - * @return the number of connected set of intenal boundaries. + * @return the number of connected set of internal boundaries. */ index_t manage_internal_boundary( - const std::vector< LineIncidentSurfacePair >& + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { @@ -1330,12 +1340,14 @@ namespace RINGMesh // TODO by Emna // find the englobing surface for the current line // implement the following function - index_t englobing_surface_id = - find_englobing_surface( line_id ); - // reset the index of line incident surfaces to + // reset the index of line incident surfaces to // englobing_surface_id - //(line_indicent_surfaces[line_id].plus_surface_index() & - // line_indicent_surfaces[line_id].minus_surface_index()) + + index_t englobing_surface_id = + find_englobing_surface( line_id ); + + line_indicent_surfaces[line_id].set_side_surface_index( true, englobing_surface_id); + line_indicent_surfaces[line_id].set_side_surface_index( false, englobing_surface_id); } } return { static_cast< index_t >( std::count( @@ -1347,28 +1359,64 @@ namespace RINGMesh * @return a set of line index that are either the minus or the plus * boundary. */ - std::set< index_t > get_line_boundary_indices( - index_t surface_id ) const - { - // Todo implement it - return std::set< index_t >(); + std::set< index_t > get_line_boundary_indices(const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, index_t surface_id ) const + { + std::set< index_t > line_boundary_indices; + + for (auto line_id : range(geomodel_.nb_lines())) + { + + if ((line_indicent_surfaces[line_id].plus_surface_index() == surface_id) || + (line_indicent_surfaces[line_id].minus_surface_index()== surface_id)) + + { + line_boundary_indices.emplace(line_id); + } + } + + return line_boundary_indices; } /*! * TODO by Emna */ - void manage_intrusion_surface() const - { - // iterate on every surfaces - index_t surface_id; - std::set< index_t > line_boundary_indices = - get_line_boundary_indices( surface_id ); - // interates on every other surfaces - index_t upper_surface_id; - std::set< index_t > upper_line_boundary_indices = - get_line_boundary_indices( upper_surface_id ); + void manage_intrusion_surface(const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces ) const + { + + for (auto surface_id : range(geomodel_.nb_surfaces())) + { + for (index_t upper_surface_id = surface_id +1; upper_surface_id <= geomodel_.nb_surfaces(); ++ upper_surface_id) + { + // iterate on every surfaces + std::set< index_t > line_boundary_indices = + get_line_boundary_indices(line_indicent_surfaces, surface_id); + + // interates on every other surfaces + + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( line_indicent_surfaces, upper_surface_id); + + if (line_boundary_indices == upper_line_boundary_indices) + { + index_t englobing_surface_id_for_upper_line = find_englobing_surface(surface_id); + + std::set ::iterator it; + + for (it = line_boundary_indices.begin(); it != line_boundary_indices.end(); it++) + + { + line_indicent_surfaces[it].set_side_surface_index(true, englobing_surface_id_for_upper_line); + } + + //index_t englobing_surface_id = line_indicent_surfaces[upper_line_boundary_indices].plus_surface_index();// + } + } + } + // compare the two sets: line_boundary_indices and - // upper_line_boundary_indices if equal do: + // upper_line_boundary_indices if equal do:// // find englobing_surface_index for upper_line_boundary_indices // set line_indicent_surfaces corresponding to every // upper_line_boundary_indices to @@ -1378,25 +1426,27 @@ namespace RINGMesh } void check_internal_intrusion_or_boundaries( - const std::vector< LineIncidentSurfacePair >& + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { index_t nb_floating_set_of_lines = manage_internal_boundary( line_indicent_surfaces, nb_found_surfaces ); - if( nb_floating_set_of_lines > 0 ) - { - // TODO by EMNA + if (nb_floating_set_of_lines > 0) + { + Logger::out(" During surface from corners ", + " and lines build, ", + nb_floating_set_of_lines, + " group(s) of lines are " + "floating inside a surface : These Internal Boundaries were taken into account "); + } + + + // TODO by EMNA // Done // update message to say that we have taken into account the // internal boundary. remove exception - throw RINGMeshException( "Surface2D", - "During surface from corners " - " and lines build, ", - nb_floating_set_of_lines, - " group(s) of lines are " - "floating inside a surface. This is not yet handled by the " - "algorithm. Aborting..." ); - } + + // TODO Manage intrusions surfaces // manage_intrusion_surface(); } From 467d20c37868b7d58da483565d0b82231a727dbd Mon Sep 17 00:00:00 2001 From: emnabelazi Date: Thu, 2 May 2019 17:27:21 +0200 Subject: [PATCH 20/24] implementation of find_englobing_surface and manage_intrusion_surface --- .../geomodel/builder/geomodel_builder.cpp | 162 ++++++++++++------ 1 file changed, 109 insertions(+), 53 deletions(-) diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index f3b048408..e4d0929ab 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1293,19 +1293,50 @@ namespace RINGMesh * @return the englobing surface index * @note you may need other inputs. */ - index_t find_englobing_surface( index_t line_id ) const + index_t find_englobing_surface(index_t line_id, std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) const { // implement geometrical test to detect the index of the surface // that englobe the line + // create Line2D = tracer de rayon - //for (index_t surface_id; surface_id <= geomodel_.nb_surfaces;++ surface_id) - //{ - - - - - //} - + const Line2D & line = geomodel_.line(line_id); + + Geometry::Line2D Ray_tracer{ { 0.5, 0.5 }, line.vertex(0) }; + + int intersection_count = 0; + + for (auto surface_id : range(geomodel_.nb_surfaces())) + { + std::vector< OrientedLine > boundaries_of_curr_surface = + get_surface_boundaries(surface_id, line_indicent_surfaces); + + for ( index_t id=0; id <= boundaries_of_curr_surface.size(); ++ id) + { + const Line2D & line_boundary = geomodel_.line(id); + + for (index_t segment_id : range(line_boundary.nb_mesh_elements())) + { + const Geometry::Segment2D segment_of_line( + line_boundary.mesh_element_vertex({ segment_id, 0 }), + line_boundary.mesh_element_vertex({ segment_id, 1 }) + ); + + // Geometry::Line2D line_id = line_indicent_surfaces[id]; + + std::tuple< bool, vec2 > inter = Intersection::segment_line(segment_of_line, Ray_tracer); + + if (std::get<0>(inter) == true) + { + ++ intersection_count; } + } + } + + if (intersection_count % 2 != 0) + { + return surface_id; } + + break; + } return 0; } @@ -1344,7 +1375,7 @@ namespace RINGMesh // englobing_surface_id index_t englobing_surface_id = - find_englobing_surface( line_id ); + find_englobing_surface(line_id, line_indicent_surfaces); line_indicent_surfaces[line_id].set_side_surface_index( true, englobing_surface_id); line_indicent_surfaces[line_id].set_side_surface_index( false, englobing_surface_id); @@ -1366,7 +1397,7 @@ namespace RINGMesh for (auto line_id : range(geomodel_.nb_lines())) { - + if ((line_indicent_surfaces[line_id].plus_surface_index() == surface_id) || (line_indicent_surfaces[line_id].minus_surface_index()== surface_id)) @@ -1377,51 +1408,80 @@ namespace RINGMesh return line_boundary_indices; } + // determine if the lines index are the minus or the plus + // @return the side of the line ( true = plus, false = minus) + + bool line_side (const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, index_t surface_id, index_t line_id)const + { + if ( line_indicent_surfaces[line_id].plus_surface_index() == surface_id) + { return true; + } + + return false; + } + //// set line_indicent_surfaces corresponding to every + // upper_line_boundary_indices to + // englobing_surface_index (it correspond to eitehr plus + // or minus side) + //@param line_id, surface_id and line_indicent_surface + + void set_line_indices_surface (std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, index_t line_id, index_t surface_id, index_t englobing_surface_id_for_upper_line)const + { + if (line_side (line_indicent_surfaces,surface_id, line_id)== true) + { + line_indicent_surfaces[line_id].set_side_surface_index(true, englobing_surface_id_for_upper_line); + } + + line_indicent_surfaces[line_id].set_side_surface_index(false, englobing_surface_id_for_upper_line); + } /*! * TODO by Emna */ - void manage_intrusion_surface(const std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces ) const - { - - for (auto surface_id : range(geomodel_.nb_surfaces())) - { - for (index_t upper_surface_id = surface_id +1; upper_surface_id <= geomodel_.nb_surfaces(); ++ upper_surface_id) - { - // iterate on every surfaces - std::set< index_t > line_boundary_indices = - get_line_boundary_indices(line_indicent_surfaces, surface_id); - - // interates on every other surfaces + // TODO Manage intrusions surfaces + // manage_intrusion_surface(); + // compare the two sets: line_boundary_indices and + // upper_line_boundary_indices if equal do:// + // find englobing_surface_index for upper_line_boundary_indices + + void manage_intrusion_surface( std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces) const + { + for (auto surface_id : range(geomodel_.nb_surfaces())) + { + // iterate on every surfaces + std::set< index_t > line_boundary_indices = + get_line_boundary_indices(line_indicent_surfaces, surface_id); - std::set< index_t > upper_line_boundary_indices = + for (index_t upper_surface_id = surface_id +1; upper_surface_id <= geomodel_.nb_surfaces(); ++ upper_surface_id) + { + // interates on every other surfaces + std::set< index_t > upper_line_boundary_indices = get_line_boundary_indices( line_indicent_surfaces, upper_surface_id); - if (line_boundary_indices == upper_line_boundary_indices) - { - index_t englobing_surface_id_for_upper_line = find_englobing_surface(surface_id); + if (line_boundary_indices == upper_line_boundary_indices) + { + std::set::iterator i; - std::set ::iterator it; - - for (it = line_boundary_indices.begin(); it != line_boundary_indices.end(); it++) - - { - line_indicent_surfaces[it].set_side_surface_index(true, englobing_surface_id_for_upper_line); - } - - //index_t englobing_surface_id = line_indicent_surfaces[upper_line_boundary_indices].plus_surface_index();// - } - } - } - - // compare the two sets: line_boundary_indices and - // upper_line_boundary_indices if equal do:// - // find englobing_surface_index for upper_line_boundary_indices - // set line_indicent_surfaces corresponding to every - // upper_line_boundary_indices to - // englobing_surface_index (be careful it correspond to eitehr plus - // or minus side) + for (i = upper_line_boundary_indices.begin(); i != upper_line_boundary_indices.end(); ++i) + { + if (line_indicent_surfaces[*i].plus_surface_index() == *i) + { + index_t line_id = *i ; + index_t englobing_surface_id_for_upper_line = find_englobing_surface(line_id, line_indicent_surfaces); + + for (index_t it; it <= upper_line_boundary_indices.size(); ++it) + { + set_line_indices_surface(line_indicent_surfaces, it, surface_id, englobing_surface_id_for_upper_line); + } + break; + } + } + } + } + } return; } @@ -1444,11 +1504,7 @@ namespace RINGMesh // TODO by EMNA // Done // update message to say that we have taken into account the - // internal boundary. remove exception - - - // TODO Manage intrusions surfaces - // manage_intrusion_surface(); + // internal boundary. remove exception } std::vector< vec2 > get_surface_polygon_vertices( From 7ca6e0617bc82821ac7a9e357ce4612e972414b3 Mon Sep 17 00:00:00 2001 From: emnabelazi Date: Thu, 2 May 2019 18:16:15 +0200 Subject: [PATCH 21/24] minor change --- include/ringmesh/geomodel/builder/geomodel_builder.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/ringmesh/geomodel/builder/geomodel_builder.h b/include/ringmesh/geomodel/builder/geomodel_builder.h index ea14518d6..614762765 100644 --- a/include/ringmesh/geomodel/builder/geomodel_builder.h +++ b/include/ringmesh/geomodel/builder/geomodel_builder.h @@ -33,6 +33,7 @@ * FRANCE */ + #pragma once #include From c82e3aaa8cc6ea764c05b6c697c384af8a493d5c Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Thu, 2 May 2019 16:29:53 +0000 Subject: [PATCH 22/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.h | 1 - .../geomodel/builder/geomodel_builder.cpp | 340 ++++++++++-------- 2 files changed, 188 insertions(+), 153 deletions(-) diff --git a/include/ringmesh/geomodel/builder/geomodel_builder.h b/include/ringmesh/geomodel/builder/geomodel_builder.h index 614762765..ea14518d6 100644 --- a/include/ringmesh/geomodel/builder/geomodel_builder.h +++ b/include/ringmesh/geomodel/builder/geomodel_builder.h @@ -33,7 +33,6 @@ * FRANCE */ - #pragma once #include diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index e4d0929ab..f937d6e92 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1293,50 +1293,61 @@ namespace RINGMesh * @return the englobing surface index * @note you may need other inputs. */ - index_t find_englobing_surface(index_t line_id, std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) const + index_t find_englobing_surface( index_t line_id, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) + const { // implement geometrical test to detect the index of the surface // that englobe the line - // create Line2D = tracer de rayon - - const Line2D & line = geomodel_.line(line_id); - - Geometry::Line2D Ray_tracer{ { 0.5, 0.5 }, line.vertex(0) }; - - int intersection_count = 0; - - for (auto surface_id : range(geomodel_.nb_surfaces())) - { - std::vector< OrientedLine > boundaries_of_curr_surface = - get_surface_boundaries(surface_id, line_indicent_surfaces); - - for ( index_t id=0; id <= boundaries_of_curr_surface.size(); ++ id) - { - const Line2D & line_boundary = geomodel_.line(id); - - for (index_t segment_id : range(line_boundary.nb_mesh_elements())) - { - const Geometry::Segment2D segment_of_line( - line_boundary.mesh_element_vertex({ segment_id, 0 }), - line_boundary.mesh_element_vertex({ segment_id, 1 }) - ); - - // Geometry::Line2D line_id = line_indicent_surfaces[id]; - - std::tuple< bool, vec2 > inter = Intersection::segment_line(segment_of_line, Ray_tracer); - - if (std::get<0>(inter) == true) - { - ++ intersection_count; } - } - } - - if (intersection_count % 2 != 0) - { - return surface_id; } - - break; - } + // create Line2D = tracer de rayon + + const Line2D& line = geomodel_.line( line_id ); + + Geometry::Line2D Ray_tracer{ { 0.5, 0.5 }, line.vertex( 0 ) }; + + int intersection_count = 0; + + for( auto surface_id : range( geomodel_.nb_surfaces() ) ) + { + std::vector< OrientedLine > boundaries_of_curr_surface = + get_surface_boundaries( + surface_id, line_indicent_surfaces ); + + for( index_t id = 0; id <= boundaries_of_curr_surface.size(); + ++id ) + { + const Line2D& line_boundary = geomodel_.line( id ); + + for( index_t segment_id : + range( line_boundary.nb_mesh_elements() ) ) + { + const Geometry::Segment2D segment_of_line( + line_boundary.mesh_element_vertex( + { segment_id, 0 } ), + line_boundary.mesh_element_vertex( + { segment_id, 1 } ) ); + + // Geometry::Line2D line_id = + // line_indicent_surfaces[id]; + + std::tuple< bool, vec2 > inter = + Intersection::segment_line( + segment_of_line, Ray_tracer ); + + if( std::get< 0 >( inter ) == true ) + { + ++intersection_count; + } + } + } + + if( intersection_count % 2 != 0 ) + { + return surface_id; + } + + break; + } return 0; } @@ -1350,8 +1361,7 @@ namespace RINGMesh * @return the number of connected set of internal boundaries. */ index_t manage_internal_boundary( - std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); @@ -1371,14 +1381,16 @@ namespace RINGMesh // TODO by Emna // find the englobing surface for the current line // implement the following function - // reset the index of line incident surfaces to + // reset the index of line incident surfaces to // englobing_surface_id - - index_t englobing_surface_id = - find_englobing_surface(line_id, line_indicent_surfaces); - line_indicent_surfaces[line_id].set_side_surface_index( true, englobing_surface_id); - line_indicent_surfaces[line_id].set_side_surface_index( false, englobing_surface_id); + index_t englobing_surface_id = find_englobing_surface( + line_id, line_indicent_surfaces ); + + line_indicent_surfaces[line_id].set_side_surface_index( + true, englobing_surface_id ); + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id ); } } return { static_cast< index_t >( std::count( @@ -1390,121 +1402,145 @@ namespace RINGMesh * @return a set of line index that are either the minus or the plus * boundary. */ - std::set< index_t > get_line_boundary_indices(const std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces, index_t surface_id ) const - { - std::set< index_t > line_boundary_indices; - - for (auto line_id : range(geomodel_.nb_lines())) - { - - if ((line_indicent_surfaces[line_id].plus_surface_index() == surface_id) || - (line_indicent_surfaces[line_id].minus_surface_index()== surface_id)) - - { - line_boundary_indices.emplace(line_id); - } - } - - return line_boundary_indices; - } - // determine if the lines index are the minus or the plus - // @return the side of the line ( true = plus, false = minus) - - bool line_side (const std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces, index_t surface_id, index_t line_id)const - { - if ( line_indicent_surfaces[line_id].plus_surface_index() == surface_id) - { return true; - } - - return false; - } - //// set line_indicent_surfaces corresponding to every - // upper_line_boundary_indices to - // englobing_surface_index (it correspond to eitehr plus - // or minus side) - //@param line_id, surface_id and line_indicent_surface - - void set_line_indices_surface (std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces, index_t line_id, index_t surface_id, index_t englobing_surface_id_for_upper_line)const - { - if (line_side (line_indicent_surfaces,surface_id, line_id)== true) - { - line_indicent_surfaces[line_id].set_side_surface_index(true, englobing_surface_id_for_upper_line); - } - - line_indicent_surfaces[line_id].set_side_surface_index(false, englobing_surface_id_for_upper_line); - } + std::set< index_t > get_line_boundary_indices( + const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, + index_t surface_id ) const + { + std::set< index_t > line_boundary_indices; + + for( auto line_id : range( geomodel_.nb_lines() ) ) + { + if( ( line_indicent_surfaces[line_id].plus_surface_index() + == surface_id ) + || ( line_indicent_surfaces[line_id].minus_surface_index() + == surface_id ) ) + + { + line_boundary_indices.emplace( line_id ); + } + } + + return line_boundary_indices; + } + // determine if the lines index are the minus or the plus + // @return the side of the line ( true = plus, false = minus) + + bool line_side( const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, + index_t surface_id, + index_t line_id ) const + { + if( line_indicent_surfaces[line_id].plus_surface_index() + == surface_id ) + { + return true; + } + + return false; + } + //// set line_indicent_surfaces corresponding to every + // upper_line_boundary_indices to + // englobing_surface_index (it correspond to eitehr plus + // or minus side) + //@param line_id, surface_id and line_indicent_surface + + void set_line_indices_surface( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + index_t line_id, + index_t surface_id, + index_t englobing_surface_id_for_upper_line ) const + { + if( line_side( line_indicent_surfaces, surface_id, line_id ) + == true ) + { + line_indicent_surfaces[line_id].set_side_surface_index( + true, englobing_surface_id_for_upper_line ); + } + + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id_for_upper_line ); + } /*! * TODO by Emna */ - // TODO Manage intrusions surfaces - // manage_intrusion_surface(); - // compare the two sets: line_boundary_indices and - // upper_line_boundary_indices if equal do:// - // find englobing_surface_index for upper_line_boundary_indices - - void manage_intrusion_surface( std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces) const - { - for (auto surface_id : range(geomodel_.nb_surfaces())) - { - // iterate on every surfaces - std::set< index_t > line_boundary_indices = - get_line_boundary_indices(line_indicent_surfaces, surface_id); - - for (index_t upper_surface_id = surface_id +1; upper_surface_id <= geomodel_.nb_surfaces(); ++ upper_surface_id) - { - // interates on every other surfaces - std::set< index_t > upper_line_boundary_indices = - get_line_boundary_indices( line_indicent_surfaces, upper_surface_id); - - if (line_boundary_indices == upper_line_boundary_indices) - { - std::set::iterator i; - - for (i = upper_line_boundary_indices.begin(); i != upper_line_boundary_indices.end(); ++i) - { - if (line_indicent_surfaces[*i].plus_surface_index() == *i) - { - index_t line_id = *i ; - index_t englobing_surface_id_for_upper_line = find_englobing_surface(line_id, line_indicent_surfaces); - - for (index_t it; it <= upper_line_boundary_indices.size(); ++it) - { - set_line_indices_surface(line_indicent_surfaces, it, surface_id, englobing_surface_id_for_upper_line); - } - break; - } - } - } - } - } + // TODO Manage intrusions surfaces + // manage_intrusion_surface(); + // compare the two sets: line_boundary_indices and + // upper_line_boundary_indices if equal do:// + // find englobing_surface_index for upper_line_boundary_indices + + void manage_intrusion_surface( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) + const + { + for( auto surface_id : range( geomodel_.nb_surfaces() ) ) + { + // iterate on every surfaces + std::set< index_t > line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, surface_id ); + + for( index_t upper_surface_id = surface_id + 1; + upper_surface_id <= geomodel_.nb_surfaces(); + ++upper_surface_id ) + { + // interates on every other surfaces + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, upper_surface_id ); + + if( line_boundary_indices == upper_line_boundary_indices ) + { + std::set< index_t >::iterator i; + + for( i = upper_line_boundary_indices.begin(); + i != upper_line_boundary_indices.end(); ++i ) + { + if( line_indicent_surfaces[*i].plus_surface_index() + == *i ) + { + index_t line_id = *i; + index_t englobing_surface_id_for_upper_line = + find_englobing_surface( + line_id, line_indicent_surfaces ); + + for( index_t it; + it <= upper_line_boundary_indices.size(); + ++it ) + { + set_line_indices_surface( + line_indicent_surfaces, it, surface_id, + englobing_surface_id_for_upper_line ); + } + break; + } + } + } + } + } return; } void check_internal_intrusion_or_boundaries( - std::vector< LineIncidentSurfacePair >& - line_indicent_surfaces, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { index_t nb_floating_set_of_lines = manage_internal_boundary( line_indicent_surfaces, nb_found_surfaces ); - if (nb_floating_set_of_lines > 0) - { - Logger::out(" During surface from corners ", - " and lines build, ", - nb_floating_set_of_lines, - " group(s) of lines are " - "floating inside a surface : These Internal Boundaries were taken into account "); - } - - - // TODO by EMNA // Done - // update message to say that we have taken into account the - // internal boundary. remove exception + if( nb_floating_set_of_lines > 0 ) + { + Logger::out( " During surface from corners ", + " and lines build, ", nb_floating_set_of_lines, + " group(s) of lines are " + "floating inside a surface : These Internal Boundaries " + "were taken into account " ); + } + + // TODO by EMNA // Done + // update message to say that we have taken into account the + // internal boundary. remove exception } std::vector< vec2 > get_surface_polygon_vertices( From 0daa1ab4440be27a6e9a1782beb896c1c1ca0021 Mon Sep 17 00:00:00 2001 From: belazi Date: Tue, 18 Jun 2019 15:03:53 +0200 Subject: [PATCH 23/24] problem with number of universe and englobing surfaces --- .../geomodel/builder/geomodel_builder.h | 6 +- include/ringmesh/geomodel/core/geomodel.h | 2 +- .../geomodel/builder/geomodel_builder.cpp | 638 +++++++++++++----- ...ild-2d-geomodel-with-internal-features.cpp | 8 +- 4 files changed, 464 insertions(+), 190 deletions(-) diff --git a/include/ringmesh/geomodel/builder/geomodel_builder.h b/include/ringmesh/geomodel/builder/geomodel_builder.h index ea14518d6..c81a6612d 100644 --- a/include/ringmesh/geomodel/builder/geomodel_builder.h +++ b/include/ringmesh/geomodel/builder/geomodel_builder.h @@ -125,7 +125,7 @@ namespace RINGMesh /*! * @brief Finish up geomodel building and complete missing information. */ - void end_geomodel(); + virtual void end_geomodel() = 0; void build_corners_from_lines(); @@ -164,6 +164,8 @@ namespace RINGMesh ~GeoModelBuilder(); + void end_geomodel() final; + void build_surfaces_from_corners_and_lines(); private: @@ -177,6 +179,8 @@ namespace RINGMesh public: explicit GeoModelBuilder( GeoModel3D& geomodel ); + void end_geomodel() final; + void build_regions_from_lines_and_surfaces(); }; diff --git a/include/ringmesh/geomodel/core/geomodel.h b/include/ringmesh/geomodel/core/geomodel.h index 52a2ae46b..4d3954f0b 100644 --- a/include/ringmesh/geomodel/core/geomodel.h +++ b/include/ringmesh/geomodel/core/geomodel.h @@ -206,7 +206,7 @@ namespace RINGMesh return static_cast< index_t >( lines_.size() ); } index_t nb_surfaces() const - { + { return static_cast< index_t >( surfaces_.size() ); } diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index f937d6e92..bfb00ee06 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1066,17 +1066,6 @@ namespace RINGMesh geometry.clear_geomodel_mesh(); } - template < index_t DIMENSION > - void GeoModelBuilderBase< DIMENSION >::end_geomodel() - { - if( geomodel_.name().empty() ) - { - info.set_geomodel_name( "model_default_name" ); - } - - cut_geomodel_on_internal_boundaries(); - print_geomodel( geomodel_ ); - } class GeoModelBuilder< 2 >::Impl { @@ -1225,7 +1214,7 @@ namespace RINGMesh } std::vector< OrientedLine > get_surface_boundaries( - const index_t cur_surface_id, + index_t cur_surface_id, std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) const { @@ -1237,31 +1226,32 @@ namespace RINGMesh // From the first line, the lines are walked turning around corners // in the same direction (clockwise). Line after line, the - // boundaries - // of the currently processed surface are found until the algorithm - // has gone back to the first line. + // boundaries of the currently processed surface are found until + // the algorithm has gone back to the first line. // By convention, if a line is walked from its first boundary // towards // its second boundary, the surface is set as incident by the + side // of the line. do { - ringmesh_assert( + //ringmesh_assert( line_indicent_surfaces[cur_line_and_side.index] .side_surface_index( cur_line_and_side.side ) - == NO_ID ); + == NO_ID ; line_indicent_surfaces[cur_line_and_side.index] .set_side_surface_index( cur_line_and_side.side, cur_surface_id ); + cur_surface_boundaries.emplace_back( cur_line_and_side ); cur_line_and_side = get_next_surface_boundary_line( cur_line_and_side ); } while( cur_line_and_side != first_line_and_side ); + return cur_surface_boundaries; } - void find_surfaces_boundary_lines( + void find_surfaces_boundary_lines( std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const @@ -1269,7 +1259,7 @@ namespace RINGMesh // This vector registers for each line the index of the two incident // surfaces line_indicent_surfaces.resize( this->geomodel_.nb_lines() ); - index_t surface_counter{ 0 }; + index_t surface_counter{0}; while( std::count_if( line_indicent_surfaces.begin(), line_indicent_surfaces.end(), []( const LineIncidentSurfacePair& line ) { @@ -1279,78 +1269,88 @@ namespace RINGMesh { auto cur_surface_boundaries = get_surface_boundaries( surface_counter, line_indicent_surfaces ); - + surface_boundary_lines.emplace_back( std::move( cur_surface_boundaries ) ); ++surface_counter; - } + std::cout << " counter" << surface_counter << std::endl; + } } /*! * This function implements a geometric test to find the englobing * surface index for the current line - * @param line_id index of the current line + * @param line_id index of the current line, line_indicent_surfaces for each line , number of the found surfaces * @return the englobing surface index * @note you may need other inputs. */ + /* Check that the found surface id is different from itself + */ index_t find_englobing_surface( index_t line_id, - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) + const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, index_t nb_found_surfaces) const { - // implement geometrical test to detect the index of the surface - // that englobe the line - // create Line2D = tracer de rayon - + // implement geometrical test to detect the index of the surface + // that englobe the line + // create Line2D = tracer de rayon + const Line2D& line = geomodel_.line( line_id ); - Geometry::Line2D Ray_tracer{ { 0.5, 0.5 }, line.vertex( 0 ) }; - - int intersection_count = 0; - - for( auto surface_id : range( geomodel_.nb_surfaces() ) ) - { - std::vector< OrientedLine > boundaries_of_curr_surface = - get_surface_boundaries( - surface_id, line_indicent_surfaces ); - - for( index_t id = 0; id <= boundaries_of_curr_surface.size(); - ++id ) - { - const Line2D& line_boundary = geomodel_.line( id ); - - for( index_t segment_id : - range( line_boundary.nb_mesh_elements() ) ) - { - const Geometry::Segment2D segment_of_line( - line_boundary.mesh_element_vertex( - { segment_id, 0 } ), - line_boundary.mesh_element_vertex( - { segment_id, 1 } ) ); - - // Geometry::Line2D line_id = - // line_indicent_surfaces[id]; - - std::tuple< bool, vec2 > inter = - Intersection::segment_line( - segment_of_line, Ray_tracer ); - - if( std::get< 0 >( inter ) == true ) - { - ++intersection_count; - } - } - } - - if( intersection_count % 2 != 0 ) - { - return surface_id; - } - - break; - } - - return 0; - } + Geometry::Line2D Ray_tracer{ { 0.5,0.7 }, line.vertex( 0 ) }; + + for(index_t surface_id = 0; surface_id < nb_found_surfaces; ++surface_id) + { + int intersection_count = 0; + std::set< index_t > boundaries_of_curr_surface = + get_line_boundary_indices( + line_indicent_surfaces, surface_id ); + + std::tuple< bool, vec2 > inter(false, {0,0}); + for( index_t id : boundaries_of_curr_surface ) + { + if (line_indicent_surfaces[id].plus_surface_index() + == line_indicent_surfaces[id].minus_surface_index()) + { + continue ; + } + + const Line2D& line_boundary = geomodel_.line( id ); + + for( index_t segment_id : + range( line_boundary.nb_mesh_elements() ) ) + { + const Geometry::Segment2D segment_of_line( + line_boundary.mesh_element_vertex( + { segment_id, 0 } ), + line_boundary.mesh_element_vertex( + { segment_id, 1 } ) ); + + inter = Intersection::segment_line( + segment_of_line, Ray_tracer ); + + vec2 inter_point = std::get< 1 >(inter); + vec2 vec_origin_point; + + vec_origin_point[0] = (inter_point[0] - line.vertex(0)[0]); + vec_origin_point[1] = (inter_point[1] - line.vertex(0)[1]); + + double vec_dir = dot(vec_origin_point, vec2( 0.5, 0.7 )); + + if (std::get< 0 >(inter) == true && vec_dir >0) + { + ++intersection_count; + } + } + } + + if( intersection_count % 2 != 0 ) + { + return surface_id; + } + } + + return NO_ID; + } /*! * This function iterates on lines and manages internal boundaries. @@ -1364,41 +1364,50 @@ namespace RINGMesh std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { + index_t count = 0; std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { if( line_indicent_surfaces[line_id].plus_surface_index() != line_indicent_surfaces[line_id].minus_surface_index() ) { - are_surfaces_hole[line_indicent_surfaces[line_id] - .plus_surface_index()] = false; - are_surfaces_hole[line_indicent_surfaces[line_id] - .minus_surface_index()] = false; + if (line_indicent_surfaces[line_id].plus_surface_index() != NO_ID){ + are_surfaces_hole[line_indicent_surfaces[line_id] + .plus_surface_index()] = false; + } + if (line_indicent_surfaces[line_id].minus_surface_index() != NO_ID){ + are_surfaces_hole[line_indicent_surfaces[line_id] + .minus_surface_index()] = false; + } } else { // if a line have the same minus and plus surface index this - // line is an internal boundary. - // TODO by Emna - // find the englobing surface for the current line - // implement the following function - // reset the index of line incident surfaces to - // englobing_surface_id + // line is an internal boundary. + // find the englobing surface for the current line + // implement the following function + // reset the index of line incident surfaces to + // englobing_surface_id + + index_t englobing_surface_id = find_englobing_surface( + line_id, line_indicent_surfaces, nb_found_surfaces); + + Logger::out("the line id is` ", line_id, + "the englobing surface is ", englobing_surface_id); - index_t englobing_surface_id = find_englobing_surface( - line_id, line_indicent_surfaces ); - - line_indicent_surfaces[line_id].set_side_surface_index( + line_indicent_surfaces[line_id].set_side_surface_index( true, englobing_surface_id ); - line_indicent_surfaces[line_id].set_side_surface_index( - false, englobing_surface_id ); + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id ); } } - return { static_cast< index_t >( std::count( - are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; + + return { static_cast< index_t >( std::count( + are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; } + /*! * This function finds all line boundary indices associated to a surface - * @param surface_id index of the current surface + * @param surface_id index of the current surface and line_indicent_surfaces of each line * @return a set of line index that are either the minus or the plus * boundary. */ @@ -1408,22 +1417,22 @@ namespace RINGMesh index_t surface_id ) const { std::set< index_t > line_boundary_indices; + for( auto line_id : range( geomodel_.nb_lines() ) ) - for( auto line_id : range( geomodel_.nb_lines() ) ) - { + { if( ( line_indicent_surfaces[line_id].plus_surface_index() == surface_id ) || ( line_indicent_surfaces[line_id].minus_surface_index() - == surface_id ) ) - + == surface_id)) { - line_boundary_indices.emplace( line_id ); + line_boundary_indices.emplace(line_id); } } return line_boundary_indices; } - // determine if the lines index are the minus or the plus + + // this function determine if the lines index are the minus or the plus // @return the side of the line ( true = plus, false = minus) bool line_side( const std::vector< LineIncidentSurfacePair >& @@ -1439,116 +1448,186 @@ namespace RINGMesh return false; } + //// set line_indicent_surfaces corresponding to every // upper_line_boundary_indices to // englobing_surface_index (it correspond to eitehr plus // or minus side) //@param line_id, surface_id and line_indicent_surface - void set_line_indices_surface( - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - index_t line_id, - index_t surface_id, - index_t englobing_surface_id_for_upper_line ) const - { - if( line_side( line_indicent_surfaces, surface_id, line_id ) - == true ) - { - line_indicent_surfaces[line_id].set_side_surface_index( - true, englobing_surface_id_for_upper_line ); - } - - line_indicent_surfaces[line_id].set_side_surface_index( - false, englobing_surface_id_for_upper_line ); - } - - /*! - * TODO by Emna - */ - // TODO Manage intrusions surfaces - // manage_intrusion_surface(); - // compare the two sets: line_boundary_indices and - // upper_line_boundary_indices if equal do:// - // find englobing_surface_index for upper_line_boundary_indices - - void manage_intrusion_surface( - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) - const - { - for( auto surface_id : range( geomodel_.nb_surfaces() ) ) - { - // iterate on every surfaces - std::set< index_t > line_boundary_indices = - get_line_boundary_indices( - line_indicent_surfaces, surface_id ); - - for( index_t upper_surface_id = surface_id + 1; - upper_surface_id <= geomodel_.nb_surfaces(); - ++upper_surface_id ) - { - // interates on every other surfaces - std::set< index_t > upper_line_boundary_indices = - get_line_boundary_indices( - line_indicent_surfaces, upper_surface_id ); - - if( line_boundary_indices == upper_line_boundary_indices ) - { - std::set< index_t >::iterator i; - - for( i = upper_line_boundary_indices.begin(); - i != upper_line_boundary_indices.end(); ++i ) - { - if( line_indicent_surfaces[*i].plus_surface_index() - == *i ) - { - index_t line_id = *i; - index_t englobing_surface_id_for_upper_line = - find_englobing_surface( - line_id, line_indicent_surfaces ); - - for( index_t it; - it <= upper_line_boundary_indices.size(); - ++it ) - { - set_line_indices_surface( - line_indicent_surfaces, it, surface_id, - englobing_surface_id_for_upper_line ); - } - break; - } - } - } - } - } + void reset_line_indicent_surfaces( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + index_t line_id, + index_t surface_id, + index_t englobing_surface_id_for_upper_line) const + { + if (line_side(line_indicent_surfaces, surface_id, line_id) + == true) + { + line_indicent_surfaces[line_id].set_side_surface_index( + true, englobing_surface_id_for_upper_line); + } + else{ + + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id_for_upper_line); + } + } + + + bool check_the_englobing_surface(std::set min, std::setmax, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces) + { + for (auto i : min) { + if (std::find(max.begin(), max.end(), i) == max.end()){ + // Cur element of min is not in max + return false; + } + } + return true; + } + + void check_size( std::set line_boundaries, std::setupper_line_boundaries, + std::set &min,std::set& max) + { + + if (line_boundaries.size() < upper_line_boundaries.size()) + { + min = line_boundaries; + max = upper_line_boundaries; + } + + else + { + max = line_boundaries; + min = upper_line_boundaries; + } + } + + // this function compare the two sets: + // line_boundary_indices and upper_line_boundary_indices + // if they are equal do: it find englobing_surface_index + // for upper_line_boundary_indices + + void manage_intrusion_surface( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, index_t nb_found_surfaces) + { + std::set min; + std::set max; + + for (index_t surface_id = 0; surface_id <= nb_found_surfaces; ++surface_id) + { + // iterate on every surfaces + std::set< index_t > line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, surface_id); + + for( index_t upper_surface_id = surface_id; + upper_surface_id <= nb_found_surfaces; + ++upper_surface_id ) + { + if (upper_surface_id == surface_id) + { + continue; + } + + // interates on every other surfaces + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, upper_surface_id ); + + check_size(line_boundary_indices, upper_line_boundary_indices, + min, max); + if (min.size() == 0) { + continue; + } + + if (check_the_englobing_surface(min, max, line_indicent_surfaces) == true) + + { + std::set< index_t >::iterator i; + + for (i = min.begin(); + i != min.end(); ++i) + { + if (line_indicent_surfaces[*i].plus_surface_index() == + line_indicent_surfaces[*i].minus_surface_index()) + { + continue ; + } + Logger::out(" S_id ", surface_id); + Logger::out(" US_id ", upper_surface_id); + Logger::out("try", line_indicent_surfaces[*i].plus_surface_index(), " ", + line_indicent_surfaces[*i].minus_surface_index()); + + index_t englobing_surface_id_for_upper_line = + find_englobing_surface( + *i, line_indicent_surfaces, nb_found_surfaces); + + Logger::out("englobing surface", englobing_surface_id_for_upper_line); + + if (englobing_surface_id_for_upper_line != NO_ID) + { + std::set< index_t >::iterator it; + for (it = min.begin(); + it != min.end(); ++it) + { + if (line_boundary_indices.size() < upper_line_boundary_indices.size()) { + reset_line_indicent_surfaces( + line_indicent_surfaces, *it, surface_id, + englobing_surface_id_for_upper_line); + } + else { + reset_line_indicent_surfaces( + line_indicent_surfaces, *it, upper_surface_id, + englobing_surface_id_for_upper_line); + } + } + break; + } + + } + + } + } + + } + return; } + + void check_internal_intrusion_or_boundaries( std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - const index_t nb_found_surfaces ) const + const index_t nb_found_surfaces ) { index_t nb_floating_set_of_lines = manage_internal_boundary( line_indicent_surfaces, nb_found_surfaces ); + if( nb_floating_set_of_lines > 0 ) - { + { Logger::out( " During surface from corners ", " and lines build, ", nb_floating_set_of_lines, " group(s) of lines are " "floating inside a surface : These Internal Boundaries " - "were taken into account " ); - } + "were taken into account !!! " ); + } - // TODO by EMNA // Done - // update message to say that we have taken into account the - // internal boundary. remove exception + manage_intrusion_surface(line_indicent_surfaces, nb_found_surfaces); } + std::vector< vec2 > get_surface_polygon_vertices( const std::vector< OrientedLine >& surface_boundaries ) const { std::vector< vec2 > polygon_vertices; + std::set< index_t > added_line_id; for( auto cur_surf_boundary : surface_boundaries ) { + if (added_line_id.find(cur_surf_boundary.index) != added_line_id.end()) { + continue; + } const auto& cur_line = this->geomodel_.line( cur_surf_boundary.index ); for( auto vertex : range( 1, cur_line.nb_vertices() ) ) @@ -1558,6 +1637,7 @@ namespace RINGMesh ? vertex : ( cur_line.nb_vertices() - 1 ) - vertex ) ); } + added_line_id.insert(cur_surf_boundary.index); } return polygon_vertices; } @@ -1568,10 +1648,10 @@ namespace RINGMesh { for( const auto& surface_boundaries : surface_boundary_lines ) { - std::vector< vec2 > polygon_vertices = + std::vector< vec2 > polygon_vertices = get_surface_polygon_vertices( surface_boundaries ); std::vector< index_t > polygon_corners( - polygon_vertices.size() ); + polygon_vertices.size() ); std::iota( polygon_corners.begin(), polygon_corners.end(), 0 ); auto surface_id = builder.topology.create_mesh_entity( surface_type_name_static() ); @@ -1583,7 +1663,50 @@ namespace RINGMesh } } + void remove_universe(std::vector< LineIncidentSurfacePair >& line_incident_surfaces, index_t nb_found_surfaces) + { + std::set< index_t > universe_candidates; + std::set< index_t > tmp_cand; + for (auto surface_id : range( nb_found_surfaces ) ) + { + + index_t first_line_id; + for (auto line_id : range(line_incident_surfaces.size())){ + if (line_incident_surfaces[line_id].plus_surface_index() == surface_id || line_incident_surfaces[line_id].minus_surface_index() == surface_id) { + first_line_id = line_id; + break; + } + } + index_t englobing_id = find_englobing_surface( + first_line_id, line_incident_surfaces, nb_found_surfaces); + + //if (englobing_id == NO_ID || englobing_id == surface_id ) { + if (englobing_id == NO_ID || tmp_cand.find(englobing_id) != tmp_cand.end()){ + universe_candidates.emplace(surface_id); + } + if (englobing_id == surface_id){ + tmp_cand.emplace(surface_id); + } + } + /* Check == 1 seems not good*/ + //if (universe_candidates.size() == 2 || universe_candidates.size() == 1) { + index_t universe_id = *universe_candidates.begin(); + for (auto line_id : range(line_incident_surfaces.size())){ + if (line_incident_surfaces[line_id].plus_surface_index() == universe_id){ + line_incident_surfaces[line_id].set_side_surface_index(true, NO_ID); + } if (line_incident_surfaces[line_id].minus_surface_index() == universe_id){ + line_incident_surfaces[line_id].set_side_surface_index(false, NO_ID); + } + } + /*} + else { + throw RINGMeshException("Universe", "Finding Universe in a model with several Surfaces not yet implemented..."); + }*/ + } + + /*Function to remove*/ void find_exterior_and_remove_it( GeoModelBuilder2D& builder, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const { @@ -1592,12 +1715,31 @@ namespace RINGMesh for( const auto& surface : geomodel_.surfaces() ) { double surface_area{ surface.size() }; + Logger::out("Universe", surface.index(), " ", surface_area, " ", surface.nb_boundaries(), " ", surface_boundary_lines[surface.index()].size()); if( surface_area > max_surface_area ) { max_surface_area = surface_area; exterior_surface_id = surface.index(); - } + } } + + DEBUG(exterior_surface_id); + index_t count = 0; + std::set< index_t > other_candidates; + for (auto line : surface_boundary_lines[exterior_surface_id]) + { + index_t other_surface = line_indicent_surfaces[line.index].side_surface_index(!line.side); + if (other_surface != exterior_surface_id){ + other_candidates.emplace(other_surface); + } + } + DEBUG(other_candidates.size()); + if (other_candidates.size() == 1){ + if (surface_boundary_lines[*other_candidates.begin()].size() < surface_boundary_lines[exterior_surface_id].size()){ + exterior_surface_id = *other_candidates.begin(); + } + } + DEBUG(exterior_surface_id); std::set< gmme_id > to_remove; to_remove.insert( { surface_type_name_static(), exterior_surface_id } ); @@ -1623,6 +1765,21 @@ namespace RINGMesh } } + + /*std::vector< bool > check_kept_surface_ids(std::vector< LineIncidentSurfacePair >& line_incident_surfaces ) + { + std::vector< bool > kept_surface_ids(index_t size, bool ); + for (auto id : range(line_incident_surfaces.size())) + { + std::cout << + "after " << id << " " << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; + + kept_surface_ids[line_incident_surfaces[id].plus_surface_index()] = true; + kept_surface_ids[line_incident_surfaces[id].minus_surface_index()] = true; + } + }*/ + private: GeoModel2D& geomodel_; }; @@ -1640,6 +1797,21 @@ namespace RINGMesh geometry.cut_surfaces_by_internal_lines(); } + void GeoModelBuilder< 2 >::end_geomodel() + { + if (geomodel_.name().empty()) + { + info.set_geomodel_name("model_default_name"); + } + + if (geomodel_.nb_surfaces() == 0) { + build_surfaces_from_corners_and_lines(); + } + + //cut_geomodel_on_internal_boundaries(); + print_geomodel(geomodel_); + } + void GeoModelBuilder< 2 >::build_surfaces_from_corners_and_lines() { if( geomodel_.nb_surfaces() > 0 ) @@ -1652,12 +1824,91 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); + for (auto id : range (line_incident_surfaces.size())) { + std::cout << + "before "<< id<< " "<< line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() <remove_universe(line_incident_surfaces, + static_cast< index_t >(surface_boundary_lines.size())); + + for (auto id : range(line_incident_surfaces.size())) { + std::cout << + "universe " << id << " " << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; + } + impl_->check_internal_intrusion_or_boundaries( line_incident_surfaces, - static_cast< index_t >( surface_boundary_lines.size() ) ); + static_cast< index_t >(surface_boundary_lines.size())); + + std::vector< bool > kept_surface_ids(surface_boundary_lines.size(), false); + for (auto id : range(line_incident_surfaces.size())) + { + std::cout << + "after " << id << " " << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; + + if (line_incident_surfaces[id].plus_surface_index() != NO_ID){ + kept_surface_ids[line_incident_surfaces[id].plus_surface_index()] = true; + } + if (line_incident_surfaces[id].minus_surface_index() != NO_ID){ + kept_surface_ids[line_incident_surfaces[id].minus_surface_index()] = true; + } + } + + // decalage + for (auto surf_id : range(surface_boundary_lines.size())) + { + auto nb_remove_surfaces_before = std::count(kept_surface_ids.begin(), kept_surface_ids.begin() + surf_id, false); + + for (auto id : range(line_incident_surfaces.size())) + { + if (line_incident_surfaces[id].plus_surface_index() == surf_id) + { + line_incident_surfaces[id].set_side_surface_index(true, + line_incident_surfaces[id].plus_surface_index()- nb_remove_surfaces_before); + } + if (line_incident_surfaces[id].minus_surface_index() == surf_id) + { + line_incident_surfaces[id].set_side_surface_index(false, + line_incident_surfaces[id].minus_surface_index() - nb_remove_surfaces_before); + } + } + } + + for (auto id : range(line_incident_surfaces.size())) + { + std::cout << + "after decalage " << id << " " << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; + } + + // todo : in a single function + surface_boundary_lines.clear(); + auto nb_surfaces = std::count(kept_surface_ids.begin(), kept_surface_ids.end(), true); + for (auto surf_id : range(nb_surfaces)) + { + std::vector< Impl::OrientedLine > cur_surface_boundaries; + for (auto line_id : range(line_incident_surfaces.size())) + { + if (line_incident_surfaces[line_id].plus_surface_index() == surf_id) + { + cur_surface_boundaries.emplace_back(line_id, true); + } + if (line_incident_surfaces[line_id].minus_surface_index() == surf_id) + { + cur_surface_boundaries.emplace_back(line_id, false); + } + } + surface_boundary_lines.push_back(cur_surface_boundaries); + } + //system("pause"); + // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); - impl_->find_exterior_and_remove_it( *this, surface_boundary_lines ); + //impl_->find_exterior_and_remove_it( *this,line_incident_surfaces, surface_boundary_lines ); // Update topology impl_->set_surface_line_boundary_relationships( @@ -1676,6 +1927,17 @@ namespace RINGMesh geometry.cut_regions_by_internal_surfaces(); } + void GeoModelBuilder<3>::end_geomodel() + { + if (geomodel_.name().empty()) + { + info.set_geomodel_name("model_default_name"); + } + + cut_geomodel_on_internal_boundaries(); + print_geomodel(geomodel_); + } + void GeoModelBuilder< 3 >::build_regions_from_lines_and_surfaces() { std::set< gmme_id > regions_to_delete; @@ -1793,6 +2055,8 @@ namespace RINGMesh remove.remove_mesh_entities( to_erase ); } + + template class geomodel_builder_api GeoModelBuilderBase< 2 >; template class geomodel_builder_api GeoModelBuilderInfo< 2 >; diff --git a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp index d6c90b15f..9ad0bec6f 100644 --- a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp +++ b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp @@ -91,7 +91,9 @@ void test_geomodel_2D_with_internal_features() Logger::out( "TEST", "Load GeoModel2D with internal features" ); GeoModel2D geomodel; geomodel_load( - geomodel, ringmesh_test_data_path + "model_with_internal_features.gm" ); + geomodel, ringmesh_test_data_path + "ModelA4_2d_nofracs.gm" ); + + check_geomodel( geomodel ); } @@ -101,17 +103,21 @@ int main() { Logger::out( "TEST", "Import GeoModel files" ); test_geomodel_2D_with_internal_features(); + } catch( const RINGMeshException& e ) { Logger::err( e.category(), e.what() ); + system("pause"); return 1; } catch( const std::exception& e ) { Logger::err( "Exception", e.what() ); + system("pause"); return 1; } Logger::out( "TEST", "SUCCESS" ); + system("pause"); return 0; } From cd80b92c77bb83ce77cf4734bf21d3c05939e1e4 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Tue, 18 Jun 2019 13:10:39 +0000 Subject: [PATCH 24/24] Travis CI format update --- .../geomodel/builder/geomodel_builder.h | 6 +- include/ringmesh/geomodel/core/geomodel.h | 2 +- .../geomodel/builder/geomodel_builder.cpp | 934 ++++++++++-------- ...ild-2d-geomodel-with-internal-features.cpp | 8 +- 4 files changed, 509 insertions(+), 441 deletions(-) diff --git a/include/ringmesh/geomodel/builder/geomodel_builder.h b/include/ringmesh/geomodel/builder/geomodel_builder.h index c81a6612d..6452946cd 100644 --- a/include/ringmesh/geomodel/builder/geomodel_builder.h +++ b/include/ringmesh/geomodel/builder/geomodel_builder.h @@ -125,7 +125,7 @@ namespace RINGMesh /*! * @brief Finish up geomodel building and complete missing information. */ - virtual void end_geomodel() = 0; + virtual void end_geomodel() = 0; void build_corners_from_lines(); @@ -164,7 +164,7 @@ namespace RINGMesh ~GeoModelBuilder(); - void end_geomodel() final; + void end_geomodel() final; void build_surfaces_from_corners_and_lines(); @@ -179,7 +179,7 @@ namespace RINGMesh public: explicit GeoModelBuilder( GeoModel3D& geomodel ); - void end_geomodel() final; + void end_geomodel() final; void build_regions_from_lines_and_surfaces(); }; diff --git a/include/ringmesh/geomodel/core/geomodel.h b/include/ringmesh/geomodel/core/geomodel.h index 4d3954f0b..52a2ae46b 100644 --- a/include/ringmesh/geomodel/core/geomodel.h +++ b/include/ringmesh/geomodel/core/geomodel.h @@ -206,7 +206,7 @@ namespace RINGMesh return static_cast< index_t >( lines_.size() ); } index_t nb_surfaces() const - { + { return static_cast< index_t >( surfaces_.size() ); } diff --git a/src/ringmesh/geomodel/builder/geomodel_builder.cpp b/src/ringmesh/geomodel/builder/geomodel_builder.cpp index bfb00ee06..965dd1490 100644 --- a/src/ringmesh/geomodel/builder/geomodel_builder.cpp +++ b/src/ringmesh/geomodel/builder/geomodel_builder.cpp @@ -1066,7 +1066,6 @@ namespace RINGMesh geometry.clear_geomodel_mesh(); } - class GeoModelBuilder< 2 >::Impl { public: @@ -1214,7 +1213,7 @@ namespace RINGMesh } std::vector< OrientedLine > get_surface_boundaries( - index_t cur_surface_id, + index_t cur_surface_id, std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) const { @@ -1226,7 +1225,7 @@ namespace RINGMesh // From the first line, the lines are walked turning around corners // in the same direction (clockwise). Line after line, the - // boundaries of the currently processed surface are found until + // boundaries of the currently processed surface are found until // the algorithm has gone back to the first line. // By convention, if a line is walked from its first boundary // towards @@ -1234,24 +1233,24 @@ namespace RINGMesh // of the line. do { - //ringmesh_assert( - line_indicent_surfaces[cur_line_and_side.index] + // ringmesh_assert( + line_indicent_surfaces[cur_line_and_side.index] .side_surface_index( cur_line_and_side.side ) - == NO_ID ; + == NO_ID; line_indicent_surfaces[cur_line_and_side.index] .set_side_surface_index( cur_line_and_side.side, cur_surface_id ); - + cur_surface_boundaries.emplace_back( cur_line_and_side ); cur_line_and_side = get_next_surface_boundary_line( cur_line_and_side ); } while( cur_line_and_side != first_line_and_side ); - + return cur_surface_boundaries; } - void find_surfaces_boundary_lines( + void find_surfaces_boundary_lines( std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const @@ -1259,7 +1258,7 @@ namespace RINGMesh // This vector registers for each line the index of the two incident // surfaces line_indicent_surfaces.resize( this->geomodel_.nb_lines() ); - index_t surface_counter{0}; + index_t surface_counter{ 0 }; while( std::count_if( line_indicent_surfaces.begin(), line_indicent_surfaces.end(), []( const LineIncidentSurfacePair& line ) { @@ -1269,88 +1268,94 @@ namespace RINGMesh { auto cur_surface_boundaries = get_surface_boundaries( surface_counter, line_indicent_surfaces ); - + surface_boundary_lines.emplace_back( std::move( cur_surface_boundaries ) ); ++surface_counter; - std::cout << " counter" << surface_counter << std::endl; - } + std::cout << " counter" << surface_counter << std::endl; + } } /*! * This function implements a geometric test to find the englobing * surface index for the current line - * @param line_id index of the current line, line_indicent_surfaces for each line , number of the found surfaces + * @param line_id index of the current line, line_indicent_surfaces for + * each line , number of the found surfaces * @return the englobing surface index * @note you may need other inputs. */ - /* Check that the found surface id is different from itself - */ + /* Check that the found surface id is different from itself + */ index_t find_englobing_surface( index_t line_id, - const std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, index_t nb_found_surfaces) - const + const std::vector< LineIncidentSurfacePair >& + line_indicent_surfaces, + index_t nb_found_surfaces ) const { - // implement geometrical test to detect the index of the surface - // that englobe the line - // create Line2D = tracer de rayon - + // implement geometrical test to detect the index of the surface + // that englobe the line + // create Line2D = tracer de rayon + const Line2D& line = geomodel_.line( line_id ); - Geometry::Line2D Ray_tracer{ { 0.5,0.7 }, line.vertex( 0 ) }; - - for(index_t surface_id = 0; surface_id < nb_found_surfaces; ++surface_id) - { - int intersection_count = 0; - std::set< index_t > boundaries_of_curr_surface = - get_line_boundary_indices( - line_indicent_surfaces, surface_id ); - - std::tuple< bool, vec2 > inter(false, {0,0}); - for( index_t id : boundaries_of_curr_surface ) - { - if (line_indicent_surfaces[id].plus_surface_index() - == line_indicent_surfaces[id].minus_surface_index()) - { - continue ; - } - - const Line2D& line_boundary = geomodel_.line( id ); - - for( index_t segment_id : - range( line_boundary.nb_mesh_elements() ) ) - { - const Geometry::Segment2D segment_of_line( - line_boundary.mesh_element_vertex( - { segment_id, 0 } ), - line_boundary.mesh_element_vertex( - { segment_id, 1 } ) ); - - inter = Intersection::segment_line( - segment_of_line, Ray_tracer ); - - vec2 inter_point = std::get< 1 >(inter); - vec2 vec_origin_point; - - vec_origin_point[0] = (inter_point[0] - line.vertex(0)[0]); - vec_origin_point[1] = (inter_point[1] - line.vertex(0)[1]); - - double vec_dir = dot(vec_origin_point, vec2( 0.5, 0.7 )); - - if (std::get< 0 >(inter) == true && vec_dir >0) - { - ++intersection_count; - } - } - } - - if( intersection_count % 2 != 0 ) - { - return surface_id; - } - } - + Geometry::Line2D Ray_tracer{ { 0.5, 0.7 }, line.vertex( 0 ) }; + + for( index_t surface_id = 0; surface_id < nb_found_surfaces; + ++surface_id ) + { + int intersection_count = 0; + std::set< index_t > boundaries_of_curr_surface = + get_line_boundary_indices( + line_indicent_surfaces, surface_id ); + + std::tuple< bool, vec2 > inter( false, { 0, 0 } ); + for( index_t id : boundaries_of_curr_surface ) + { + if( line_indicent_surfaces[id].plus_surface_index() + == line_indicent_surfaces[id].minus_surface_index() ) + { + continue; + } + + const Line2D& line_boundary = geomodel_.line( id ); + + for( index_t segment_id : + range( line_boundary.nb_mesh_elements() ) ) + { + const Geometry::Segment2D segment_of_line( + line_boundary.mesh_element_vertex( + { segment_id, 0 } ), + line_boundary.mesh_element_vertex( + { segment_id, 1 } ) ); + + inter = Intersection::segment_line( + segment_of_line, Ray_tracer ); + + vec2 inter_point = std::get< 1 >( inter ); + vec2 vec_origin_point; + + vec_origin_point[0] = + ( inter_point[0] - line.vertex( 0 )[0] ); + vec_origin_point[1] = + ( inter_point[1] - line.vertex( 0 )[1] ); + + double vec_dir = + dot( vec_origin_point, vec2( 0.5, 0.7 ) ); + + if( std::get< 0 >( inter ) == true && vec_dir > 0 ) + { + ++intersection_count; + } + } + } + + if( intersection_count % 2 != 0 ) + { + return surface_id; + } + } + return NO_ID; - } + } /*! * This function iterates on lines and manages internal boundaries. @@ -1364,50 +1369,55 @@ namespace RINGMesh std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, const index_t nb_found_surfaces ) const { - index_t count = 0; + index_t count = 0; std::vector< bool > are_surfaces_hole( nb_found_surfaces, true ); for( auto line_id : range( geomodel_.nb_lines() ) ) { if( line_indicent_surfaces[line_id].plus_surface_index() != line_indicent_surfaces[line_id].minus_surface_index() ) { - if (line_indicent_surfaces[line_id].plus_surface_index() != NO_ID){ - are_surfaces_hole[line_indicent_surfaces[line_id] - .plus_surface_index()] = false; - } - if (line_indicent_surfaces[line_id].minus_surface_index() != NO_ID){ - are_surfaces_hole[line_indicent_surfaces[line_id] - .minus_surface_index()] = false; - } + if( line_indicent_surfaces[line_id].plus_surface_index() + != NO_ID ) + { + are_surfaces_hole[line_indicent_surfaces[line_id] + .plus_surface_index()] = false; + } + if( line_indicent_surfaces[line_id].minus_surface_index() + != NO_ID ) + { + are_surfaces_hole[line_indicent_surfaces[line_id] + .minus_surface_index()] = false; + } } else { // if a line have the same minus and plus surface index this - // line is an internal boundary. + // line is an internal boundary. // find the englobing surface for the current line // implement the following function // reset the index of line incident surfaces to // englobing_surface_id - - index_t englobing_surface_id = find_englobing_surface( - line_id, line_indicent_surfaces, nb_found_surfaces); - - Logger::out("the line id is` ", line_id, - "the englobing surface is ", englobing_surface_id); - line_indicent_surfaces[line_id].set_side_surface_index( + index_t englobing_surface_id = find_englobing_surface( + line_id, line_indicent_surfaces, nb_found_surfaces ); + + Logger::out( "the line id is` ", line_id, + "the englobing surface is ", englobing_surface_id ); + + line_indicent_surfaces[line_id].set_side_surface_index( true, englobing_surface_id ); - line_indicent_surfaces[line_id].set_side_surface_index( - false, englobing_surface_id ); + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id ); } } - - return { static_cast< index_t >( std::count( - are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; + + return { static_cast< index_t >( std::count( + are_surfaces_hole.begin(), are_surfaces_hole.end(), true ) ) }; } /*! * This function finds all line boundary indices associated to a surface - * @param surface_id index of the current surface and line_indicent_surfaces of each line + * @param surface_id index of the current surface and + * line_indicent_surfaces of each line * @return a set of line index that are either the minus or the plus * boundary. */ @@ -1417,15 +1427,15 @@ namespace RINGMesh index_t surface_id ) const { std::set< index_t > line_boundary_indices; - for( auto line_id : range( geomodel_.nb_lines() ) ) + for( auto line_id : range( geomodel_.nb_lines() ) ) - { + { if( ( line_indicent_surfaces[line_id].plus_surface_index() == surface_id ) || ( line_indicent_surfaces[line_id].minus_surface_index() - == surface_id)) + == surface_id ) ) { - line_boundary_indices.emplace(line_id); + line_boundary_indices.emplace( line_id ); } } @@ -1455,179 +1465,191 @@ namespace RINGMesh // or minus side) //@param line_id, surface_id and line_indicent_surface - void reset_line_indicent_surfaces( - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - index_t line_id, - index_t surface_id, - index_t englobing_surface_id_for_upper_line) const - { - if (line_side(line_indicent_surfaces, surface_id, line_id) - == true) - { - line_indicent_surfaces[line_id].set_side_surface_index( - true, englobing_surface_id_for_upper_line); - } - else{ - - line_indicent_surfaces[line_id].set_side_surface_index( - false, englobing_surface_id_for_upper_line); - } - } - - - bool check_the_englobing_surface(std::set min, std::setmax, - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces) - { - for (auto i : min) { - if (std::find(max.begin(), max.end(), i) == max.end()){ - // Cur element of min is not in max - return false; - } - } - return true; - } - - void check_size( std::set line_boundaries, std::setupper_line_boundaries, - std::set &min,std::set& max) - { - - if (line_boundaries.size() < upper_line_boundaries.size()) - { - min = line_boundaries; - max = upper_line_boundaries; - } - - else - { - max = line_boundaries; - min = upper_line_boundaries; - } - } - + void reset_line_indicent_surfaces( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + index_t line_id, + index_t surface_id, + index_t englobing_surface_id_for_upper_line ) const + { + if( line_side( line_indicent_surfaces, surface_id, line_id ) + == true ) + { + line_indicent_surfaces[line_id].set_side_surface_index( + true, englobing_surface_id_for_upper_line ); + } + else + { + line_indicent_surfaces[line_id].set_side_surface_index( + false, englobing_surface_id_for_upper_line ); + } + } + + bool check_the_englobing_surface( std::set< index_t > min, + std::set< index_t > max, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces ) + { + for( auto i : min ) + { + if( std::find( max.begin(), max.end(), i ) == max.end() ) + { + // Cur element of min is not in max + return false; + } + } + return true; + } + + void check_size( std::set< index_t > line_boundaries, + std::set< index_t > upper_line_boundaries, + std::set< index_t >& min, + std::set< index_t >& max ) + { + if( line_boundaries.size() < upper_line_boundaries.size() ) + { + min = line_boundaries; + max = upper_line_boundaries; + } + + else + { + max = line_boundaries; + min = upper_line_boundaries; + } + } + // this function compare the two sets: // line_boundary_indices and upper_line_boundary_indices // if they are equal do: it find englobing_surface_index // for upper_line_boundary_indices - - void manage_intrusion_surface( - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, index_t nb_found_surfaces) - { - std::set min; - std::set max; - - for (index_t surface_id = 0; surface_id <= nb_found_surfaces; ++surface_id) - { - // iterate on every surfaces - std::set< index_t > line_boundary_indices = - get_line_boundary_indices( - line_indicent_surfaces, surface_id); - - for( index_t upper_surface_id = surface_id; - upper_surface_id <= nb_found_surfaces; - ++upper_surface_id ) - { - if (upper_surface_id == surface_id) - { - continue; - } - - // interates on every other surfaces - std::set< index_t > upper_line_boundary_indices = - get_line_boundary_indices( - line_indicent_surfaces, upper_surface_id ); - - check_size(line_boundary_indices, upper_line_boundary_indices, - min, max); - if (min.size() == 0) { - continue; - } - - if (check_the_englobing_surface(min, max, line_indicent_surfaces) == true) - - { - std::set< index_t >::iterator i; - - for (i = min.begin(); - i != min.end(); ++i) - { - if (line_indicent_surfaces[*i].plus_surface_index() == - line_indicent_surfaces[*i].minus_surface_index()) - { - continue ; - } - Logger::out(" S_id ", surface_id); - Logger::out(" US_id ", upper_surface_id); - Logger::out("try", line_indicent_surfaces[*i].plus_surface_index(), " ", - line_indicent_surfaces[*i].minus_surface_index()); - - index_t englobing_surface_id_for_upper_line = - find_englobing_surface( - *i, line_indicent_surfaces, nb_found_surfaces); - - Logger::out("englobing surface", englobing_surface_id_for_upper_line); - - if (englobing_surface_id_for_upper_line != NO_ID) - { - std::set< index_t >::iterator it; - for (it = min.begin(); - it != min.end(); ++it) - { - if (line_boundary_indices.size() < upper_line_boundary_indices.size()) { - reset_line_indicent_surfaces( - line_indicent_surfaces, *it, surface_id, - englobing_surface_id_for_upper_line); - } - else { - reset_line_indicent_surfaces( - line_indicent_surfaces, *it, upper_surface_id, - englobing_surface_id_for_upper_line); - } - } - break; - } - - } - - } - } - - } - + + void manage_intrusion_surface( + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + index_t nb_found_surfaces ) + { + std::set< index_t > min; + std::set< index_t > max; + + for( index_t surface_id = 0; surface_id <= nb_found_surfaces; + ++surface_id ) + { + // iterate on every surfaces + std::set< index_t > line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, surface_id ); + + for( index_t upper_surface_id = surface_id; + upper_surface_id <= nb_found_surfaces; ++upper_surface_id ) + { + if( upper_surface_id == surface_id ) + { + continue; + } + + // interates on every other surfaces + std::set< index_t > upper_line_boundary_indices = + get_line_boundary_indices( + line_indicent_surfaces, upper_surface_id ); + + check_size( line_boundary_indices, + upper_line_boundary_indices, min, max ); + if( min.size() == 0 ) + { + continue; + } + + if( check_the_englobing_surface( + min, max, line_indicent_surfaces ) + == true ) + + { + std::set< index_t >::iterator i; + + for( i = min.begin(); i != min.end(); ++i ) + { + if( line_indicent_surfaces[*i].plus_surface_index() + == line_indicent_surfaces[*i] + .minus_surface_index() ) + { + continue; + } + Logger::out( " S_id ", surface_id ); + Logger::out( " US_id ", upper_surface_id ); + Logger::out( "try", + line_indicent_surfaces[*i].plus_surface_index(), + " ", + line_indicent_surfaces[*i] + .minus_surface_index() ); + + index_t englobing_surface_id_for_upper_line = + find_englobing_surface( *i, + line_indicent_surfaces, nb_found_surfaces ); + + Logger::out( "englobing surface", + englobing_surface_id_for_upper_line ); + + if( englobing_surface_id_for_upper_line != NO_ID ) + { + std::set< index_t >::iterator it; + for( it = min.begin(); it != min.end(); ++it ) + { + if( line_boundary_indices.size() + < upper_line_boundary_indices.size() ) + { + reset_line_indicent_surfaces( + line_indicent_surfaces, *it, + surface_id, + englobing_surface_id_for_upper_line ); + } + else + { + reset_line_indicent_surfaces( + line_indicent_surfaces, *it, + upper_surface_id, + englobing_surface_id_for_upper_line ); + } + } + break; + } + } + } + } + } + return; } - - void check_internal_intrusion_or_boundaries( std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, - const index_t nb_found_surfaces ) + const index_t nb_found_surfaces ) { index_t nb_floating_set_of_lines = manage_internal_boundary( line_indicent_surfaces, nb_found_surfaces ); - + if( nb_floating_set_of_lines > 0 ) - { + { Logger::out( " During surface from corners ", " and lines build, ", nb_floating_set_of_lines, " group(s) of lines are " "floating inside a surface : These Internal Boundaries " "were taken into account !!! " ); - } + } - manage_intrusion_surface(line_indicent_surfaces, nb_found_surfaces); + manage_intrusion_surface( + line_indicent_surfaces, nb_found_surfaces ); } - std::vector< vec2 > get_surface_polygon_vertices( const std::vector< OrientedLine >& surface_boundaries ) const { std::vector< vec2 > polygon_vertices; - std::set< index_t > added_line_id; + std::set< index_t > added_line_id; for( auto cur_surf_boundary : surface_boundaries ) { - if (added_line_id.find(cur_surf_boundary.index) != added_line_id.end()) { - continue; - } + if( added_line_id.find( cur_surf_boundary.index ) + != added_line_id.end() ) + { + continue; + } const auto& cur_line = this->geomodel_.line( cur_surf_boundary.index ); for( auto vertex : range( 1, cur_line.nb_vertices() ) ) @@ -1637,7 +1659,7 @@ namespace RINGMesh ? vertex : ( cur_line.nb_vertices() - 1 ) - vertex ) ); } - added_line_id.insert(cur_surf_boundary.index); + added_line_id.insert( cur_surf_boundary.index ); } return polygon_vertices; } @@ -1648,10 +1670,10 @@ namespace RINGMesh { for( const auto& surface_boundaries : surface_boundary_lines ) { - std::vector< vec2 > polygon_vertices = + std::vector< vec2 > polygon_vertices = get_surface_polygon_vertices( surface_boundaries ); std::vector< index_t > polygon_corners( - polygon_vertices.size() ); + polygon_vertices.size() ); std::iota( polygon_corners.begin(), polygon_corners.end(), 0 ); auto surface_id = builder.topology.create_mesh_entity( surface_type_name_static() ); @@ -1663,50 +1685,69 @@ namespace RINGMesh } } - void remove_universe(std::vector< LineIncidentSurfacePair >& line_incident_surfaces, index_t nb_found_surfaces) - { - std::set< index_t > universe_candidates; - std::set< index_t > tmp_cand; - for (auto surface_id : range( nb_found_surfaces ) ) - { - - index_t first_line_id; - for (auto line_id : range(line_incident_surfaces.size())){ - if (line_incident_surfaces[line_id].plus_surface_index() == surface_id || line_incident_surfaces[line_id].minus_surface_index() == surface_id) { - first_line_id = line_id; - break; - } - } - index_t englobing_id = find_englobing_surface( - first_line_id, line_incident_surfaces, nb_found_surfaces); - - //if (englobing_id == NO_ID || englobing_id == surface_id ) { - if (englobing_id == NO_ID || tmp_cand.find(englobing_id) != tmp_cand.end()){ - universe_candidates.emplace(surface_id); - } - if (englobing_id == surface_id){ - tmp_cand.emplace(surface_id); - } - } - /* Check == 1 seems not good*/ - //if (universe_candidates.size() == 2 || universe_candidates.size() == 1) { - index_t universe_id = *universe_candidates.begin(); - for (auto line_id : range(line_incident_surfaces.size())){ - if (line_incident_surfaces[line_id].plus_surface_index() == universe_id){ - line_incident_surfaces[line_id].set_side_surface_index(true, NO_ID); - } if (line_incident_surfaces[line_id].minus_surface_index() == universe_id){ - line_incident_surfaces[line_id].set_side_surface_index(false, NO_ID); - } - } - /*} - else { - throw RINGMeshException("Universe", "Finding Universe in a model with several Surfaces not yet implemented..."); - }*/ - } - - /*Function to remove*/ + void remove_universe( + std::vector< LineIncidentSurfacePair >& line_incident_surfaces, + index_t nb_found_surfaces ) + { + std::set< index_t > universe_candidates; + std::set< index_t > tmp_cand; + for( auto surface_id : range( nb_found_surfaces ) ) + { + index_t first_line_id; + for( auto line_id : range( line_incident_surfaces.size() ) ) + { + if( line_incident_surfaces[line_id].plus_surface_index() + == surface_id + || line_incident_surfaces[line_id].minus_surface_index() + == surface_id ) + { + first_line_id = line_id; + break; + } + } + index_t englobing_id = find_englobing_surface( + first_line_id, line_incident_surfaces, nb_found_surfaces ); + + // if (englobing_id == NO_ID || englobing_id == surface_id ) { + if( englobing_id == NO_ID + || tmp_cand.find( englobing_id ) != tmp_cand.end() ) + { + universe_candidates.emplace( surface_id ); + } + if( englobing_id == surface_id ) + { + tmp_cand.emplace( surface_id ); + } + } + /* Check == 1 seems not good*/ + // if (universe_candidates.size() == 2 || universe_candidates.size() + // == 1) { + index_t universe_id = *universe_candidates.begin(); + for( auto line_id : range( line_incident_surfaces.size() ) ) + { + if( line_incident_surfaces[line_id].plus_surface_index() + == universe_id ) + { + line_incident_surfaces[line_id].set_side_surface_index( + true, NO_ID ); + } + if( line_incident_surfaces[line_id].minus_surface_index() + == universe_id ) + { + line_incident_surfaces[line_id].set_side_surface_index( + false, NO_ID ); + } + } + /*} + else { + throw RINGMeshException("Universe", "Finding Universe in a model + with several Surfaces not yet implemented..."); + }*/ + } + + /*Function to remove*/ void find_exterior_and_remove_it( GeoModelBuilder2D& builder, - std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, + std::vector< LineIncidentSurfacePair >& line_indicent_surfaces, std::vector< std::vector< OrientedLine > >& surface_boundary_lines ) const { @@ -1715,31 +1756,39 @@ namespace RINGMesh for( const auto& surface : geomodel_.surfaces() ) { double surface_area{ surface.size() }; - Logger::out("Universe", surface.index(), " ", surface_area, " ", surface.nb_boundaries(), " ", surface_boundary_lines[surface.index()].size()); + Logger::out( "Universe", surface.index(), " ", surface_area, + " ", surface.nb_boundaries(), " ", + surface_boundary_lines[surface.index()].size() ); if( surface_area > max_surface_area ) { max_surface_area = surface_area; exterior_surface_id = surface.index(); - } - } - - DEBUG(exterior_surface_id); - index_t count = 0; - std::set< index_t > other_candidates; - for (auto line : surface_boundary_lines[exterior_surface_id]) - { - index_t other_surface = line_indicent_surfaces[line.index].side_surface_index(!line.side); - if (other_surface != exterior_surface_id){ - other_candidates.emplace(other_surface); - } - } - DEBUG(other_candidates.size()); - if (other_candidates.size() == 1){ - if (surface_boundary_lines[*other_candidates.begin()].size() < surface_boundary_lines[exterior_surface_id].size()){ - exterior_surface_id = *other_candidates.begin(); - } - } - DEBUG(exterior_surface_id); + } + } + + DEBUG( exterior_surface_id ); + index_t count = 0; + std::set< index_t > other_candidates; + for( auto line : surface_boundary_lines[exterior_surface_id] ) + { + index_t other_surface = + line_indicent_surfaces[line.index].side_surface_index( + !line.side ); + if( other_surface != exterior_surface_id ) + { + other_candidates.emplace( other_surface ); + } + } + DEBUG( other_candidates.size() ); + if( other_candidates.size() == 1 ) + { + if( surface_boundary_lines[*other_candidates.begin()].size() + < surface_boundary_lines[exterior_surface_id].size() ) + { + exterior_surface_id = *other_candidates.begin(); + } + } + DEBUG( exterior_surface_id ); std::set< gmme_id > to_remove; to_remove.insert( { surface_type_name_static(), exterior_surface_id } ); @@ -1765,20 +1814,23 @@ namespace RINGMesh } } + /*std::vector< bool > check_kept_surface_ids(std::vector< + LineIncidentSurfacePair >& line_incident_surfaces ) + { + std::vector< bool > kept_surface_ids(index_t size, bool ); + for (auto id : range(line_incident_surfaces.size())) + { + std::cout << + "after " << id << " " << + line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() << + std::endl; - /*std::vector< bool > check_kept_surface_ids(std::vector< LineIncidentSurfacePair >& line_incident_surfaces ) - { - std::vector< bool > kept_surface_ids(index_t size, bool ); - for (auto id : range(line_incident_surfaces.size())) - { - std::cout << - "after " << id << " " << line_incident_surfaces[id].minus_surface_index() - << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; - - kept_surface_ids[line_incident_surfaces[id].plus_surface_index()] = true; - kept_surface_ids[line_incident_surfaces[id].minus_surface_index()] = true; - } - }*/ + kept_surface_ids[line_incident_surfaces[id].plus_surface_index()] = + true; kept_surface_ids[line_incident_surfaces[id].minus_surface_index()] + = true; + } + }*/ private: GeoModel2D& geomodel_; @@ -1797,20 +1849,21 @@ namespace RINGMesh geometry.cut_surfaces_by_internal_lines(); } - void GeoModelBuilder< 2 >::end_geomodel() - { - if (geomodel_.name().empty()) - { - info.set_geomodel_name("model_default_name"); - } + void GeoModelBuilder< 2 >::end_geomodel() + { + if( geomodel_.name().empty() ) + { + info.set_geomodel_name( "model_default_name" ); + } - if (geomodel_.nb_surfaces() == 0) { - build_surfaces_from_corners_and_lines(); - } + if( geomodel_.nb_surfaces() == 0 ) + { + build_surfaces_from_corners_and_lines(); + } - //cut_geomodel_on_internal_boundaries(); - print_geomodel(geomodel_); - } + // cut_geomodel_on_internal_boundaries(); + print_geomodel( geomodel_ ); + } void GeoModelBuilder< 2 >::build_surfaces_from_corners_and_lines() { @@ -1824,91 +1877,110 @@ namespace RINGMesh impl_->find_surfaces_boundary_lines( line_incident_surfaces, surface_boundary_lines ); - for (auto id : range (line_incident_surfaces.size())) { - std::cout << - "before "<< id<< " "<< line_incident_surfaces[id].minus_surface_index() - << " " << line_incident_surfaces[id].plus_surface_index() <remove_universe(line_incident_surfaces, - static_cast< index_t >(surface_boundary_lines.size())); - - for (auto id : range(line_incident_surfaces.size())) { - std::cout << - "universe " << id << " " << line_incident_surfaces[id].minus_surface_index() - << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; - } - + for( auto id : range( line_incident_surfaces.size() ) ) + { + std::cout << "before " << id << " " + << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() + << std::endl; + } + + impl_->remove_universe( line_incident_surfaces, + static_cast< index_t >( surface_boundary_lines.size() ) ); + + for( auto id : range( line_incident_surfaces.size() ) ) + { + std::cout << "universe " << id << " " + << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() + << std::endl; + } + impl_->check_internal_intrusion_or_boundaries( line_incident_surfaces, - static_cast< index_t >(surface_boundary_lines.size())); - - std::vector< bool > kept_surface_ids(surface_boundary_lines.size(), false); - for (auto id : range(line_incident_surfaces.size())) - { - std::cout << - "after " << id << " " << line_incident_surfaces[id].minus_surface_index() - << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; - - if (line_incident_surfaces[id].plus_surface_index() != NO_ID){ - kept_surface_ids[line_incident_surfaces[id].plus_surface_index()] = true; - } - if (line_incident_surfaces[id].minus_surface_index() != NO_ID){ - kept_surface_ids[line_incident_surfaces[id].minus_surface_index()] = true; - } - } - - // decalage - for (auto surf_id : range(surface_boundary_lines.size())) - { - auto nb_remove_surfaces_before = std::count(kept_surface_ids.begin(), kept_surface_ids.begin() + surf_id, false); - - for (auto id : range(line_incident_surfaces.size())) - { - if (line_incident_surfaces[id].plus_surface_index() == surf_id) - { - line_incident_surfaces[id].set_side_surface_index(true, - line_incident_surfaces[id].plus_surface_index()- nb_remove_surfaces_before); - } - if (line_incident_surfaces[id].minus_surface_index() == surf_id) - { - line_incident_surfaces[id].set_side_surface_index(false, - line_incident_surfaces[id].minus_surface_index() - nb_remove_surfaces_before); - } - } - } - - for (auto id : range(line_incident_surfaces.size())) - { - std::cout << - "after decalage " << id << " " << line_incident_surfaces[id].minus_surface_index() - << " " << line_incident_surfaces[id].plus_surface_index() << std::endl; - } - - // todo : in a single function - surface_boundary_lines.clear(); - auto nb_surfaces = std::count(kept_surface_ids.begin(), kept_surface_ids.end(), true); - for (auto surf_id : range(nb_surfaces)) - { - std::vector< Impl::OrientedLine > cur_surface_boundaries; - for (auto line_id : range(line_incident_surfaces.size())) - { - if (line_incident_surfaces[line_id].plus_surface_index() == surf_id) - { - cur_surface_boundaries.emplace_back(line_id, true); - } - if (line_incident_surfaces[line_id].minus_surface_index() == surf_id) - { - cur_surface_boundaries.emplace_back(line_id, false); - } - } - surface_boundary_lines.push_back(cur_surface_boundaries); - } - //system("pause"); + static_cast< index_t >( surface_boundary_lines.size() ) ); + std::vector< bool > kept_surface_ids( + surface_boundary_lines.size(), false ); + for( auto id : range( line_incident_surfaces.size() ) ) + { + std::cout << "after " << id << " " + << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() + << std::endl; + + if( line_incident_surfaces[id].plus_surface_index() != NO_ID ) + { + kept_surface_ids[line_incident_surfaces[id] + .plus_surface_index()] = true; + } + if( line_incident_surfaces[id].minus_surface_index() != NO_ID ) + { + kept_surface_ids[line_incident_surfaces[id] + .minus_surface_index()] = true; + } + } + + // decalage + for( auto surf_id : range( surface_boundary_lines.size() ) ) + { + auto nb_remove_surfaces_before = + std::count( kept_surface_ids.begin(), + kept_surface_ids.begin() + surf_id, false ); + + for( auto id : range( line_incident_surfaces.size() ) ) + { + if( line_incident_surfaces[id].plus_surface_index() == surf_id ) + { + line_incident_surfaces[id].set_side_surface_index( + true, line_incident_surfaces[id].plus_surface_index() + - nb_remove_surfaces_before ); + } + if( line_incident_surfaces[id].minus_surface_index() + == surf_id ) + { + line_incident_surfaces[id].set_side_surface_index( + false, line_incident_surfaces[id].minus_surface_index() + - nb_remove_surfaces_before ); + } + } + } + + for( auto id : range( line_incident_surfaces.size() ) ) + { + std::cout << "after decalage " << id << " " + << line_incident_surfaces[id].minus_surface_index() + << " " << line_incident_surfaces[id].plus_surface_index() + << std::endl; + } + + // todo : in a single function + surface_boundary_lines.clear(); + auto nb_surfaces = std::count( + kept_surface_ids.begin(), kept_surface_ids.end(), true ); + for( auto surf_id : range( nb_surfaces ) ) + { + std::vector< Impl::OrientedLine > cur_surface_boundaries; + for( auto line_id : range( line_incident_surfaces.size() ) ) + { + if( line_incident_surfaces[line_id].plus_surface_index() + == surf_id ) + { + cur_surface_boundaries.emplace_back( line_id, true ); + } + if( line_incident_surfaces[line_id].minus_surface_index() + == surf_id ) + { + cur_surface_boundaries.emplace_back( line_id, false ); + } + } + surface_boundary_lines.push_back( cur_surface_boundaries ); + } + // system("pause"); // Generate surface polygons impl_->build_surface_polygons( *this, surface_boundary_lines ); - //impl_->find_exterior_and_remove_it( *this,line_incident_surfaces, surface_boundary_lines ); + // impl_->find_exterior_and_remove_it( *this,line_incident_surfaces, + // surface_boundary_lines ); // Update topology impl_->set_surface_line_boundary_relationships( @@ -1927,16 +1999,16 @@ namespace RINGMesh geometry.cut_regions_by_internal_surfaces(); } - void GeoModelBuilder<3>::end_geomodel() - { - if (geomodel_.name().empty()) - { - info.set_geomodel_name("model_default_name"); - } + void GeoModelBuilder< 3 >::end_geomodel() + { + if( geomodel_.name().empty() ) + { + info.set_geomodel_name( "model_default_name" ); + } - cut_geomodel_on_internal_boundaries(); - print_geomodel(geomodel_); - } + cut_geomodel_on_internal_boundaries(); + print_geomodel( geomodel_ ); + } void GeoModelBuilder< 3 >::build_regions_from_lines_and_surfaces() { @@ -2055,8 +2127,6 @@ namespace RINGMesh remove.remove_mesh_entities( to_erase ); } - - template class geomodel_builder_api GeoModelBuilderBase< 2 >; template class geomodel_builder_api GeoModelBuilderInfo< 2 >; diff --git a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp index 9ad0bec6f..90bad2d3e 100644 --- a/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp +++ b/tests/geomodel/builder/test-build-2d-geomodel-with-internal-features.cpp @@ -92,7 +92,6 @@ void test_geomodel_2D_with_internal_features() GeoModel2D geomodel; geomodel_load( geomodel, ringmesh_test_data_path + "ModelA4_2d_nofracs.gm" ); - check_geomodel( geomodel ); } @@ -103,21 +102,20 @@ int main() { Logger::out( "TEST", "Import GeoModel files" ); test_geomodel_2D_with_internal_features(); - } catch( const RINGMeshException& e ) { Logger::err( e.category(), e.what() ); - system("pause"); + system( "pause" ); return 1; } catch( const std::exception& e ) { Logger::err( "Exception", e.what() ); - system("pause"); + system( "pause" ); return 1; } Logger::out( "TEST", "SUCCESS" ); - system("pause"); + system( "pause" ); return 0; }