From 41ba20ca9a2c447d5307db0cf875df84699bdbbe Mon Sep 17 00:00:00 2001 From: Moritz Kobitzsch Date: Thu, 21 Jul 2016 14:34:32 +0200 Subject: [PATCH] switch api format to new structure --- CHANGELOG.md | 1 + docs/http.md | 33 ++++++++++++------- features/support/route.js | 4 +-- include/engine/guidance/assemble_steps.hpp | 37 ++++++++++++---------- include/engine/guidance/route_step.hpp | 11 ++++++- include/engine/guidance/step_maneuver.hpp | 9 +----- src/engine/api/json_factory.cpp | 22 ++++++------- src/engine/guidance/lane_processing.cpp | 4 +-- src/engine/guidance/post_processing.cpp | 14 ++++---- 9 files changed, 76 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 614b42fac..a657c7c29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Changes from 5.3.0-rc.3 - Guidance - Only announce `use lane` on required turns (not using all lanes to go straight) + - Moved `lanes` to the intersection objects. This is BREAKING in relation to other Release Candidates but not with respect to other releases. - Bugfixes - Fix BREAKING: bug that could result in failure to load 'osrm.icd' files. This breaks the dataformat - Fix: bug that results in segfaults when `use lane` instructions are suppressed diff --git a/docs/http.md b/docs/http.md index f9f27f798..fca068042 100644 --- a/docs/http.md +++ b/docs/http.md @@ -453,24 +453,28 @@ step. "maneuver":{ "type":"turn", "modifier":"right", - "lanes":[ - {"indications":["left","straight"], "valid":"false"}, - {"indications":["right"], "valid":"true"} - ]}, + }, "geometry":"{lu_IypwpAVrAvAdI", "mode":"driving", "intersections":[ {"location":[13.39677,52.54366], "in":3, - "out":1, + "out":2, "bearings":[10,92,184,270], - "entry":[false,"true","true"]}, + "entry":["true","true","true","false"], + "lanes":[ + {"indications":["left","straight"], "valid":"false"}, + {"indications":["right"], "valid":"true"} + ]}, {"location":[13.394718,52.543096], "in":0, - "out":2, - "bearings":[60,150,240,330], - "entry":["false","true","true","true"] - } + "out":1, + "bearings":[60,240,330], + "entry":["false","true","true"] + "lanes":[ + {"indications":["straight"], "valid":"true"}, + {"indications":["right"], "valid":"false"} + ]} ]} ``` @@ -536,8 +540,7 @@ step. |------------------------|---------------------------------------------------------------------------------------------------------------------------| | `roundabout` | Number of the roundabout exit to take. If exit is `undefined` the destination is on the roundabout. | | else | Indicates the number of intersections passed until the turn. Example instruction: `at the fourth intersection, turn left` | - -- `lanes`: Array of `Lane` objects that denote the available turn lanes at the turn location + New properties (potentially depending on `type`) may be introduced in the future without an API version change. @@ -588,6 +591,7 @@ location of the StepManeuver. Further intersections are listed for every cross-w in the direction of driving, the bearing has to be rotated by a value of 180. The value is not supplied for `depart` maneuvers. - `out`: index into the bearings/entry array. Used to extract the bearing just after the turn. Namely, The clockwise angle from true north to the direction of travel immediately after the maneuver/passing the intersection. The value is not supplied for `arrive` maneuvers. +- `lanes`: Array of `Lane` objects that denote the available turn lanes at the turn location #### Example ``` @@ -597,6 +601,11 @@ location of the StepManeuver. Further intersections are listed for every cross-w "out":2, "bearings":[60,150,240,330], "entry":["false","true","true","true"] + "lanes":{ + "indications": ["left", "straight"], + "valid": "false" + } + ]} } ``` diff --git a/features/support/route.js b/features/support/route.js index a08dc9329..a453ca484 100644 --- a/features/support/route.js +++ b/features/support/route.js @@ -170,9 +170,9 @@ module.exports = function () { this.lanesList = (instructions) => { return this.extractInstructionList(instructions, instruction => { - if( 'lanes' in instruction.maneuver ) + if( 'lanes' in instruction.intersections[0] ) { - return instruction.maneuver.lanes.map( p => { return (p.indications).join(';') + ':' + p.valid; } ).join(' '); + return instruction.intersections[0].lanes.map( p => { return (p.indications).join(';') + ':' + p.valid; } ).join(' '); } else { return ''; diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index 943c1b9d8..2febaea60 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -2,8 +2,8 @@ #define ENGINE_GUIDANCE_ASSEMBLE_STEPS_HPP_ #include "extractor/guidance/turn_instruction.hpp" -#include "extractor/travel_mode.hpp" #include "extractor/guidance/turn_lane_types.hpp" +#include "extractor/travel_mode.hpp" #include "engine/datafacade/datafacade_base.hpp" #include "engine/guidance/leg_geometry.hpp" #include "engine/guidance/route_step.hpp" @@ -72,14 +72,15 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa bearings.second, extractor::guidance::TurnInstruction::NO_TURN(), WaypointType::Depart, - 0, - util::guidance::LaneTupel(), - {}}; + 0}; + Intersection intersection{source_node.location, std::vector({bearings.second}), std::vector({true}), Intersection::NO_INDEX, - 0}; + 0, + util::guidance::LaneTupel(), + {}}; if (leg_data.size() > 0) { @@ -138,6 +139,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa intersection.location = facade.GetCoordinateOfNode(path_point.turn_via_node); intersection.bearings.clear(); intersection.bearings.reserve(bearing_class.getAvailableBearings().size()); + intersection.lanes = path_point.lane_data.first; + intersection.lane_description = + path_point.lane_data.second != INVALID_LANE_DESCRIPTIONID + ? facade.GetTurnDescription(path_point.lane_data.second) + : extractor::guidance::TurnLaneDescription(); std::copy(bearing_class.getAvailableBearings().begin(), bearing_class.getAvailableBearings().end(), std::back_inserter(intersection.bearings)); @@ -151,11 +157,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa bearings.second, path_point.turn_instruction, WaypointType::None, - 0, - path_point.lane_data.first, - (path_point.lane_data.second != INVALID_LANE_DESCRIPTIONID - ? facade.GetTurnDescription(path_point.lane_data.second) - : extractor::guidance::TurnLaneDescription())}; + 0}; segment_index++; segment_duration = 0; } @@ -210,15 +212,16 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa bearings.second, extractor::guidance::TurnInstruction::NO_TURN(), WaypointType::Arrive, - 0, - util::guidance::LaneTupel(), - {}}; + 0}; + intersection = { target_node.location, std::vector({static_cast(util::bearing::reverseBearing(bearings.first))}), std::vector({true}), 0, - Intersection::NO_INDEX}; + Intersection::NO_INDEX, + util::guidance::LaneTupel(), + {}}; BOOST_ASSERT(!leg_geometry.locations.empty()); steps.push_back(RouteStep{target_node.name_id, @@ -243,9 +246,9 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa BOOST_ASSERT(steps.back().intersections.front().bearings.size() == 1); BOOST_ASSERT(steps.back().intersections.front().entry.size() == 1); BOOST_ASSERT(steps.back().maneuver.waypoint_type == WaypointType::Arrive); - BOOST_ASSERT(steps.back().maneuver.lanes.lanes_in_turn == 0); - BOOST_ASSERT(steps.back().maneuver.lanes.first_lane_from_the_right == INVALID_LANEID); - BOOST_ASSERT(steps.back().maneuver.lane_description.empty()); + BOOST_ASSERT(steps.back().intersections.front().lanes.lanes_in_turn == 0); + BOOST_ASSERT(steps.back().intersections.front().lanes.first_lane_from_the_right == INVALID_LANEID); + BOOST_ASSERT(steps.back().intersections.front().lane_description.empty()); return steps; } diff --git a/include/engine/guidance/route_step.hpp b/include/engine/guidance/route_step.hpp index 16876984a..7106091c6 100644 --- a/include/engine/guidance/route_step.hpp +++ b/include/engine/guidance/route_step.hpp @@ -7,6 +7,9 @@ #include "util/guidance/bearing_class.hpp" #include "util/guidance/entry_class.hpp" +#include "extractor/guidance/turn_lane_types.hpp" +#include "util/guidance/turn_lanes.hpp" + #include #include @@ -34,6 +37,10 @@ struct Intersection std::vector entry; std::size_t in; std::size_t out; + + // turn lane information + util::guidance::LaneTupel lanes; + extractor::guidance::TurnLaneDescription lane_description; }; inline Intersection getInvalidIntersection() @@ -42,7 +49,9 @@ inline Intersection getInvalidIntersection() {}, {}, Intersection::NO_INDEX, - Intersection::NO_INDEX}; + Intersection::NO_INDEX, + util::guidance::LaneTupel(), + {}}; } struct RouteStep diff --git a/include/engine/guidance/step_maneuver.hpp b/include/engine/guidance/step_maneuver.hpp index 3a765c5e3..114a822ec 100644 --- a/include/engine/guidance/step_maneuver.hpp +++ b/include/engine/guidance/step_maneuver.hpp @@ -2,9 +2,7 @@ #define ENGINE_GUIDANCE_STEP_MANEUVER_HPP #include "extractor/guidance/turn_instruction.hpp" -#include "extractor/guidance/turn_lane_types.hpp" #include "util/coordinate.hpp" -#include "util/guidance/turn_lanes.hpp" #include #include @@ -33,9 +31,6 @@ struct StepManeuver WaypointType waypoint_type; unsigned exit; - - util::guidance::LaneTupel lanes; - extractor::guidance::TurnLaneDescription lane_description; }; inline StepManeuver getInvalidStepManeuver() @@ -45,9 +40,7 @@ inline StepManeuver getInvalidStepManeuver() 0, extractor::guidance::TurnInstruction::NO_TURN(), WaypointType::None, - 0, - util::guidance::LaneTupel(), - {}}; + 0}; } } // namespace guidance diff --git a/src/engine/api/json_factory.cpp b/src/engine/api/json_factory.cpp index 2fa00dae8..70579b7d9 100644 --- a/src/engine/api/json_factory.cpp +++ b/src/engine/api/json_factory.cpp @@ -61,9 +61,9 @@ inline bool isValidModifier(const guidance::StepManeuver maneuver) maneuver.instruction.direction_modifier != DirectionModifier::UTurn); } -inline bool hasValidLanes(const guidance::StepManeuver maneuver) +inline bool hasValidLanes(const guidance::Intersection &intersection) { - return maneuver.lanes.lanes_in_turn > 0; + return intersection.lanes.lanes_in_turn > 0; } std::string instructionTypeToString(const TurnType::Enum type) @@ -71,19 +71,19 @@ std::string instructionTypeToString(const TurnType::Enum type) return turn_type_names[static_cast(type)]; } -util::json::Array lanesFromManeuver(const guidance::StepManeuver &maneuver) +util::json::Array lanesFromIntersection(const guidance::Intersection &intersection) { - BOOST_ASSERT(maneuver.lanes.lanes_in_turn >= 1); + BOOST_ASSERT(intersection.lanes.lanes_in_turn >= 1); util::json::Array result; - LaneID lane_id = maneuver.lane_description.size(); + LaneID lane_id = intersection.lane_description.size(); - for (const auto &lane_desc : maneuver.lane_description) + for (const auto &lane_desc : intersection.lane_description) { --lane_id; util::json::Object lane; lane.values["indications"] = extractor::guidance::TurnLaneType::toJsonArray(lane_desc); - if (lane_id >= maneuver.lanes.first_lane_from_the_right && - lane_id < maneuver.lanes.first_lane_from_the_right + maneuver.lanes.lanes_in_turn) + if (lane_id >= intersection.lanes.first_lane_from_the_right && + lane_id < intersection.lanes.first_lane_from_the_right + intersection.lanes.lanes_in_turn) lane.values["valid"] = util::json::True(); else lane.values["valid"] = util::json::False(); @@ -175,9 +175,6 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver) step_maneuver.values["modifier"] = detail::instructionModifierToString(maneuver.instruction.direction_modifier); - if (detail::hasValidLanes(maneuver)) - step_maneuver.values["lanes"] = detail::lanesFromManeuver(maneuver); - step_maneuver.values["location"] = detail::coordinateToLonLat(maneuver.location); step_maneuver.values["bearing_before"] = std::round(maneuver.bearing_before); step_maneuver.values["bearing_after"] = std::round(maneuver.bearing_after); @@ -217,6 +214,9 @@ util::json::Object makeIntersection(const guidance::Intersection &intersection) if (intersection.out != guidance::Intersection::NO_INDEX) result.values["out"] = intersection.out; + if (detail::hasValidLanes(intersection)) + result.values["lanes"] = detail::lanesFromIntersection(intersection); + return result; } diff --git a/src/engine/guidance/lane_processing.cpp b/src/engine/guidance/lane_processing.cpp index 799f7fa13..03bb3c452 100644 --- a/src/engine/guidance/lane_processing.cpp +++ b/src/engine/guidance/lane_processing.cpp @@ -60,10 +60,10 @@ std::vector anticipateLaneChange(std::vector steps, // the current turn lanes constrain the lanes we have to take in the previous turn. util::for_each_pair(rev_first, rev_last, [](RouteStep ¤t, RouteStep &previous) { const auto current_inst = current.maneuver.instruction; - const auto current_lanes = current.maneuver.lanes; + const auto current_lanes = current.intersections.front().lanes; // Constrain the previous turn's lanes - auto &previous_lanes = previous.maneuver.lanes; + auto &previous_lanes = previous.intersections.front().lanes; // Lane mapping (N:M) from previous lanes (N) to current lanes (M), with: // N > M, N > 1 fan-in situation, constrain N lanes to min(N,M) shared lanes // otherwise nothing to constrain diff --git a/src/engine/guidance/post_processing.cpp b/src/engine/guidance/post_processing.cpp index 7ebced348..e85966778 100644 --- a/src/engine/guidance/post_processing.cpp +++ b/src/engine/guidance/post_processing.cpp @@ -9,6 +9,7 @@ #include "util/guidance/turn_lanes.hpp" #include +#include #include #include @@ -912,8 +913,8 @@ void trimShortSegments(std::vector &steps, LegGeometry &geometry) designated_depart.maneuver.instruction = TurnInstruction::NO_TURN(); // we need to make this conform with the intersection format for the first intersection auto &first_intersection = designated_depart.intersections.front(); - designated_depart.maneuver.lanes = util::guidance::LaneTupel(); - designated_depart.maneuver.lane_description.clear(); + designated_depart.intersections.front().lanes = util::guidance::LaneTupel(); + designated_depart.intersections.front().lane_description.clear(); first_intersection.bearings = {first_intersection.bearings[first_intersection.out]}; first_intersection.entry = {true}; first_intersection.in = Intersection::NO_INDEX; @@ -980,8 +981,8 @@ void trimShortSegments(std::vector &steps, LegGeometry &geometry) next_to_last_step.maneuver.waypoint_type = WaypointType::Arrive; next_to_last_step.maneuver.instruction = TurnInstruction::NO_TURN(); next_to_last_step.maneuver.bearing_after = 0; - next_to_last_step.maneuver.lanes = util::guidance::LaneTupel(); - next_to_last_step.maneuver.lane_description.clear(); + next_to_last_step.intersections.front().lanes = util::guidance::LaneTupel(); + next_to_last_step.intersections.front().lane_description.clear(); BOOST_ASSERT(next_to_last_step.intersections.size() == 1); auto &last_intersection = next_to_last_step.intersections.back(); last_intersection.bearings = {last_intersection.bearings[last_intersection.in]}; @@ -1178,7 +1179,7 @@ std::vector collapseUseLane(std::vector steps) return false; const auto lane_to_the_right = lanes.first_lane_from_the_right + lanes.lanes_in_turn; - if (lane_to_the_right < lane_description.size() && + if (lane_to_the_right < boost::numeric_cast(lane_description.size()) && containsTag(*(lane_description.rbegin() + lane_to_the_right), (extractor::guidance::TurnLaneType::straight | extractor::guidance::TurnLaneType::none))) @@ -1191,7 +1192,8 @@ std::vector collapseUseLane(std::vector steps) { const auto &step = steps[step_index]; if (step.maneuver.instruction.type == TurnType::UseLane && - canCollapeUseLane(step.maneuver.lanes, step.maneuver.lane_description)) + canCollapeUseLane(step.intersections.front().lanes, + step.intersections.front().lane_description)) { const auto previous = getPreviousIndex(step_index); steps[previous] = elongate(steps[previous], steps[step_index]);