Skip to content

Commit 79ef9d0

Browse files
fix(BRepTopologyInspector): added executable to inspect BRep model. (#12)
1 parent 1fc764c commit 79ef9d0

File tree

5 files changed

+326
-4
lines changed

5 files changed

+326
-4
lines changed

include/geode/inspector/topology/brep_topology.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ namespace geode
5353

5454
bool brep_components_are_linked_to_a_unique_vertex() const;
5555

56+
index_t nb_corners_not_linked_to_a_unique_vertex() const;
57+
58+
index_t nb_lines_not_linked_to_a_unique_vertex() const;
59+
60+
index_t nb_surfaces_not_linked_to_a_unique_vertex() const;
61+
62+
index_t nb_blocks_not_linked_to_a_unique_vertex() const;
63+
5664
std::vector< index_t >
5765
invalid_components_topology_unique_vertices() const;
5866

src/bin/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ add_geode_binary(
2929
OpenGeode::mesh
3030
OpenGeode-IO::mesh
3131
${PROJECT_NAME}::inspector
32+
)
33+
34+
add_geode_binary(
35+
SOURCE "geode-inspector-brep-topology.cpp"
36+
DEPENDENCIES
37+
Async++
38+
absl::flags
39+
absl::flags_parse
40+
absl::flags_usage
41+
OpenGeode::basic
42+
OpenGeode::geometry
43+
OpenGeode::mesh
44+
OpenGeode::model
45+
OpenGeode-IO::mesh
46+
OpenGeode-IO::model
47+
${PROJECT_NAME}::inspector
3248
)
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
* Copyright (c) 2019 - 2021 Geode-solutions. All rights reserved.
3+
*/
4+
5+
#include <absl/flags/flag.h>
6+
#include <absl/flags/parse.h>
7+
#include <absl/flags/usage.h>
8+
9+
#include <async++.h>
10+
11+
#include <geode/basic/assert.h>
12+
#include <geode/basic/filename.h>
13+
#include <geode/basic/logger.h>
14+
15+
#include <geode/model/representation/core/brep.h>
16+
#include <geode/model/representation/io/brep_input.h>
17+
18+
#include <geode/io/model/detail/common.h>
19+
20+
#include <geode/inspector/topology/brep_topology.h>
21+
22+
ABSL_FLAG( std::string, input, "/path/my/model.og_brep", "Input model" );
23+
ABSL_FLAG( bool,
24+
component_linking,
25+
true,
26+
"Toggle components linking to unique vertices criterion" );
27+
ABSL_FLAG( bool,
28+
corners,
29+
true,
30+
"Toggle inspection of corner topology through unique vertices" );
31+
ABSL_FLAG( bool,
32+
lines,
33+
true,
34+
"Toggle inspection of lines topology through unique vertices" );
35+
ABSL_FLAG( bool,
36+
surfaces,
37+
true,
38+
"Toggle inspection of surfaces topology through unique vertices" );
39+
ABSL_FLAG( bool,
40+
blocks,
41+
true,
42+
"Toggle inspection of block topology through unique vertices" );
43+
44+
void inspect_brep( const geode::BRep& brep )
45+
{
46+
const geode::BRepTopologyInspector brep_inspector{ brep };
47+
absl::InlinedVector< async::task< void >, 17 > tasks;
48+
if( absl::GetFlag( FLAGS_component_linking ) )
49+
{
50+
tasks.emplace_back( async::spawn( [&brep_inspector] {
51+
const auto nb_corners =
52+
brep_inspector.nb_corners_not_linked_to_a_unique_vertex();
53+
geode::Logger::info(
54+
nb_corners, " corners not linked to a unique vertex" );
55+
} ) );
56+
tasks.emplace_back( async::spawn( [&brep_inspector] {
57+
const auto nb_lines =
58+
brep_inspector.nb_lines_not_linked_to_a_unique_vertex();
59+
geode::Logger::info(
60+
nb_lines, " corners not linked to a unique vertex" );
61+
} ) );
62+
tasks.emplace_back( async::spawn( [&brep_inspector] {
63+
const auto nb_surfaces =
64+
brep_inspector.nb_surfaces_not_linked_to_a_unique_vertex();
65+
geode::Logger::info(
66+
nb_surfaces, " surfaces not linked to a unique vertex" );
67+
} ) );
68+
tasks.emplace_back( async::spawn( [&brep_inspector] {
69+
const auto nb_blocks =
70+
brep_inspector.nb_blocks_not_linked_to_a_unique_vertex();
71+
geode::Logger::info(
72+
nb_blocks, " blocks not linked to a unique vertex" );
73+
} ) );
74+
}
75+
if( absl::GetFlag( FLAGS_corners ) )
76+
{
77+
tasks.emplace_back( async::spawn( [&brep_inspector] {
78+
const auto nb =
79+
brep_inspector.multiple_corners_unique_vertices().size();
80+
geode::Logger::info(
81+
nb, " unique vertices associated to multiple corners." );
82+
} ) );
83+
tasks.emplace_back( async::spawn( [&brep_inspector] {
84+
const auto nb =
85+
brep_inspector.multiple_internals_corner_vertices().size();
86+
geode::Logger::info( nb, " unique vertices associated to a corner "
87+
"with multiple internals." );
88+
} ) );
89+
tasks.emplace_back( async::spawn( [&brep_inspector] {
90+
const auto nb =
91+
brep_inspector.not_internal_nor_boundary_corner_vertices()
92+
.size();
93+
geode::Logger::info( nb,
94+
" unique vertices associated to a corner which is neither "
95+
"internal nor boundary." );
96+
} ) );
97+
tasks.emplace_back( async::spawn( [&brep_inspector] {
98+
const auto nb =
99+
brep_inspector.line_corners_without_boundary_status().size();
100+
geode::Logger::info( nb, " unique vertices associated to a corner "
101+
"part of a line but not boundary of it." );
102+
} ) );
103+
}
104+
if( absl::GetFlag( FLAGS_lines ) )
105+
{
106+
tasks.emplace_back( async::spawn( [&brep_inspector] {
107+
const auto nb =
108+
brep_inspector
109+
.part_of_not_boundary_nor_internal_line_unique_vertices()
110+
.size();
111+
geode::Logger::info( nb, " unique vertices part of a line which is "
112+
"neither internal nor boundary." );
113+
} ) );
114+
tasks.emplace_back( async::spawn( [&brep_inspector] {
115+
const auto nb =
116+
brep_inspector
117+
.part_of_line_with_invalid_internal_topology_unique_vertices()
118+
.size();
119+
geode::Logger::info( nb, " unique vertices part of a line with "
120+
"invalid internal topology." );
121+
} ) );
122+
tasks.emplace_back( async::spawn( [&brep_inspector] {
123+
const auto nb =
124+
brep_inspector.part_of_invalid_unique_line_unique_vertices()
125+
.size();
126+
geode::Logger::info( nb, " unique vertices part of a unique line "
127+
"with invalid topology." );
128+
} ) );
129+
tasks.emplace_back( async::spawn( [&brep_inspector] {
130+
const auto nb =
131+
brep_inspector.part_of_lines_but_not_corner_unique_vertices()
132+
.size();
133+
geode::Logger::info( nb,
134+
" unique vertices part of multiple lines but not a corner." );
135+
} ) );
136+
}
137+
if( absl::GetFlag( FLAGS_surfaces ) )
138+
{
139+
tasks.emplace_back( async::spawn( [&brep_inspector] {
140+
const auto nb =
141+
brep_inspector
142+
.part_of_not_boundary_nor_internal_surface_unique_vertices()
143+
.size();
144+
geode::Logger::info( nb, " unique vertices part of a surface which "
145+
"is neither internal nor boundary." );
146+
} ) );
147+
tasks.emplace_back( async::spawn( [&brep_inspector] {
148+
const auto nb =
149+
brep_inspector
150+
.part_of_surface_with_invalid_internal_topology_unique_vertices()
151+
.size();
152+
geode::Logger::info( nb, " unique vertices part of a surface with "
153+
"invalid internal topology." );
154+
} ) );
155+
tasks.emplace_back( async::spawn( [&brep_inspector] {
156+
const auto nb =
157+
brep_inspector.part_of_invalid_unique_surface_unique_vertices()
158+
.size();
159+
geode::Logger::info( nb, " unique vertices part of a unique "
160+
"surface with invalid topology." );
161+
} ) );
162+
tasks.emplace_back( async::spawn( [&brep_inspector] {
163+
const auto nb =
164+
brep_inspector
165+
.part_of_invalid_multiple_surfaces_unique_vertices()
166+
.size();
167+
geode::Logger::info( nb, " unique vertices part of multiple "
168+
"surfaces with invalid topology." );
169+
} ) );
170+
}
171+
if( absl::GetFlag( FLAGS_blocks ) )
172+
{
173+
tasks.emplace_back( async::spawn( [&brep_inspector] {
174+
const auto nb =
175+
brep_inspector.part_of_invalid_blocks_unique_vertices().size();
176+
geode::Logger::info(
177+
nb, " unique vertices part of blocks with invalid topology." );
178+
} ) );
179+
}
180+
async::when_all( tasks.begin(), tasks.end() ).wait();
181+
}
182+
183+
int main( int argc, char* argv[] )
184+
{
185+
try
186+
{
187+
absl::SetProgramUsageMessage(
188+
absl::StrCat( "BRep inspector from Geode-solutions.\n",
189+
"Sample usage:\n", argv[0], " --input my_brep.og_brep3d\n",
190+
"Default behavior tests all available criteria, to disable one "
191+
"use --noXXX, e.g. --nocomponent_linking" ) );
192+
absl::ParseCommandLine( argc, argv );
193+
194+
geode::detail::initialize_model_io();
195+
const auto filename = absl::GetFlag( FLAGS_input );
196+
197+
inspect_brep( geode::load_brep( filename ) );
198+
199+
return 0;
200+
}
201+
catch( ... )
202+
{
203+
return geode::geode_lippincott();
204+
}
205+
}

src/geode/inspector/topology/brep_topology.cpp

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,79 @@ namespace geode
107107
return false;
108108
}
109109
}
110+
for( const auto& surface : brep_.surfaces() )
111+
{
112+
if( !brep_has_unique_vertex_associated_to_component_id(
113+
brep_, surface.id() ) )
114+
{
115+
return false;
116+
}
117+
}
118+
for( const auto& block : brep_.blocks() )
119+
{
120+
if( !brep_has_unique_vertex_associated_to_component_id(
121+
brep_, block.id() ) )
122+
{
123+
return false;
124+
}
125+
}
126+
return true;
127+
}
128+
129+
index_t nb_corners_not_linked_to_a_unique_vertex() const
130+
{
131+
index_t counter{ 0 };
132+
for( const auto& corner : brep_.corners() )
133+
{
134+
if( !brep_has_unique_vertex_associated_to_component_id(
135+
brep_, corner.id() ) )
136+
{
137+
counter++;
138+
}
139+
}
140+
return counter;
141+
}
142+
143+
index_t nb_lines_not_linked_to_a_unique_vertex() const
144+
{
145+
index_t counter{ 0 };
110146
for( const auto& line : brep_.lines() )
111147
{
112148
if( !brep_has_unique_vertex_associated_to_component_id(
113149
brep_, line.id() ) )
114150
{
115-
return false;
151+
counter++;
116152
}
117153
}
154+
return counter;
155+
}
156+
157+
index_t nb_surfaces_not_linked_to_a_unique_vertex() const
158+
{
159+
index_t counter{ 0 };
118160
for( const auto& surface : brep_.surfaces() )
119161
{
120162
if( !brep_has_unique_vertex_associated_to_component_id(
121163
brep_, surface.id() ) )
122164
{
123-
return false;
165+
counter++;
124166
}
125167
}
168+
return counter;
169+
}
170+
171+
index_t nb_blocks_not_linked_to_a_unique_vertex() const
172+
{
173+
index_t counter{ 0 };
126174
for( const auto& block : brep_.blocks() )
127175
{
128176
if( !brep_has_unique_vertex_associated_to_component_id(
129177
brep_, block.id() ) )
130178
{
131-
return false;
179+
counter++;
132180
}
133181
}
134-
return true;
182+
return counter;
135183
}
136184

