Skip to content

Commit e2b4a01

Browse files
committed
feat(criterion): Added adjacency criterion for the inspection of SurfaceMeshes
1 parent 996929a commit e2b4a01

File tree

5 files changed

+518
-0
lines changed

5 files changed

+518
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2019 - 2021 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <geode/basic/pimpl.h>
27+
28+
#include <geode/inspector/common.h>
29+
30+
namespace geode
31+
{
32+
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh );
33+
struct PolygonEdge;
34+
} // namespace geode
35+
36+
namespace geode
37+
{
38+
/*!
39+
* Class for inspecting the adjacency on the edges of a SurfaceMesh
40+
*/
41+
template < index_t dimension >
42+
class opengeode_inspector_inspector_api SurfaceMeshAdjacency
43+
{
44+
OPENGEODE_DISABLE_COPY( SurfaceMeshAdjacency );
45+
46+
public:
47+
SurfaceMeshAdjacency( const SurfaceMesh< dimension >& mesh );
48+
~SurfaceMeshAdjacency();
49+
50+
bool mesh_has_wrong_adjacencies() const;
51+
52+
index_t nb_edges_with_wrong_adjacency() const;
53+
54+
const std::vector< PolygonEdge >&
55+
polygon_edges_with_wrong_adjacency() const;
56+
57+
private:
58+
IMPLEMENTATION_MEMBER( impl_ );
59+
};
60+
ALIAS_2D_AND_3D( SurfaceMeshAdjacency );
61+
} // namespace geode

src/geode/inspector/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_geode_library(
3131
"criterion/colocation/edgedcurve_colocation.cpp"
3232
"criterion/colocation/surface_colocation.cpp"
3333
"criterion/colocation/solid_colocation.cpp"
34+
"criterion/adjacency/surface_adjacency.cpp"
3435
"criterion/private/colocation_impl.cpp"
3536
PUBLIC_HEADERS
3637
"common.h"
@@ -41,6 +42,7 @@ add_geode_library(
4142
"criterion/colocation/edgedcurve_colocation.h"
4243
"criterion/colocation/surface_colocation.h"
4344
"criterion/colocation/solid_colocation.h"
45+
"criterion/adjacency/surface_adjacency.h"
4446
PRIVATE_HEADERS
4547
"criterion/private/degeneration_impl.h"
4648
"criterion/private/colocation_impl.h"
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2019 - 2021 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#include <geode/inspector/criterion/adjacency/surface_adjacency.h>
25+
26+
#include <geode/basic/pimpl_impl.h>
27+
28+
#include <geode/mesh/core/surface_mesh.h>
29+
30+
namespace geode
31+
{
32+
template < index_t dimension >
33+
class SurfaceMeshAdjacency< dimension >::Impl
34+
{
35+
public:
36+
Impl( const SurfaceMesh< dimension >& mesh )
37+
{
38+
for( const auto polygon_id : Range{ mesh.nb_polygons() } )
39+
{
40+
for( const auto edge_id :
41+
LRange{ mesh.nb_polygon_edges( polygon_id ) } )
42+
{
43+
const PolygonEdge polygon_edge{ polygon_id, edge_id };
44+
if( !mesh.is_edge_on_border( polygon_edge )
45+
&& !mesh_polygon_edge_has_right_adjacency(
46+
mesh, polygon_edge ) )
47+
{
48+
polygons_wrong_adjacency_edges_.push_back(
49+
polygon_edge );
50+
}
51+
}
52+
}
53+
}
54+
55+
bool mesh_has_wrong_adjacencies() const
56+
{
57+
return polygons_wrong_adjacency_edges_.size() > 0;
58+
}
59+
60+
index_t nb_edges_with_wrong_adjacency() const
61+
{
62+
return polygons_wrong_adjacency_edges_.size();
63+
}
64+
65+
const std::vector< PolygonEdge >&
66+
polygon_edges_with_wrong_adjacency() const
67+
{
68+
return polygons_wrong_adjacency_edges_;
69+
}
70+
71+
private:
72+
bool mesh_polygon_edge_has_right_adjacency(
73+
const SurfaceMesh< dimension >& mesh,
74+
const PolygonEdge& polygon_edge )
75+
{
76+
const auto adjacent_polygon = mesh.polygon_adjacent( polygon_edge );
77+
const auto polygon_adj_id = adjacent_polygon.value();
78+
const auto v0 = mesh.polygon_vertex( polygon_edge );
79+
const auto v1 = mesh.polygon_edge_vertex( polygon_edge, 1 );
80+
for( const auto e :
81+
LRange{ mesh.nb_polygon_edges( polygon_adj_id ) } )
82+
{
83+
const PolygonEdge adj_edge{ polygon_adj_id, e };
84+
const auto adj_v0 = mesh.polygon_vertex( adj_edge );
85+
if( adj_v0 == v1 )
86+
{
87+
const auto adj_v1 = mesh.polygon_edge_vertex( adj_edge, 1 );
88+
if( adj_v1 == v0
89+
&& mesh.polygon_adjacent( adj_edge )
90+
== polygon_edge.polygon_id )
91+
{
92+
return true;
93+
}
94+
}
95+
}
96+
return false;
97+
}
98+
99+
private:
100+
std::vector< PolygonEdge > polygons_wrong_adjacency_edges_;
101+
};
102+
103+
template < index_t dimension >
104+
SurfaceMeshAdjacency< dimension >::SurfaceMeshAdjacency(
105+
const SurfaceMesh< dimension >& mesh )
106+
: impl_( mesh )
107+
{
108+
}
109+
110+
template < index_t dimension >
111+
SurfaceMeshAdjacency< dimension >::~SurfaceMeshAdjacency()
112+
{
113+
}
114+
115+
template < index_t dimension >
116+
bool SurfaceMeshAdjacency< dimension >::mesh_has_wrong_adjacencies() const
117+
{
118+
return impl_->mesh_has_wrong_adjacencies();
119+
}
120+
121+
template < index_t dimension >
122+
index_t
123+
SurfaceMeshAdjacency< dimension >::nb_edges_with_wrong_adjacency() const
124+
{
125+
return impl_->nb_edges_with_wrong_adjacency();
126+
}
127+
128+
template < index_t dimension >
129+
const std::vector< PolygonEdge >&
130+
SurfaceMeshAdjacency< dimension >::polygon_edges_with_wrong_adjacency()
131+
const
132+
{
133+
return impl_->polygon_edges_with_wrong_adjacency();
134+
}
135+
136+
template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 2 >;
137+
template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 3 >;
138+
} // namespace geode

tests/inspector/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,13 @@ add_geode_test(
7979
OpenGeode::geometry
8080
OpenGeode::mesh
8181
${PROJECT_NAME}::inspector
82+
)
83+
84+
add_geode_test(
85+
SOURCE "test-surface-adjacency.cpp"
86+
DEPENDENCIES
87+
OpenGeode::basic
88+
OpenGeode::geometry
89+
OpenGeode::mesh
90+
${PROJECT_NAME}::inspector
8291
)

0 commit comments

Comments
 (0)