Skip to content

Commit e17082f

Browse files
committed
fix(DegenerationInspection): Fixed the multiple calls to enable_edges/disable_edges when checking for model degenerations.
1 parent f2c0755 commit e17082f

File tree

5 files changed

+125
-29
lines changed

5 files changed

+125
-29
lines changed

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

Lines changed: 12 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,13 @@ namespace geode
6672

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

75+
private:
76+
void enable_edges_on_surface(
77+
const Surface< Model::dim >& surface ) const;
78+
6979
private:
7080
const Model& model_;
81+
mutable absl::flat_hash_set< uuid > enabled_edges_surfaces_;
7182
};
7283
} // namespace internal
7384
} // 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/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: 78 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,65 @@ 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+
tasks;
67+
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+
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( tasks.begin(), 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+
tasks;
90+
tasks.reserve( model_.nb_surfaces() );
6591
for( const auto& surface : model_.surfaces() )
6692
{
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" ) );
93+
tasks.emplace_back( async::spawn( [&threshold, &surface] {
94+
enable_edges_on_surface( surface );
95+
const geode::SurfaceMeshDegeneration< Model::dim >
96+
inspector{ surface.mesh() };
97+
auto issues = inspector.small_edges( threshold );
98+
issues.set_description( absl::StrCat(
99+
"Surface ", surface.id().string(), " small edges" ) );
100+
return std::make_pair( surface.id(), std::move( issues ) );
101+
} ) );
102+
}
103+
for( auto& task :
104+
async::when_all( tasks.begin(), tasks.end() ).get() )
105+
{
106+
auto [surface_id, issues] = task.get();
73107
components_small_edges.add_issues_to_map(
74-
surface.id(), std::move( issues ) );
108+
surface_id, std::move( issues ) );
75109
}
76110
}
77111

@@ -87,16 +121,27 @@ namespace geode
87121
InspectionIssuesMap< index_t >& components_small_polygons,
88122
double threshold ) const
89123
{
124+
std::vector<
125+
async::task< std::pair< uuid, InspectionIssues< index_t > > > >
126+
tasks;
127+
tasks.reserve( model_.nb_surfaces() );
90128
for( const auto& surface : model_.surfaces() )
91129
{
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" ) );
130+
tasks.emplace_back( async::spawn( [&threshold, &surface] {
131+
const geode::SurfaceMeshDegeneration< Model::dim >
132+
inspector{ surface.mesh() };
133+
auto issues = inspector.small_height_polygons( threshold );
134+
issues.set_description( absl::StrCat( "Surface ",
135+
surface.id().string(), " small polygons" ) );
136+
return std::make_pair( surface.id(), std::move( issues ) );
137+
} ) );
138+
}
139+
for( auto& task :
140+
async::when_all( tasks.begin(), tasks.end() ).get() )
141+
{
142+
auto [surface_id, issues] = task.get();
98143
components_small_polygons.add_issues_to_map(
99-
surface.id(), std::move( issues ) );
144+
surface_id, std::move( issues ) );
100145
}
101146
}
102147

@@ -115,6 +160,18 @@ namespace geode
115160
return model_;
116161
}
117162

163+
template < typename Model >
164+
void ComponentMeshesDegeneration< Model >::enable_edges_on_surface(
165+
const Surface< Model::dim >& surface ) const
166+
{
167+
const auto& mesh = surface.mesh();
168+
if( !mesh.are_edges_enabled() )
169+
{
170+
mesh.enable_edges();
171+
enabled_edges_surfaces_.emplace( surface.id() );
172+
}
173+
}
174+
118175
template class opengeode_inspector_inspector_api
119176
ComponentMeshesDegeneration< Section >;
120177
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)