Skip to content

Commit 2d0a59b

Browse files
authored
Merge pull request #149 from Geode-solutions/fix/multiple_creation_of_edges
fix(DegenerationInspection): Fixed the multiple calls to enable_edges…
2 parents f2c0755 + 4526483 commit 2d0a59b

File tree

7 files changed

+156
-41
lines changed

7 files changed

+156
-41
lines changed

bindings/python/tests/test-py-brep.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,7 @@ def check_a1(verbose):
224224
"[Test] model model_A1_valid should have 13494 component meshes issues (pairs of component meshes triangles intersecting)."
225225
)
226226

227-
228-
def check_a1_valid(verbose):
229-
test_dir = os.path.dirname(__file__)
230-
data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data"))
231-
model_brep = opengeode.load_brep(data_dir + "/model_A1_valid.og_brep")
227+
def inspect_model_A1(model_brep,verbose):
232228
brep_inspector = inspector.BRepInspector(model_brep)
233229
result = brep_inspector.inspect_brep()
234230
if brep_inspector.brep_topology_is_valid():
@@ -248,11 +244,13 @@ def check_a1_valid(verbose):
248244
"[Test] model model_A1_valid should have 13494 component meshes issues (pairs of component meshes triangles intersecting)."
249245
)
250246

251-
252-
def check_model_mss(verbose):
247+
def check_a1_valid(verbose):
253248
test_dir = os.path.dirname(__file__)
254249
data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data"))
255-
model_brep = opengeode.load_brep(data_dir + "/mss.og_brep")
250+
model_brep = opengeode.load_brep(data_dir + "/model_A1_valid.og_brep")
251+
inspect_model_A1(model_brep,verbose)
252+
253+
def inspect_model_mss(model_brep,verbose):
256254
brep_inspector = inspector.BRepInspector(model_brep)
257255
result = brep_inspector.inspect_brep()
258256
if brep_inspector.brep_topology_is_valid():
@@ -270,11 +268,13 @@ def check_model_mss(verbose):
270268
if nb_component_meshes_issues != 0:
271269
raise ValueError("[Test] model mss should have no component meshes issues.")
272270

273-
274-
def check_model_D(verbose):
271+
def check_model_mss(verbose):
275272
test_dir = os.path.dirname(__file__)
276273
data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data"))
277-
model_brep = opengeode.load_brep(data_dir + "/model_D.og_brep")
274+
model_brep = opengeode.load_brep(data_dir + "/mss.og_brep")
275+
inspect_model_mss(model_brep,verbose)
276+
277+
def inspect_model_D(model_brep,verbose):
278278
brep_inspector = inspector.BRepInspector(model_brep)
279279
result = brep_inspector.inspect_brep()
280280

@@ -292,7 +292,13 @@ def check_model_D(verbose):
292292
)
293293
if nb_component_meshes_issues != 0:
294294
raise ValueError("[Test] model_D should have no component meshes issues.")
295+
295296

297+
def check_model_D(verbose):
298+
test_dir = os.path.dirname(__file__)
299+
data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data"))
300+
model_brep = opengeode.load_brep(data_dir + "/model_D.og_brep")
301+
inspect_model_D(model_brep,verbose)
296302

297303
if __name__ == "__main__":
298304
inspector.InspectorInspectorLibrary.initialize()

include/geode/inspector/criterion/internal/component_meshes_degeneration.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323

2424
#pragma once
2525

26-
#include <absl/container/flat_hash_map.h>
26+
#include <absl/container/flat_hash_set.h>
2727

2828
#include <geode/inspector/common.hpp>
2929
#include <geode/inspector/information.hpp>
3030

3131
namespace geode
3232
{
33+
FORWARD_DECLARATION_DIMENSION_CLASS( Line );
34+
FORWARD_DECLARATION_DIMENSION_CLASS( Surface );
35+
ALIAS_2D_AND_3D( Line );
36+
ALIAS_2D_AND_3D( Surface );
3337
struct uuid;
3438
struct PolygonEdge;
3539
} // namespace geode
@@ -48,6 +52,8 @@ namespace geode
4852
OPENGEODE_DISABLE_COPY( ComponentMeshesDegeneration );
4953

