mirror of https://github.com/CGAL/cgal
Fix and simplify polygon soup repairing subfunction "simplify_polygon"
This commit is contained in:
parent
655135011f
commit
5a6fc89495
|
|
@ -126,43 +126,21 @@ bool simplify_polygon(PointRange& points,
|
||||||
{
|
{
|
||||||
const std::size_t ini_polygon_size = polygon.size();
|
const std::size_t ini_polygon_size = polygon.size();
|
||||||
|
|
||||||
// Start at the last since if two points are identical, the second one gets removed.
|
for(std::size_t i=0; i<polygon.size(); ++i)
|
||||||
// By starting at 'last', we ensure that 'to_remove' is ordered from closest to .begin()
|
|
||||||
// to closest to .end()
|
|
||||||
std::size_t last = ini_polygon_size - 1, i = last;
|
|
||||||
bool stop = false;
|
|
||||||
std::vector<std::size_t> to_remove;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
std::size_t next_i = (i == last) ? 0 : i+1;
|
const std::size_t s = polygon.size();
|
||||||
stop = (next_i == last);
|
if(s == 1)
|
||||||
|
|
||||||
while(polygon[i] == polygon[next_i] || // combinatorial equality
|
|
||||||
traits.equal_3_object()(points[polygon[i]], points[polygon[next_i]])) // geometric equality
|
|
||||||
{
|
|
||||||
to_remove.push_back(next_i);
|
|
||||||
#ifdef CGAL_PMP_REPAIR_POLYGON_SOUP_VERBOSE_PP
|
|
||||||
std::cout << "Duplicate point: polygon[" << next_i << "] = " << polygon[next_i] << std::endl;
|
|
||||||
#endif
|
|
||||||
next_i = (next_i == last) ? 0 : next_i+1;
|
|
||||||
|
|
||||||
// Every duplicate in front of 'last' (circularly-speaking) has already been cleared
|
|
||||||
if(next_i == last)
|
|
||||||
{
|
|
||||||
stop = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = next_i;
|
const std::size_t ni = (i + 1) % s;
|
||||||
}
|
if(polygon[i] == polygon[ni] ||
|
||||||
while(!stop);
|
traits.equal_3_object()(points[polygon[i]], points[polygon[ni]]))
|
||||||
|
|
||||||
while(!to_remove.empty())
|
|
||||||
{
|
{
|
||||||
polygon.erase(polygon.begin() + to_remove.back());
|
#ifdef CGAL_PMP_REPAIR_POLYGON_SOUP_VERBOSE_PP
|
||||||
to_remove.pop_back();
|
std::cout << "Duplicate point: polygon[" << ni << "] = " << polygon[ni] << std::endl;
|
||||||
|
#endif
|
||||||
|
polygon.erase(polygon.begin() + i--);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::size_t removed_points_n = ini_polygon_size - polygon.size();
|
const std::size_t removed_points_n = ini_polygon_size - polygon.size();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue