diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-10-27 13:04:44 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-11-10 18:58:19 +0300 |
commit | 44d7d2efa2c57566ffd70a8431c7d09403b19b02 (patch) | |
tree | 2497322750a6c2c5f9c0fba4170e7ee43119682c /generator | |
parent | b416d8430631b9b8f7a8d50867ddbcb9b4a37ddf (diff) |
Using RestrictionCollector on 2nd generation step to generate restrictions in feature id terms.
Diffstat (limited to 'generator')
-rw-r--r-- | generator/feature_builder.hpp | 1 | ||||
-rw-r--r-- | generator/feature_generator.hpp | 2 | ||||
-rw-r--r-- | generator/osm_source.cpp | 11 | ||||
-rw-r--r-- | generator/osm_source.hpp | 8 | ||||
-rw-r--r-- | generator/osm_translator.hpp | 31 | ||||
-rw-r--r-- | generator/polygonizer.hpp | 24 | ||||
-rw-r--r-- | generator/restrictions.cpp | 2 | ||||
-rw-r--r-- | generator/world_map_generator.hpp | 6 |
8 files changed, 66 insertions, 19 deletions
diff --git a/generator/feature_builder.hpp b/generator/feature_builder.hpp index e766211121..efc16df14f 100644 --- a/generator/feature_builder.hpp +++ b/generator/feature_builder.hpp @@ -171,6 +171,7 @@ public: osm::Id GetMostGenericOsmId() const; bool HasOsmId(osm::Id const & id) const; string GetOsmIdsString() const; + vector<osm::Id> const & GetOsmIds() const { return m_osmIds; } //@} uint64_t GetWayIDForRouting() const; diff --git a/generator/feature_generator.hpp b/generator/feature_generator.hpp index 7d82086846..f050d2bcd3 100644 --- a/generator/feature_generator.hpp +++ b/generator/feature_generator.hpp @@ -40,6 +40,8 @@ public: string const & GetFilePath() const { return m_datFile.GetName(); } + uint32_t GetNextFeatureId() const { return m_featureID; } + virtual void operator()(FeatureBuilder1 const & f); }; diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 4b1ec3759e..e0fdc5f26e 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -24,6 +24,7 @@ #include "base/stl_helpers.hpp" +#include "coding/file_name_utils.hpp" #include "coding/parse_xml.hpp" #include "std/fstream.hpp" @@ -140,8 +141,10 @@ public: string const & relationType = e.GetType(); if (!(relationType == "multipolygon" || relationType == "route" || relationType == "boundary" || relationType == "associatedStreet" || - relationType == "building")) + relationType == "building" || relationType == "restriction")) + { return; + } m_relations.Write(id, e); AddToIndex(m_nodeToRelations, id, e.nodes); @@ -440,7 +443,7 @@ public: auto & emitter = m_countries->Parent(); emitter.Start(); - (*m_countries)(fb); + (*m_countries)(fb, GetRestrictionCollector()); emitter.Finish(); if (m_coastsHolder) @@ -497,7 +500,7 @@ private: (*m_world)(fb); if (m_countries) - (*m_countries)(fb); + (*m_countries)(fb, GetRestrictionCollector()); } void DumpSkippedElements() @@ -722,6 +725,8 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info, EmitterBase & emitter) if (!emitter.Finish()) return false; + emitter.GetRestrictionCollector().ComposeRestrictionsAndSave( + info.GetIntermediateFileName("restrictions", ".csv")); emitter.GetNames(info.m_bucketNames); } catch (Reader::Exception const & ex) diff --git a/generator/osm_source.hpp b/generator/osm_source.hpp index d5688043e9..a03b9b7fdf 100644 --- a/generator/osm_source.hpp +++ b/generator/osm_source.hpp @@ -2,6 +2,7 @@ #include "generator/generate_info.hpp" #include "generator/osm_element.hpp" +#include "generator/restrictions.hpp" #include "std/function.hpp" #include "std/iostream.hpp" @@ -35,6 +36,8 @@ class FeatureBuilder1; // Emitter is used in OsmElemen to FeatureBuilder translation process. class EmitterBase { + RestrictionCollector m_restrictions; + public: virtual ~EmitterBase() = default; @@ -46,6 +49,11 @@ public: /// Sets buckets (mwm names). // TODO(syershov): Make this topic clear. virtual void GetNames(vector<string> & names) const = 0; + + RestrictionCollector & GetRestrictionCollector() + { + return m_restrictions; + } }; unique_ptr<EmitterBase> MakeMainFeatureEmitter(feature::GenerateInfo const & info); diff --git a/generator/osm_translator.hpp b/generator/osm_translator.hpp index ffa9c641fb..5ea392751c 100644 --- a/generator/osm_translator.hpp +++ b/generator/osm_translator.hpp @@ -3,6 +3,7 @@ #include "generator/feature_builder.hpp" #include "generator/osm2type.hpp" #include "generator/osm_element.hpp" +#include "generator/restrictions.hpp" #include "generator/ways_merger.hpp" #include "indexer/classificator.hpp" @@ -19,6 +20,7 @@ #include "std/list.hpp" #include "std/type_traits.hpp" #include "std/unordered_set.hpp" +#include "std/vector.hpp" namespace { @@ -27,7 +29,8 @@ namespace class RelationTagsBase { public: - RelationTagsBase() : m_cache(14) {} + RelationTagsBase(RestrictionCollector & restrictionCollector) + : m_restrictionCollector(restrictionCollector), m_cache(14) {} void Reset(uint64_t fID, OsmElement * p) { @@ -51,7 +54,7 @@ protected: static bool IsSkipRelation(string const & type) { /// @todo Skip special relation types. - return (type == "multipolygon" || type == "bridge" || type == "restriction"); + return (type == "multipolygon" || type == "bridge"); } bool IsKeyTagExists(string const & key) const @@ -72,6 +75,7 @@ protected: protected: uint64_t m_featureID; OsmElement * m_current; + RestrictionCollector & m_restrictionCollector; private: my::Cache<uint64_t, RelationElement> m_cache; @@ -81,6 +85,10 @@ class RelationTagsNode : public RelationTagsBase { using TBase = RelationTagsBase; +public: + RelationTagsNode(RestrictionCollector & restrictionCollector) + : RelationTagsBase(restrictionCollector) {} + protected: void Process(RelationElement const & e) override { @@ -88,6 +96,9 @@ protected: if (TBase::IsSkipRelation(type)) return; + if (type == "restriction") + m_restrictionCollector.AddRestriction(e); + bool const processAssociatedStreet = type == "associatedStreet" && TBase::IsKeyTagExists("addr:housenumber") && !TBase::IsKeyTagExists("addr:street"); @@ -112,6 +123,11 @@ protected: class RelationTagsWay : public RelationTagsBase { +public: + RelationTagsWay(RestrictionCollector & restrictionCollector) + : RelationTagsBase(restrictionCollector) {} + +private: using TBase = RelationTagsBase; using TNameKeys = unordered_set<string>; @@ -134,6 +150,9 @@ protected: if (TBase::IsSkipRelation(type) || type == "route") return; + if (type == "restriction") + m_restrictionCollector.AddRestriction(e); + if (type == "building") { // If this way has "outline" role, add [building=has_parts] type. @@ -289,11 +308,12 @@ class OsmToFeatureTranslator } } - void EmitLine(FeatureBuilder1 & ft, FeatureParams params, bool isCoastLine) const + void EmitLine(FeatureBuilder1 & ft, FeatureParams params, bool isCoastLine, osm::Id id) const { if (isCoastLine || feature::RemoveNoDrawableTypes(params.m_Types, feature::GEOM_LINE)) { ft.SetLinear(params.m_reverseGeometry); + ft.AddOsmId(id); EmitFeatureBase(ft, params); } } @@ -400,7 +420,7 @@ public: ft.SetAreaAddHoles(processor.GetHoles()); }); - EmitLine(ft, params, isCoastLine); + EmitLine(ft, params, isCoastLine, osm::Id::Node(p->id)); state = FeatureState::Ok; break; } @@ -485,7 +505,8 @@ public: public: OsmToFeatureTranslator(TEmitter & emitter, TCache & holder, uint32_t coastType, string const & addrFilePath = {}) - : m_emitter(emitter), m_holder(holder), m_coastType(coastType) + : m_emitter(emitter), m_holder(holder), m_coastType(coastType), + m_nodeRelations(m_emitter.GetRestrictionCollector()), m_wayRelations(m_emitter.GetRestrictionCollector()) { if (!addrFilePath.empty()) m_addrWriter.reset(new FileWriter(addrFilePath)); diff --git a/generator/polygonizer.hpp b/generator/polygonizer.hpp index 2879bfbd2a..2c42a5f00f 100644 --- a/generator/polygonizer.hpp +++ b/generator/polygonizer.hpp @@ -3,6 +3,7 @@ #include "generator/borders_loader.hpp" #include "generator/feature_builder.hpp" #include "generator/generate_info.hpp" +#include "generator/restrictions.hpp" #include "indexer/feature_visibility.hpp" #include "indexer/cell_id.hpp" @@ -29,6 +30,7 @@ #include <QtCore/QMutexLocker> #endif +class RestrictionCollector; namespace feature { @@ -110,7 +112,7 @@ namespace feature } }; - void operator () (FeatureBuilder1 const & fb) + void operator () (FeatureBuilder1 & fb, RestrictionCollector & restrictions) { buffer_vector<borders::CountryPolygons const *, 32> vec; m_countries.ForEachInRect(fb.GetLimitRect(), InsertCountriesPtr(vec)); @@ -120,15 +122,15 @@ namespace feature case 0: break; case 1: - EmitFeature(vec[0], fb); + EmitFeature(vec[0], fb, restrictions); break; default: { #if PARALLEL_POLYGONIZER m_ThreadPoolSemaphore.acquire(); - m_ThreadPool.start(new PolygonizerTask(this, vec, fb)); + m_ThreadPool.start(new PolygonizerTask(this, vec, fb, restrictions)); #else - PolygonizerTask task(this, vec, fb); + PolygonizerTask task(this, vec, fb, restrictions); task.RunBase(); #endif } @@ -149,7 +151,8 @@ namespace feature #endif } - void EmitFeature(borders::CountryPolygons const * country, FeatureBuilder1 const & fb) + void EmitFeature(borders::CountryPolygons const * country, FeatureBuilder1 const & fb, + RestrictionCollector & restriction) { #if PARALLEL_POLYGONIZER QMutexLocker mutexLocker(&m_EmitFeatureMutex); @@ -167,6 +170,10 @@ namespace feature m_currentNames += country->m_name; (*(m_Buckets[country->m_index]))(fb); + uint32_t const nextFeatureId = m_Buckets[country->m_index]->GetNextFeatureId(); + CHECK_LESS(0, nextFeatureId, ("GetNextFeatureId() is called before WriteFeatureBase(...)")); + if (fb.IsLine()) + restriction.AddFeatureId(fb.GetOsmIds(), nextFeatureId - 1 /* feature id of |fb| */); } vector<string> const & Names() const @@ -185,8 +192,8 @@ namespace feature public: PolygonizerTask(Polygonizer * pPolygonizer, buffer_vector<borders::CountryPolygons const *, 32> const & countries, - FeatureBuilder1 const & fb) - : m_pPolygonizer(pPolygonizer), m_Countries(countries), m_FB(fb) {} + FeatureBuilder1 const & fb, RestrictionCollector & restrictions) + : m_pPolygonizer(pPolygonizer), m_Countries(countries), m_FB(fb), m_restrictions(restrictions) {} void RunBase() { @@ -196,7 +203,7 @@ namespace feature m_FB.ForEachGeometryPoint(doCheck); if (doCheck.m_belongs) - m_pPolygonizer->EmitFeature(m_Countries[i], m_FB); + m_pPolygonizer->EmitFeature(m_Countries[i], m_FB, m_restrictions); } } @@ -213,6 +220,7 @@ namespace feature Polygonizer * m_pPolygonizer; buffer_vector<borders::CountryPolygons const *, 32> m_Countries; FeatureBuilder1 m_FB; + RestrictionCollector & m_restrictions; }; }; } diff --git a/generator/restrictions.cpp b/generator/restrictions.cpp index f0f9ec1246..2ca647b750 100644 --- a/generator/restrictions.cpp +++ b/generator/restrictions.cpp @@ -108,7 +108,7 @@ void RestrictionCollector::AddRestriction(RelationElement const & relationElemen if (tagIt == relationElement.tags.end()) return; // Type of the element is different from "restriction". - auto typeResult = TagToType(tagIt->second); + auto const typeResult = TagToType(tagIt->second); if (typeResult.second == false) return; // Unsupported restriction type. diff --git a/generator/world_map_generator.hpp b/generator/world_map_generator.hpp index ad26cc5bb4..c6473e467e 100644 --- a/generator/world_map_generator.hpp +++ b/generator/world_map_generator.hpp @@ -13,6 +13,8 @@ #include "defines.hpp" +class RestrictionCollector; + namespace { class WaterBoundaryChecker @@ -314,10 +316,10 @@ class CountryMapGenerator public: explicit CountryMapGenerator(feature::GenerateInfo const & info) : m_bucket(info) {} - void operator()(FeatureBuilder1 fb) + void operator()(FeatureBuilder1 fb, RestrictionCollector & restrictions) { if (feature::PreprocessForCountryMap(fb)) - m_bucket(fb); + m_bucket(fb, restrictions); } inline FeatureOutT & Parent() { return m_bucket; } |