diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2018-01-29 18:53:35 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2018-02-19 20:26:27 +0300 |
commit | fa014c60f13372cb3967a395a28c1d4d1b6b9c9f (patch) | |
tree | 7fa39a3b84b30f421257bfbb66eddf1e2ab9e748 /routing | |
parent | c345efacdd427ee4888fefd581b8adcd8aeffb50 (diff) |
Fixing turn angle correction.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/bicycle_directions.cpp | 6 | ||||
-rw-r--r-- | routing/routing_helpers.hpp | 2 | ||||
-rw-r--r-- | routing/turn_candidate.hpp | 12 | ||||
-rw-r--r-- | routing/turns.cpp | 11 | ||||
-rw-r--r-- | routing/turns.hpp | 6 | ||||
-rw-r--r-- | routing/turns_generator.cpp | 23 | ||||
-rw-r--r-- | routing/turns_generator.hpp | 7 |
7 files changed, 45 insertions, 22 deletions
diff --git a/routing/bicycle_directions.cpp b/routing/bicycle_directions.cpp index 362d52741d..38e169b815 100644 --- a/routing/bicycle_directions.cpp +++ b/routing/bicycle_directions.cpp @@ -169,6 +169,8 @@ bool BicycleDirectionsEngine::Generate(IndexRoadGraph const & graph, vector<Junc Route::TStreets & streetNames, vector<Junction> & routeGeometry, vector<Segment> & segments) { + CHECK(m_numMwmIds, ()); + m_adjacentEdges.clear(); m_pathSegments.clear(); turns.clear(); @@ -198,7 +200,7 @@ bool BicycleDirectionsEngine::Generate(IndexRoadGraph const & graph, vector<Junc ::RoutingResult resultGraph(routeEdges, m_adjacentEdges, m_pathSegments); RouterDelegate delegate; - MakeTurnAnnotation(resultGraph, delegate, routeGeometry, turns, streetNames, segments); + MakeTurnAnnotation(resultGraph, *m_numMwmIds, delegate, routeGeometry, turns, streetNames, segments); CHECK_EQUAL(routeGeometry.size(), pathSize, ()); // In case of bicycle routing |m_pathSegments| may have an empty // |LoadedPathSegment::m_segments| fields. In that case |segments| is empty @@ -277,7 +279,7 @@ void BicycleDirectionsEngine::GetSegmentRangeAndAdjacentEdges( // should not be used for turn generation. outgoingTurns.isCandidatesAngleValid = false; } - outgoingTurns.candidates.emplace_back(angle, segmentRange, highwayClass); + outgoingTurns.candidates.emplace_back(angle, ConvertEdgeToSegment(*m_numMwmIds, edge), highwayClass); } } diff --git a/routing/routing_helpers.hpp b/routing/routing_helpers.hpp index acf92e4f7d..f3dc3d752f 100644 --- a/routing/routing_helpers.hpp +++ b/routing/routing_helpers.hpp @@ -40,7 +40,7 @@ void ReconstructRoute(IDirectionsEngine & engine, IndexRoadGraph const & graph, Route::TTimes && times, Route & route); /// \brief Converts |edge| to |segment|. -/// \returns false if mwm of |edge| is not alive. +/// \returns Segment() if mwm of |edge| is not alive. Segment ConvertEdgeToSegment(NumMwmIds const & numMwmIds, Edge const & edge); /// \brief Fills |times| according to max speed at |graph| and |path|. diff --git a/routing/turn_candidate.hpp b/routing/turn_candidate.hpp index 17c9cfe611..e06c863c70 100644 --- a/routing/turn_candidate.hpp +++ b/routing/turn_candidate.hpp @@ -1,5 +1,6 @@ #pragma once +#include "routing/segment.hpp" #include "routing/turns.hpp" #include "base/math.hpp" @@ -28,25 +29,24 @@ struct TurnCandidate */ double angle; /*! - * |m_segmentRange| is a possible way from the junction. - * |m_segmentRange| contains mwm id, feature id, segment id and direction in case of A*. + * |m_segment| is a first segment of a possible way from the junction. */ - SegmentRange m_segmentRange; + Segment m_segment; /*! * \brief highwayClass field for the road class caching. Because feature reading is a long * function. */ ftypes::HighwayClass highwayClass; - TurnCandidate(double a, SegmentRange const & segmentRange, ftypes::HighwayClass c) - : angle(a), m_segmentRange(segmentRange), highwayClass(c) + TurnCandidate(double a, Segment const & segment, ftypes::HighwayClass c) + : angle(a), m_segment(segment), highwayClass(c) { } bool IsAlmostEqual(TurnCandidate const & rhs) const { double constexpr kEpsilon = 0.01; - return my::AlmostEqualAbs(angle, rhs.angle, kEpsilon) && m_segmentRange == rhs.m_segmentRange && + return my::AlmostEqualAbs(angle, rhs.angle, kEpsilon) && m_segment == rhs.m_segment && highwayClass == rhs.highwayClass; } }; diff --git a/routing/turns.cpp b/routing/turns.cpp index a5c31746e7..1ce83e6d9e 100644 --- a/routing/turns.cpp +++ b/routing/turns.cpp @@ -2,6 +2,8 @@ #include "geometry/angles.hpp" +#include "platform/country_file.hpp" + #include "base/internal/message.hpp" #include "base/stl_helpers.hpp" #include "base/string_utils.hpp" @@ -110,6 +112,15 @@ bool SegmentRange::IsCorrect() const return (m_forward && m_startSegId <= m_endSegId) || (!m_forward && m_endSegId <= m_startSegId); } +Segment SegmentRange::GetFirstSegment(NumMwmIds const & numMwmIds) const +{ + if (!m_featureId.IsValid()) + return Segment(); + + return Segment(numMwmIds.GetId(platform::CountryFile(m_featureId.GetMwmName())), + m_featureId.m_index, m_startSegId, m_forward); +} + string DebugPrint(SegmentRange const & segmentRange) { stringstream out; diff --git a/routing/turns.hpp b/routing/turns.hpp index 538cb52cd9..3c33c502fe 100644 --- a/routing/turns.hpp +++ b/routing/turns.hpp @@ -1,5 +1,9 @@ #pragma once +#include "routing/segment.hpp" + +#include "routing_common/num_mwm_id.hpp" + #include "indexer/feature_decl.hpp" #include "geometry/point2d.hpp" @@ -27,6 +31,8 @@ struct SegmentRange FeatureID const & GetFeature() const; /// \returns true if the instance of SegmentRange is correct. bool IsCorrect() const; + /// \returns First Segment of this SegmentRange. + Segment GetFirstSegment(NumMwmIds const & numMwmIds) const; private: FeatureID m_featureId; diff --git a/routing/turns_generator.cpp b/routing/turns_generator.cpp index 7fe9df964c..aa14426906 100644 --- a/routing/turns_generator.cpp +++ b/routing/turns_generator.cpp @@ -32,7 +32,7 @@ double constexpr kNotSoCloseMinDistMeters = 30.; * - and the turn is GoStraight or TurnSlight*. */ bool KeepTurnByHighwayClass(CarDirection turn, TurnCandidates const & possibleTurns, - TurnInfo const & turnInfo) + TurnInfo const & turnInfo, NumMwmIds const & numMwmIds) { if (!IsGoStraightOrSlightTurn(turn)) return true; // The road significantly changes its direction here. So this turn shall be kept. @@ -44,7 +44,7 @@ bool KeepTurnByHighwayClass(CarDirection turn, TurnCandidates const & possibleTu ftypes::HighwayClass maxClassForPossibleTurns = ftypes::HighwayClass::Error; for (auto const & t : possibleTurns.candidates) { - if (t.m_segmentRange == turnInfo.m_outgoing.m_segmentRange) + if (t.m_segment == turnInfo.m_outgoing.m_segmentRange.GetFirstSegment(numMwmIds)) continue; ftypes::HighwayClass const highwayClass = t.highwayClass; if (static_cast<int>(highwayClass) > static_cast<int>(maxClassForPossibleTurns)) @@ -79,11 +79,11 @@ bool KeepTurnByHighwayClass(CarDirection turn, TurnCandidates const & possibleTu * \brief Returns false when other possible turns leads to service roads; */ bool KeepRoundaboutTurnByHighwayClass(CarDirection turn, TurnCandidates const & possibleTurns, - TurnInfo const & turnInfo) + TurnInfo const & turnInfo, NumMwmIds const & numMwmIds) { for (auto const & t : possibleTurns.candidates) { - if (t.m_segmentRange == turnInfo.m_outgoing.m_segmentRange) + if (t.m_segment == turnInfo.m_outgoing.m_segmentRange.GetFirstSegment(numMwmIds)) continue; if (static_cast<int>(t.highwayClass) != static_cast<int>(ftypes::HighwayClass::Service)) return true; @@ -252,7 +252,7 @@ bool TurnInfo::IsSegmentsValid() const return true; } -IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, +IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, NumMwmIds const & numMwmIds, RouterDelegate const & delegate, vector<Junction> & junctions, Route::TTurns & turnsDir, Route::TStreets & streets, vector<Segment> & segments) @@ -286,7 +286,7 @@ IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, turns::TurnInfo turnInfo(loadedSegments[segmentIndex - 1], *loadedSegmentIt); if (turnItem.m_turn == turns::CarDirection::None) - turns::GetTurnDirection(result, turnInfo, turnItem); + turns::GetTurnDirection(result, numMwmIds, turnInfo, turnItem); // Lane information. if (turnItem.m_turn != turns::CarDirection::None) @@ -537,7 +537,8 @@ CarDirection IntermediateDirection(const double angle) return FindDirectionByAngle(kLowerBounds, angle); } -void GetTurnDirection(IRoutingResult const & result, TurnInfo & turnInfo, TurnItem & turn) +void GetTurnDirection(IRoutingResult const & result, NumMwmIds const & numMwmIds, + TurnInfo & turnInfo, TurnItem & turn) { if (!turnInfo.IsSegmentsValid() || turnInfo.m_ingoing.m_segmentRange.IsEmpty()) return; @@ -586,9 +587,9 @@ void GetTurnDirection(IRoutingResult const & result, TurnInfo & turnInfo, TurnIt } else { - if (nodes.candidates.front().m_segmentRange == turnInfo.m_outgoing.m_segmentRange) + if (nodes.candidates.front().m_segment == turnInfo.m_outgoing.m_segmentRange.GetFirstSegment(numMwmIds)) turn.m_turn = LeftmostDirection(turnAngle); - else if (nodes.candidates.back().m_segmentRange == turnInfo.m_outgoing.m_segmentRange) + else if (nodes.candidates.back().m_segment == turnInfo.m_outgoing.m_segmentRange.GetFirstSegment(numMwmIds)) turn.m_turn = RightmostDirection(turnAngle); else turn.m_turn = intermediateDirection; @@ -597,14 +598,14 @@ void GetTurnDirection(IRoutingResult const & result, TurnInfo & turnInfo, TurnIt if (turnInfo.m_ingoing.m_onRoundabout || turnInfo.m_outgoing.m_onRoundabout) { bool const keepTurnByHighwayClass = - KeepRoundaboutTurnByHighwayClass(turn.m_turn, nodes, turnInfo); + KeepRoundaboutTurnByHighwayClass(turn.m_turn, nodes, turnInfo, numMwmIds); turn.m_turn = GetRoundaboutDirection(turnInfo.m_ingoing.m_onRoundabout, turnInfo.m_outgoing.m_onRoundabout, hasMultiTurns, keepTurnByHighwayClass); return; } - bool const keepTurnByHighwayClass = KeepTurnByHighwayClass(turn.m_turn, nodes, turnInfo); + bool const keepTurnByHighwayClass = KeepTurnByHighwayClass(turn.m_turn, nodes, turnInfo, numMwmIds); if (!turn.m_keepAnyway && !keepTurnByHighwayClass) { turn.m_turn = CarDirection::None; diff --git a/routing/turns_generator.hpp b/routing/turns_generator.hpp index b221c18f34..e50b59db67 100644 --- a/routing/turns_generator.hpp +++ b/routing/turns_generator.hpp @@ -8,6 +8,8 @@ #include "routing/turn_candidate.hpp" #include "routing/segment.hpp" +#include "routing_common/num_mwm_id.hpp" + #include "traffic/traffic_info.hpp" #include "std/function.hpp" @@ -43,7 +45,7 @@ using TGetIndexFunction = function<size_t(pair<size_t, size_t>)>; * \param traffic road traffic information. * \return routing operation result code. */ -IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, +IRouter::ResultCode MakeTurnAnnotation(turns::IRoutingResult const & result, NumMwmIds const & numMwmIds, RouterDelegate const & delegate, vector<Junction> & points, Route::TTurns & turnsDir, Route::TStreets & streets, vector<Segment> & segments); @@ -128,7 +130,8 @@ CarDirection GetRoundaboutDirection(bool isIngoingEdgeRoundabout, bool isOutgoin * \param turnInfo is used for cashing some information while turn calculation. * \param turn is used for keeping the result of turn calculation. */ -void GetTurnDirection(IRoutingResult const & result, turns::TurnInfo & turnInfo, TurnItem & turn); +void GetTurnDirection(IRoutingResult const & result, NumMwmIds const & numMwmIds, + turns::TurnInfo & turnInfo, TurnItem & turn); /*! * \brief Finds an U-turn that starts from master segment and returns how many segments it lasts. |