diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-08-31 17:33:23 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2016-09-08 12:49:54 +0300 |
commit | 3e66bede21f8a6755897f65c95bc91b0066a4c14 (patch) | |
tree | 76638327f3903c1bcd805b6e8cb3944e9af28b4e /routing | |
parent | 93baffbcb2681df9065c7e4bf758b9a7451524a1 (diff) |
Generating route altitude chart image.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/base/followed_polyline.hpp | 1 | ||||
-rw-r--r-- | routing/osrm_router.cpp | 12 | ||||
-rw-r--r-- | routing/road_graph_router.cpp | 13 | ||||
-rw-r--r-- | routing/route.cpp | 1 | ||||
-rw-r--r-- | routing/route.hpp | 23 | ||||
-rw-r--r-- | routing/routing_session.cpp | 29 | ||||
-rw-r--r-- | routing/routing_session.hpp | 12 | ||||
-rw-r--r-- | routing/routing_tests/route_tests.cpp | 10 |
8 files changed, 81 insertions, 20 deletions
diff --git a/routing/base/followed_polyline.hpp b/routing/base/followed_polyline.hpp index 36d700d27d..66d3fd8a85 100644 --- a/routing/base/followed_polyline.hpp +++ b/routing/base/followed_polyline.hpp @@ -23,6 +23,7 @@ public: bool IsValid() const { return (m_current.IsValid() && m_poly.GetSize() > 1); } m2::PolylineD const & GetPolyline() const { return m_poly; } + vector<double> const & GetSegDistanceM() const { return m_segDistance; } double GetTotalDistanceM() const; double GetDistanceFromBeginM() const; diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 01954a3416..4d94c0d33c 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -366,9 +366,9 @@ OsrmRouter::ResultCode OsrmRouter::MakeRouteFromCrossesPath(TCheckedPath const & } route.SetGeometry(points.begin(), points.end()); - route.SetTurnInstructions(turnsDir); - route.SetSectionTimes(times); - route.SetStreetNames(streets); + route.SwapTurnInstructions(turnsDir); + route.SwapSectionTimes(times); + route.SwapStreetNames(streets); return NoError; } @@ -504,9 +504,9 @@ OsrmRouter::ResultCode OsrmRouter::CalculateRoute(m2::PointD const & startPoint, } route.SetGeometry(points.begin(), points.end()); - route.SetTurnInstructions(turnsDir); - route.SetSectionTimes(times); - route.SetStreetNames(streets); + route.SwapTurnInstructions(turnsDir); + route.SwapSectionTimes(times); + route.SwapStreetNames(streets); return NoError; } diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 8970f54d07..1b11626688 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -9,6 +9,7 @@ #include "coding/reader_wrapper.hpp" +#include "indexer/feature_altitude.hpp" #include "indexer/feature.hpp" #include "indexer/ftypes_matcher.hpp" #include "indexer/index.hpp" @@ -19,6 +20,7 @@ #include "geometry/distance.hpp" +#include "std/algorithm.hpp" #include "std/queue.hpp" #include "std/set.hpp" @@ -247,10 +249,15 @@ void RoadGraphRouter::ReconstructRoute(vector<Junction> && path, Route & route, if (m_directionsEngine) m_directionsEngine->Generate(*m_roadGraph, path, times, turnsDir, geometry, cancellable); + feature::TAltitudes altitudes(path.size()); + for (size_t i = 0; i < path.size(); ++i) + altitudes[i] = path[i].GetAltitude(); + route.SetGeometry(geometry.begin(), geometry.end()); - route.SetSectionTimes(times); - route.SetTurnInstructions(turnsDir); - route.SetStreetNames(streetNames); + route.SwapSectionTimes(times); + route.SwapTurnInstructions(turnsDir); + route.SwapStreetNames(streetNames); + route.SwapAltitudes(altitudes); } unique_ptr<IRouter> CreatePedestrianAStarRouter(Index & index, TCountryFileFn const & countryFileFn) diff --git a/routing/route.cpp b/routing/route.cpp index da81fb98dd..27ed38b71c 100644 --- a/routing/route.cpp +++ b/routing/route.cpp @@ -41,6 +41,7 @@ void Route::Swap(Route & rhs) swap(m_times, rhs.m_times); swap(m_streets, rhs.m_streets); m_absentCountries.swap(rhs.m_absentCountries); + m_altitudes.swap(rhs.m_altitudes); } void Route::AddAbsentCountry(string const & name) diff --git a/routing/route.hpp b/routing/route.hpp index 0014f81f88..55aeab4eee 100644 --- a/routing/route.hpp +++ b/routing/route.hpp @@ -1,11 +1,14 @@ #pragma once -#include "base/followed_polyline.hpp" -#include "routing_settings.hpp" -#include "turns.hpp" +#include "routing/routing_settings.hpp" +#include "routing/turns.hpp" + +#include "indexer/feature_altitude.hpp" #include "geometry/polyline2d.hpp" +#include "base/followed_polyline.hpp" + #include "std/vector.hpp" #include "std/set.hpp" #include "std/string.hpp" @@ -52,21 +55,26 @@ public: Update(); } - inline void SetTurnInstructions(TTurns & v) + inline void SwapTurnInstructions(TTurns & v) { swap(m_turns, v); } - inline void SetSectionTimes(TTimes & v) + inline void SwapSectionTimes(TTimes & v) { swap(m_times, v); } - inline void SetStreetNames(TStreets & v) + inline void SwapStreetNames(TStreets & v) { swap(m_streets, v); } + inline void SwapAltitudes(feature::TAltitudes & v) + { + swap(m_altitudes, v); + } + uint32_t GetTotalTimeSec() const; uint32_t GetCurrentTimeToEndSec() const; @@ -75,6 +83,8 @@ public: string const & GetRouterId() const { return m_router; } m2::PolylineD const & GetPoly() const { return m_poly.GetPolyline(); } TTurns const & GetTurns() const { return m_turns; } + feature::TAltitudes const & GetAltitudes() const { return m_altitudes; } + vector<double> const & GetSegDistanceM() const { return m_poly.GetSegDistanceM(); } void GetTurnsDistances(vector<double> & distances) const; string const & GetName() const { return m_name; } bool IsValid() const { return (m_poly.GetPolyline().GetSize() > 1); } @@ -148,6 +158,7 @@ private: TTurns m_turns; TTimes m_times; TStreets m_streets; + feature::TAltitudes m_altitudes; mutable double m_currentTime; }; diff --git a/routing/routing_session.cpp b/routing/routing_session.cpp index 0de247706d..bc57f7f772 100644 --- a/routing/routing_session.cpp +++ b/routing/routing_session.cpp @@ -523,6 +523,35 @@ void RoutingSession::EmitCloseRoutingEvent() const alohalytics::Location::FromLatLon(lastGoodPoint.lat, lastGoodPoint.lon)); } +bool RoutingSession::HasRouteAltitudeImpl() const +{ + return !m_route.GetAltitudes().empty(); +} + +bool RoutingSession::HasRouteAltitude() const +{ + threads::MutexGuard guard(m_routeSessionMutex); + return HasRouteAltitudeImpl(); +} + +bool RoutingSession::GetRouteAltitudes(feature::TAltitudes & routeAltitudes) const +{ + threads::MutexGuard guard(m_routeSessionMutex); + if (!HasRouteAltitudeImpl()) + return false; + routeAltitudes.assign(m_route.GetAltitudes().begin(), m_route.GetAltitudes().end()); + return true; +} + +bool RoutingSession::GetSegDistanceM(deque<double> & routeSegDistanceM) const +{ + threads::MutexGuard guard(m_routeSessionMutex); + if (!m_route.IsValid()) + return false; + routeSegDistanceM.assign(m_route.GetSegDistanceM().begin(), m_route.GetSegDistanceM().end()); + return true; +} + string DebugPrint(RoutingSession::State state) { switch (state) diff --git a/routing/routing_session.hpp b/routing/routing_session.hpp index 478d4c9f98..b92fa320df 100644 --- a/routing/routing_session.hpp +++ b/routing/routing_session.hpp @@ -15,6 +15,7 @@ #include "base/mutex.hpp" #include "std/atomic.hpp" +#include "std/deque.hpp" #include "std/limits.hpp" #include "std/unique_ptr.hpp" @@ -105,6 +106,15 @@ public: inline void SetState(State state) { m_state = state; } Route const & GetRoute() const { return m_route; } + /// \returns true if any altitude information along |m_route| is available and + /// false otherwise. + bool HasRouteAltitude() const; + /// \brief copies route altitude information to |routeAltitudes| if any is available and + /// returns true. If no route altitude information is available returns false. + bool GetRouteAltitudes(feature::TAltitudes & routeAltitudes) const; + /// \brief copies distance from route beginning to ends of route segments in meters and + /// returns true. If the route is not valid returns false. + bool GetSegDistanceM(deque<double> & routeSegDistanceM) const; State OnLocationPositionChanged(location::GpsInfo const & info, Index const & index); void GetRouteFollowingInfo(location::FollowingInfo & info) const; @@ -165,6 +175,8 @@ private: void RemoveRoute(); void RemoveRouteImpl(); + bool HasRouteAltitudeImpl() const; + private: unique_ptr<AsyncRouter> m_router; Route m_route; diff --git a/routing/routing_tests/route_tests.cpp b/routing/routing_tests/route_tests.cpp index bbb2c7a06f..821e4a59ac 100644 --- a/routing/routing_tests/route_tests.cpp +++ b/routing/routing_tests/route_tests.cpp @@ -50,7 +50,7 @@ UNIT_TEST(DistanceToCurrentTurnTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SetTurnInstructions(turns); + route.SwapTurnInstructions(turns); double distance; turns::TurnItem turn; @@ -85,7 +85,7 @@ UNIT_TEST(NextTurnTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SetTurnInstructions(turns); + route.SwapTurnInstructions(turns); double distance, nextDistance; turns::TurnItem turn; @@ -114,7 +114,7 @@ UNIT_TEST(NextTurnsTest) Route route("TestRouter"); route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SetTurnInstructions(turns); + route.SwapTurnInstructions(turns); vector<turns::TurnItemDist> turnsDist; { @@ -165,9 +165,9 @@ UNIT_TEST(RouteNameTest) route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end()); vector<turns::TurnItem> turns(kTestTurns); - route.SetTurnInstructions(turns); + route.SwapTurnInstructions(turns); Route::TStreets names(kTestNames); - route.SetStreetNames(names); + route.SwapStreetNames(names); string name; route.GetCurrentStreetName(name); |