Collapse consequtive identical vertices instead of deleting the whole polygon. Fixes #1138

master
Marius Kintel 2015-01-05 16:04:48 -05:00
parent f79414a208
commit 1ad4af8b0b
1 changed files with 7 additions and 14 deletions

View File

@ -79,20 +79,13 @@ namespace /* anonymous */ {
indices.push_back(grid.data(v));
}
// We perform this test since there is a bug in CGAL's
// Polyhedron_incremental_builder_3::test_facet() which
// fails to detect duplicate indices
bool err = false;
for (std::size_t i = 0; i < indices.size(); ++i) {
// check if vertex indices[i] is already in the sequence [0..i-1]
for (std::size_t k = 0; k < i && !err; ++k) {
if (indices[k] == indices[i]) {
err = true;
break;
}
}
}
if (!err && B.test_facet(indices.begin(), indices.end())) {
// We remove duplicate indices since there is a bug in CGAL's
// Polyhedron_incremental_builder_3::test_facet() which fails to detect this
std::vector<size_t>::iterator last = std::unique(indices.begin(), indices.end());
std::advance(last, -1);
if (*last != indices.front()) last++; // In case the first & last are equal
indices.erase(last, indices.end());
if (indices.size() >= 3 && B.test_facet(indices.begin(), indices.end())) {
B.add_facet(indices.begin(), indices.end());
}
#ifdef GEN_SURFACE_DEBUG