fix for collinear cycle + update tests

This commit is contained in:
Sébastien Loriot 2020-10-28 10:11:34 +01:00
parent 7309b09169
commit 61174c8359
4 changed files with 66 additions and 47 deletions

View File

@ -56,8 +56,12 @@ void simplify_polyline(const PointRangeIn& input,
{
case ITERATIVE:
{
const bool is_closed = input.front()==input.back();
std::size_t nb_points = is_closed ? input.size()-1 : input.size();
// skip points in the input range that do not contains any information
if (input.size()<=2)
if (nb_points<=2)
{
output.reserve(input.size());
for (const auto& p : input)
@ -75,6 +79,7 @@ void simplify_polyline(const PointRangeIn& input,
typename Kernel::Compare_squared_distance_3 compare_squared_distance;
for (std::size_t i=b+1; i<e; ++i)
{
if (compare_squared_distance(get(in_pm, input[i]), line, max_squared_frechet_distance) == LARGER)
return false;
}
@ -82,15 +87,17 @@ void simplify_polyline(const PointRangeIn& input,
};
std::size_t bi=0;
while(bi!=input.size())
while(bi!=nb_points)
{
std::size_t ei=bi+2;
output.push_back(input[bi]);
put(out_pm, output.back(), get(in_pm, input[bi]));
while(ei<input.size())
while(ei<nb_points)
{
typename Kernel::Line_3 sl(get(in_pm,input[bi]), get(in_pm,input[ei]));
if (is_valid_approx(bi,ei,sl))
++ei; // we skip ei-1
else
@ -99,10 +106,15 @@ void simplify_polyline(const PointRangeIn& input,
break;
}
}
if(ei>=input.size()) break;
if(ei>=nb_points) break;
}
output.push_back(input[nb_points-1]);
put(out_pm, output.back(), get(in_pm, input[nb_points-1]));
if (is_closed)
{
output.push_back(input.back());
put(out_pm, output.back(), get(in_pm, input.back()));
}
output.push_back(input.back());
put(out_pm, output.back(), get(in_pm, input.back()));
return;
}
case DOUGLAS_PEUCKER:

View File

@ -0,0 +1 @@
78 1.9655199999999999 -1 -4.6410200000000001e-08 1.8620699999999999 -1 -4.6410200000000001e-08 1.7586200000000001 -1 -4.6410200000000001e-08 1.65517 -1 -4.6410200000000001e-08 1.55172 -1 -4.6410200000000001e-08 1.44828 -1 -4.6410200000000001e-08 1.34483 -1 -4.6410200000000001e-08 1.2413799999999999 -1 -4.6410200000000001e-08 1.1379300000000001 -1 -4.6410200000000001e-08 1.0344800000000001 -1 -4.6410200000000001e-08 0.93103400000000003 -1 -4.6410200000000001e-08 0.82758600000000004 -1 -4.6410200000000001e-08 0.72413799999999995 -1 -4.6410200000000001e-08 0.62068999999999996 -1 -4.6410200000000001e-08 0.51724099999999995 -1 -4.6410200000000001e-08 0.41379300000000002 -1 -4.6410200000000001e-08 0.31034499999999998 -1 -4.6410200000000001e-08 0.206897 -1 -4.6410200000000001e-08 0.103448 -1 -4.6410200000000001e-08 0 -1 -4.6410200000000001e-08 0 -0.996757 0.080466499999999996 0 -0.98704999999999998 0.160411 0 -0.97094199999999997 0.239316 0 -0.94853600000000005 0.31666800000000001 0 -0.91997899999999999 0.39196700000000001 0 -0.88545600000000002 0.464723 0 -0.84519 0.534466 0 -0.79944300000000001 0.600742 0 -0.74851100000000004 0.66312300000000002 0 -0.69272400000000001 0.72120200000000001 0 -0.63244500000000003 0.77460499999999999 0 -0.56806500000000004 0.82298400000000005 0 -0.5 0.86602500000000004 0 -0.42869299999999999 0.90344999999999998 0 -0.354605 0.93501599999999996 0 -0.27821699999999999 0.96051799999999998 0 -0.20002600000000001 0.97979099999999997 0 -0.12053700000000001 0.99270899999999995 0 -0.040266000000000003 0.99918899999999999 0 0.0402659 0.99918899999999999 0 0.12053700000000001 0.99270899999999995 0 0.20002600000000001 0.97979099999999997 0 0.27821699999999999 0.96051799999999998 0 0.354605 0.93501599999999996 0 0.42869299999999999 0.90344999999999998 0 0.5 0.86602500000000004 0 0.56806500000000004 0.82298400000000005 0 0.63244500000000003 0.77460499999999999 0 0.69272400000000001 0.72120200000000001 0 0.74851100000000004 0.66312300000000002 0 0.79944300000000001 0.600742 0 0.84519 0.534466 0 0.88545600000000002 0.464723 0 0.91997899999999999 0.39196700000000001 0 0.94853600000000005 0.31666800000000001 0 0.97094199999999997 0.239316 0 0.98704999999999998 0.160411 0 0.996757 0.080466599999999999 0 1 0 0.103448 1 0 0.206897 1 0 0.31034499999999998 1 0 0.41379300000000002 1 0 0.51724099999999995 1 0 0.62068999999999996 1 0 0.72413799999999995 1 0 0.82758600000000004 1 0 0.93103400000000003 1 0 1.0344800000000001 1 0 1.1379300000000001 1 0 1.2413799999999999 1 0 1.34483 1 0 1.44828 1 0 1.55172 1 0 1.65517 1 0 1.7586200000000001 1 0 1.8620699999999999 1 0 1.9655199999999999 1 0

View File

@ -1 +1,4 @@
data/U.polylines.txt 0.000001
data/collinear.polylines.txt 0.1
data/null_edge.polylines.txt 0.1
data/open.polylines.txt 0.001

View File

@ -12,49 +12,52 @@ namespace PMP_exp=CGAL::Polygon_mesh_processing::experimental;
int main(int argc, char **argv)
{
if (argc!=3)
for (int i=1; i<argc; i+=2)
{
std::cerr << "Usage: " << argv[0] << " in.polylines.txt max_squared_frechet_distance\n";
return 1;
if (i+1>=argc)
{
std::cerr << "Usage: " << argv[0] << " in.polylines_0.txt max_squared_frechet_distance_0 ... in.polylines_n.txt max_squared_frechet_distance_n \n";
return 1;
}
std::ifstream in(argv[i]);
const double max_squared_frechet_distance = atof(argv[i+1]);
//TODO read more than 1 poly or use CGAL I/O function
int n;
in >> n;
std::vector<Point_3> polyline(n);
for(int i=0; i<n; ++i)
in >> polyline[i];
// first run
std::vector<Point_3> simplified_polyline;
PMP_exp::simplify_polyline(polyline, simplified_polyline, max_squared_frechet_distance,
CGAL::parameters::algorithm(PMP_exp::ITERATIVE));
std::cout << "Polyline of " << n << " points simplified (ITERATIVE) into a polyline of " << simplified_polyline.size() << " points\n";
std::ofstream out("out_iterative_"+std::to_string((i-1)/2)+".polylines.txt");
out << simplified_polyline.size();
for (auto p : simplified_polyline)
out << " " << p;
out << "\n";
out.close();
// second run
simplified_polyline.clear();
PMP_exp::simplify_polyline(polyline, simplified_polyline, max_squared_frechet_distance,
CGAL::parameters::algorithm(PMP_exp::DOUGLAS_PEUCKER));
std::cout << "Polyline of " << n << " points simplified (DOUGLAS_PEUCKER) into a polyline of " << simplified_polyline.size() << " points\n";
out.open("out_dp_"+std::to_string((i-1)/2)+".polylines.txt");
out << simplified_polyline.size();
for (auto p : simplified_polyline)
out << " " << p;
out << "\n";
}
std::ifstream in(argv[1]);
const double max_squared_frechet_distance = atof(argv[2]);
//TODO read more than 1 poly or use CGAL I/O function
int n;
in >> n;
std::vector<Point_3> polyline(n);
for(int i=0; i<n; ++i)
in >> polyline[i];
// first run
std::vector<Point_3> simplified_polyline;
PMP_exp::simplify_polyline(polyline, simplified_polyline, max_squared_frechet_distance,
CGAL::parameters::algorithm(PMP_exp::ITERATIVE));
std::cout << "Polyline of " << n << " points simplified into a polyline of " << simplified_polyline.size() << " points\n";
std::ofstream out("out_iterative.polylines.txt");
out << simplified_polyline.size();
for (auto p : simplified_polyline)
out << " " << p;
out << "\n";
out.close();
// second run
simplified_polyline.clear();
PMP_exp::simplify_polyline(polyline, simplified_polyline, max_squared_frechet_distance,
CGAL::parameters::algorithm(PMP_exp::DOUGLAS_PEUCKER));
std::cout << "Polyline of " << n << " points simplified into a polyline of " << simplified_polyline.size() << " points\n";
out.open("out_dp.polylines.txt");
out << simplified_polyline.size();
for (auto p : simplified_polyline)
out << " " << p;
out << "\n";
return 0;
}