Refactors Karen's work a bit

This commit is contained in:
Daniel J. Hofmann 2016-12-21 12:30:56 +01:00 committed by Daniel J. H
parent 8ffe915395
commit 9af67c5a9f
3 changed files with 37 additions and 30 deletions

View File

@ -15,6 +15,9 @@ namespace extractor
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
{
public:
@ -26,15 +29,13 @@ class SuppressModeHandler final : public IntersectionHandler
~SuppressModeHandler() override final = default;
bool canProcess(const NodeID /*nid*/,
bool canProcess(const NodeID nid,
const EdgeID via_eid,
const Intersection &intersection) const override final;
Intersection operator()(const NodeID nid,
const EdgeID via_eid,
Intersection intersection) const override final;
using SuppressModeListT = std::array<osrm::extractor::TravelMode, 2>;
};
} // namespace osrm

View File

@ -1,9 +1,8 @@
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/suppress_mode_handler.hpp"
#include "extractor/travel_mode.hpp"
#include <algorithm>
#include <boost/assert.hpp>
#include <iterator>
namespace osrm
{
@ -25,39 +24,43 @@ SuppressModeHandler::SuppressModeHandler(const IntersectionGenerator &intersecti
{
}
// travel modes for which navigation should be suppressed
const SuppressModeHandler::SuppressModeListT constexpr SUPPRESS_MODE_LIST = {
{TRAVEL_MODE_TRAIN, TRAVEL_MODE_FERRY}};
bool SuppressModeHandler::canProcess(const NodeID /*nid*/,
bool SuppressModeHandler::canProcess(const NodeID,
const EdgeID via_eid,
const Intersection &intersection) const
{
// 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(SUPPRESS_MODE_LIST), end(SUPPRESS_MODE_LIST), in_mode);
using std::begin;
using std::end;
auto Begin = begin(intersection) + 1;
auto End = end(intersection);
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;
// travel modes for which navigation should be suppressed
static const constexpr char suppressed[] = {TRAVEL_MODE_TRAIN, TRAVEL_MODE_FERRY};
// 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::
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);
if (suppress_all)
{
std::for_each(begin(intersection) + 1, end(intersection), [&](ConnectedRoad &out_way) {
out_way.instruction = {TurnType::Suppressed, getTurnDirection(out_way.angle)};
const auto first = begin(intersection) + 1;
const auto last = end(intersection);
std::for_each(first, last, [&](auto &road) {
const auto modifier = road.instruction.direction_modifier;
const auto type = TurnType::Suppressed;
road.instruction = {type, modifier};
});
}
return intersection;
}

View File

@ -1,6 +1,6 @@
#include "extractor/guidance/turn_analysis.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/road_classification.hpp"
#include "extractor/guidance/turn_analysis.hpp"
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
@ -111,7 +111,10 @@ Intersection TurnAnalysis::AssignTurnTypes(const NodeID node_prior_to_intersecti
{TurnType::Invalid, DirectionModifier::UTurn},
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(
node_prior_to_intersection, entering_via_edge, intersection))
{