From e6102cebc82a3afc6042f6ec80a9f142fd98e71d Mon Sep 17 00:00:00 2001 From: MapsWithMe OSM User Date: Fri, 12 Apr 2013 13:28:25 +0200 Subject: [PATCH] [generator] Added -fail_on_coasts flag which will stop generation if coasts are not merged --- generator/coastlines_generator.cpp | 40 +++++++++++++++++++-- generator/coastlines_generator.hpp | 3 +- generator/feature_generator.cpp | 14 +++++--- generator/generator_tool/generator_tool.cpp | 2 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/generator/coastlines_generator.cpp b/generator/coastlines_generator.cpp index 28f3ea03d1..ea82f85b84 100644 --- a/generator/coastlines_generator.cpp +++ b/generator/coastlines_generator.cpp @@ -8,6 +8,8 @@ #include "../base/string_utils.hpp" #include "../base/logging.hpp" +#include "../../3party/gflags/src/gflags/gflags.h" + #include "../std/bind.hpp" @@ -15,6 +17,7 @@ typedef m2::RegionI RegionT; typedef m2::PointI PointT; typedef m2::RectI RectT; +DECLARE_bool(fail_on_coasts); CoastlineFeaturesGenerator::CoastlineFeaturesGenerator(uint32_t coastType, int lowLevel, int highLevel, int maxPoints) @@ -97,23 +100,56 @@ namespace class DoAddToTree : public FeatureEmitterIFace { CoastlineFeaturesGenerator & m_rMain; + size_t m_notMergedCoastsCount; + size_t m_totalNotMergedCoastsPoints; + public: - DoAddToTree(CoastlineFeaturesGenerator & rMain) : m_rMain(rMain) {} + DoAddToTree(CoastlineFeaturesGenerator & rMain) + : m_rMain(rMain), m_notMergedCoastsCount(0), m_totalNotMergedCoastsPoints(0) {} virtual void operator() (FeatureBuilder1 const & fb) { if (fb.IsGeometryClosed()) m_rMain.AddRegionToTree(fb); else + { LOG(LINFO, ("Not merged coastline", fb.GetOsmIdsString())); + ++m_notMergedCoastsCount; + m_totalNotMergedCoastsPoints += fb.GetPointsCount(); + } + } + + bool HasNotMergedCoasts() const + { + return m_notMergedCoastsCount != 0; + } + + size_t GetNotMergedCoastsCount() const + { + return m_notMergedCoastsCount; + } + + size_t GetNotMergedCoastsPoints() const + { + return m_totalNotMergedCoastsPoints; } }; } -void CoastlineFeaturesGenerator::Finish() +bool CoastlineFeaturesGenerator::Finish() { DoAddToTree doAdd(*this); m_merger.DoMerge(doAdd); + + if (doAdd.HasNotMergedCoasts()) + { + LOG(LINFO, ("Total not merged coasts:", doAdd.GetNotMergedCoastsCount())); + LOG(LINFO, ("Total points in not merged coasts:", doAdd.GetNotMergedCoastsPoints())); + if (FLAGS_fail_on_coasts) + return false; + } + + return true; } namespace diff --git a/generator/coastlines_generator.hpp b/generator/coastlines_generator.hpp index f52ccd52ca..40fb2ae9e2 100644 --- a/generator/coastlines_generator.hpp +++ b/generator/coastlines_generator.hpp @@ -31,7 +31,8 @@ public: void AddRegionToTree(FeatureBuilder1 const & fb); void operator() (FeatureBuilder1 const & fb); - void Finish(); + /// @return false if coasts are not merged and FLAG_fail_on_coasts is set + bool Finish(); inline size_t GetCellsCount() const { return 1 << 2 * m_lowLevel; } void GetFeatures(size_t i, vector & vecFb); diff --git a/generator/feature_generator.cpp b/generator/feature_generator.cpp index 4e23c671ac..2f7fb54a8d 100644 --- a/generator/feature_generator.cpp +++ b/generator/feature_generator.cpp @@ -334,15 +334,17 @@ public: (*m_countries)(fb); } } - - void Finish() + /// @return false if coasts are not merged and FLAG_fail_on_coasts is set + bool Finish() { if (m_world) m_world->DoMerge(); if (m_coasts) { - m_coasts->Finish(); + // Check and stop if some coasts were not merged + if (!m_coasts->Finish()) + return false; size_t const count = m_coasts->GetCellsCount(); LOG(LINFO, ("Generating coastline polygons", count)); @@ -363,6 +365,8 @@ public: Polygonizer > emitter(m_coastsHolder.get(), m_countries.get()); feature::ForEachFromDatRawFormat(m_srcCoastsFile, emitter); } + + return true; } inline void GetNames(vector & names) const @@ -392,7 +396,9 @@ bool GenerateImpl(GenerateInfo & info) bucketer, holder, info.m_makeCoasts ? classif().GetCoastType() : 0); ParseXMLFromStdIn(parser); - bucketer.Finish(); + // Stop if coasts are not merged and FLAG_fail_on_coasts is set + if (!bucketer.Finish()) + return false; bucketer.GetNames(info.m_bucketNames); } catch (Reader::Exception const & e) diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 52d0230c15..063ff20fdc 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -62,7 +62,7 @@ DEFINE_bool(unpack_mwm, false, "Unpack each section of mwm into a separate file DEFINE_bool(generate_packed_borders, false, "Generate packed file with country polygons."); DEFINE_bool(check_mwm, false, "Check map file to be correct."); DEFINE_string(delete_section, "", "Delete specified section (defines.hpp) from container."); - +DEFINE_bool(fail_on_coasts, false, "Stop and exit with '255' code if some coastlines are not merged."); string AddSlashIfNeeded(string const & str) {