2016-01-28 10:28:44 -05:00
|
|
|
#ifndef ENGINE_GUIDANCE_ASSEMBLE_STEPS_HPP_
|
|
|
|
#define ENGINE_GUIDANCE_ASSEMBLE_STEPS_HPP_
|
|
|
|
|
2016-03-23 08:04:23 -04:00
|
|
|
#include "engine/guidance/leg_geometry.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "engine/guidance/route_step.hpp"
|
|
|
|
#include "engine/guidance/step_maneuver.hpp"
|
2016-03-01 16:30:31 -05:00
|
|
|
#include "engine/guidance/toolkit.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "engine/internal_route_result.hpp"
|
|
|
|
#include "engine/phantom_node.hpp"
|
2016-03-23 08:04:23 -04:00
|
|
|
#include "extractor/guidance/turn_instruction.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
#include "extractor/travel_mode.hpp"
|
2016-03-23 08:04:23 -04:00
|
|
|
#include "util/bearing.hpp"
|
|
|
|
#include "util/coordinate.hpp"
|
|
|
|
#include "util/coordinate_calculation.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/guidance/entry_class.hpp"
|
2016-05-25 09:24:11 -04:00
|
|
|
#include "util/guidance/toolkit.hpp"
|
2016-04-26 07:27:40 -04:00
|
|
|
#include "util/typedefs.hpp"
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-02-25 04:01:16 -05:00
|
|
|
#include <boost/optional.hpp>
|
2016-04-21 07:59:03 -04:00
|
|
|
#include <cstddef>
|
2016-03-23 08:04:23 -04:00
|
|
|
#include <vector>
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace engine
|
|
|
|
{
|
|
|
|
namespace guidance
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
2016-05-18 11:53:05 -04:00
|
|
|
std::pair<short, short> getDepartBearings(const LegGeometry &leg_geometry);
|
|
|
|
std::pair<short, short> getArriveBearings(const LegGeometry &leg_geometry);
|
|
|
|
std::pair<short, short> getIntermediateBearings(const LegGeometry &leg_geometry,
|
|
|
|
const std::size_t segment_index);
|
2016-03-03 09:34:13 -05:00
|
|
|
} // ns detail
|
2016-01-28 10:28:44 -05:00
|
|
|
|
|
|
|
template <typename DataFacadeT>
|
|
|
|
std::vector<RouteStep> assembleSteps(const DataFacadeT &facade,
|
|
|
|
const std::vector<PathData> &leg_data,
|
|
|
|
const LegGeometry &leg_geometry,
|
|
|
|
const PhantomNode &source_node,
|
|
|
|
const PhantomNode &target_node,
|
|
|
|
const bool source_traversed_in_reverse,
|
2016-03-07 12:59:39 -05:00
|
|
|
const bool target_traversed_in_reverse)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-22 09:17:17 -04:00
|
|
|
const double constexpr ZERO_DURATION = 0., ZERO_DISTANCE = 0.;
|
2016-03-23 08:04:23 -04:00
|
|
|
const constexpr char *NO_ROTARY_NAME = "";
|
2016-03-17 15:39:19 -04:00
|
|
|
const EdgeWeight source_duration =
|
2016-03-18 11:14:48 -04:00
|
|
|
source_traversed_in_reverse ? source_node.reverse_weight : source_node.forward_weight;
|
2016-01-28 10:28:44 -05:00
|
|
|
const auto source_mode = source_traversed_in_reverse ? source_node.backward_travel_mode
|
|
|
|
: source_node.forward_travel_mode;
|
|
|
|
|
2016-03-17 15:39:19 -04:00
|
|
|
const EdgeWeight target_duration =
|
2016-03-18 11:14:48 -04:00
|
|
|
target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight;
|
2016-01-28 10:28:44 -05:00
|
|
|
const auto target_mode = target_traversed_in_reverse ? target_node.backward_travel_mode
|
|
|
|
: target_node.forward_travel_mode;
|
|
|
|
|
|
|
|
const auto number_of_segments = leg_geometry.GetNumberOfSegments();
|
|
|
|
|
|
|
|
std::vector<RouteStep> steps;
|
|
|
|
steps.reserve(number_of_segments);
|
|
|
|
|
2016-02-29 10:24:42 -05:00
|
|
|
std::size_t segment_index = 0;
|
2016-03-08 10:46:01 -05:00
|
|
|
BOOST_ASSERT(leg_geometry.locations.size() >= 2);
|
|
|
|
|
2016-05-18 11:53:05 -04:00
|
|
|
auto bearings = detail::getDepartBearings(leg_geometry);
|
2016-02-25 04:01:16 -05:00
|
|
|
|
2016-05-18 11:53:05 -04:00
|
|
|
StepManeuver maneuver{source_node.location, bearings.first,
|
|
|
|
bearings.second, extractor::guidance::TurnInstruction::NO_TURN(),
|
|
|
|
WaypointType::Depart, 0};
|
2016-05-25 09:24:11 -04:00
|
|
|
Intersection intersection{source_node.location, std::vector<short>({bearings.second}),
|
|
|
|
std::vector<bool>({true}), Intersection::NO_INDEX, 0};
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-05-18 11:53:05 -04:00
|
|
|
if (leg_data.size() > 0)
|
|
|
|
{
|
2016-01-28 10:28:44 -05:00
|
|
|
// PathData saves the information we need of the segment _before_ the turn,
|
|
|
|
// but a RouteStep is with regard to the segment after the turn.
|
|
|
|
// We need to skip the first segment because it is already covered by the
|
2016-02-24 04:29:23 -05:00
|
|
|
// initial start of a route
|
2016-03-17 15:39:19 -04:00
|
|
|
int segment_duration = 0;
|
2016-04-21 07:59:03 -04:00
|
|
|
|
|
|
|
// some name changes are not announced in our processing. For these, we have to keep the
|
|
|
|
// first name on the segment
|
2016-04-22 05:31:46 -04:00
|
|
|
auto step_name_id = source_node.name_id;
|
2016-04-21 07:59:03 -04:00
|
|
|
for (std::size_t leg_data_index = 0; leg_data_index < leg_data.size(); ++leg_data_index)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-04-21 07:59:03 -04:00
|
|
|
const auto &path_point = leg_data[leg_data_index];
|
2016-03-17 15:39:19 -04:00
|
|
|
segment_duration += path_point.duration_until_turn;
|
|
|
|
|
2016-03-22 08:40:13 -04:00
|
|
|
// all changes to this check have to be matched with assemble_geometry
|
2016-03-21 13:07:28 -04:00
|
|
|
if (path_point.turn_instruction.type != extractor::guidance::TurnType::NoTurn)
|
2016-01-28 10:28:44 -05:00
|
|
|
{
|
2016-03-17 15:39:19 -04:00
|
|
|
BOOST_ASSERT(segment_duration >= 0);
|
2016-04-21 07:59:03 -04:00
|
|
|
const auto name = facade.GetNameForID(step_name_id);
|
2016-01-28 10:28:44 -05:00
|
|
|
const auto distance = leg_geometry.segment_distances[segment_index];
|
2016-05-18 11:53:05 -04:00
|
|
|
|
2016-05-25 09:24:11 -04:00
|
|
|
steps.push_back(RouteStep{step_name_id,
|
|
|
|
name,
|
|
|
|
NO_ROTARY_NAME,
|
|
|
|
segment_duration / 10.0,
|
|
|
|
distance,
|
|
|
|
path_point.travel_mode,
|
|
|
|
maneuver,
|
|
|
|
leg_geometry.FrontIndex(segment_index),
|
|
|
|
leg_geometry.BackIndex(segment_index) + 1,
|
|
|
|
{intersection}});
|
|
|
|
|
2016-05-10 02:37:45 -04:00
|
|
|
if (leg_data_index + 1 < leg_data.size())
|
|
|
|
{
|
2016-04-21 07:59:03 -04:00
|
|
|
step_name_id = leg_data[leg_data_index + 1].name_id;
|
2016-05-10 02:37:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-21 07:59:03 -04:00
|
|
|
step_name_id = target_node.name_id;
|
|
|
|
}
|
2016-05-18 11:53:05 -04:00
|
|
|
|
|
|
|
bearings = detail::getIntermediateBearings(leg_geometry, segment_index);
|
|
|
|
const auto entry_class = facade.GetEntryClass(path_point.entry_classid);
|
2016-05-25 09:24:11 -04:00
|
|
|
const auto bearing_class =
|
|
|
|
facade.GetBearingClass(facade.GetBearingClassID(path_point.turn_via_node));
|
|
|
|
intersection.in = bearing_class.findMatchingBearing(
|
|
|
|
util::bearing::reverseBearing(bearings.first));
|
2016-05-18 11:53:05 -04:00
|
|
|
intersection.out = bearing_class.findMatchingBearing(bearings.second);
|
|
|
|
intersection.location = facade.GetCoordinateOfNode(path_point.turn_via_node);
|
|
|
|
intersection.bearings.clear();
|
2016-05-25 09:24:11 -04:00
|
|
|
std::copy(bearing_class.getAvailableBearings().begin(),
|
|
|
|
bearing_class.getAvailableBearings().end(),
|
2016-05-18 11:53:05 -04:00
|
|
|
std::back_inserter(intersection.bearings));
|
|
|
|
intersection.entry.clear();
|
|
|
|
for (auto idx : util::irange<std::size_t>(0, intersection.bearings.size()))
|
|
|
|
{
|
|
|
|
intersection.entry.push_back(entry_class.allowsEntry(idx));
|
|
|
|
}
|
2016-05-25 09:24:11 -04:00
|
|
|
maneuver = {intersection.location, bearings.first, bearings.second,
|
|
|
|
path_point.turn_instruction, WaypointType::None, 0};
|
2016-01-28 10:28:44 -05:00
|
|
|
segment_index++;
|
2016-03-17 15:39:19 -04:00
|
|
|
segment_duration = 0;
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto distance = leg_geometry.segment_distances[segment_index];
|
2016-03-17 15:39:19 -04:00
|
|
|
const int duration = segment_duration + target_duration;
|
|
|
|
BOOST_ASSERT(duration >= 0);
|
2016-05-25 09:24:11 -04:00
|
|
|
steps.push_back(RouteStep{step_name_id,
|
|
|
|
facade.GetNameForID(step_name_id),
|
|
|
|
NO_ROTARY_NAME,
|
|
|
|
duration / 10.,
|
|
|
|
distance,
|
|
|
|
target_mode,
|
|
|
|
maneuver,
|
|
|
|
leg_geometry.FrontIndex(segment_index),
|
|
|
|
leg_geometry.BackIndex(segment_index) + 1,
|
|
|
|
{intersection}});
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
2016-03-17 15:39:19 -04:00
|
|
|
// In this case the source + target are on the same edge segment
|
2016-01-28 10:28:44 -05:00
|
|
|
else
|
|
|
|
{
|
2016-03-17 15:39:19 -04:00
|
|
|
BOOST_ASSERT(source_node.fwd_segment_position == target_node.fwd_segment_position);
|
|
|
|
// s t
|
|
|
|
// u-------------v
|
|
|
|
// |---| source_duration
|
|
|
|
// |---------| target_duration
|
|
|
|
|
|
|
|
int duration = target_duration - source_duration;
|
|
|
|
BOOST_ASSERT(duration >= 0);
|
2016-02-24 04:29:23 -05:00
|
|
|
|
2016-05-25 09:24:11 -04:00
|
|
|
steps.push_back(RouteStep{source_node.name_id,
|
|
|
|
facade.GetNameForID(source_node.name_id),
|
|
|
|
NO_ROTARY_NAME,
|
|
|
|
duration / 10.,
|
|
|
|
leg_geometry.segment_distances[segment_index],
|
|
|
|
source_mode,
|
|
|
|
std::move(maneuver),
|
|
|
|
leg_geometry.FrontIndex(segment_index),
|
|
|
|
leg_geometry.BackIndex(segment_index) + 1,
|
|
|
|
{intersection}});
|
2016-01-28 10:28:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_ASSERT(segment_index == number_of_segments - 1);
|
2016-05-18 11:53:05 -04:00
|
|
|
bearings = detail::getArriveBearings(leg_geometry);
|
2016-01-28 10:28:44 -05:00
|
|
|
// This step has length zero, the only reason we need it is the target location
|
2016-05-25 09:24:11 -04:00
|
|
|
maneuver = {intersection.location, bearings.first,
|
|
|
|
bearings.second, extractor::guidance::TurnInstruction::NO_TURN(),
|
|
|
|
WaypointType::Arrive, 0};
|
2016-05-18 11:53:05 -04:00
|
|
|
intersection = {
|
|
|
|
target_node.location,
|
|
|
|
std::vector<short>({static_cast<short>(util::bearing::reverseBearing(bearings.first))}),
|
|
|
|
std::vector<bool>({true}), 0, Intersection::NO_INDEX};
|
2016-04-06 10:47:16 -04:00
|
|
|
|
|
|
|
BOOST_ASSERT(!leg_geometry.locations.empty());
|
2016-05-25 09:24:11 -04:00
|
|
|
steps.push_back(RouteStep{target_node.name_id,
|
|
|
|
facade.GetNameForID(target_node.name_id),
|
|
|
|
NO_ROTARY_NAME,
|
|
|
|
ZERO_DURATION,
|
|
|
|
ZERO_DISTANCE,
|
|
|
|
target_mode,
|
|
|
|
std::move(maneuver),
|
|
|
|
leg_geometry.locations.size() - 1,
|
2016-05-10 02:37:45 -04:00
|
|
|
leg_geometry.locations.size(),
|
2016-05-18 11:53:05 -04:00
|
|
|
{intersection}});
|
|
|
|
|
|
|
|
BOOST_ASSERT(steps.front().intersections.size() == 1);
|
|
|
|
BOOST_ASSERT(steps.front().intersections.front().bearings.size() == 1);
|
|
|
|
BOOST_ASSERT(steps.front().intersections.front().entry.size() == 1);
|
|
|
|
BOOST_ASSERT(steps.front().maneuver.waypoint_type == WaypointType::Depart);
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-05-18 11:53:05 -04:00
|
|
|
BOOST_ASSERT(steps.back().intersections.size() == 1);
|
|
|
|
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);
|
2016-01-28 10:28:44 -05:00
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace guidance
|
|
|
|
} // namespace engine
|
|
|
|
} // namespace osrm
|
|
|
|
|
|
|
|
#endif // ENGINE_GUIDANCE_SEGMENT_LIST_HPP_
|