Refactors Karen's work a bit
This commit is contained in:
		
							parent
							
								
									8ffe915395
								
							
						
					
					
						commit
						9af67c5a9f
					
				| @ -15,6 +15,9 @@ namespace extractor | |||||||
| namespace guidance | namespace guidance | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|  | // Suppresses instructions for certain modes.
 | ||||||
|  | // Think: ferry route. This handler suppresses all instructions while on the ferry route.
 | ||||||
|  | // We don't want to announce "Turn Right", "Turn Left" while on ferries, as one example.
 | ||||||
| class SuppressModeHandler final : public IntersectionHandler | class SuppressModeHandler final : public IntersectionHandler | ||||||
| { | { | ||||||
|   public: |   public: | ||||||
| @ -26,15 +29,13 @@ class SuppressModeHandler final : public IntersectionHandler | |||||||
| 
 | 
 | ||||||
|     ~SuppressModeHandler() override final = default; |     ~SuppressModeHandler() override final = default; | ||||||
| 
 | 
 | ||||||
|     bool canProcess(const NodeID /*nid*/, |     bool canProcess(const NodeID nid, | ||||||
|                     const EdgeID via_eid, |                     const EdgeID via_eid, | ||||||
|                     const Intersection &intersection) const override final; |                     const Intersection &intersection) const override final; | ||||||
| 
 | 
 | ||||||
|     Intersection operator()(const NodeID nid, |     Intersection operator()(const NodeID nid, | ||||||
|                             const EdgeID via_eid, |                             const EdgeID via_eid, | ||||||
|                             Intersection intersection) const override final; |                             Intersection intersection) const override final; | ||||||
| 
 |  | ||||||
|     using SuppressModeListT = std::array<osrm::extractor::TravelMode, 2>; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // namespace osrm
 | } // namespace osrm
 | ||||||
|  | |||||||
| @ -1,9 +1,8 @@ | |||||||
| #include "extractor/guidance/constants.hpp" |  | ||||||
| #include "extractor/guidance/suppress_mode_handler.hpp" | #include "extractor/guidance/suppress_mode_handler.hpp" | ||||||
| #include "extractor/travel_mode.hpp" | #include "extractor/travel_mode.hpp" | ||||||
| 
 | 
 | ||||||
| #include <algorithm> | #include <algorithm> | ||||||
| #include <boost/assert.hpp> | #include <iterator> | ||||||
| 
 | 
 | ||||||
| namespace osrm | namespace osrm | ||||||
| { | { | ||||||
| @ -25,39 +24,43 @@ SuppressModeHandler::SuppressModeHandler(const IntersectionGenerator &intersecti | |||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // travel modes for which navigation should be suppressed
 | bool SuppressModeHandler::canProcess(const NodeID, | ||||||
| const SuppressModeHandler::SuppressModeListT constexpr SUPPRESS_MODE_LIST = { |  | ||||||
|     {TRAVEL_MODE_TRAIN, TRAVEL_MODE_FERRY}}; |  | ||||||
| 
 |  | ||||||
| bool SuppressModeHandler::canProcess(const NodeID /*nid*/, |  | ||||||
|                                      const EdgeID via_eid, |                                      const EdgeID via_eid, | ||||||
|                                      const Intersection &intersection) const |                                      const Intersection &intersection) const | ||||||
| { | { | ||||||
|     // if the approach way is not on the suppression blacklist, and not all the exit ways share that mode,
 |     using std::begin; | ||||||
|     // there are no ways to suppress by this criteria
 |     using std::end; | ||||||
|     const auto in_mode = node_based_graph.GetEdgeData(via_eid).travel_mode; |  | ||||||
|     const auto suppress_in_mode = |  | ||||||
|         std::find(begin(SUPPRESS_MODE_LIST), end(SUPPRESS_MODE_LIST), in_mode); |  | ||||||
| 
 | 
 | ||||||
|     auto Begin = begin(intersection) + 1; |     // travel modes for which navigation should be suppressed
 | ||||||
|     auto End = end(intersection); |     static const constexpr char suppressed[] = {TRAVEL_MODE_TRAIN, TRAVEL_MODE_FERRY}; | ||||||
|     const auto all_share_mode = std::all_of(Begin, End, [this, &in_mode](const ConnectedRoad &way) { | 
 | ||||||
|         return node_based_graph.GetEdgeData(way.eid).travel_mode == in_mode; |     // If the approach way is not on the suppression blacklist, and not all the exit ways share that
 | ||||||
|  |     // mode, there are no ways to suppress by this criteria.
 | ||||||
|  |     const auto in_mode = node_based_graph.GetEdgeData(via_eid).travel_mode; | ||||||
|  |     const auto suppress_in_mode = std::find(begin(suppressed), end(suppressed), in_mode); | ||||||
|  | 
 | ||||||
|  |     const auto first = begin(intersection) + 1; | ||||||
|  |     const auto last = end(intersection); | ||||||
|  | 
 | ||||||
|  |     const auto all_share_mode = std::all_of(first, last, [this, &in_mode](const auto &road) { | ||||||
|  |         return node_based_graph.GetEdgeData(road.eid).travel_mode == in_mode; | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     return (suppress_in_mode != end(SUPPRESS_MODE_LIST)) && all_share_mode; |     return (suppress_in_mode != end(suppressed)) && all_share_mode; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Intersection SuppressModeHandler:: | Intersection SuppressModeHandler:: | ||||||
| operator()(const NodeID nid, const EdgeID via_eid, Intersection intersection) const | operator()(const NodeID, const EdgeID, Intersection intersection) const | ||||||
| { | { | ||||||
|     const auto suppress_all = SuppressModeHandler::canProcess(nid, via_eid, intersection); |     const auto first = begin(intersection) + 1; | ||||||
|     if (suppress_all) |     const auto last = end(intersection); | ||||||
|     { | 
 | ||||||
|         std::for_each(begin(intersection) + 1, end(intersection), [&](ConnectedRoad &out_way) { |     std::for_each(first, last, [&](auto &road) { | ||||||
|             out_way.instruction = {TurnType::Suppressed, getTurnDirection(out_way.angle)}; |         const auto modifier = road.instruction.direction_modifier; | ||||||
|  |         const auto type = TurnType::Suppressed; | ||||||
|  | 
 | ||||||
|  |         road.instruction = {type, modifier}; | ||||||
|     }); |     }); | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     return intersection; |     return intersection; | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
|  | #include "extractor/guidance/turn_analysis.hpp" | ||||||
| #include "extractor/guidance/constants.hpp" | #include "extractor/guidance/constants.hpp" | ||||||
| #include "extractor/guidance/road_classification.hpp" | #include "extractor/guidance/road_classification.hpp" | ||||||
| #include "extractor/guidance/turn_analysis.hpp" |  | ||||||
| 
 | 
 | ||||||
| #include "util/coordinate.hpp" | #include "util/coordinate.hpp" | ||||||
| #include "util/coordinate_calculation.hpp" | #include "util/coordinate_calculation.hpp" | ||||||
| @ -111,7 +111,10 @@ Intersection TurnAnalysis::AssignTurnTypes(const NodeID node_prior_to_intersecti | |||||||
|                                             {TurnType::Invalid, DirectionModifier::UTurn}, |                                             {TurnType::Invalid, DirectionModifier::UTurn}, | ||||||
|                                             INVALID_LANE_DATAID); |                                             INVALID_LANE_DATAID); | ||||||
|                    }); |                    }); | ||||||
|     // Suppress turns on ways between mode types that do not need guidance
 | 
 | ||||||
|  |     // Suppress turns on ways between mode types that do not need guidance, think ferry routes.
 | ||||||
|  |     // This handler has to come first and when it triggers we're done with the intersection: there's
 | ||||||
|  |     // nothing left to be done once we suppressed instructions on such routes. Exit early.
 | ||||||
|     if (suppress_mode_handler.canProcess( |     if (suppress_mode_handler.canProcess( | ||||||
|             node_prior_to_intersection, entering_via_edge, intersection)) |             node_prior_to_intersection, entering_via_edge, intersection)) | ||||||
|     { |     { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user