2525
2626#include < absl/container/flat_hash_set.h>
2727
28+ #include < geode/basic/logger.hpp>
29+
2830#include < geode/geometry/point.hpp>
2931
3032#include < geode/mesh/core/solid_mesh.hpp>
@@ -53,19 +55,24 @@ namespace
5355 return counter;
5456 }
5557
56- bool line_is_on_block_boundary ( const geode::BRep& brep,
58+ geode:: index_t line_on_block_boundary_count ( const geode::BRep& brep,
5759 const geode::Line3D& line,
5860 const geode::Block3D& block )
5961 {
62+ geode::index_t counter{ 0 };
6063 for ( const auto & boundary_surface : brep.boundaries ( block ) )
6164 {
62- if ( brep.is_boundary ( line, boundary_surface )
63- || brep.is_internal ( line, boundary_surface ) )
65+ if ( brep.is_boundary ( line, boundary_surface ) )
66+ {
67+ counter++;
68+ }
69+ if ( brep.is_internal ( line, boundary_surface ) )
6470 {
65- return true ;
71+ counter += 2 ;
6672 }
6773 }
68- return false ;
74+ counter /= 2 ;
75+ return counter;
6976 }
7077
7178 bool line_is_inside_block ( const geode::BRep& brep,
@@ -109,6 +116,8 @@ namespace
109116 }
110117 }
111118 geode::index_t nb_line_on_boundary_cmvs{ 0 };
119+ geode::index_t nb_lines_on_several_boundaries{ 0 };
120+ geode::index_t nb_additional_corners_count{ 0 };
112121 geode::index_t nb_line_internal_to_internal_surface_cmvs{ 0 };
113122 geode::index_t nb_free_line_cmvs{ 0 };
114123 geode::index_t nb_line_boundary_to_several_internal_surfaces_cmvs{ 0 };
@@ -119,9 +128,16 @@ namespace
119128 {
120129 continue ;
121130 }
122- if ( line_is_on_block_boundary ( brep, cmv_line, block ) )
131+ const auto boundary_count =
132+ line_on_block_boundary_count ( brep, cmv_line, block );
133+ if ( boundary_count > 0 )
123134 {
124- nb_line_on_boundary_cmvs++;
135+ nb_line_on_boundary_cmvs += boundary_count;
136+ if ( boundary_count > 1 )
137+ {
138+ nb_lines_on_several_boundaries++;
139+ nb_additional_corners_count += boundary_count - 1 ;
140+ }
125141 continue ;
126142 }
127143 if ( brep.nb_embedding_surfaces ( cmv_line ) > 0 )
@@ -162,6 +178,27 @@ namespace
162178 if ( nb_line_cmvs_to_remove != 0 || nb_line_on_boundary_cmvs != 0 )
163179 {
164180 predicted_nb_block_cmvs += unique_vertex_cmvs.corner_cmvs .size ();
181+ predicted_nb_block_cmvs += nb_additional_corners_count / 2 ;
182+ }
183+ if ( nb_lines_on_several_boundaries % 2 == 1 )
184+ {
185+ // / On one side of a topological non-manifold => 2 cases possible,
186+ // / depending on wether the topological non-manifold is on the
187+ // / interior or exterior of the block
188+ geode::Logger::warn ( absl::StrCat (
189+ " [expected_block_cmvs_and_error] Unique vertex " ,
190+ unique_vertex_id, " at position [" ,
191+ brep.block ( unique_vertex_cmvs.block_cmvs [0 ].component_id .id () )
192+ .mesh ()
193+ .point ( unique_vertex_cmvs.block_cmvs [0 ].vertex )
194+ .string (),
195+ " ] is on a topological non-manifold, which makes the correct "
196+ " number of block cmvs unsure." ) );
197+ if ( nb_block_cmvs
198+ == predicted_nb_block_cmvs + nb_lines_on_several_boundaries )
199+ {
200+ return std::make_pair ( nb_block_cmvs, std::nullopt );
201+ }
165202 }
166203 return std::make_pair ( predicted_nb_block_cmvs,
167204 nb_block_cmvs == predicted_nb_block_cmvs
@@ -187,9 +224,9 @@ namespace
187224 nb_boundary_surface_cmvs,
188225 " cmvs of surfaces boundary to the block, and " ,
189226 nb_line_on_boundary_cmvs,
190- " cmvs of lines on the boundary, with " , nb_block_cmvs ,
191- " Block CMVs (expected " , predicted_nb_block_cmvs ,
192- " ) with valid topology." ) ) );
227+ " cmvs counted for lines on the boundary, with " ,
228+ nb_block_cmvs, " Block CMVs (expected " ,
229+ predicted_nb_block_cmvs, " with valid topology) ." ) ) );
193230 }
194231} // namespace
195232
0 commit comments