137185
std::vector< index_t >
@@ -368,6 +416,30 @@ namespace geode
368416
return impl_->brep_topology_is_valid();
369417
}
370418

419+
index_t
420+
BRepTopologyInspector::nb_corners_not_linked_to_a_unique_vertex() const
421+
{
422+
return impl_->nb_corners_not_linked_to_a_unique_vertex();
423+
}
424+
425+
index_t
426+
BRepTopologyInspector::nb_lines_not_linked_to_a_unique_vertex() const
427+
{
428+
return impl_->nb_lines_not_linked_to_a_unique_vertex();
429+
}
430+
431+
index_t
432+
BRepTopologyInspector::nb_surfaces_not_linked_to_a_unique_vertex() const
433+
{
434+
return impl_->nb_surfaces_not_linked_to_a_unique_vertex();
435+
}
436+
437+
index_t
438+
BRepTopologyInspector::nb_blocks_not_linked_to_a_unique_vertex() const
439+
{
440+
return impl_->nb_blocks_not_linked_to_a_unique_vertex();
441+
}
442+
371443
std::vector< index_t >
372444
BRepTopologyInspector::invalid_components_topology_unique_vertices()
373445
const

tests/inspector/test-brep-topology.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@
3232

3333
#include <geode/inspector/topology/brep_topology.h>
3434

