From 61f3a3626cc1ac29107dc146842b4ac479a0f2cd Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Mon, 18 Feb 2019 13:29:51 +0300 Subject: [PATCH] Adding methods for getting info if route crosses mwm where warnings about speedcams are prohibited. --- generator/camera_info_collector.cpp | 19 -------- generator/camera_info_collector.hpp | 4 -- generator/generator_tool/generator_tool.cpp | 3 +- routing/CMakeLists.txt | 2 + routing/index_router.cpp | 28 +++++++++-- routing/index_router.hpp | 8 ++++ routing/route.cpp | 15 ++++++ routing/route.hpp | 16 +++++++ routing/speed_camera_prohibition.cpp | 46 +++++++++++++++++++ routing/speed_camera_prohibition.hpp | 12 +++++ .../routing/routing.xcodeproj/project.pbxproj | 8 ++++ 11 files changed, 134 insertions(+), 27 deletions(-) create mode 100644 routing/speed_camera_prohibition.cpp create mode 100644 routing/speed_camera_prohibition.hpp diff --git a/generator/camera_info_collector.cpp b/generator/camera_info_collector.cpp index 0ec2f5b725..add2eb4799 100644 --- a/generator/camera_info_collector.cpp +++ b/generator/camera_info_collector.cpp @@ -16,7 +16,6 @@ #include "base/string_utils.hpp" #include -#include #include namespace generator @@ -317,24 +316,6 @@ void CamerasInfoCollector::Camera::Serialize(FileWriter & writer, routing::SerializeSpeedCamera(writer, m_data, prevFeatureId); } -bool IsCamerasInfoProhibited(std::string const & mwmName) -{ - std::array kCountryBlockList = { - "Cyprus", - "Macedonia", - "Switzerland", - "Turkey", - }; - - for (auto const & country : kCountryBlockList) - { - if (strings::StartsWith(mwmName, country)) - return true; - } - - return false; -} - void BuildCamerasInfo(std::string const & dataFilePath, std::string const & camerasInfoPath, std::string const & osmIdsToFeatureIdsPath) diff --git a/generator/camera_info_collector.hpp b/generator/camera_info_collector.hpp index 1fe8f33fb6..07e9d7fdf7 100644 --- a/generator/camera_info_collector.hpp +++ b/generator/camera_info_collector.hpp @@ -86,10 +86,6 @@ private: std::vector m_cameras; }; -/// \returns true if any information about speed cameras is prohibited in |mwmName|. -/// \param mwmName is mwm name without extention. E.g. "Russia_Moscow". -bool IsCamerasInfoProhibited(std::string const & mwmName); - // To start building camera info, the following data must be ready: // 1. GenerateIntermediateData(). Cached data about camera node to ways. // 2. GenerateFeatures(). Data about cameras from OSM. diff --git a/generator/generator_tool/generator_tool.cpp b/generator/generator_tool/generator_tool.cpp index 6bcb7ed59a..8e500e7f68 100644 --- a/generator/generator_tool/generator_tool.cpp +++ b/generator/generator_tool/generator_tool.cpp @@ -34,6 +34,7 @@ #include "generator/wiki_url_dumper.hpp" #include "routing/cross_mwm_ids.hpp" +#include "routing/speed_camera_prohibition.hpp" #include "indexer/classificator.hpp" #include "indexer/classificator_loader.hpp" @@ -529,7 +530,7 @@ int GeneratorToolMain(int argc, char ** argv) if (FLAGS_generate_cameras) { - if (IsCamerasInfoProhibited(country)) + if (routing::ShouldRemoveSpeedcamWhileMapGeneration(platform::CountryFile(country))) { LOG(LINFO, ("Cameras info is prohibited for", country, "and speedcams section is not generated.")); diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index 4605e5ab92..a45f433be0 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -119,6 +119,8 @@ set( speed_camera.hpp speed_camera_manager.cpp speed_camera_manager.hpp + speed_camera_prohibition.cpp + speed_camera_prohibition.hpp speed_camera_ser_des.cpp speed_camera_ser_des.hpp traffic_stash.cpp diff --git a/routing/index_router.cpp b/routing/index_router.cpp index 13cbab4575..67b996939e 100644 --- a/routing/index_router.cpp +++ b/routing/index_router.cpp @@ -15,6 +15,7 @@ #include "routing/routing_exceptions.hpp" #include "routing/routing_helpers.hpp" #include "routing/single_vehicle_world_graph.hpp" +#include "routing/speed_camera_prohibition.hpp" #include "routing/transit_info.hpp" #include "routing/transit_world_graph.hpp" #include "routing/turns_generator.hpp" @@ -29,13 +30,13 @@ #include "indexer/data_source.hpp" #include "indexer/feature_altitude.hpp" +#include "platform/mwm_traits.hpp" + #include "geometry/mercator.hpp" #include "geometry/parametrized_segment.hpp" #include "geometry/point2d.hpp" -#include "platform/country_file.hpp" -#include "platform/mwm_traits.hpp" - +#include "base/assert.hpp" #include "base/exception.hpp" #include "base/logging.hpp" #include "base/stl_helpers.hpp" @@ -963,6 +964,10 @@ RouterResultCode IndexRouter::RedressRoute(vector const & segments, routeSegment.SetSpeedCameraInfo(worldGraph.GetSpeedCamInfo(routeSegment.GetSegment())); } + vector speedcamProhibited; + FillsSpeedcamProhibitedMwms(segments, speedcamProhibited); + route.StealSpeedcamProhibited(move(speedcamProhibited)); + if (delegate.IsCancelled()) return RouterResultCode::Cancelled; @@ -1016,4 +1021,21 @@ RouterResultCode IndexRouter::ConvertTransitResult(set const & mwmIds, return RouterResultCode::TransitRouteNotFoundTooLongPedestrian; } + +void IndexRouter::FillsSpeedcamProhibitedMwms(vector const & segments, + vector & speedcamProhibitedMwms) const +{ + CHECK(m_numMwmIds, ()); + + set mwmIds; + for (auto const & s : segments) + mwmIds.insert(s.GetMwmId()); + + for (auto const id : mwmIds) + { + auto const & country = m_numMwmIds->GetFile(id); + if (ShouldWarnAboutSpeedcam(country)) + speedcamProhibitedMwms.push_back(country); + } +} } // namespace routing diff --git a/routing/index_router.hpp b/routing/index_router.hpp index 22d07d75e9..351ae7ea1d 100644 --- a/routing/index_router.hpp +++ b/routing/index_router.hpp @@ -12,6 +12,7 @@ #include "routing/joint.hpp" #include "routing/router.hpp" #include "routing/routing_callbacks.hpp" +#include "routing/segment.hpp" #include "routing/segmented_route.hpp" #include "routing/world_graph.hpp" @@ -20,6 +21,8 @@ #include "indexer/mwm_set.hpp" +#include "platform/country_file.hpp" + #include "geometry/tree4d.hpp" #include "std/unique_ptr.hpp" @@ -121,6 +124,11 @@ private: RouterResultCode ConvertTransitResult(std::set const & mwmIds, RouterResultCode resultCode) const; + /// \brief Fills |speedcamProhibitedMwms| with mwms which are crossed by |segments| + /// where speed cameras are prohibited. + void FillsSpeedcamProhibitedMwms(std::vector const & segments, + std::vector & speedcamProhibitedMwms) const; + template RouterResultCode ConvertResult(typename AStarAlgorithm::Result result) const { diff --git a/routing/route.cpp b/routing/route.cpp index 7c838ba8b4..99e35eee66 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -368,6 +368,21 @@ double Route::GetSegLenMeters(size_t segIdx) const (segIdx == 0 ? 0.0 : m_routeSegments[segIdx - 1].GetDistFromBeginningMeters()); } +void Route::StealSpeedcamProhibited(vector && speedcamProhibited) +{ + m_speedcamProhibited = move(speedcamProhibited); +} + +bool Route::CrossSpeedcomProhibited() const +{ + return m_speedcamProhibited.empty(); +} + +std::vector const & Route::GetSpeedcamProhibited() const +{ + return m_speedcamProhibited; +} + double Route::GetETAToLastPassedPointSec() const { CHECK(IsValid(), ()); diff --git a/routing/route.hpp b/routing/route.hpp index cdd06b472e..60b3cd8237 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -12,6 +12,8 @@ #include "indexer/feature_altitude.hpp" +#include "platform/country_file.hpp" + #include "geometry/polyline2d.hpp" #include "base/assert.hpp" @@ -372,6 +374,17 @@ public: /// \returns Length of the route segment with |segIdx| in meters. double GetSegLenMeters(size_t segIdx) const; + /// \brief Moves |speedcamProhibited| to |m_speedcamProhibited|. + void StealSpeedcamProhibited(std::vector && speedcamProhibited); + + /// \returns true if the route crosses at lease one mwm where there are restrictions on warning + /// about speed cameras. + bool CrossSpeedcomProhibited() const; + + /// \returns mwm list which is crossed by the route and where there are restrictions on warning + /// about speed cameras. + std::vector const & GetSpeedcamProhibited() const; + private: friend std::string DebugPrint(Route const & r); @@ -402,5 +415,8 @@ private: std::vector m_subrouteAttrs; // Route identifier. It's unique within single program session. uint64_t m_routeId = 0; + + // Mwms which are crossed by the route where speed cameras are prohibited. + std::vector m_speedcamProhibited; }; } // namespace routing diff --git a/routing/speed_camera_prohibition.cpp b/routing/speed_camera_prohibition.cpp new file mode 100644 index 0000000000..03b7915f3a --- /dev/null +++ b/routing/speed_camera_prohibition.cpp @@ -0,0 +1,46 @@ +#include "routing/speed_camera_prohibition.hpp" + +#include "base/string_utils.hpp" + +#include + +namespace +{ +// List of country names where mwm should be generated without speedcameras. +std::vector kCountryBlockListForMapGeneration = { + "Cyprus", + "Macedonia", + "Switzerland", + "Turkey", +}; + +// List of country names where an end user should be warned about speedcameras. +std::vector kCountryWarnList = { + "France", + "Germany", +}; + +bool IsMwmContained(platform::CountryFile const & mwm, std::vector const & countryList) +{ + for (auto const & country : countryList) + { + if (strings::StartsWith(mwm.GetName(), country)) + return true; + } + + return false; +} +} // namespace + +namespace routing +{ +bool ShouldRemoveSpeedcamWhileMapGeneration(platform::CountryFile const & mwm) +{ + return IsMwmContained(mwm, kCountryBlockListForMapGeneration); +} + +bool ShouldWarnAboutSpeedcam(platform::CountryFile const & mwm) +{ + return ShouldRemoveSpeedcamWhileMapGeneration(mwm) || IsMwmContained(mwm, kCountryWarnList); +} +} // namespace routing diff --git a/routing/speed_camera_prohibition.hpp b/routing/speed_camera_prohibition.hpp new file mode 100644 index 0000000000..297b628310 --- /dev/null +++ b/routing/speed_camera_prohibition.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "platform/country_file.hpp" + +namespace routing +{ +/// \returns true if any information about speed cameras is prohibited in |mwm|. +bool ShouldRemoveSpeedcamWhileMapGeneration(platform::CountryFile const & mwm); + +/// \returns true if any information about speed cameras is prohibited or partly prohibited in |mwm|. +bool ShouldWarnAboutSpeedcam(platform::CountryFile const & mwm); +} // namespace routing diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index afc0f16c1b..2bb0744486 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -93,6 +93,8 @@ 56099E2B1CC7C97D00A7772A /* turn_candidate.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56099E271CC7C97D00A7772A /* turn_candidate.hpp */; }; 56099E331CC9247E00A7772A /* bicycle_directions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56099E301CC9247E00A7772A /* bicycle_directions.cpp */; }; 56099E341CC9247E00A7772A /* bicycle_directions.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56099E311CC9247E00A7772A /* bicycle_directions.hpp */; }; + 5610731B221ABF96008447B2 /* speed_camera_prohibition.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56107319221ABF96008447B2 /* speed_camera_prohibition.hpp */; }; + 5610731C221ABF96008447B2 /* speed_camera_prohibition.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5610731A221ABF96008447B2 /* speed_camera_prohibition.cpp */; }; 56290B87206A3232003892E0 /* routing_algorithm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56290B85206A3231003892E0 /* routing_algorithm.cpp */; }; 56290B88206A3232003892E0 /* routing_algorithm.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56290B86206A3231003892E0 /* routing_algorithm.hpp */; }; 562BDE2020D14860008EFF6F /* routing_callbacks.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 562BDE1F20D14860008EFF6F /* routing_callbacks.hpp */; }; @@ -387,6 +389,8 @@ 56099E271CC7C97D00A7772A /* turn_candidate.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = turn_candidate.hpp; sourceTree = ""; }; 56099E301CC9247E00A7772A /* bicycle_directions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bicycle_directions.cpp; sourceTree = ""; }; 56099E311CC9247E00A7772A /* bicycle_directions.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bicycle_directions.hpp; sourceTree = ""; }; + 56107319221ABF96008447B2 /* speed_camera_prohibition.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = speed_camera_prohibition.hpp; sourceTree = ""; }; + 5610731A221ABF96008447B2 /* speed_camera_prohibition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = speed_camera_prohibition.cpp; sourceTree = ""; }; 56290B85206A3231003892E0 /* routing_algorithm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_algorithm.cpp; sourceTree = ""; }; 56290B86206A3231003892E0 /* routing_algorithm.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = routing_algorithm.hpp; sourceTree = ""; }; 562BDE1F20D14860008EFF6F /* routing_callbacks.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = routing_callbacks.hpp; sourceTree = ""; }; @@ -812,6 +816,8 @@ 675343FA1A3F640D00A0A8C3 /* routing */ = { isa = PBXGroup; children = ( + 5610731A221ABF96008447B2 /* speed_camera_prohibition.cpp */, + 56107319221ABF96008447B2 /* speed_camera_prohibition.hpp */, 4408A63721F1E7F0008171B8 /* index_graph_starter_joints.cpp */, 4408A63921F1E7F0008171B8 /* index_graph_starter_joints.hpp */, 4408A63A21F1E7F0008171B8 /* joint_segment.cpp */, @@ -1012,6 +1018,7 @@ 56CA09E61E30E73B00D05C9A /* index_graph_tools.hpp in Headers */, 0C81E1581F0258AA00DC66DF /* segmented_route.hpp in Headers */, 671F58BE1B874EC80032311E /* followed_polyline.hpp in Headers */, + 5610731B221ABF96008447B2 /* speed_camera_prohibition.hpp in Headers */, 0C5FEC6A1DDE193F0017688C /* road_index.hpp in Headers */, 674F9BCD1B0A580E00704FFA /* features_road_graph.hpp in Headers */, 40576F781F7A788B000B593B /* fake_vertex.hpp in Headers */, @@ -1328,6 +1335,7 @@ 674F9BCC1B0A580E00704FFA /* features_road_graph.cpp in Sources */, 0C5FEC5E1DDE192A0017688C /* geometry.cpp in Sources */, 674F9BD01B0A580E00704FFA /* online_cross_fetcher.cpp in Sources */, + 5610731C221ABF96008447B2 /* speed_camera_prohibition.cpp in Sources */, 56290B87206A3232003892E0 /* routing_algorithm.cpp in Sources */, 670EE5751B664796001E8064 /* router.cpp in Sources */, 5670595D1F3AF97F0062672D /* checkpoint_predictor.cpp in Sources */,