From 770c00d653c5592151e3e2e84e267e16b1a17beb Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Wed, 19 Jan 2011 01:58:55 +0200 Subject: [PATCH] Moved feature::SimplifyPoints to header and made it more generic --- indexer/indexer_tool/feature_sorter.cpp | 23 ++++--------- indexer/indexer_tool/feature_sorter.hpp | 43 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/indexer/indexer_tool/feature_sorter.cpp b/indexer/indexer_tool/feature_sorter.cpp index 06cc7bf28c..f0f835f0f4 100644 --- a/indexer/indexer_tool/feature_sorter.cpp +++ b/indexer/indexer_tool/feature_sorter.cpp @@ -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 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 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(); diff --git a/indexer/indexer_tool/feature_sorter.hpp b/indexer/indexer_tool/feature_sorter.hpp index 810f66b3d9..8426c51d5b 100644 --- a/indexer/indexer_tool/feature_sorter.hpp +++ b/indexer/indexer_tool/feature_sorter.hpp @@ -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 + inline bool are_points_equal(PointT const & p1, PointT const & p2) + { + return p1 == p2; + } + + template <> + inline bool are_points_equal(m2::PointD const & p1, m2::PointD const & p2) + { + return AlmostEqual(p1, p2); + } + + template + void SimplifyPoints(PointsContainerT const & in, PointsContainerT & out, int level) + { + if (in.size() >= 2) + { + SimplifyNearOptimal >( + 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()); + } + } + } }