From 2fb40944bf408e1b6e673e32827c6e251e501541 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Fri, 4 Nov 2016 12:04:07 +0100 Subject: [PATCH] pull in intersection finder accumulator --- .../guidance/node_based_graph_walker.hpp | 29 ++++++++++++++++- .../guidance/node_based_graph_walker.cpp | 31 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/include/extractor/guidance/node_based_graph_walker.hpp b/include/extractor/guidance/node_based_graph_walker.hpp index 661436568..a4f9a1e50 100644 --- a/include/extractor/guidance/node_based_graph_walker.hpp +++ b/include/extractor/guidance/node_based_graph_walker.hpp @@ -11,6 +11,7 @@ #include #include +#include #include namespace osrm @@ -89,7 +90,7 @@ struct LengthLimitedCoordinateAccumulator }; /* - * The FollowRoadNameSelector tries to follow a given name along a route. We offer methods to skip + * The SelectRoadByNameOnlyChoiceAndStraightness tries to follow a given name along a route. We offer methods to skip * over bridges/similar situations if desired, following narrow turns * This struct offers an example implementation of a possible road selector for traversing the * node-based graph using the NodeBasedGraphWalker @@ -114,6 +115,32 @@ struct SelectRoadByNameOnlyChoiceAndStraightness const bool requires_entry; }; +// find the next intersection given a hop limit +struct IntersectionFinderAccumulator +{ + IntersectionFinderAccumulator(const std::uint8_t hop_limit, const IntersectionGenerator &intersection_generator); + // true if the path has traversed enough distance + bool terminate(); + + // update the accumulator + void update(const NodeID from_node, + const EdgeID via_edge, + const NodeID to_node); + + std::uint8_t hops; + const std::uint8_t hop_limit; + + // we need to be able to look-up the intersection + const IntersectionGenerator &intersection_generator; + + // the result we are looking for + NodeID nid; + EdgeID via_edge_id; + Intersection intersection; +}; + + + template boost::optional> NodeBasedGraphWalker::TraverseRoad(NodeID current_node_id, diff --git a/src/extractor/guidance/node_based_graph_walker.cpp b/src/extractor/guidance/node_based_graph_walker.cpp index 1a489e0c5..fbad27cab 100644 --- a/src/extractor/guidance/node_based_graph_walker.cpp +++ b/src/extractor/guidance/node_based_graph_walker.cpp @@ -93,6 +93,37 @@ operator()(const NodeID /*nid*/, return (*min_element).eid; } +// --------------------------------------------------------------------------------- +IntersectionFinderAccumulator::IntersectionFinderAccumulator( + const std::uint8_t hop_limit, const IntersectionGenerator &intersection_generator) + : hops(0), hop_limit(hop_limit), intersection_generator(intersection_generator) +{ +} + +bool IntersectionFinderAccumulator::terminate() +{ + if (intersection.size() > 2 || hops == hop_limit) + { + hops = 0; + return true; + } + else + { + return false; + } +} + +void IntersectionFinderAccumulator::update(const NodeID from_node, + const EdgeID via_edge, + const NodeID /*to_node*/) +{ + ++hops; + nid = from_node; + via_edge_id = via_edge; + + intersection = intersection_generator.GetConnectedRoads(from_node, via_edge); +} + } // namespace guidance } // namespace extractor } // namespace osrm