Skip to content

Commit

Permalink
Merge pull request #119 from Geode-solutions/adding_block_inspection_…
Browse files Browse the repository at this point in the history
…bsurf_test

feat(BRepBlocksTopology): adding boundary surface inspection test
  • Loading branch information
MelchiorSchuh authored Nov 29, 2024
2 parents c86caaf + e60a7e8 commit 79b121c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/geode/inspector/topology/brep_blocks_topology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace geode
InspectionIssues< uuid > blocks_not_meshed{
"uuids of Blocks without mesh."
};
InspectionIssues< uuid > wrong_block_boundary_surface{
"uuids of surfaces boundary to a block when they should not."
};
InspectionIssuesMap< index_t > blocks_not_linked_to_a_unique_vertex{
"Blocks with mesh vertices not linked to a unique vertex"
};
Expand Down
74 changes: 74 additions & 0 deletions src/geode/inspector/topology/brep_blocks_topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,56 @@

namespace
{
std::vector< geode::uuid > block_boundary_surfaces(
const geode::BRep& brep, const geode::Block3D& block )
{
std::vector< geode::uuid > block_boundary_uuids;
block_boundary_uuids.reserve( brep.nb_boundaries( block.id() ) );
for( const auto& boundary_surface : brep.boundaries( block ) )
{
block_boundary_uuids.push_back( boundary_surface.id() );
}
return block_boundary_uuids;
}

bool is_line_incident_to_another_block_boundary_surface(
const geode::Line3D& line,
const geode::BRep& brep,
absl::Span< const geode::uuid > block_boundary_uuids,
const geode::uuid& boundary_surface_id )
{
for( const auto& incident_surface : brep.incidences( line ) )
{
if( incident_surface.id() == boundary_surface_id )
{
continue;
}
if( absl::c_find( block_boundary_uuids, incident_surface.id() )
!= block_boundary_uuids.end() )
{
return true;
}
}
return false;
}

bool surface_should_not_be_boundary_to_block( const geode::uuid& bsurf_uuid,
const geode::BRep& brep,
const std::vector< geode::uuid >& block_boundary_uuids )
{
const auto& surface = brep.surface( bsurf_uuid );
for( const auto& line : brep.boundaries( surface ) )
{
if( is_line_incident_to_another_block_boundary_surface(
line, brep, block_boundary_uuids, bsurf_uuid ) )
{
continue;
}
return true;
}
return false;
}

template < typename Condition >
geode::index_t count_cmvs(
absl::Span< const geode::ComponentMeshVertex > cmvs,
Expand All @@ -66,6 +116,11 @@ namespace geode
std::string BRepBlocksTopologyInspectionResult::string() const
{
std::string message;
if( wrong_block_boundary_surface.nb_issues() != 0 )
{
absl::StrAppend(
&message, wrong_block_boundary_surface.string(), "\n" );
}
if( blocks_not_meshed.nb_issues() != 0 )
{
absl::StrAppend( &message, blocks_not_meshed.string(), "\n" );
Expand Down Expand Up @@ -371,6 +426,25 @@ namespace geode
.add_issue( unique_vertex_id, problem_message.value() );
}
}
for( const auto& block : brep_.blocks() )
{
const auto block_boundary_uuids =
block_boundary_surfaces( brep_, block );
for( const auto& bsurf_uuid : block_boundary_uuids )
{
if( surface_should_not_be_boundary_to_block(
bsurf_uuid, brep_, block_boundary_uuids ) )
{
result.wrong_block_boundary_surface.add_issue( bsurf_uuid,
absl::StrCat( "Surface ", bsurf_uuid.string(),
" should not be boundary of Block ",
block.id().string(),
" : it has a boundary line not incident to any "
"other block "
"boundary surface." ) );
}
}
}
return result;
}
} // namespace geode
Binary file added tests/data/wrong_boundary_surface_model.og_brep
Binary file not shown.
29 changes: 29 additions & 0 deletions tests/inspector/test-brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,34 @@ void check_model_D( bool string )
nb_component_meshes_issues, " meshes problems instead of 0." );
}

void check_wrong_bsurfaces_model()
{
const auto model_brep = geode::load_brep( absl::StrCat(
geode::DATA_PATH, "wrong_boundary_surface_model.og_brep" ) );
const geode::BRepInspector brep_inspector{ model_brep };
const auto result = brep_inspector.inspect_brep();
OPENGEODE_EXCEPTION(
result.topology.blocks.wrong_block_boundary_surface.nb_issues() == 3,
absl::StrCat(
"[Test] Wrong number of wrong block boundary surfaces detected: "
"should be 3, and it is ",
result.topology.blocks.wrong_block_boundary_surface.nb_issues(),
"." ) );
std::vector< geode::uuid > wrong_bsurf{
geode::uuid{ "00000000-78d4-4e10-8000-0000cb3a3a27" },
geode::uuid{ "00000000-7a4e-4a1c-8000-00003732de1f" },
geode::uuid{ "00000000-980f-49d4-8000-00002f79374e" }
};
for( const auto& issue :
result.topology.blocks.wrong_block_boundary_surface.issues() )
{
OPENGEODE_EXCEPTION(
absl::c_find( wrong_bsurf, issue ) != wrong_bsurf.end(),
"[Test] Surface (", issue.string(),
") is detected as a wrong boundary surface but is not one." );
}
}

int main()
{
try
Expand All @@ -396,6 +424,7 @@ int main()
check_model_a1_valid( false );
check_model_mss( false );
check_model_D( false );
check_wrong_bsurfaces_model();
geode::Logger::info( "TEST SUCCESS" );
return 0;
}
Expand Down

0 comments on commit 79b121c

Please sign in to comment.