From e6cf0a8589bc40b6f435f19568d91148d51f89bb Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Thu, 27 Jan 2011 22:09:37 +0200 Subject: [PATCH] - Polygons now are using doubles instead of uints - Added optimization: if feature is included only in one country, it's automatically added to this country --- indexer/indexer_tool/kml_parser.cpp | 10 +--- indexer/indexer_tool/kml_parser.hpp | 2 +- indexer/indexer_tool/polygonizer.hpp | 71 ++++++++++++++++------------ 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/indexer/indexer_tool/kml_parser.cpp b/indexer/indexer_tool/kml_parser.cpp index 0ab82b060a..13d2403808 100644 --- a/indexer/indexer_tool/kml_parser.cpp +++ b/indexer/indexer_tool/kml_parser.cpp @@ -85,14 +85,6 @@ namespace kml } }; - m2::PointU MercatorPointToPointU(m2::PointD const & pt) - { - typedef CellIdConverter CellIdConverterType; - uint32_t const ix = static_cast(CellIdConverterType::XToCellIdX(pt.x)); - uint32_t const iy = static_cast(CellIdConverterType::YToCellIdY(pt.y)); - return m2::PointU(ix, iy); - } - void KmlParser::Pop(string const & element) { if (element == "Placemark") @@ -134,7 +126,7 @@ namespace kml { m_country.push_back(Region()); for (MercPointsContainerT::iterator it = points.begin(); it != points.end(); ++it) - m_country.back().AddPoint(MercatorPointToPointU(*it)); + m_country.back().AddPoint(*it); } } else diff --git a/indexer/indexer_tool/kml_parser.hpp b/indexer/indexer_tool/kml_parser.hpp index 848e6afe05..e09bd1e813 100644 --- a/indexer/indexer_tool/kml_parser.hpp +++ b/indexer/indexer_tool/kml_parser.hpp @@ -8,7 +8,7 @@ namespace kml { - typedef m2::RegionU Region; + typedef m2::RegionD Region; typedef m4::Tree RegionsContainerT; struct CountryPolygons diff --git a/indexer/indexer_tool/polygonizer.hpp b/indexer/indexer_tool/polygonizer.hpp index 91d758e874..63d52030e4 100644 --- a/indexer/indexer_tool/polygonizer.hpp +++ b/indexer/indexer_tool/polygonizer.hpp @@ -2,13 +2,15 @@ #include "../../base/base.hpp" +#include "../../indexer/feature.hpp" +#include "../../indexer/feature_visibility.hpp" +#include "../../indexer/cell_id.hpp" + #include "../../coding/file_writer.hpp" #include "../../geometry/rect2d.hpp" -#include "../../indexer/feature.hpp" -#include "../../indexer/feature_visibility.hpp" -#include "../../indexer/cell_id.hpp" +#include "../../base/buffer_vector.hpp" #include "../../std/string.hpp" @@ -22,8 +24,6 @@ namespace feature template class Polygonizer { - typedef CellIdConverter CellIdConverterType; - public: template Polygonizer(TInfo & info) @@ -43,12 +43,6 @@ namespace feature for_each(m_Buckets.begin(), m_Buckets.end(), DeleteFunctor()); } - static m2::PointU Mercator2CellId(m2::PointD const & pt) - { - return m2::PointU(static_cast(CellIdConverterType::XToCellIdX(pt.x)), - static_cast(CellIdConverterType::YToCellIdY(pt.y))); - } - struct PointChecker { kml::RegionsContainerT const & m_regions; @@ -59,10 +53,7 @@ namespace feature bool operator()(m2::PointD const & pt) { - kml::Region::value_type const point = Mercator2CellId(pt); - - m_regions.ForEachInRect(m2::RectD(point, point), bind(ref(*this), _1, cref(point))); - + m_regions.ForEachInRect(m2::RectD(pt, pt), bind(ref(*this), _1, cref(pt))); return !m_belongs; } @@ -73,30 +64,52 @@ namespace feature } }; + class InsertCountriesPtr + { + typedef buffer_vector vec_type; + vec_type & m_vec; + + public: + InsertCountriesPtr(vec_type & vec) : m_vec(vec) {} + void operator() (kml::CountryPolygons const & c) + { + m_vec.push_back(&c); + } + }; + void operator () (FeatureBuilder1 const & fb) { - m2::RectD const r = fb.GetLimitRect(); - m_countries.ForEachInRect( - m2::RectD(Mercator2CellId(r.LeftBottom()), Mercator2CellId(r.RightTop())), - bind(ref(*this), _1, cref(fb))); + buffer_vector vec; + m_countries.ForEachInRect(fb.GetLimitRect(), InsertCountriesPtr(vec)); + + if (vec.size() == 1) + EmitFeature(vec[0], fb); + else + { + for (size_t i = 0; i < vec.size(); ++i) + this->operator()(vec[i], fb); + } } - void operator() (kml::CountryPolygons const & country, FeatureBuilder1 const & fb) + void operator() (kml::CountryPolygons const * country, FeatureBuilder1 const & fb) { - PointChecker doCheck(country.m_regions); + PointChecker doCheck(country->m_regions); fb.ForEachTruePointRef(doCheck); if (doCheck.m_belongs) - { - if (country.m_index == -1) - { - m_Names.push_back(country.m_name); - m_Buckets.push_back(new FeatureOutT(country.m_name, m_FeatureOutInitData)); - country.m_index = m_Buckets.size()-1; - } + EmitFeature(country, fb); + } - (*(m_Buckets[country.m_index]))(fb); + void EmitFeature(kml::CountryPolygons const * country, FeatureBuilder1 const & fb) + { + if (country->m_index == -1) + { + m_Names.push_back(country->m_name); + m_Buckets.push_back(new FeatureOutT(country->m_name, m_FeatureOutInitData)); + country->m_index = m_Buckets.size()-1; } + + (*(m_Buckets[country->m_index]))(fb); } private: