Use correct SimplifyDP instead of SimplifyNearOptimal.

This commit is contained in:
vng 2011-01-21 10:36:28 +02:00 committed by Alex Zolotarev
parent 778041a43f
commit ffe9341ceb
2 changed files with 28 additions and 20 deletions

View file

@ -260,7 +260,10 @@ namespace feature
ASSERT ( m_buffer.m_innerTrg.empty(), () );
if (!IsPolygonCCW(points.begin(), points.end()))
{
reverse(points.begin(), points.end());
ASSERT ( IsPolygonCCW(points.begin(), points.end()), (points) );
}
size_t const index = FindSingleStrip(count,
IsDiagonalVisibleFunctor<points_t::const_iterator>(points.begin(), points.end()));
@ -306,7 +309,7 @@ namespace feature
if (isLine)
holder.AddPoints(points, i);
if (isArea && points.size() > 2 && holder.NeedProcessTriangles())
if (isArea && points.size() > 3 && holder.NeedProcessTriangles())
{
// simplify and serialize triangles

View file

@ -35,28 +35,33 @@ namespace feature
typedef mn::DistanceToLineSquare<m2::PointD> DistanceF;
double const eps = my::sq(scales::GetEpsilonForSimplify(level));
SimplifyNearOptimal<DistanceF>(20, in.begin(), in.end()-1,
eps, MakeBackInsertFunctor(out));
//SimplifyNearOptimal<DistanceF>(20, in.begin(), in.end()-1, eps, MakeBackInsertFunctor(out));
//switch (out.size())
//{
//case 0:
// out.push_back(in.front());
// // no break
//case 1:
// out.push_back(in.back());
// break;
//default:
// if (!are_points_equal(out.back(), in.back()))
// out.push_back(in.back());
//}
switch (out.size())
{
case 0:
out.push_back(in.front());
// no break
case 1:
out.push_back(in.back());
break;
default:
if (!are_points_equal(out.back(), in.back()))
out.push_back(in.back());
}
SimplifyDP<DistanceF>(in.begin(), in.end(), eps,
AccumulateSkipSmallTrg<DistanceF, m2::PointD>(out, eps));
ASSERT_GREATER ( out.size(), 1, () );
ASSERT ( are_points_equal(in.front(), out.front()), () );
ASSERT ( are_points_equal(in.back(), out.back()), () );
#ifdef DEBUG
for (size_t i = 2; i < out.size(); ++i)
{
double const dist = DistanceF(out[i-2], out[i])(out[i-1]);
ASSERT_GREATER(dist, eps, ());
}
//for (size_t i = 2; i < out.size(); ++i)
//{
// double const dist = DistanceF(out[i-2], out[i])(out[i-1]);
// ASSERT ( dist >= eps, (dist, eps, in) );
//}
#endif
}
}