-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsurface_adjacency.cpp
More file actions
143 lines (130 loc) · 5.36 KB
/
surface_adjacency.cpp
File metadata and controls
143 lines (130 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright (c) 2019 - 2026 Geode-solutions
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#include <geode/inspector/criterion/adjacency/surface_adjacency.hpp>
#include <geode/basic/pimpl_impl.hpp>
#include <geode/basic/uuid.hpp>
#include <geode/mesh/core/surface_mesh.hpp>
namespace geode
{
template < index_t dimension >
class SurfaceMeshAdjacency< dimension >::Impl
{
public:
Impl( const SurfaceMesh< dimension >& mesh ) : mesh_( mesh ) {}
bool mesh_has_wrong_adjacencies() const
{
for( const auto polygon_id : Range{ mesh_.nb_polygons() } )
{
for( const auto edge_id :
LRange{ mesh_.nb_polygon_edges( polygon_id ) } )
{
const PolygonEdge polygon_edge{ polygon_id, edge_id };
if( !mesh_.is_edge_on_border( polygon_edge )
&& !mesh_polygon_edge_has_right_adjacency(
polygon_edge ) )
{
return true;
}
}
}
return false;
}
InspectionIssues< PolygonEdge >
polygon_edges_with_wrong_adjacency() const
{
InspectionIssues< PolygonEdge > wrong_adjacency_edges{ absl::StrCat(
"Surface ", mesh_.name().value_or( mesh_.id().string() ),
" polygon edges adjacencies issues" ) };
for( const auto polygon_id : Range{ mesh_.nb_polygons() } )
{
for( const auto edge_id :
LRange{ mesh_.nb_polygon_edges( polygon_id ) } )
{
const PolygonEdge polygon_edge{ polygon_id, edge_id };
if( !mesh_.is_edge_on_border( polygon_edge )
&& !mesh_polygon_edge_has_right_adjacency(
polygon_edge ) )
{
wrong_adjacency_edges.add_issue( polygon_edge,
absl::StrCat( "edge ", edge_id, " of polygon ",
polygon_id, " has wrong adjacencies" ) );
}
}
}
return wrong_adjacency_edges;
}
private:
bool mesh_polygon_edge_has_right_adjacency(
const PolygonEdge& polygon_edge ) const
{
const auto adjacent_polygon =
mesh_.polygon_adjacent( polygon_edge );
const auto polygon_adj_id = adjacent_polygon.value();
const auto v0 = mesh_.polygon_edge_vertex( polygon_edge, 0 );
const auto v1 = mesh_.polygon_edge_vertex( polygon_edge, 1 );
for( const auto edge_id :
LRange{ mesh_.nb_polygon_edges( polygon_adj_id ) } )
{
const PolygonEdge adj_edge{ polygon_adj_id, edge_id };
const auto adj_v0 =
mesh_.polygon_vertex( PolygonVertex{ adj_edge } );
if( adj_v0 == v1 )
{
const auto adj_v1 =
mesh_.polygon_edge_vertex( adj_edge, 1 );
if( adj_v1 == v0
&& mesh_.polygon_adjacent( adj_edge )
== polygon_edge.polygon_id )
{
return true;
}
}
}
return false;
}
private:
const SurfaceMesh< dimension >& mesh_;
};
template < index_t dimension >
SurfaceMeshAdjacency< dimension >::SurfaceMeshAdjacency(
const SurfaceMesh< dimension >& mesh )
: impl_( mesh )
{
}
template < index_t dimension >
SurfaceMeshAdjacency< dimension >::~SurfaceMeshAdjacency() = default;
template < index_t dimension >
bool SurfaceMeshAdjacency< dimension >::mesh_has_wrong_adjacencies() const
{
return impl_->mesh_has_wrong_adjacencies();
}
template < index_t dimension >
InspectionIssues< PolygonEdge >
SurfaceMeshAdjacency< dimension >::polygon_edges_with_wrong_adjacency()
const
{
return impl_->polygon_edges_with_wrong_adjacency();
}
template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 2 >;
template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 3 >;
} // namespace geode