switch api format to new structure

This commit is contained in:
Moritz Kobitzsch 2016-07-21 14:34:32 +02:00
parent 57e3f173d3
commit 41ba20ca9a
9 changed files with 76 additions and 59 deletions

View File

@ -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

View File

@ -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"
}
]}
}
```

View File

@ -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 '';

View File

@ -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<RouteStep> 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<short>({bearings.second}),
std::vector<bool>({true}),
Intersection::NO_INDEX,
0};
0,
util::guidance::LaneTupel(),
{}};
if (leg_data.size() > 0)
{
@ -138,6 +139,11 @@ inline std::vector<RouteStep> 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<RouteStep> 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<RouteStep> 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<short>({static_cast<short>(util::bearing::reverseBearing(bearings.first))}),
std::vector<bool>({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<RouteStep> 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;
}

View File

@ -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 <cstddef>
#include <string>
@ -34,6 +37,10 @@ struct Intersection
std::vector<bool> 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

View File

@ -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 <cstdint>
#include <string>
@ -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

View File

@ -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<std::size_t>(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;
}

View File

@ -60,10 +60,10 @@ std::vector<RouteStep> anticipateLaneChange(std::vector<RouteStep> 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 &current, 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

View File

@ -9,6 +9,7 @@
#include "util/guidance/turn_lanes.hpp"
#include <boost/assert.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/range/algorithm_ext/erase.hpp>
#include <algorithm>
@ -912,8 +913,8 @@ void trimShortSegments(std::vector<RouteStep> &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<RouteStep> &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<RouteStep> collapseUseLane(std::vector<RouteStep> 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<int>(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<RouteStep> collapseUseLane(std::vector<RouteStep> 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]);