forked from organicmaps/organicmaps
Moved feature::SimplifyPoints to header and made it more generic
This commit is contained in:
parent
3aa1625c45
commit
770c00d653
2 changed files with 49 additions and 17 deletions
|
@ -7,11 +7,8 @@
|
|||
#include "../../indexer/feature_processor.hpp"
|
||||
#include "../../indexer/feature_visibility.hpp"
|
||||
#include "../../indexer/feature_impl.hpp"
|
||||
#include "../../indexer/scales.hpp"
|
||||
#include "../../indexer/cell_id.hpp"
|
||||
|
||||
#include "../../geometry/distance.hpp"
|
||||
#include "../../geometry/simplification.hpp"
|
||||
#include "../../geometry/polygon.hpp"
|
||||
|
||||
#include "../../platform/platform.hpp"
|
||||
|
@ -75,15 +72,7 @@ namespace
|
|||
namespace feature
|
||||
{
|
||||
typedef vector<m2::PointD> points_t;
|
||||
|
||||
namespace
|
||||
{
|
||||
bool is_equal(m2::PointD const & p1, m2::PointD const & p2)
|
||||
{
|
||||
return AlmostEqual(p1, p2);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void SimplifyPoints(points_t const & in, points_t & out, int level)
|
||||
{
|
||||
if (in.size() >= 2)
|
||||
|
@ -116,7 +105,7 @@ namespace feature
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
void TesselateInterior(points_t const & bound, list<points_t> const & holes, points_t & triangles);
|
||||
|
||||
|
||||
|
@ -216,15 +205,15 @@ namespace feature
|
|||
points_t const & src = m_buffer.m_innerPts;
|
||||
ASSERT ( !src.empty(), () );
|
||||
|
||||
ASSERT ( is_equal(src.front(), points.front()), () );
|
||||
ASSERT ( is_equal(src.back(), points.back()), () );
|
||||
ASSERT ( are_points_equal(src.front(), points.front()), () );
|
||||
ASSERT ( are_points_equal(src.back(), points.back()), () );
|
||||
|
||||
size_t j = 1;
|
||||
for (size_t i = 1; i < points.size()-1; ++i)
|
||||
{
|
||||
for (; j < src.size()-1; ++j)
|
||||
{
|
||||
if (is_equal(src[j], points[i]))
|
||||
if (are_points_equal(src[j], points[i]))
|
||||
{
|
||||
// set corresponding 2 bits for source point [j] to scaleIndex
|
||||
uint32_t mask = 0x3;
|
||||
|
@ -291,7 +280,7 @@ namespace feature
|
|||
|
||||
bool TryToMakeStrip(points_t & points)
|
||||
{
|
||||
ASSERT ( is_equal(points.front(), points.back()), () );
|
||||
ASSERT ( are_points_equal(points.front(), points.back()), () );
|
||||
// At this point we don't need last point equal to first.
|
||||
// If you try to remove it in first step, 'simplify' will work bad for such polygons.
|
||||
points.pop_back();
|
||||
|
|
|
@ -1,10 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include "../../geometry/point2d.hpp"
|
||||
#include "../../geometry/simplification.hpp"
|
||||
#include "../../geometry/distance.hpp"
|
||||
|
||||
#include "../../indexer/scales.hpp"
|
||||
|
||||
#include "../../std/string.hpp"
|
||||
#include "../../std/vector.hpp"
|
||||
|
||||
namespace feature
|
||||
{
|
||||
/// Final generation of data from input feature-dat-file.
|
||||
/// @param[in] bSort sorts features in the given file by their mid points
|
||||
bool GenerateFinalFeatures(string const & datFile, bool bSort);
|
||||
|
||||
template <class PointT>
|
||||
inline bool are_points_equal(PointT const & p1, PointT const & p2)
|
||||
{
|
||||
return p1 == p2;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool are_points_equal<m2::PointD>(m2::PointD const & p1, m2::PointD const & p2)
|
||||
{
|
||||
return AlmostEqual(p1, p2);
|
||||
}
|
||||
|
||||
template <class PointsContainerT>
|
||||
void SimplifyPoints(PointsContainerT const & in, PointsContainerT & out, int level)
|
||||
{
|
||||
if (in.size() >= 2)
|
||||
{
|
||||
SimplifyNearOptimal<mn::DistanceToLineSquare<typename PointsContainerT::value_type> >(
|
||||
20, in.begin(), in.end()-1, my::sq(scales::GetEpsilonForSimplify(level)),
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue