Skip to content

Commit 25a3234

Browse files
authored
Fix local classification bug (#26)
1 parent c5da22b commit 25a3234

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

include/kigumi/Classify_faces_locally.h

+43-46
Original file line numberDiff line numberDiff line change
@@ -118,63 +118,60 @@ class Classify_faces_locally {
118118
}
119119
}
120120

121-
if (is_undefined_configuration) {
122-
return {};
123-
}
124-
125-
// Check consistency and tag rest of the faces.
126-
127-
// An example case of an inconsistent configuration:
128-
//
129-
// Right, Int.
130-
// //|
131-
// //|
132-
// //|
133-
// /////////|/////////
134-
// Left, ??? ---------+--------- Left, Ext.
135-
// :
136-
// Should be tagged as interior according to global classification.
137-
138-
auto consistent = true;
139-
for (auto dry_run : {true, false}) {
140-
auto tag = m.data(faces_.at(k).fi).tag;
141-
auto orientation = faces_.at(k).orientation;
142-
// Go around and return to the starting point to check consistency.
143-
for (std::size_t i = k + 1; i <= k + faces_.size(); ++i) {
144-
const auto& f = faces_.at(i % faces_.size());
145-
auto& f_data = m.data(f.fi);
146-
147-
if (f.orientation == orientation) {
148-
tag = tag == Face_tag::EXTERIOR ? Face_tag::INTERIOR : Face_tag::EXTERIOR;
121+
if (!is_undefined_configuration) {
122+
// Check consistency and tag rest of the faces.
123+
124+
// An example case of an inconsistent configuration:
125+
//
126+
// Right, Int.
127+
// //|
128+
// //|
129+
// //|
130+
// /////////|/////////
131+
// Left, ??? ---------+--------- Left, Ext.
132+
// :
133+
// Should be tagged as interior according to global classification.
134+
135+
auto consistent = true;
136+
for (auto dry_run : {true, false}) {
137+
auto tag = m.data(faces_.at(k).fi).tag;
138+
auto orientation = faces_.at(k).orientation;
139+
// Go around and return to the starting point to check consistency.
140+
for (std::size_t i = k + 1; i <= k + faces_.size(); ++i) {
141+
const auto& f = faces_.at(i % faces_.size());
142+
auto& f_data = m.data(f.fi);
143+
144+
if (f.orientation == orientation) {
145+
tag = tag == Face_tag::EXTERIOR ? Face_tag::INTERIOR : Face_tag::EXTERIOR;
146+
}
147+
orientation = f.orientation;
148+
149+
if (f_data.tag == Face_tag::UNKNOWN) {
150+
if (!dry_run) {
151+
f_data.tag = tag;
152+
}
153+
} else if ((f_data.tag == Face_tag::EXTERIOR || f_data.tag == Face_tag::INTERIOR) &&
154+
f_data.tag != tag) {
155+
consistent = false;
156+
break;
157+
}
149158
}
150-
orientation = f.orientation;
151159

152-
if (f_data.tag == Face_tag::UNKNOWN) {
153-
if (!dry_run) {
154-
f_data.tag = tag;
155-
}
156-
} else if ((f_data.tag == Face_tag::EXTERIOR || f_data.tag == Face_tag::INTERIOR) &&
157-
f_data.tag != tag) {
158-
consistent = false;
160+
if (!consistent) {
161+
// Leave unknown faces to the global classifier.
159162
break;
160163
}
161164
}
162-
163-
if (!consistent) {
164-
// Leave unknown faces to the global classifier.
165-
break;
166-
}
167165
}
168166

169-
// Propagate face tags.
167+
// Propagate the tags.
170168

171169
Warnings warnings{};
172170

173171
for (const auto& f : faces_) {
174-
auto fi = f.fi;
175-
auto f_tag = m.data(fi).tag;
176-
if (f_tag == Face_tag::EXTERIOR || f_tag == Face_tag::INTERIOR) {
177-
warnings |= propagate_face_tags_(m, border_edges, fi);
172+
const auto& f_data = m.data(f.fi);
173+
if (f_data.tag != Face_tag::UNKNOWN) {
174+
warnings |= propagate_face_tags_(m, border_edges, f.fi);
178175
}
179176
}
180177

include/kigumi/Corefine.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ class Corefine {
204204
}
205205
}
206206

207-
std::vector<Edge> get_intersecting_edges() const {
208-
std::vector<Edge> edges;
207+
Edge_set get_intersecting_edges() const {
208+
Edge_set edges;
209209

210210
for (const auto& info : infos_) {
211211
auto n = info.intersections.size();
@@ -217,7 +217,7 @@ class Corefine {
217217
auto j = i < n - 1 ? i + 1 : 0;
218218
auto a = info.intersections.at(i);
219219
auto b = info.intersections.at(j);
220-
edges.push_back(make_edge(Vertex_index{a}, Vertex_index{b}));
220+
edges.insert(make_edge(Vertex_index{a}, Vertex_index{b}));
221221
}
222222
}
223223

include/kigumi/Mix.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class Mix {
5353

5454
std::cout << "Local classification..." << std::endl;
5555

56-
auto intersecting_edges = corefine.get_intersecting_edges();
57-
Edge_set border_edges(intersecting_edges.begin(), intersecting_edges.end());
56+
auto border_edges = corefine.get_intersecting_edges();
57+
std::vector<Edge> intersecting_edges(border_edges.begin(), border_edges.end());
5858
Warnings warnings{};
5959

6060
parallel_do(

include/kigumi/Propagate_face_tags.h

-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <kigumi/Warnings.h>
88

99
#include <queue>
10-
#include <stdexcept>
1110

1211
namespace kigumi {
1312

@@ -21,10 +20,6 @@ class Propagate_face_tags {
2120
auto from_left = data.from_left;
2221
auto tag = data.tag;
2322

24-
if (tag != Face_tag::INTERIOR && tag != Face_tag::EXTERIOR) {
25-
throw std::runtime_error("the seed face must be tagged as either interior or exterior");
26-
}
27-
2823
Warnings warnings{};
2924

3025
queue_.push(seed);

0 commit comments

Comments
 (0)