Skip to content

Commit 32b7ee6

Browse files
Merge pull request #141 from Geode-solutions/fix/add_check_on_component_mesh_edges
fix(topology): Added check on model component edges and polygons.
2 parents 9b99c0b + f676b38 commit 32b7ee6

File tree

5 files changed

+192
-50
lines changed

5 files changed

+192
-50
lines changed

include/geode/inspector/topology/brep_lines_topology.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ namespace geode
6868
"Indices of unique vertices linked to several Lines but not "
6969
"linked to a Corner."
7070
};
71+
InspectionIssuesMap< index_t >
72+
line_edges_with_wrong_component_edges_around{
73+
"Indices of line edges with wrong component edges around"
74+
};
7175

7276
[[nodiscard]] index_t nb_issues() const;
7377

@@ -118,6 +122,10 @@ namespace geode
118122
vertex_has_lines_but_is_not_a_corner(
119123
index_t unique_vertex_index ) const;
120124

125+
[[nodiscard]] std::optional< std::string >
126+
line_edge_has_wrong_component_edges_around(
127+
const Line3D& line, const index_t edge_index ) const;
128+
121129
[[nodiscard]] BRepLinesTopologyInspectionResult
122130
inspect_lines_topology() const;
123131

include/geode/inspector/topology/brep_surfaces_topology.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ namespace geode
6262
"Indices of unique vertices linked to a Line but not linked to "
6363
"a Surface border."
6464
};
65+
InspectionIssuesMap< index_t >
66+
surface_polygons_with_wrong_component_facets_around{
67+
"Indices of surface polygons with wrong component facets around"
68+
};
6569

6670
[[nodiscard]] index_t nb_issues() const;
6771

@@ -114,6 +118,10 @@ namespace geode
114118
vertex_is_part_of_line_and_not_on_surface_border(
115119
index_t unique_vertex_index ) const;
116120

121+
[[nodiscard]] std::optional< std::string >
122+
surface_facet_has_wrong_component_facets_around(
123+
const Surface3D& line, const index_t facet_index ) const;
124+
117125
[[nodiscard]] BRepSurfacesTopologyInspectionResult
118126
inspect_surfaces_topology() const;
119127

src/geode/inspector/topology/brep_blocks_topology.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <geode/mesh/core/solid_mesh.hpp>
4141
#include <geode/mesh/core/surface_edges.hpp>
4242

