2016-03-23 08:04:23 -04:00
|
|
|
#include "extractor/guidance/constants.hpp"
|
2016-03-01 16:30:31 -05:00
|
|
|
#include "extractor/guidance/turn_analysis.hpp"
|
2016-02-25 08:40:26 -05:00
|
|
|
|
2016-03-03 09:36:03 -05:00
|
|
|
#include "util/coordinate.hpp"
|
2016-03-23 10:28:53 -04:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
2016-03-23 08:04:23 -04:00
|
|
|
#include "util/simple_logger.hpp"
|
2016-02-26 11:33:18 -05:00
|
|
|
|
|
|
|
#include <cstddef>
|
2016-03-04 09:10:33 -05:00
|
|
|
#include <iomanip>
|
2016-03-23 08:04:23 -04:00
|
|
|
#include <limits>
|
2016-03-23 10:28:53 -04:00
|
|
|
#include <set>
|
|
|
|
#include <unordered_set>
|
2016-02-26 11:33:18 -05:00
|
|
|
|
2016-02-25 08:40:26 -05:00
|
|
|
namespace osrm
|
|
|
|
{
|
|
|
|
namespace extractor
|
|
|
|
{
|
2016-03-01 16:30:31 -05:00
|
|
|
namespace guidance
|
2016-02-25 08:40:26 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
using EdgeData = util::NodeBasedDynamicGraph::EdgeData;
|
|
|
|
|
2016-03-08 05:30:33 -05:00
|
|
|
bool requiresAnnouncement(const EdgeData &from, const EdgeData &to)
|
2016-03-04 06:17:06 -05:00
|
|
|
{
|
|
|
|
return !from.IsCompatibleTo(to);
|
|
|
|
}
|
|
|
|
|
2016-03-08 06:40:45 -05:00
|
|
|
TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
|
|
|
|
const std::vector<QueryNode> &node_info_list,
|
|
|
|
const RestrictionMap &restriction_map,
|
|
|
|
const std::unordered_set<NodeID> &barrier_nodes,
|
2016-03-16 10:47:33 -04:00
|
|
|
const CompressedEdgeContainer &compressed_edge_container,
|
|
|
|
const util::NameTable &name_table)
|
2016-04-08 06:49:14 -04:00
|
|
|
: node_based_graph(node_based_graph), intersection_generator(node_based_graph,
|
|
|
|
restriction_map,
|
|
|
|
barrier_nodes,
|
|
|
|
node_info_list,
|
|
|
|
compressed_edge_container),
|
|
|
|
roundabout_handler(node_based_graph, node_info_list, name_table),
|
|
|
|
motorway_handler(node_based_graph, node_info_list, name_table),
|
|
|
|
turn_handler(node_based_graph, node_info_list, name_table)
|
2016-03-07 08:52:26 -05:00
|
|
|
{
|
2016-03-23 10:28:53 -04:00
|
|
|
}
|
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
std::vector<TurnOperation> TurnAnalysis::getTurns(const NodeID from_nid, const EdgeID via_eid) const
|
2016-02-25 08:40:26 -05:00
|
|
|
{
|
2016-04-08 06:49:14 -04:00
|
|
|
auto intersection = intersection_generator(from_nid, via_eid);
|
2016-03-07 04:38:13 -05:00
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
// Roundabouts are a main priority. If there is a roundabout instruction present, we process the
|
|
|
|
// turn as a roundabout
|
|
|
|
if (roundabout_handler.canProcess(from_nid, via_eid, intersection))
|
2016-02-25 12:31:29 -05:00
|
|
|
{
|
2016-04-08 06:49:14 -04:00
|
|
|
intersection = roundabout_handler(from_nid, via_eid, std::move(intersection));
|
2016-03-07 08:52:26 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-17 09:09:09 -04:00
|
|
|
// set initial defaults for normal turns and modifier based on angle
|
2016-04-08 06:49:14 -04:00
|
|
|
intersection = setTurnTypes(from_nid, via_eid, std::move(intersection));
|
|
|
|
if (motorway_handler.canProcess(from_nid, via_eid, intersection))
|
2016-03-17 09:09:09 -04:00
|
|
|
{
|
2016-04-08 06:49:14 -04:00
|
|
|
intersection = motorway_handler(from_nid, via_eid, std::move(intersection));
|
2016-03-17 09:09:09 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-08 06:49:14 -04:00
|
|
|
BOOST_ASSERT(turn_handler.canProcess(from_nid, via_eid, intersection));
|
|
|
|
intersection = turn_handler(from_nid, via_eid, std::move(intersection));
|
2016-03-17 09:09:09 -04:00
|
|
|
}
|
2016-03-07 08:52:26 -05:00
|
|
|
}
|
2016-02-26 11:33:18 -05:00
|
|
|
|
2016-03-17 09:09:09 -04:00
|
|
|
std::vector<TurnOperation> turns;
|
|
|
|
for (auto road : intersection)
|
|
|
|
if (road.entry_allowed)
|
|
|
|
turns.emplace_back(road.turn);
|
|
|
|
|
|
|
|
return turns;
|
2016-02-25 08:40:26 -05:00
|
|
|
}
|
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
// Sets basic turn types as fallback for otherwise unhandled turns
|
2016-04-11 06:51:06 -04:00
|
|
|
Intersection
|
|
|
|
TurnAnalysis::setTurnTypes(const NodeID from_nid, const EdgeID, Intersection intersection) const
|
2016-02-26 11:33:18 -05:00
|
|
|
{
|
2016-03-17 09:09:09 -04:00
|
|
|
for (auto &road : intersection)
|
2016-02-26 11:33:18 -05:00
|
|
|
{
|
2016-03-17 09:09:09 -04:00
|
|
|
if (!road.entry_allowed)
|
2016-02-26 11:33:18 -05:00
|
|
|
continue;
|
2016-03-03 09:36:03 -05:00
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
const EdgeID onto_edge = road.turn.eid;
|
|
|
|
const NodeID to_nid = node_based_graph.GetTarget(onto_edge);
|
2016-02-26 11:33:18 -05:00
|
|
|
|
2016-04-08 06:49:14 -04:00
|
|
|
road.turn.instruction = {TurnType::Turn, (from_nid == to_nid)
|
|
|
|
? DirectionModifier::UTurn
|
|
|
|
: getTurnDirection(road.turn.angle)};
|
2016-03-04 06:17:06 -05:00
|
|
|
}
|
2016-03-17 09:09:09 -04:00
|
|
|
return intersection;
|
2016-03-04 06:17:06 -05:00
|
|
|
}
|
|
|
|
|
2016-03-01 16:30:31 -05:00
|
|
|
} // namespace guidance
|
2016-02-25 08:40:26 -05:00
|
|
|
} // namespace extractor
|
2016-02-26 11:33:18 -05:00
|
|
|
} // namespace osrm
|