35+
void check_components_linking( geode::BRepTopologyInspector& brep_inspector )
36+
{
37+
const auto nb_unlinked_corners =
38+
brep_inspector.nb_corners_not_linked_to_a_unique_vertex();
39+
geode::Logger::info( "There are ", nb_unlinked_corners,
40+
" corners not linked to a unique vertex." );
41+
const auto nb_unlinked_lines =
42+
brep_inspector.nb_lines_not_linked_to_a_unique_vertex();
43+
geode::Logger::info( "There are ", nb_unlinked_lines,
44+
" lines not linked to a unique vertex." );
45+
const auto nb_unlinked_surfaces =
46+
brep_inspector.nb_surfaces_not_linked_to_a_unique_vertex();
47+
geode::Logger::info( "There are ", nb_unlinked_surfaces,
48+
" surfaces not linked to a unique vertex." );
49+
const auto nb_unlinked_blocks =
50+
brep_inspector.nb_blocks_not_linked_to_a_unique_vertex();
51+
geode::Logger::info( "There are ", nb_unlinked_blocks,
52+
" blocks not linked to a unique vertex." );
53+
}
54+
3555
void check_invalid_components_topology_unique_vertices(
3656
geode::BRepTopologyInspector& brep_inspector )
3757
{
@@ -262,6 +282,7 @@ void check_part_of_invalid_blocks_unique_vertices(
262282
void launch_topological_validity_checks(
263283
geode::BRepTopologyInspector& brep_inspector )
264284
{
285+
check_components_linking( brep_inspector );
265286
check_invalid_components_topology_unique_vertices( brep_inspector );
266287
check_multiple_corners_unique_vertices( brep_inspector );
267288
check_multiple_internals_corner_vertices( brep_inspector );

0 commit comments

Comments
 (0)