Lazily generate optional route path data (#6045)
Currently route results are annotated with additional path information, such as geometries, turn-by-turn steps and other metadata. These annotations are generated if they are not requested or returned in the response. Datasets needed to generate these annotations are loaded and available to the OSRM process even when unused. This commit is a first step towards making the loading of these datasets optional. We refactor the code so that route annotations are only generated if explicitly requested and needed in the response. Specifically, we change the following annotations to be lazily generated: - Turn-by-turn steps - Route Overview geometry - Route segment metadata For example. a /route/v1 request with steps=false&overview=false&annotations=false would no longer call the following data facade methods: - GetOSMNodeIDOfNode - GetTurnInstructionForEdgeID - GetNameIndex - GetNameForID - GetRefForID - GetTurnInstructionForEdgeID - GetClassData - IsLeftHandDriving - GetTravelMode - IsSegregated - PreTurnBearing - PostTurnBearing - HasLaneData - GetLaneData - GetEntryClass Requests that include segment metadata and/or overview geometry but not turn-by-turn instructions will also benefit from this, although there is some interdependency with the step instructions - a call to GetTurnInstructionForEdgeID is still required. Requests for OSM annotations will understandably still need to call GetOSMNodeIDOfNode. Making these changes unlocks the optional loading of data contained in the following OSRM files: - osrm.names - osrm.icd - osrm.nbg_nodes (partial) - osrm.ebg_nodes (partial) - osrm.edges
This commit is contained in:
@@ -279,8 +279,7 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
|
||||
geometry.locations.begin() + offset);
|
||||
geometry.annotations.erase(geometry.annotations.begin(),
|
||||
geometry.annotations.begin() + offset);
|
||||
geometry.osm_node_ids.erase(geometry.osm_node_ids.begin(),
|
||||
geometry.osm_node_ids.begin() + offset);
|
||||
geometry.node_ids.erase(geometry.node_ids.begin(), geometry.node_ids.begin() + offset);
|
||||
}
|
||||
|
||||
auto const first_bearing = steps.front().maneuver.bearing_after;
|
||||
@@ -377,7 +376,7 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
|
||||
// remove all the last coordinates from the geometry
|
||||
geometry.locations.resize(geometry.segment_offsets.back() + 1);
|
||||
geometry.annotations.resize(geometry.segment_offsets.back());
|
||||
geometry.osm_node_ids.resize(geometry.segment_offsets.back() + 1);
|
||||
geometry.node_ids.resize(geometry.segment_offsets.back() + 1);
|
||||
|
||||
BOOST_ASSERT(geometry.segment_distances.back() <= 1);
|
||||
geometry.segment_distances.pop_back();
|
||||
@@ -414,7 +413,7 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
|
||||
// This can happen if the last coordinate snaps to a node in the unpacked geometry
|
||||
geometry.locations.pop_back();
|
||||
geometry.annotations.pop_back();
|
||||
geometry.osm_node_ids.pop_back();
|
||||
geometry.node_ids.pop_back();
|
||||
geometry.segment_offsets.back()--;
|
||||
// since the last geometry includes the location of arrival, the arrival instruction
|
||||
// geometry overlaps with the previous segment
|
||||
@@ -436,7 +435,7 @@ void trimShortSegments(std::vector<RouteStep> &steps, LegGeometry &geometry)
|
||||
}
|
||||
|
||||
BOOST_ASSERT(geometry.segment_offsets.back() + 1 == geometry.locations.size());
|
||||
BOOST_ASSERT(geometry.segment_offsets.back() + 1 == geometry.osm_node_ids.size());
|
||||
BOOST_ASSERT(geometry.segment_offsets.back() + 1 == geometry.node_ids.size());
|
||||
BOOST_ASSERT(geometry.segment_offsets.back() == geometry.annotations.size());
|
||||
|
||||
BOOST_ASSERT(steps.back().geometry_end == geometry.locations.size());
|
||||
@@ -541,7 +540,7 @@ std::vector<RouteStep> buildIntersections(std::vector<RouteStep> steps)
|
||||
{
|
||||
|
||||
// End of road is a turn that helps to identify the location of a turn. If the turn does
|
||||
// not pass by any oter intersections, the end-of-road characteristic does not improve
|
||||
// not pass by any other intersections, the end-of-road characteristic does not improve
|
||||
// the instructions.
|
||||
// Here we reduce the verbosity of our output by reducing end-of-road emissions in cases
|
||||
// where no intersections have been passed in between.
|
||||
|
||||
@@ -71,7 +71,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(
|
||||
const extractor::LaneDescriptionMap &lane_description_map)
|
||||
: m_edge_based_node_container(node_data_container), m_connectivity_checksum(0),
|
||||
m_number_of_edge_based_nodes(0), m_coordinates(coordinates),
|
||||
m_node_based_graph(std::move(node_based_graph)), m_barrier_nodes(barrier_nodes),
|
||||
m_node_based_graph(node_based_graph), m_barrier_nodes(barrier_nodes),
|
||||
m_traffic_lights(traffic_lights), m_compressed_edge_container(compressed_edge_container),
|
||||
name_table(name_table), segregated_edges(segregated_edges),
|
||||
lane_description_map(lane_description_map)
|
||||
|
||||
Reference in New Issue
Block a user