@@ -156,16 +156,57 @@ namespace
156156 const geode::BRep& brep )
157157 {
158158 std::vector< geode::uuid > not_boundaries_surfaces;
159- auto graph = geode::Graph::create ();
160- auto graph_builder = geode::GraphBuilder::create ( *graph );
161159 geode::GenericMapping< geode::uuid, geode::index_t >
162160 surface_uuids_to_graph_edges;
163161 geode::BijectiveMapping< geode::uuid, geode::index_t >
164162 line_uuids_to_graph_vertices;
163+ auto graph = geode::Graph::create ();
164+ auto graph_builder = geode::GraphBuilder::create ( *graph );
165+ build_surface_line_graph ( brep, *graph, *graph_builder,
166+ surface_uuids_to_graph_edges, line_uuids_to_graph_vertices );
167+ bool found_not_boundary_surface{ true };
168+ while ( found_not_boundary_surface )
169+ {
170+ const auto to_delete = find_graph_surfaces_to_delete (
171+ *graph, surface_uuids_to_graph_edges, not_boundaries_surfaces );
172+ if ( !absl::c_contains ( to_delete, true ) )
173+ {
174+ found_not_boundary_surface = false ;
175+ continue ;
176+ }
177+ const auto old2new = graph_builder->delete_edges ( to_delete );
178+ geode::GenericMapping< geode::uuid, geode::index_t >
179+ new_surface_uuids_to_graph_edges;
180+ for ( const auto & [surface_id, graph_edges] :
181+ surface_uuids_to_graph_edges.in2out_map () )
182+ {
183+ for ( const auto graph_edge : graph_edges )
184+ {
185+ if ( old2new.at ( graph_edge ) != geode::NO_ID )
186+ {
187+ new_surface_uuids_to_graph_edges.map (
188+ surface_id, old2new.at ( graph_edge ) );
189+ }
190+ }
191+ }
192+ surface_uuids_to_graph_edges = new_surface_uuids_to_graph_edges;
193+ graph_builder->delete_isolated_vertices ();
194+ }
195+ return not_boundaries_surfaces;
196+ }
197+
198+ void build_surface_line_graph ( const geode::BRep& brep,
199+ geode::Graph& graph,
200+ geode::GraphBuilder& graph_builder,
201+ geode::GenericMapping< geode::uuid, geode::index_t >&
202+ surface_uuids_to_graph_edges,
203+ geode::BijectiveMapping< geode::uuid, geode::index_t >&
204+ line_uuids_to_graph_vertices )
205+ {
165206 for ( const auto & line : brep.lines () )
166207 {
167208 line_uuids_to_graph_vertices.map (
168- line.id (), graph_builder-> create_vertex () );
209+ line.id (), graph_builder. create_vertex () );
169210 }
170211 for ( const auto & line : brep.lines () )
171212 {
@@ -179,7 +220,7 @@ namespace
179220 const auto boundary_line_vertex =
180221 line_uuids_to_graph_vertices.in2out (
181222 boundary_line.id () );
182- if ( const auto existing_edge = graph-> edge_from_vertices (
223+ if ( const auto existing_edge = graph. edge_from_vertices (
183224 boundary_line_vertex, line_vertex ) )
184225 {
185226 if ( surface_uuids_to_graph_edges
@@ -191,80 +232,60 @@ namespace
191232 }
192233 }
193234 surface_uuids_to_graph_edges.map ( incident_surface.id (),
194- graph_builder-> create_edge (
235+ graph_builder. create_edge (
195236 boundary_line_vertex, line_vertex ) );
196237 }
197238 }
198239 }
199- bool found_not_boundary_surface{ true };
200- while ( found_not_boundary_surface )
240+ }
241+
242+ std::vector< bool > find_graph_surfaces_to_delete (
243+ const geode::Graph& graph,
244+ const geode::GenericMapping< geode::uuid, geode::index_t >&
245+ surface_uuids_to_graph_edges,
246+ std::vector< geode::uuid > not_boundaries_surfaces )
247+ {
248+ std::vector< bool > to_delete ( graph.nb_edges (), false );
249+ for ( const auto graph_vertex : geode::Range{ graph.nb_vertices () } )
201250 {
202- std::vector< bool > to_delete ( graph->nb_edges (), false );
203- for ( const auto graph_vertex :
204- geode::Range{ graph->nb_vertices () } )
251+ if ( graph.edges_around_vertex ( graph_vertex ).empty () )
205252 {
206- if ( graph->edges_around_vertex ( graph_vertex ).empty () )
207- {
208- continue ;
209- }
210- const auto surface_id =
211- surface_uuids_to_graph_edges
212- .out2in ( graph->edges_around_vertex ( graph_vertex )
213- .at ( 0 )
214- .edge_id )
215- .at ( 0 );
216- bool should_delete{ true };
217- for ( const auto & edge_around :
218- graph->edges_around_vertex ( graph_vertex ) )
219- {
220- if ( surface_uuids_to_graph_edges
221- .out2in ( edge_around.edge_id )
253+ continue ;
254+ }
255+ const auto surface_id =
256+ surface_uuids_to_graph_edges
257+ .out2in ( graph.edges_around_vertex ( graph_vertex )
222258 .at ( 0 )
223- != surface_id )
224- {
225- should_delete = false ;
226- break ;
227- }
228- }
229- if ( !should_delete )
230- {
231- continue ;
232- }
233- if ( absl::c_contains ( not_boundaries_surfaces, surface_id ) )
234- {
235- continue ;
236- }
237- for ( const auto & edge :
238- surface_uuids_to_graph_edges.in2out ( surface_id ) )
259+ .edge_id )
260+ .at ( 0 );
261+ bool should_delete{ true };
262+ for ( const auto & edge_around :
263+ graph.edges_around_vertex ( graph_vertex ) )
264+ {
265+ if ( surface_uuids_to_graph_edges.out2in ( edge_around.edge_id )
266+ .at ( 0 )
267+ != surface_id )
239268 {
240- to_delete[edge] = true ;
269+ should_delete = false ;
270+ break ;
241271 }
242- not_boundaries_surfaces.push_back ( surface_id );
243272 }
244- if ( !absl::c_contains ( to_delete, true ) )
273+ if ( !should_delete )
245274 {
246- found_not_boundary_surface = false ;
247275 continue ;
248276 }
249- const auto old2new = graph_builder->delete_edges ( to_delete );
250- geode::GenericMapping< geode::uuid, geode::index_t >
251- new_surface_uuids_to_graph_edges;
252- for ( const auto & [surface_id, graph_edges] :
253- surface_uuids_to_graph_edges.in2out_map () )
277+ if ( absl::c_contains ( not_boundaries_surfaces, surface_id ) )
254278 {
255- for ( const auto graph_edge : graph_edges )
256- {
257- if ( old2new.at ( graph_edge ) != geode::NO_ID )
258- {
259- new_surface_uuids_to_graph_edges.map (
260- surface_id, old2new.at ( graph_edge ) );
261- }
262- }
279+ continue ;
263280 }
264- surface_uuids_to_graph_edges = new_surface_uuids_to_graph_edges;
265- graph_builder->delete_isolated_vertices ();
281+ for ( const auto & edge :
282+ surface_uuids_to_graph_edges.in2out ( surface_id ) )
283+ {
284+ to_delete[edge] = true ;
285+ }
286+ not_boundaries_surfaces.push_back ( surface_id );
266287 }
267- return not_boundaries_surfaces ;
288+ return to_delete ;
268289 }
269290
270291 bool verify_blocks_boundaries (
0 commit comments