Skip to content

Commit

Permalink
syncronize geometry and steps after post-processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Kobitzsch committed Mar 23, 2016
1 parent 05c8834 commit 7a925da
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class RouteAPI : public BaseAPI
*/

leg.steps = guidance::postProcess(std::move(steps));
leg_geometry = guidance::resyncGeometry(std::move(leg_geometry),leg.steps);
}

leg_geometries.push_back(std::move(leg_geometry));
Expand Down
2 changes: 1 addition & 1 deletion include/engine/guidance/assemble_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ LegGeometry assembleGeometry(const DataFacadeT &facade,
current_distance +=
util::coordinate_calculation::haversineDistance(prev_coordinate, coordinate);

//all changes to this check have to be matched with assemble_steps
// all changes to this check have to be matched with assemble_steps
if (path_point.turn_instruction.type != extractor::guidance::TurnType::NoTurn)
{
geometry.segment_distances.push_back(current_distance);
Expand Down
10 changes: 9 additions & 1 deletion include/engine/guidance/post_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ENGINE_GUIDANCE_POST_PROCESSING_HPP

#include "engine/guidance/route_step.hpp"
#include "engine/guidance/leg_geometry.hpp"

#include <vector>

Expand All @@ -12,9 +13,16 @@ namespace engine
namespace guidance
{

//passed as none-reference to modify in-place and move out again
// passed as none-reference to modify in-place and move out again
std::vector<RouteStep> postProcess(std::vector<RouteStep> steps);

// postProcess will break the connection between the leg geometry
// for which a segment is supposed to represent exactly the coordinates
// between routing maneuvers and the route steps itself.
// If required, we can get both in sync again using this function.
// Move in LegGeometry for modification in place.
LegGeometry resyncGeometry(LegGeometry leg_geometry, const std::vector<RouteStep> &steps);

} // namespace guidance
} // namespace engine
} // namespace osrm
Expand Down
8 changes: 4 additions & 4 deletions src/engine/api/json_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ util::json::Object makeStepManeuver(const guidance::StepManeuver &maneuver)
if (maneuver.exit != 0)
step_maneuver.values["exit"] = maneuver.exit;

//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.intersections.empty() && maneuver.exit == 0 )
// 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.intersections.empty() && maneuver.exit == 0)
step_maneuver.values["exit"] = maneuver.intersections.size();
return step_maneuver;
}
Expand Down
29 changes: 26 additions & 3 deletions src/engine/guidance/post_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ void fixFinalRoundabout(std::vector<RouteStep> &steps)
}
else if (propagation_step.maneuver.instruction.type == TurnType::StayOnRoundabout)
{
//TODO this operates on the data that is in the instructions.
//We are missing out on the final segment after the last stay-on-roundabout
//instruction though. it is not contained somewhere until now
// TODO this operates on the data that is in the instructions.
// We are missing out on the final segment after the last stay-on-roundabout
// instruction though. it is not contained somewhere until now
steps[propagation_index - 1] =
forwardInto(std::move(steps[propagation_index - 1]), propagation_step);
propagation_step.maneuver.instruction =
Expand Down Expand Up @@ -292,6 +292,29 @@ std::vector<RouteStep> postProcess(std::vector<RouteStep> steps)
return steps;
}

LegGeometry resyncGeometry(LegGeometry leg_geometry, const std::vector<RouteStep> &steps)
{
// The geometry uses an adjacency array-like structure for representation.
// To sync it back up with the steps, we cann add a segment for every step.
leg_geometry.segment_offsets.clear();
leg_geometry.segment_distances.clear();
leg_geometry.segment_offsets.push_back(0);

for (const auto &step : steps)
{
leg_geometry.segment_distances.push_back(step.distance);
// the leg geometry does not follow the begin/end-convetion. So we have to subtract one
// to get the back-index.
leg_geometry.segment_offsets.push_back(step.geometry_end - 1);
}

//remove the data fromt the reached-target step again
leg_geometry.segment_offsets.pop_back();
leg_geometry.segment_distances.pop_back();

return leg_geometry;
}

} // namespace guidance
} // namespace engine
} // namespace osrm

0 comments on commit 7a925da

Please sign in to comment.