5054
public:
55+
virtual ~ComponentMeshesDegeneration();
56+
5157
void add_small_edges( InspectionIssuesMap< index_t >& issues_map,
5258
double threshold ) const;
5359

@@ -66,8 +72,12 @@ namespace geode
6672

6773
[[nodiscard]] const Model& model() const;
6874

75+
private:
76+
std::vector< uuid > surfaces_on_which_enable_edges() const;
77+
6978
private:
7079
const Model& model_;
80+
mutable absl::flat_hash_set< uuid > enabled_edges_surfaces_;
7181
};
7282
} // namespace internal
7383
} // namespace geode

include/geode/inspector/criterion/internal/degeneration_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ namespace geode
5252

5353
[[nodiscard]] bool edge_is_degenerated( index_t edge_index ) const;
5454

55+
void enable_edges_on_mesh() const;
56+
5557
protected:
5658
explicit DegenerationImpl( const Mesh& mesh );
5759

5860
[[nodiscard]] const Mesh& mesh() const;
5961

6062
private:
6163
const Mesh& mesh_;
62-
bool enabled_edges_;
64+
mutable bool enabled_edges_;
6365
};
6466
} // namespace internal
6567
} // namespace geode

src/geode/inspector/brep_inspector.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ namespace geode
6363
} );
6464
return result;
6565
}
66-
6766
} // namespace geode

src/geode/inspector/criterion/degeneration/brep_meshes_degeneration.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <geode/basic/logger.hpp>
2727
#include <geode/basic/pimpl_impl.hpp>
2828

29+
#include <geode/mesh/core/solid_mesh.hpp>
30+
2931
#include <geode/model/mixin/core/block.hpp>
3032
#include <geode/model/representation/core/brep.hpp>
3133

@@ -76,14 +78,28 @@ namespace geode
7678
{
7779
}
7880

81+
~Impl()
82+
{
83+
for( const auto& block_id : enabled_edges_blocks_ )
84+
{
85+
model().block( block_id ).mesh().disable_edges();
86+
}
87+
}
88+
7989
void add_solid_small_elements(
8090
InspectionIssuesMap< index_t >& small_edges_map,
8191
InspectionIssuesMap< index_t >& small_polyhedra_map,
8292
double threshold ) const
8393
{
8494
for( const auto& block : model().blocks() )
8595
{
86-
const geode::SolidMeshDegeneration3D inspector{ block.mesh() };
96+
const auto& mesh = block.mesh();
97+
if( !mesh.are_edges_enabled() )
98+
{
99+
mesh.enable_edges();
100+
enabled_edges_blocks_.emplace( block.id() );
101+
}
102+
const geode::SolidMeshDegeneration3D inspector{ mesh };
87103
auto small_edges = inspector.small_edges( threshold );
88104
small_edges.set_description( absl::StrCat(
89105
"Block ", block.id().string(), " small edges" ) );
@@ -105,6 +121,9 @@ namespace geode
105121
add_solid_small_elements( degenerated_edges_map,
106122
degenerated_polyhedra_map, GLOBAL_EPSILON );
107123
}
124+
125+
private:
126+
mutable absl::flat_hash_set< uuid > enabled_edges_blocks_;
108127
};
109128

