From 4f15498fec4132a00b1769468cae528c6ecfc467 Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Tue, 22 Mar 2016 14:17:17 +0100 Subject: [PATCH] added list of intersections to the step-maneuver, not in api so far --- include/engine/guidance/step_maneuver.hpp | 11 +++++++- src/engine/api/json_factory.cpp | 4 +-- src/engine/guidance/assemble_steps.cpp | 32 +++++++++++++---------- src/engine/guidance/post_processing.cpp | 25 ++++++++++++------ 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/include/engine/guidance/step_maneuver.hpp b/include/engine/guidance/step_maneuver.hpp index 1a2bb02faad..5ae70f9f6ba 100644 --- a/include/engine/guidance/step_maneuver.hpp +++ b/include/engine/guidance/step_maneuver.hpp @@ -5,6 +5,7 @@ #include "extractor/guidance/turn_instruction.hpp" #include +#include namespace osrm { @@ -20,6 +21,14 @@ enum class WaypointType : std::uint8_t Depart, }; +//A represenetation of intermediate intersections +struct IntermediateIntersection +{ + double duration; + double distance; + util::Coordinate location; +}; + struct StepManeuver { util::Coordinate location; @@ -28,7 +37,7 @@ struct StepManeuver extractor::guidance::TurnInstruction instruction; WaypointType waypoint_type; unsigned exit; - unsigned intersection; + std::vector intersections; }; } // namespace guidance } // namespace engine diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 56d6d3008bd..123ded8016e 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -153,8 +153,8 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver) //TODO currently we need this to comply with the api. //We should move this to an additional entry, the moment we //actually compute the correct locations of the intersections - if (maneuver.intersection != 0 && maneuver.exit == 0 ) - step_maneuver.values["exit"] = maneuver.intersection; + if (!maneuver.intersections.empty() && maneuver.exit == 0 ) + step_maneuver.values["exit"] = maneuver.intersections.size(); return step_maneuver; } diff --git a/src/engine/guidance/assemble_steps.cpp b/src/engine/guidance/assemble_steps.cpp index 84b5fa61999..ee08a7525c4 100644 --- a/src/engine/guidance/assemble_steps.cpp +++ b/src/engine/guidance/assemble_steps.cpp @@ -37,13 +37,15 @@ StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instr pre_turn_bearing = util::coordinate_calculation::bearing(pre_turn_coordinate, turn_coordinate); } - return StepManeuver{turn_coordinate, - pre_turn_bearing, - post_turn_bearing, - instruction, - waypoint_type, - INVALID_EXIT_NR, - INVALID_EXIT_NR}; + return StepManeuver{ + turn_coordinate, + pre_turn_bearing, + post_turn_bearing, + instruction, + waypoint_type, + INVALID_EXIT_NR, + {} // no intermediate intersections + }; } StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instruction, @@ -64,13 +66,15 @@ StepManeuver stepManeuverFromGeometry(extractor::guidance::TurnInstruction instr const double post_turn_bearing = util::coordinate_calculation::bearing(turn_coordinate, post_turn_coordinate); - return StepManeuver{turn_coordinate, - pre_turn_bearing, - post_turn_bearing, - instruction, - WaypointType::None, - INVALID_EXIT_NR, - INVALID_EXIT_NR}; + return StepManeuver{ + turn_coordinate, + pre_turn_bearing, + post_turn_bearing, + instruction, + WaypointType::None, + INVALID_EXIT_NR, + {} // no intermediate intersections + }; } } // ns detail } // ns engine diff --git a/src/engine/guidance/post_processing.cpp b/src/engine/guidance/post_processing.cpp index 2ecbce477d6..3db78c1736f 100644 --- a/src/engine/guidance/post_processing.cpp +++ b/src/engine/guidance/post_processing.cpp @@ -32,8 +32,8 @@ RouteStep forwardInto(RouteStep destination, const RouteStep &source) // Overwrites turn instruction and increases exit NR destination.duration += source.duration; destination.distance += source.distance; - destination.geometry_begin = std::min( destination.geometry_begin, source.geometry_begin ); - destination.geometry_end = std::max( destination.geometry_end, source.geometry_end ); + destination.geometry_begin = std::min(destination.geometry_begin, source.geometry_begin); + destination.geometry_end = std::max(destination.geometry_end, source.geometry_end); return destination; } @@ -51,8 +51,13 @@ void print(const std::vector &steps) std::cout << "\t[" << ++segment << "]: " << type << " " << modifier << " Duration: " << step.duration << " Distance: " << step.distance << " Geometry: " << step.geometry_begin << " " << step.geometry_end - << " exit: " << step.maneuver.exit << " Intersection: " << step.maneuver.intersection << " name[" << step.name_id - << "]: " << step.name << std::endl; + << " exit: " << step.maneuver.exit + << " Intersections: " << step.maneuver.intersections.size() << " ["; + + for (auto intersection : step.maneuver.intersections) + std::cout << "(" << intersection.duration << " " << intersection.distance << ")"; + + std::cout << "] name[" << step.name_id << "]: " << step.name << std::endl; } } @@ -149,7 +154,7 @@ std::vector postProcess(std::vector steps) ? TurnType::EnterRotary : TurnType::EnterRoundabout; - //remember the now enter-instruction as valid + // remember the now enter-instruction as valid last_valid_instruction = 1; } @@ -191,14 +196,18 @@ std::vector postProcess(std::vector steps) } else if (instruction.type == TurnType::Suppressed) { - // count intersections. We cannot use exit, since intersections can follow directly after a roundabout - steps[last_valid_instruction].maneuver.intersection += 1; + // count intersections. We cannot use exit, since intersections can follow directly + // after a roundabout + steps[last_valid_instruction].maneuver.intersections.push_back( + {steps[last_valid_instruction].duration, + steps[last_valid_instruction].distance, + step.maneuver.location}); steps[last_valid_instruction] = detail::forwardInto(steps[last_valid_instruction], step); step.maneuver.instruction = TurnInstruction::NO_TURN(); } - else if( !isSilent(instruction) ) + else if (!isSilent(instruction)) { // Remember the last non silent instruction last_valid_instruction = step_index;