introduce roundabout-turns into instruction set

This commit is contained in:
Moritz Kobitzsch
2016-04-18 13:41:19 +02:00
parent 8d68d4c050
commit 1544a08ea2
19 changed files with 791 additions and 141 deletions
@@ -205,7 +205,7 @@ Intersection IntersectionGenerator::mergeSegregatedRoads(Intersection intersecti
return result;
}
};
if (intersection.size() == 1)
if (intersection.size() <= 1)
return intersection;
const bool is_connected_to_roundabout = [this,&intersection]() {
@@ -245,7 +245,6 @@ Intersection IntersectionGenerator::mergeSegregatedRoads(Intersection intersecti
intersection.pop_back();
}
else if (mergable(0, 1))
{
const double correction_factor = (intersection[1].turn.angle) / 2;
@@ -2,11 +2,13 @@
#include "extractor/guidance/intersection_handler.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/simple_logger.hpp"
#include <algorithm>
using EdgeData = osrm::util::NodeBasedDynamicGraph::EdgeData;
using osrm::util::guidance::getTurnDirection;
namespace osrm
{
@@ -2,6 +2,10 @@
#include "extractor/guidance/intersection_scenario_three_way.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
using osrm::util::guidance::angularDeviation;
namespace osrm
{
namespace extractor
@@ -3,12 +3,16 @@
#include "extractor/guidance/toolkit.hpp"
#include "util/simple_logger.hpp"
#include "util/guidance/toolkit.hpp"
#include <limits>
#include <utility>
#include <boost/assert.hpp>
using osrm::util::guidance::angularDeviation;
using osrm::util::guidance::getTurnDirection;
namespace osrm
{
namespace extractor
+144 -38
View File
@@ -2,14 +2,18 @@
#include "extractor/guidance/roundabout_handler.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/simple_logger.hpp"
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_set>
#include <boost/assert.hpp>
using osrm::util::guidance::getTurnDirection;
namespace osrm
{
namespace extractor
@@ -19,8 +23,10 @@ namespace guidance
RoundaboutHandler::RoundaboutHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::vector<QueryNode> &node_info_list,
const util::NameTable &name_table)
: IntersectionHandler(node_based_graph, node_info_list, name_table)
const util::NameTable &name_table,
const CompressedEdgeContainer &compressed_edge_container)
: IntersectionHandler(node_based_graph, node_info_list, name_table),
compressed_edge_container(compressed_edge_container)
{
}
@@ -31,7 +37,11 @@ bool RoundaboutHandler::canProcess(const NodeID from_nid,
const Intersection &intersection) const
{
const auto flags = getRoundaboutFlags(from_nid, via_eid, intersection);
return flags.on_roundabout || flags.can_enter;
if (!flags.on_roundabout && !flags.can_enter)
return false;
const auto roundabout_type = getRoundaboutType(node_based_graph.GetTarget(via_eid));
return roundabout_type != RoundaboutType::None;
}
Intersection RoundaboutHandler::
@@ -39,10 +49,10 @@ operator()(const NodeID from_nid, const EdgeID via_eid, Intersection intersectio
{
invalidateExitAgainstDirection(from_nid, via_eid, intersection);
const auto flags = getRoundaboutFlags(from_nid, via_eid, intersection);
const bool is_rotary = isRotary(node_based_graph.GetTarget(via_eid));
const auto roundabout_type = getRoundaboutType(node_based_graph.GetTarget(via_eid));
// find the radius of the roundabout
return handleRoundabouts(is_rotary, via_eid, flags.on_roundabout, flags.can_exit_separately,
std::move(intersection));
return handleRoundabouts(roundabout_type, via_eid, flags.on_roundabout,
flags.can_exit_separately, std::move(intersection));
}
detail::RoundaboutFlags RoundaboutHandler::getRoundaboutFlags(
@@ -56,7 +66,7 @@ detail::RoundaboutFlags RoundaboutHandler::getRoundaboutFlags(
{
const auto &edge_data = node_based_graph.GetEdgeData(road.turn.eid);
// only check actual outgoing edges
if (edge_data.reversed || !road.entry_allowed )
if (edge_data.reversed || !road.entry_allowed)
continue;
if (edge_data.roundabout)
@@ -85,7 +95,7 @@ void RoundaboutHandler::invalidateExitAgainstDirection(const NodeID from_nid,
Intersection &intersection) const
{
const auto &in_edge_data = node_based_graph.GetEdgeData(via_eid);
if( in_edge_data.roundabout )
if (in_edge_data.roundabout)
return;
bool past_roundabout_angle = false;
@@ -116,7 +126,74 @@ void RoundaboutHandler::invalidateExitAgainstDirection(const NodeID from_nid,
}
}
bool RoundaboutHandler::isRotary(const NodeID nid) const
// If we want to see a roundabout as a turn, the exits have to be distinct enough to be seen a
// dedicated turns. We are limiting it to four-way intersections with well distinct bearings.
// All entry/roads and exit roads have to be simple. Not segregated roads.
// Processing segregated roads would technically require an angle of the turn to be available
// in postprocessing since we correct the turn-angle in turn-generaion.
bool RoundaboutHandler::qualifiesAsRoundaboutIntersection(
const std::set<NodeID> &roundabout_nodes) const
{
// translate a node ID into its respective coordinate stored in the node_info_list
const auto getCoordinate = [this](const NodeID node) {
return util::Coordinate(node_info_list[node].lon, node_info_list[node].lat);
};
const bool has_limited_size = roundabout_nodes.size() <= 4;
if (!has_limited_size)
return false;
const bool simple_exits = !std::find_if( roundabout_nodes.begin(), roundabout_nodes.end(), [this]( const NodeID node ){
return (node_based_graph.GetOutDegree(node) > 3);
});
if (!simple_exits)
return false;
// Find all exit bearings. Only if they are well distinct (at least 60 degrees between
// them), we allow a roundabout turn
const auto exit_bearings = [this, &roundabout_nodes, getCoordinate]() {
std::vector<double> result;
for (const auto node : roundabout_nodes)
{
// given the reverse edge and the forward edge on a roundabout, a simple entry/exit
// can only contain a single further road
for (const auto edge : node_based_graph.GetAdjacentEdgeRange(node))
{
const auto edge_data = node_based_graph.GetEdgeData(edge);
if (edge_data.roundabout)
continue;
// there is a single non-roundabout edge
const auto src_coordinate = getCoordinate(node);
const auto next_coordinate = getRepresentativeCoordinate(
node, node_based_graph.GetTarget(edge), edge, edge_data.reversed,
compressed_edge_container, node_info_list);
result.push_back(
util::coordinate_calculation::bearing(src_coordinate, next_coordinate));
break;
}
}
std::sort(result.begin(), result.end());
return result;
}();
const bool well_distinct_bearings = [](const std::vector<double> &bearings) {
for (std::size_t bearing_index = 0; bearing_index < bearings.size(); ++bearing_index)
{
const double difference =
std::abs(bearings[(bearing_index + 1) % bearings.size()] - bearings[bearing_index]);
// we assume non-narrow turns as well distinct
if (difference <= NARROW_TURN_ANGLE)
return false;
}
return true;
}(exit_bearings);
return well_distinct_bearings;
}
RoundaboutType RoundaboutHandler::getRoundaboutType(const NodeID nid) const
{
// translate a node ID into its respective coordinate stored in the node_info_list
const auto getCoordinate = [this](const NodeID node) {
@@ -168,31 +245,33 @@ bool RoundaboutHandler::isRotary(const NodeID nid) const
NodeID last_node = nid;
while (0 == roundabout_nodes.count(last_node))
{
roundabout_nodes.insert(last_node);
// only count exits/entry locations
if (node_based_graph.GetOutDegree(last_node) > 2)
roundabout_nodes.insert(last_node);
const auto eid = getNextOnRoundabout(last_node);
if (eid == SPECIAL_EDGEID)
{
util::SimpleLogger().Write(logDEBUG) << "Non-Loop Roundabout found.";
return false;
return RoundaboutType::None;
}
last_node = node_based_graph.GetTarget(eid);
if (last_node == nid)
break;
}
// do we have a dedicated name for the rotary, if not its a roundabout
// This function can theoretically fail if the roundabout name is partly
// used with a reference and without. This will be fixed automatically
// when we handle references separately or if the useage is more consistent
if (roundabout_name_id == 0 || connected_names.count(roundabout_name_id))
// a roundabout that cannot be entered or exited should not get here
if (roundabout_nodes.size() == 0)
return RoundaboutType::None;
// More a traffic loop than anything else, currently treated as roundabout turn
if (roundabout_nodes.size() == 1)
{
return false;
return RoundaboutType::RoundaboutIntersection;
}
if (roundabout_nodes.size() <= 1)
{
return false;
}
// calculate the radius of the roundabout/rotary. For two coordinates, we assume a minimal
// circle
// with both vertices right at the other side (so half their distance in meters).
@@ -217,12 +296,42 @@ bool RoundaboutHandler::isRotary(const NodeID nid) const
// The radius computation can result in infinity, if the three coordinates are non-distinct.
// To stay on the safe side, we say its not a rotary
if (std::isinf(radius))
return false;
return RoundaboutType::Roundabout;
return radius > MAX_ROUNDABOUT_RADIUS;
// not within the dedicated radii for special roundabouts
if (radius > MAX_ROUNDABOUT_INTERSECTION_RADIUS && radius <= MAX_ROUNDABOUT_RADIUS)
return RoundaboutType::Roundabout;
if (radius > MAX_ROUNDABOUT_RADIUS)
{
// do we have a dedicated name for the rotary, if not its a roundabout
// This function can theoretically fail if the roundabout name is partly
// used with a reference and without. This will be fixed automatically
// when we handle references separately or if the useage is more consistent
if (0 != roundabout_name_id && 0 == connected_names.count(roundabout_name_id))
return RoundaboutType::Rotary;
else
return RoundaboutType::Roundabout;
}
if (radius <= MAX_ROUNDABOUT_INTERSECTION_RADIUS)
{
const bool qualifies_as_roundabout_nitersection =
qualifiesAsRoundaboutIntersection(roundabout_nodes);
if (qualifies_as_roundabout_nitersection)
{
return RoundaboutType::RoundaboutIntersection;
}
else
{
return RoundaboutType::Roundabout;
}
}
return RoundaboutType::Roundabout;
}
Intersection RoundaboutHandler::handleRoundabouts(const bool is_rotary,
Intersection RoundaboutHandler::handleRoundabouts(const RoundaboutType roundabout_type,
const EdgeID via_eid,
const bool on_roundabout,
const bool can_exit_roundabout_separately,
@@ -248,14 +357,14 @@ Intersection RoundaboutHandler::handleRoundabouts(const bool is_rotary,
}
else
{
turn.instruction =
TurnInstruction::REMAIN_ROUNDABOUT(is_rotary, getTurnDirection(turn.angle));
turn.instruction = TurnInstruction::REMAIN_ROUNDABOUT(
roundabout_type, getTurnDirection(turn.angle));
}
}
else
{
turn.instruction =
TurnInstruction::EXIT_ROUNDABOUT(is_rotary, getTurnDirection(turn.angle));
TurnInstruction::EXIT_ROUNDABOUT(roundabout_type, getTurnDirection(turn.angle));
}
}
return intersection;
@@ -269,20 +378,17 @@ Intersection RoundaboutHandler::handleRoundabouts(const bool is_rotary,
const auto &out_data = node_based_graph.GetEdgeData(turn.eid);
if (out_data.roundabout)
{
turn.instruction =
TurnInstruction::ENTER_ROUNDABOUT(is_rotary, getTurnDirection(turn.angle));
if (can_exit_roundabout_separately)
{
if (turn.instruction.type == TurnType::EnterRotary)
turn.instruction.type = TurnType::EnterRotaryAtExit;
if (turn.instruction.type == TurnType::EnterRoundabout)
turn.instruction.type = TurnType::EnterRoundaboutAtExit;
}
turn.instruction = TurnInstruction::ENTER_ROUNDABOUT_AT_EXIT(
roundabout_type, getTurnDirection(turn.angle));
else
turn.instruction = TurnInstruction::ENTER_ROUNDABOUT(
roundabout_type, getTurnDirection(turn.angle));
}
else
{
turn.instruction = TurnInstruction::ENTER_AND_EXIT_ROUNDABOUT(
is_rotary, getTurnDirection(turn.angle));
roundabout_type, getTurnDirection(turn.angle));
}
}
return intersection;
+4 -1
View File
@@ -3,6 +3,7 @@
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/simple_logger.hpp"
#include <cstddef>
@@ -11,6 +12,8 @@
#include <set>
#include <unordered_set>
using osrm::util::guidance::getTurnDirection;
namespace osrm
{
namespace extractor
@@ -36,7 +39,7 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
barrier_nodes,
node_info_list,
compressed_edge_container),
roundabout_handler(node_based_graph, node_info_list, name_table),
roundabout_handler(node_based_graph, node_info_list, name_table, compressed_edge_container),
motorway_handler(node_based_graph, node_info_list, name_table),
turn_handler(node_based_graph, node_info_list, name_table)
{
+3
View File
@@ -4,6 +4,7 @@
#include "extractor/guidance/turn_handler.hpp"
#include "util/simple_logger.hpp"
#include "util/guidance/toolkit.hpp"
#include <limits>
#include <utility>
@@ -11,6 +12,8 @@
#include <boost/assert.hpp>
using EdgeData = osrm::util::NodeBasedDynamicGraph::EdgeData;
using osrm::util::guidance::getTurnDirection;
using osrm::util::guidance::angularDeviation;
namespace osrm
{