110129
BRepComponentMeshesDegeneration::BRepComponentMeshesDegeneration(

src/geode/inspector/criterion/internal/component_meshes_degeneration.cpp

Lines changed: 93 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <geode/inspector/criterion/internal/component_meshes_degeneration.hpp>
2525

26+
#include <async++.h>
27+
2628
#include <geode/basic/logger.hpp>
2729

2830
#include <geode/mesh/core/surface_mesh.hpp>
@@ -45,33 +47,74 @@ namespace geode
4547
: model_( model )
4648
{
4749
}
50+
template < typename Model >
51+
ComponentMeshesDegeneration< Model >::~ComponentMeshesDegeneration()
52+
{
53+
for( const auto& surface_id : enabled_edges_surfaces_ )
54+
{
55+
model_.surface( surface_id ).mesh().disable_edges();
56+
}
57+
}
4858

4959
template < typename Model >
5060
void ComponentMeshesDegeneration< Model >::add_small_edges(
5161
InspectionIssuesMap< index_t >& components_small_edges,
5262
double threshold ) const
5363
{
64+
std::vector<
65+
async::task< std::pair< uuid, InspectionIssues< index_t > > > >
66+
line_tasks;
67+
line_tasks.reserve( model_.nb_lines() );
5468
for( const auto& line : model_.lines() )
5569
{
56-
const EdgedCurveDegeneration< Model::dim > inspector{
57-
line.mesh()
58-
};
59-
auto issues = inspector.small_edges( threshold );
60-
issues.set_description( absl::StrCat(
61-
"Line ", line.id().string(), " small edges" ) );
70+
line_tasks.emplace_back( async::spawn( [&threshold, &line] {
71+
const EdgedCurveDegeneration< Model::dim > inspector{
72+
line.mesh()
73+
};
74+
auto issues = inspector.small_edges( threshold );
75+
issues.set_description( absl::StrCat(
76+
"Line ", line.id().string(), " small edges" ) );
77+
return std::make_pair( line.id(), std::move( issues ) );
78+
} ) );
79+
}
80+
for( auto& task :
81+
async::when_all( line_tasks.begin(), line_tasks.end() ).get() )
82+
{
83+
auto [line_id, issues] = task.get();
6284
components_small_edges.add_issues_to_map(
63-
line.id(), std::move( issues ) );
85+
line_id, std::move( issues ) );
6486
}
87+
std::vector<
88+
async::task< std::pair< uuid, InspectionIssues< index_t > > > >
89+
surface_tasks;
90+
surface_tasks.reserve( model_.nb_surfaces() );
91+
const auto surfaces_to_enable = surfaces_on_which_enable_edges();
6592
for( const auto& surface : model_.surfaces() )
6693
{
67-
const geode::SurfaceMeshDegeneration< Model::dim > inspector{
68-
surface.mesh()
69-
};
70-
auto issues = inspector.small_edges( threshold );
71-
issues.set_description( absl::StrCat(
72-
"Surface ", surface.id().string(), " small edges" ) );
94+
const auto enable_edges =
95+
absl::c_contains( surfaces_to_enable, surface.id() );
96+
surface_tasks.emplace_back(
97+
async::spawn( [&enable_edges, &threshold, &surface] {
98+
if( enable_edges )
99+
{
100+
surface.mesh().enable_edges();
101+
}
102+
const geode::SurfaceMeshDegeneration< Model::dim >
103+
inspector{ surface.mesh() };
104+
auto issues = inspector.small_edges( threshold );
105+
issues.set_description( absl::StrCat( "Surface ",
106+
surface.id().string(), " small edges" ) );
107+
return std::make_pair(
108+
surface.id(), std::move( issues ) );
109+
} ) );
110+
}
111+
for( auto& task :
112+
async::when_all( surface_tasks.begin(), surface_tasks.end() )
113+
.get() )
114+
{
115+
auto [surface_id, issues] = task.get();
73116
components_small_edges.add_issues_to_map(
74-
surface.id(), std::move( issues ) );
117+
surface_id, std::move( issues ) );
75118
}
76119
}
77120

