From cb62862b3460a4e1b5ccc7e31f1a6eaa2e185bdd Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 8 Jan 2014 13:44:31 +0300 Subject: [PATCH] [generator] Additional visibility checks for generating World and countries. --- generator/feature_builder.cpp | 9 ++------- generator/feature_generator.cpp | 18 ++++++++++-------- generator/feature_merger.cpp | 28 +++++++++++++++++++++++----- generator/feature_merger.hpp | 3 +++ generator/feature_sorter.cpp | 12 ++++++++---- generator/world_map_generator.hpp | 18 ++++++++++++++++++ indexer/feature_data.cpp | 4 +++- 7 files changed, 67 insertions(+), 25 deletions(-) diff --git a/generator/feature_builder.cpp b/generator/feature_builder.cpp index 782f8cbb67..1f5be0b099 100644 --- a/generator/feature_builder.cpp +++ b/generator/feature_builder.cpp @@ -385,15 +385,10 @@ string DebugPrint(FeatureBuilder1 const & f) case GEOM_POINT: out << DebugPrint(f.m_Center); break; case GEOM_LINE: out << "line with " << f.GetPointsCount() << " points"; break; case GEOM_AREA: out << "area with " << f.GetPointsCount() << " points"; break; - default: - out << "ERROR: unknown geometry type"; break; + default: out << "ERROR: unknown geometry type"; break; } - return (out.str() + " " + - DebugPrint(f.m_LimitRect) + " " + - DebugPrint(f.m_Params) + " " + - DebugPrint(f.m_Polygons) - ); + return (out.str() + " " + DebugPrint(f.m_LimitRect) + " " + DebugPrint(f.m_Params)); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp index d40ebfe78f..08a158e3e2 100644 --- a/generator/feature_generator.cpp +++ b/generator/feature_generator.cpp @@ -257,8 +257,11 @@ public: class MainFeaturesEmitter { - scoped_ptr > m_countries; - scoped_ptr > m_world; + typedef WorldMapGenerator WorldGenerator; + typedef CountryMapGenerator > CountriesGenerator; + scoped_ptr m_countries; + scoped_ptr m_world; + scoped_ptr m_coasts; scoped_ptr m_coastsHolder; @@ -313,7 +316,7 @@ public: if (!info.m_makeCoasts) { - m_countries.reset(new Polygonizer(info)); + m_countries.reset(new CountriesGenerator(info)); if (info.m_emitCoasts) { @@ -332,7 +335,7 @@ public: if (info.m_createWorld) { - m_world.reset(new WorldMapGenerator(info)); + m_world.reset(new WorldGenerator(info)); } } @@ -402,9 +405,8 @@ public: } else if (m_coastsHolder) { - CombinedEmitter< - FeaturesCollector, - Polygonizer > emitter(m_coastsHolder.get(), m_countries.get()); + CombinedEmitter + emitter(m_coastsHolder.get(), m_countries.get()); feature::ForEachFromDatRawFormat(m_srcCoastsFile, emitter); } @@ -414,7 +416,7 @@ public: inline void GetNames(vector & names) const { if (m_countries) - names = m_countries->Names(); + names = m_countries->Parent().Names(); else names.clear(); } diff --git a/generator/feature_merger.cpp b/generator/feature_merger.cpp index 06c83b0193..e9c853cab8 100644 --- a/generator/feature_merger.cpp +++ b/generator/feature_merger.cpp @@ -322,14 +322,21 @@ namespace feature class IsInvisibleFn { - int m_upperScale; + int m_lowScale, m_upScale; + public: - IsInvisibleFn(int scale) : m_upperScale(scale) {} + IsInvisibleFn(int lowScale, int upScale) + : m_lowScale(lowScale), m_upScale(upScale) + { + } + bool operator() (uint32_t type) const { - int const startScale = feature::GetDrawableScaleRange(type).first; + pair const range = feature::GetDrawableScaleRange(type); + // Actually it should not be equal to -1, but leave for safety reasons. - return (startScale == -1 || startScale > m_upperScale); + return (range.first == -1 || + range.first > m_upScale || range.second < m_lowScale); } }; @@ -337,7 +344,7 @@ bool PreprocessForWorldMap(FeatureBuilder1 & fb) { int const upperScale = scales::GetUpperWorldScale(); - if (fb.RemoveTypesIf(IsInvisibleFn(upperScale))) + if (fb.RemoveTypesIf(IsInvisibleFn(0, upperScale))) return false; fb.RemoveNameIfInvisible(0, upperScale); @@ -345,4 +352,15 @@ bool PreprocessForWorldMap(FeatureBuilder1 & fb) return true; } +bool PreprocessForCountryMap(FeatureBuilder1 & fb) +{ + if (fb.RemoveTypesIf(IsInvisibleFn(scales::GetUpperWorldScale() + 1, + scales::GetUpperStyleScale()))) + { + return false; + } + + return true; +} + } diff --git a/generator/feature_merger.hpp b/generator/feature_merger.hpp index 5edbd0453a..7ad2436e38 100644 --- a/generator/feature_merger.hpp +++ b/generator/feature_merger.hpp @@ -119,5 +119,8 @@ public: namespace feature { /// @return false If fb became invalid (no any suitable types). + //@{ bool PreprocessForWorldMap(FeatureBuilder1 & fb); + bool PreprocessForCountryMap(FeatureBuilder1 & fb); + //@} } diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index 9113d1d2fa..b5997d1566 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -50,11 +50,15 @@ namespace m_midLoc = m_midLoc / m_locCount; uint64_t const pointAsInt64 = PointToInt64(m_midLoc.x, m_midLoc.y, m_coordBits); - uint64_t const minScale = feature::GetMinDrawableScale(ft.GetFeatureBase()); - CHECK(minScale <= scales::GetUpperStyleScale(), ("Dat file contain invisible feature")); + int const minScale = feature::GetMinDrawableScale(ft.GetFeatureBase()); - uint64_t const order = (minScale << 59) | (pointAsInt64 >> 5); - m_vec.push_back(make_pair(order, pos)); + /// May be invisible if it's small area object with [0-9] scales. + /// @todo Probably, we need to keep that objects if 9 scale (as we do in 17 scale). + if (minScale != -1) + { + uint64_t const order = (static_cast(minScale) << 59) | (pointAsInt64 >> 5); + m_vec.push_back(make_pair(order, pos)); + } } bool operator() (m2::PointD const & p) diff --git a/generator/world_map_generator.hpp b/generator/world_map_generator.hpp index 6eb05935a3..f2091c4081 100644 --- a/generator/world_map_generator.hpp +++ b/generator/world_map_generator.hpp @@ -110,3 +110,21 @@ public: m_merger.DoMerge(m_worldBucket); } }; + +template +class CountryMapGenerator +{ + FeatureOutT m_bucket; + +public: + template + explicit CountryMapGenerator(TInfo const & info) : m_bucket(info) {} + + void operator()(FeatureBuilder1 fb) + { + if (feature::PreprocessForCountryMap(fb)) + m_bucket(fb); + } + + FeatureOutT const & Parent() const { return m_bucket; } +}; diff --git a/indexer/feature_data.cpp b/indexer/feature_data.cpp index e8bb42168b..4dd2d65bec 100644 --- a/indexer/feature_data.cpp +++ b/indexer/feature_data.cpp @@ -267,11 +267,13 @@ uint32_t FeatureParams::GetTypeForIndex(uint32_t i) string DebugPrint(FeatureParams const & p) { + Classificator const & c = classif(); + ostringstream out; out << "Types: "; for (size_t i = 0; i < p.m_Types.size(); ++i) - out << p.m_Types[i] << "; "; + out << c.GetReadableObjectName(p.m_Types[i]) << "; "; return (p.DebugString() + out.str()); }