43-
#include <geode/model/helpers/component_mesh_edges.hpp>
4443
#include <geode/model/helpers/ray_tracing.hpp>
4544
#include <geode/model/mixin/core/block.hpp>
4645
#include <geode/model/mixin/core/corner.hpp>
@@ -944,7 +943,7 @@ namespace geode
944943
}
945944
for( const auto& block : brep_.blocks() )
946945
{
947-
if( brep_.block( block.id() ).mesh().nb_vertices() != 0 )
946+
if( block_is_meshed( brep_.block( block.id() ) ) )
948947
{
949948
meshed_blocks.push_back( block.id() );
950949
}

src/geode/inspector/topology/brep_lines_topology.cpp

Lines changed: 111 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -298,60 +298,52 @@ namespace geode
298298
}
299299
const auto cme = geode::component_mesh_edges(
300300
brep_, brep_.line( cmv.component_id.id() ), 0 );
301-
if( brep_.nb_incidences( cmv.component_id.id() ) >= 1 )
301+
for( const auto& incident_surface :
302+
brep_.incidences( brep_.line( cmv.component_id.id() ) ) )
302303
{
303-
for( const auto& incident_surface :
304-
brep_.incidences( brep_.line( cmv.component_id.id() ) ) )
304+
if( !cme.surface_edges.contains( incident_surface.id() ) )
305305
{
306-
if( !cme.surface_edges.contains( incident_surface.id() ) )
307-
{
308-
return absl::StrCat( "Unique vertex with index ",
309-
unique_vertex_index, " is part of line with uuid '",
310-
cmv.component_id.id().string(),
311-
"', which should be boundary of "
312-
"surface with uuid '",
313-
incident_surface.id().string() );
314-
}
315-
const auto& surface_edges =
316-
cme.surface_edges.at( incident_surface.id() );
317-
if( surface_edges.size() != 1 )
318-
{
319-
return absl::StrCat( "Unique vertex with index ",
320-
unique_vertex_index, " is part of line with uuid '",
321-
cmv.component_id.id().string(),
322-
"', which should not be boundary of "
323-
"surface with uuid '",
324-
incident_surface.id().string() );
325-
}
306+
return absl::StrCat( "Unique vertex with index ",
307+
unique_vertex_index, " is part of line with uuid '",
308+
cmv.component_id.id().string(),
309+
"', which should be boundary of "
310+
"surface with uuid '",
311+
incident_surface.id().string() );
312+
}
313+
const auto& surface_edges =
314+
cme.surface_edges.at( incident_surface.id() );
315+
if( surface_edges.size() != 1 )
316+
{
317+
return absl::StrCat( "Unique vertex with index ",
318+
unique_vertex_index, " is part of line with uuid '",
319+
cmv.component_id.id().string(),
320+
"', which should not be boundary of "
321+
"surface with uuid '",
322+
incident_surface.id().string() );
326323
}
327324
}
328-
if( brep_.nb_embedding_surfaces(
329-
brep_.line( cmv.component_id.id() ) )
330-
>= 1 )
325+
for( const auto& embedding_surface : brep_.embedding_surfaces(
326+
brep_.line( cmv.component_id.id() ) ) )
331327
{
332-
for( const auto& embedding_surface : brep_.embedding_surfaces(
333-
brep_.line( cmv.component_id.id() ) ) )
328+
if( !cme.surface_edges.contains( embedding_surface.id() ) )
334329
{
335-
if( !cme.surface_edges.contains( embedding_surface.id() ) )
336-
{
337-
return absl::StrCat( "Unique vertex with index ",
338-
unique_vertex_index, " is part of line with uuid '",
339-
cmv.component_id.id().string(),
340-
"', which should not be embedded in "
341-
"surface with uuid '",
342-
embedding_surface.id().string() );
343-
}
344-
const auto& surface_edges =
345-
cme.surface_edges.at( embedding_surface.id() );
346-
if( surface_edges.size() <= 1 )
347-
{
348-
return absl::StrCat( "Unique vertex with index ",
349-
unique_vertex_index, " is part of line with uuid '",
350-
cmv.component_id.id().string(),
351-
"', which should not be embedded in "
352-
"surface with uuid '",
353-
embedding_surface.id().string() );
354-
}
330+
return absl::StrCat( "Unique vertex with index ",
331+
unique_vertex_index, " is part of line with uuid '",
332+
cmv.component_id.id().string(),
333+
"', which should not be embedded in "
334+
"surface with uuid '",
335+
embedding_surface.id().string() );
336+
}
337+
const auto& surface_edges =
338+
cme.surface_edges.at( embedding_surface.id() );
339+
if( surface_edges.size() <= 1 )
340+
{
341+
return absl::StrCat( "Unique vertex with index ",
342+
unique_vertex_index, " is part of line with uuid '",
343+
cmv.component_id.id().string(),
344+
"', which should not be embedded in "
345+
"surface with uuid '",
346+
embedding_surface.id().string() );
355347
}
356348
}
357349
if( brep_.nb_incidences( cmv.component_id.id() ) < 1
@@ -404,6 +396,59 @@ namespace geode
404396
return std::nullopt;
405397
}
406398

399+
std::optional< std::string >
400+
BRepLinesTopology::line_edge_has_wrong_component_edges_around(
401+
const Line3D& line, const index_t edge_index ) const
402+
{
403+
const auto cme = component_mesh_edges( brep_, line, edge_index );
404+
for( const auto& [surface_id, surface_edges] : cme.surface_edges )
405+
{
406+
if( brep_.is_boundary( line, brep_.surface( surface_id ) ) )
407+
{
408+
if( surface_edges.size() != 1 )
409+
{
410+
return absl::StrCat( "Line with uuid '", line.id().string(),
411+
"' is boundary of surface with uuid '",
412+
surface_id.string(), "', but has ",
413+
surface_edges.size(),
414+
" edges of this surface around it, it should be 1." );
415+
}
416+
continue;
417+
}
418+
if( brep_.is_internal( line, brep_.surface( surface_id ) ) )
419+
{
420+
if( surface_edges.size() != 2 )
421+
{
422+
return absl::StrCat( "Line with uuid '", line.id().string(),
423+
"' is internal to surface with uuid '",
424+
surface_id.string(), "', but has ",
425+
surface_edges.size(),
426+
" edges of this surface around it, it should be 2." );
427+
}
428+
continue;
429+
}
430+
return absl::StrCat( "Line with uuid '", line.id().string(),
431+
"' has edge with id ", edge_index,
432+
" in common with surface with uuid '", surface_id.string(),
433+
"', but is neither boundary of nor internal to it." );
434+
}
435+
for( const auto& [block_id, block_edges] : cme.block_edges )
436+
{
437+
if( brep_.is_internal( line, brep_.block( block_id ) ) )
438+
{
439+
if( block_edges.size() != 1 )
440+
{
441+
return absl::StrCat( "Line with uuid '", line.id().string(),
442+
"' is internal to block with uuid '", block_id.string(),
443+
"', but has ", block_edges.size(),
444+
" edges of this surface around it, it should be 1." );
445+
}
446+
continue;
447+
}
448+
}
449+
return std::nullopt;
450+
}
451+
407452
BRepLinesTopologyInspectionResult
408453
BRepLinesTopology::inspect_lines_topology() const
409454
{
@@ -427,6 +472,24 @@ namespace geode
427472
result.lines_not_linked_to_a_unique_vertex.add_issues_to_map(
428473
line.id(), std::move( line_result ) );
429474
}
475+
InspectionIssues< index_t > line_edges_with_wrong_cme{ absl::StrCat(
476+
"Line ", line.id().string() ) };
477+
for( const auto edge_id : Range{ line.mesh().nb_edges() } )
478+
{
479+
if( const auto problem_message =
480+
line_edge_has_wrong_component_edges_around(
481+
line, edge_id ) )
482+
{
483+
line_edges_with_wrong_cme.add_issue(
484+
edge_id, problem_message.value() );
485+
}
486+
}
487+
if( line_edges_with_wrong_cme.nb_issues() != 0 )
488+
{
489+
result.line_edges_with_wrong_component_edges_around
490+
.add_issues_to_map(
491+
line.id(), std::move( line_edges_with_wrong_cme ) );
492+
}
430493
}
431494
for( const auto unique_vertex_id : Range{ brep_.nb_unique_vertices() } )
432495
{

src/geode/inspector/topology/brep_surfaces_topology.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <geode/mesh/core/surface_mesh.hpp>
3535

36+
#include <geode/model/helpers/component_mesh_polygons.hpp>
3637
#include <geode/model/mixin/core/block.hpp>
3738
#include <geode/model/mixin/core/corner.hpp>
3839
#include <geode/model/mixin/core/line.hpp>
@@ -325,10 +326,50 @@ namespace geode
325326
return std::nullopt;
326327
}
327328

329+
std::optional< std::string >
330+
BRepSurfacesTopology::surface_facet_has_wrong_component_facets_around(
331+
const Surface3D& surface, const index_t facet_index ) const
332+
{
333+
const auto cmp = component_mesh_polygons( brep_, surface, facet_index );
334+
for( const auto& [block_id, block_facets] : cmp.block_polygons )
335+
{
336+
if( brep_.is_boundary( surface, brep_.block( block_id ) ) )
337+
{
338+
if( block_facets.size() != 1 )
339+
{
340+
return absl::StrCat( "Surface with uuid '",
341+
surface.id().string(),
342+
"' is boundary of block with uuid '", block_id.string(),
343+
"', but has ", block_facets.size(),
344+
" facets of this block around it, it should be 1." );
345+
}
346+
continue;
347+
}
348+
if( brep_.is_internal( surface, brep_.block( block_id ) ) )
349+
{
350+
if( block_facets.size() != 2 )
351+
{
352+
return absl::StrCat( "Surface with uuid '",
353+
surface.id().string(),
354+
"' is internal to block with uuid '", block_id.string(),
355+
"', but has ", block_facets.size(),
356+
" facets of this block around it, it should be 2." );
357+
}
358+
continue;
359+
}
360+
return absl::StrCat( "Surface with uuid '", surface.id().string(),
361+
"' has facet with id ", facet_index,
362+
" in common with block with uuid '", block_id.string(),
363+
"', but is neither boundary of nor internal to it." );
364+
}
365+
return std::nullopt;
366+
}
367+
328368
BRepSurfacesTopologyInspectionResult
329369
BRepSurfacesTopology::inspect_surfaces_topology() const
330370
{
331371
BRepSurfacesTopologyInspectionResult result;
372+
const auto meshed_blocks = internal::brep_blocks_are_meshed( brep_ );
332373
for( const auto& surface : brep_.surfaces() )
333374
{
334375
if( !surface_is_meshed( brep_.surface( surface.id() ) ) )
@@ -348,6 +389,29 @@ namespace geode
348389
result.surfaces_not_linked_to_a_unique_vertex.add_issues_to_map(
349390
surface.id(), std::move( surface_result ) );
350391
}
392+
if( !meshed_blocks )
393+
{
394+
continue;
395+
}
396+
InspectionIssues< index_t > surface_facets_with_wrong_cme{
397+
absl::StrCat( "Surface ", surface.id().string() )
398+
};
399+
for( const auto facet_id : Range{ surface.mesh().nb_polygons() } )
400+
{
401+
if( const auto problem_message =
402+
surface_facet_has_wrong_component_facets_around(
403+
surface, facet_id ) )
404+
{
405+
surface_facets_with_wrong_cme.add_issue(
406+
facet_id, problem_message.value() );
407+
}
408+
}
409+
if( surface_facets_with_wrong_cme.nb_issues() != 0 )
410+
{
411+
result.surface_polygons_with_wrong_component_facets_around
412+
.add_issues_to_map( surface.id(),
413+
std::move( surface_facets_with_wrong_cme ) );
414+
}
351415
}
352416
for( const auto unique_vertex_id : Range{ brep_.nb_unique_vertices() } )
353417
{

0 commit comments

Comments
 (0)