@@ -87,16 +130,27 @@ namespace geode
87130
InspectionIssuesMap< index_t >& components_small_polygons,
88131
double threshold ) const
89132
{
133+
std::vector<
134+
async::task< std::pair< uuid, InspectionIssues< index_t > > > >
135+
tasks;
136+
tasks.reserve( model_.nb_surfaces() );
90137
for( const auto& surface : model_.surfaces() )
91138
{
92-
const geode::SurfaceMeshDegeneration< Model::dim > inspector{
93-
surface.mesh()
94-
};
95-
auto issues = inspector.small_height_polygons( threshold );
96-
issues.set_description( absl::StrCat(
97-
"Surface ", surface.id().string(), " small polygons" ) );
139+
tasks.emplace_back( async::spawn( [&threshold, &surface] {
140+
const geode::SurfaceMeshDegeneration< Model::dim >
141+
inspector{ surface.mesh() };
142+
auto issues = inspector.small_height_polygons( threshold );
143+
issues.set_description( absl::StrCat( "Surface ",
144+
surface.id().string(), " small polygons" ) );
145+
return std::make_pair( surface.id(), std::move( issues ) );
146+
} ) );
147+
}
148+
for( auto& task :
149+
async::when_all( tasks.begin(), tasks.end() ).get() )
150+
{
151+
auto [surface_id, issues] = task.get();
98152
components_small_polygons.add_issues_to_map(
99-
surface.id(), std::move( issues ) );
153+
surface_id, std::move( issues ) );
100154
}
101155
}
102156

@@ -115,6 +169,24 @@ namespace geode
115169
return model_;
116170
}
117171

172+
template < typename Model >
173+
std::vector< uuid > ComponentMeshesDegeneration<
174+
Model >::surfaces_on_which_enable_edges() const
175+
{
176+
std::vector< uuid > result;
177+
for( const auto& surface : model_.surfaces() )
178+
{
179+
const auto& mesh = surface.mesh();
180+
if( !mesh.are_edges_enabled()
181+
&& !enabled_edges_surfaces_.contains( surface.id() ) )
182+
{
183+
result.emplace_back( surface.id() );
184+
enabled_edges_surfaces_.emplace( surface.id() );
185+
}
186+
}
187+
return result;
188+
}
189+
118190
template class opengeode_inspector_inspector_api
119191
ComponentMeshesDegeneration< Section >;
120192
template class opengeode_inspector_inspector_api

src/geode/inspector/criterion/internal/degeneration_impl.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ namespace geode
4141
DegenerationImpl< MeshType >::DegenerationImpl( const MeshType& mesh )
4242
: mesh_( mesh ), enabled_edges_( false )
4343
{
44-
if( !mesh_.are_edges_enabled() )
45-
{
46-
mesh_.enable_edges();
47-
enabled_edges_ = true;
48-
}
4944
}
5045

5146
template < class MeshType >
@@ -60,6 +55,7 @@ namespace geode
6055
template < class MeshType >
6156
bool DegenerationImpl< MeshType >::is_mesh_degenerated() const
6257
{
58+
enable_edges_on_mesh();
6359
for( const auto edge_index : Range{ mesh_.edges().nb_edges() } )
6460
{
6561
if( edge_is_degenerated( edge_index ) )
@@ -74,6 +70,7 @@ namespace geode
7470
InspectionIssues< index_t > DegenerationImpl< MeshType >::small_edges(
7571
double threshold ) const
7672
{
73+
enable_edges_on_mesh();
7774
InspectionIssues< index_t > degenerated_edges_index{
7875
"Degenerated Edges."
7976
};
@@ -112,6 +109,16 @@ namespace geode
112109
return point_point_distance( p1, p2 ) < threshold;
113110
}
114111

112+
template < class MeshType >
113+
void DegenerationImpl< MeshType >::enable_edges_on_mesh() const
114+
{
115+
if( !mesh_.are_edges_enabled() )
116+
{
117+
mesh_.enable_edges();
118+
enabled_edges_ = true;
119+
}
120+
}
121+
115122
template < class MeshType >
116123
bool DegenerationImpl< MeshType >::edge_is_degenerated(
117124
index_t edge_index ) const

0 commit comments

Comments
 (0)