From 265a12dd73e7c71cb5d3c883494eb23c93f68014 Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Tue, 7 May 2019 11:49:47 +0300 Subject: [PATCH] [generator] Preparing for generation 'osm only' --- generator/generator_tool/generator_tool.cpp | 4 +++- generator/node_mixer.cpp | 6 +++--- generator/node_mixer.hpp | 4 ++-- generator/osm_source.cpp | 3 +-- generator/translator_country.cpp | 24 ++++++++++++++++++--- generator/translator_country.hpp | 15 +++++++++++++ generator/translator_factory.hpp | 3 +++ 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 91891cd5ca..2eacd32225 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -112,6 +112,7 @@ DEFINE_uint64(planet_version, base::SecondsSinceEpoch(), // Preprocessing and feature generator. DEFINE_bool(preprocess, false, "1st pass - create nodes/ways/relations data."); DEFINE_bool(generate_features, false, "2nd pass - generate intermediate features."); +DEFINE_bool(no_ads, false, "generation without ads."); DEFINE_bool(generate_region_features, false, "Generate intermediate features for regions to use in regions index and borders generation."); DEFINE_bool(generate_streets_features, false, @@ -332,7 +333,8 @@ int GeneratorToolMain(int argc, char ** argv) if (FLAGS_generate_features) { auto emitter = CreateEmitter(EmitterType::Country, genInfo); - translators.Append(CreateTranslator(TranslatorType::Country, emitter, cacheLoader.GetCache(), genInfo)); + auto const translatorType = FLAGS_no_ads ? TranslatorType::Country : TranslatorType::CountryWithAds; + translators.Append(CreateTranslator(translatorType, emitter, cacheLoader.GetCache(), genInfo)); } if (FLAGS_generate_world) diff --git a/generator/node_mixer.cpp b/generator/node_mixer.cpp index e84e06b7bd..b003a042c8 100644 --- a/generator/node_mixer.cpp +++ b/generator/node_mixer.cpp @@ -7,7 +7,7 @@ using namespace std; namespace generator { -void MixFakeNodes(istream & stream, function processor) +void MixFakeNodes(istream & stream, function processor) { if (stream.fail()) return; @@ -31,7 +31,7 @@ void MixFakeNodes(istream & stream, function processor) { if (completionFlag == kCFAll) { - processor(&p); + processor(p); count++; p.Clear(); p.id = baseNodeId + count; @@ -69,7 +69,7 @@ void MixFakeNodes(istream & stream, function processor) if (completionFlag == kCFAll) { - processor(&p); + processor(p); count++; } diff --git a/generator/node_mixer.hpp b/generator/node_mixer.hpp index ecea49605c..f2b7efac4c 100644 --- a/generator/node_mixer.hpp +++ b/generator/node_mixer.hpp @@ -8,9 +8,9 @@ namespace generator { -void MixFakeNodes(std::istream & stream, std::function processor); +void MixFakeNodes(std::istream & stream, std::function processor); -inline void MixFakeNodes(std::string const filePath, std::function processor) +inline void MixFakeNodes(std::string const filePath, std::function processor) { std::ifstream stream(filePath); MixFakeNodes(stream, processor); diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 4d4d0d8fc2..bb171aad49 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -1,7 +1,6 @@ #include "generator/osm_source.hpp" #include "generator/intermediate_elements.hpp" -#include "generator/node_mixer.hpp" #include "generator/osm_element.hpp" #include "generator/osm_o5m_source.hpp" #include "generator/osm_xml_source.hpp" @@ -18,6 +17,7 @@ #include "coding/file_name_utils.hpp" #include "coding/parse_xml.hpp" +#include #include #include @@ -224,7 +224,6 @@ bool GenerateRaw(feature::GenerateInfo & info, TranslatorInterface & translators } LOG(LINFO, ("Processing", info.m_osmFileName, "done.")); - MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE, fn); if (!translators.Finish()) return false; diff --git a/generator/translator_country.cpp b/generator/translator_country.cpp index 1007200ff6..4540391ccd 100644 --- a/generator/translator_country.cpp +++ b/generator/translator_country.cpp @@ -11,6 +11,7 @@ #include "generator/intermediate_data.hpp" #include "generator/maxspeeds_collector.hpp" #include "generator/metalines_builder.hpp" +#include "generator/node_mixer.hpp" #include "generator/restriction_writer.hpp" #include "generator/road_access_generator.hpp" @@ -74,7 +75,6 @@ TranslatorCountry::TranslatorCountry(std::shared_ptr emitter, : Translator(emitter, cache, std::make_shared(cache)) , m_tagAdmixer(info.GetIntermediateFileName("ways", ".csv"), info.GetIntermediateFileName("towns", ".csv")) , m_tagReplacer(base::JoinPath(GetPlatform().ResourcesDir(), REPLACED_TAGS_FILE)) - , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) { AddFilter(std::make_shared()); AddFilter(std::make_shared(base::JoinPath(GetPlatform().ResourcesDir(), SKIPPED_ELEMENTS_FILE))); @@ -97,8 +97,6 @@ void TranslatorCountry::Preprocess(OsmElement & element) { // Here we can add new tags to the elements! m_tagReplacer(element); - m_tagAdmixer(element); - m_osmTagMixer(element); CollectFromRelations(element); } @@ -110,4 +108,24 @@ void TranslatorCountry::CollectFromRelations(OsmElement const & element) else if (element.IsWay()) m_cache.ForEachRelationByWayCached(element.id, collector); } + +TranslatorCountryWithAds::TranslatorCountryWithAds(std::shared_ptr emitter, + cache::IntermediateDataReader & cache, + feature::GenerateInfo const & info) + : TranslatorCountry(emitter, cache, info) + , m_osmTagMixer(base::JoinPath(GetPlatform().ResourcesDir(), MIXED_TAGS_FILE)) {} + +void TranslatorCountryWithAds::Preprocess(OsmElement & element) +{ + // Here we can add new tags to the elements! + m_osmTagMixer(element); + TranslatorCountry::Preprocess(element); +} + +bool TranslatorCountryWithAds::Finish() +{ + MixFakeNodes(GetPlatform().ResourcesDir() + MIXED_NODES_FILE, + std::bind(&TranslatorCountryWithAds::Emit, this, std::placeholders::_1)); + return TranslatorCountry::Finish(); +} } // namespace generator diff --git a/generator/translator_country.hpp b/generator/translator_country.hpp index 712f958be1..a774de9f25 100644 --- a/generator/translator_country.hpp +++ b/generator/translator_country.hpp @@ -33,6 +33,21 @@ private: TagAdmixer m_tagAdmixer; TagReplacer m_tagReplacer; +}; + +// The TranslatorCountryWithAds class implements translator for building countries with advertising. +class TranslatorCountryWithAds : public TranslatorCountry +{ +public: + explicit TranslatorCountryWithAds(std::shared_ptr emitter, + cache::IntermediateDataReader & cache, + feature::GenerateInfo const & info); + + // TranslatorInterface overrides: + void Preprocess(OsmElement & element) override; + bool Finish() override; + +private: OsmTagMixer m_osmTagMixer; }; } // namespace generator diff --git a/generator/translator_factory.hpp b/generator/translator_factory.hpp index 1bb10af39d..06eb27fc2b 100644 --- a/generator/translator_factory.hpp +++ b/generator/translator_factory.hpp @@ -22,6 +22,7 @@ enum class TranslatorType Streets, GeoObjects, Country, + CountryWithAds, Coastline, World }; @@ -35,6 +36,8 @@ std::shared_ptr CreateTranslator(TranslatorType type, Args& return create(std::forward(args)...); case TranslatorType::Country: return create(std::forward(args)...); + case TranslatorType::CountryWithAds: + return create(std::forward(args)...); case TranslatorType::Regions: return create(std::forward(args)...); case TranslatorType::Streets: