Remove IntersectionGenerator

This commit is contained in:
Michael Krasnyk
2017-12-04 13:11:45 +01:00
parent db7c76d04d
commit 4b9e3a8068
29 changed files with 178 additions and 319 deletions
@@ -428,12 +428,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const auto &turn_lanes_data = transformTurnLaneMapIntoArrays(lane_description_map);
guidance::CoordinateExtractor coordinate_extractor(
m_node_based_graph, m_compressed_edge_container, m_coordinates);
guidance::IntersectionGenerator intersection_generator(m_node_based_graph,
m_edge_based_node_container,
node_restriction_map,
m_barrier_nodes,
m_coordinates,
m_compressed_edge_container);
guidance::MergableRoadDetector mergable_road_detector(m_node_based_graph,
m_edge_based_node_container,
m_coordinates,
@@ -441,7 +435,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
node_restriction_map,
m_barrier_nodes,
turn_lanes_data,
intersection_generator,
coordinate_extractor,
name_table,
street_name_suffix_table);
+2 -4
View File
@@ -12,8 +12,7 @@ namespace extractor
namespace guidance
{
DrivewayHandler::DrivewayHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
DrivewayHandler::DrivewayHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
const std::vector<util::Coordinate> &node_coordinates,
const extractor::CompressedEdgeContainer &compressed_geometries,
@@ -30,8 +29,7 @@ DrivewayHandler::DrivewayHandler(const IntersectionGenerator &intersection_gener
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator)
street_name_suffix_table)
{
}
@@ -1,85 +0,0 @@
#include "extractor/guidance/intersection_generator.hpp"
#include "extractor/geojson_debug_policies.hpp"
#include "util/geojson_debug_logger.hpp"
#include "util/assert.hpp"
#include "util/bearing.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/log.hpp"
#include <algorithm>
#include <cmath>
#include <functional> // mem_fn
#include <limits>
#include <numeric>
#include <utility>
#include <boost/range/algorithm/count_if.hpp>
namespace osrm
{
namespace extractor
{
namespace guidance
{
namespace
{
const constexpr bool USE_LOW_PRECISION_MODE = true;
// the inverse of use low precision mode
const constexpr bool USE_HIGH_PRECISION_MODE = !USE_LOW_PRECISION_MODE;
}
IntersectionGenerator::IntersectionGenerator(const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
const RestrictionMap &restriction_map,
const std::unordered_set<NodeID> &barrier_nodes,
const std::vector<util::Coordinate> &coordinates,
const CompressedEdgeContainer &)
: node_based_graph(node_based_graph), node_data_container(node_data_container),
restriction_map(restriction_map), barrier_nodes(barrier_nodes), coordinates(coordinates)
{
}
IntersectionGenerationParameters
IntersectionGenerator::SkipDegreeTwoNodes(const NodeID starting_node, const EdgeID via_edge) const
{
NodeID query_node = starting_node;
EdgeID query_edge = via_edge;
const auto get_next_edge = [this](const NodeID from, const EdgeID via) {
const NodeID new_node = node_based_graph.GetTarget(via);
BOOST_ASSERT(node_based_graph.GetOutDegree(new_node) == 2);
const EdgeID begin_edges_new_node = node_based_graph.BeginEdges(new_node);
return (node_based_graph.GetTarget(begin_edges_new_node) == from) ? begin_edges_new_node + 1
: begin_edges_new_node;
};
std::unordered_set<NodeID> visited_nodes;
// skip trivial nodes without generating the intersection in between, stop at the very first
// intersection of degree > 2
while (0 == visited_nodes.count(query_node) &&
2 == node_based_graph.GetOutDegree(node_based_graph.GetTarget(query_edge)))
{
visited_nodes.insert(query_node);
const auto next_node = node_based_graph.GetTarget(query_edge);
const auto next_edge = get_next_edge(query_node, query_edge);
query_node = next_node;
query_edge = next_edge;
// check if there is a relevant change in the graph
if (!CanBeCompressed(node_based_graph.GetEdgeData(query_edge),
node_based_graph.GetEdgeData(next_edge),
node_data_container) ||
(node_based_graph.GetTarget(next_edge) == starting_node))
break;
}
return {query_node, query_edge};
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
+21 -23
View File
@@ -55,20 +55,18 @@ IntersectionHandler::IntersectionHandler(
const std::unordered_set<NodeID> &barrier_nodes,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator)
const SuffixTable &street_name_suffix_table)
: node_based_graph(node_based_graph), node_data_container(node_data_container),
node_coordinates(node_coordinates), compressed_geometries(compressed_geometries),
node_restriction_map(node_restriction_map), barrier_nodes(barrier_nodes),
turn_lanes_data(turn_lanes_data), name_table(name_table),
street_name_suffix_table(street_name_suffix_table),
intersection_generator(intersection_generator), graph_walker(node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data)
street_name_suffix_table(street_name_suffix_table), graph_walker(node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data)
{
}
@@ -475,24 +473,24 @@ IntersectionHandler::getNextIntersection(const NodeID at, const EdgeID via) cons
// Starting at node `a` via edge `e0` the intersection generator returns the intersection at `c`
// writing `tl` (traffic signal) node and the edge `e1` which has the intersection as target.
const auto intersection_parameters = intersection_generator.SkipDegreeTwoNodes(at, via);
const auto intersection_parameters =
intersection::skipDegreeTwoNodes(node_based_graph, {at, via});
// This should never happen, guard against nevertheless
if (intersection_parameters.nid == SPECIAL_NODEID ||
intersection_parameters.via_eid == SPECIAL_EDGEID)
if (intersection_parameters.node == SPECIAL_NODEID ||
intersection_parameters.edge == SPECIAL_EDGEID)
{
return boost::none;
}
auto intersection = intersection::getConnectedRoads(
node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data,
{intersection_parameters.nid, intersection_parameters.via_eid});
auto intersection_node = node_based_graph.GetTarget(intersection_parameters.via_eid);
auto intersection = intersection::getConnectedRoads(node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data,
intersection_parameters);
auto intersection_node = node_based_graph.GetTarget(intersection_parameters.edge);
if (intersection.size() <= 2 || intersection.isTrafficSignalOrBarrier())
{
@@ -1,7 +1,6 @@
#include "extractor/guidance/mergable_road_detector.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/coordinate_extractor.hpp"
#include "extractor/guidance/intersection_generator.hpp"
#include "extractor/guidance/node_based_graph_walker.hpp"
#include "extractor/intersection/intersection_analysis.hpp"
#include "extractor/query_node.hpp"
@@ -61,16 +60,14 @@ MergableRoadDetector::MergableRoadDetector(
const RestrictionMap &node_restriction_map,
const std::unordered_set<NodeID> &barrier_nodes,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const IntersectionGenerator &intersection_generator,
const CoordinateExtractor &coordinate_extractor,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table)
: node_based_graph(node_based_graph), node_data_container(node_data_container),
node_coordinates(node_coordinates), compressed_geometries(compressed_geometries),
node_restriction_map(node_restriction_map), barrier_nodes(barrier_nodes),
turn_lanes_data(turn_lanes_data), intersection_generator(intersection_generator),
coordinate_extractor(coordinate_extractor), name_table(name_table),
street_name_suffix_table(street_name_suffix_table)
turn_lanes_data(turn_lanes_data), coordinate_extractor(coordinate_extractor),
name_table(name_table), street_name_suffix_table(street_name_suffix_table)
{
}
@@ -178,8 +175,9 @@ bool MergableRoadDetector::EdgeDataSupportsMerge(
bool MergableRoadDetector::IsTrafficLoop(const NodeID intersection_node,
const MergableRoadData &road) const
{
const auto connection = intersection_generator.SkipDegreeTwoNodes(intersection_node, road.eid);
return intersection_node == node_based_graph.GetTarget(connection.via_eid);
const auto connection =
intersection::skipDegreeTwoNodes(node_based_graph, {intersection_node, road.eid});
return intersection_node == node_based_graph.GetTarget(connection.edge);
}
bool MergableRoadDetector::IsNarrowTriangle(const NodeID intersection_node,
@@ -486,12 +484,12 @@ bool MergableRoadDetector::IsTrafficIsland(const NodeID intersection_node,
* location with the same name repeatet at least three times
*/
const auto left_connection =
intersection_generator.SkipDegreeTwoNodes(intersection_node, lhs.eid);
intersection::skipDegreeTwoNodes(node_based_graph, {intersection_node, lhs.eid});
const auto right_connection =
intersection_generator.SkipDegreeTwoNodes(intersection_node, rhs.eid);
intersection::skipDegreeTwoNodes(node_based_graph, {intersection_node, rhs.eid});
const auto left_candidate = node_based_graph.GetTarget(left_connection.via_eid);
const auto right_candidate = node_based_graph.GetTarget(right_connection.via_eid);
const auto left_candidate = node_based_graph.GetTarget(left_connection.edge);
const auto right_candidate = node_based_graph.GetTarget(right_connection.edge);
const auto candidate_is_valid =
left_candidate == right_candidate && left_candidate != intersection_node;
@@ -559,16 +557,16 @@ bool MergableRoadDetector::IsLinkRoad(const NodeID intersection_node,
const MergableRoadData &road) const
{
const auto next_intersection_parameters =
intersection_generator.SkipDegreeTwoNodes(intersection_node, road.eid);
const auto next_intersection_along_road = intersection::getConnectedRoads(
node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data,
{next_intersection_parameters.nid, next_intersection_parameters.via_eid});
intersection::skipDegreeTwoNodes(node_based_graph, {intersection_node, road.eid});
const auto next_intersection_along_road =
intersection::getConnectedRoads(node_based_graph,
node_data_container,
node_coordinates,
compressed_geometries,
node_restriction_map,
barrier_nodes,
turn_lanes_data,
next_intersection_parameters);
const auto extract_name_id = [this](const MergableRoadData &road) {
return node_data_container
.GetAnnotation(node_based_graph.GetEdgeData(road.eid).annotation_data)
@@ -593,7 +591,7 @@ bool MergableRoadDetector::IsLinkRoad(const NodeID intersection_node,
// we cannot be looking at the same road we came from
if (node_based_graph.GetTarget(opposite_of_next_road_along_path->eid) ==
next_intersection_parameters.nid)
next_intersection_parameters.node)
return false;
/* check if the opposite of the next road decision was sane. It could have been just as well our
+2 -4
View File
@@ -47,8 +47,7 @@ MotorwayHandler::MotorwayHandler(const util::NodeBasedDynamicGraph &node_based_g
const std::unordered_set<NodeID> &barrier_nodes,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator)
const SuffixTable &street_name_suffix_table)
: IntersectionHandler(node_based_graph,
node_data_container,
coordinates,
@@ -57,8 +56,7 @@ MotorwayHandler::MotorwayHandler(const util::NodeBasedDynamicGraph &node_based_g
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator)
street_name_suffix_table)
{
}
@@ -32,8 +32,7 @@ RoundaboutHandler::RoundaboutHandler(
const std::unordered_set<NodeID> &barrier_nodes,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator)
const SuffixTable &street_name_suffix_table)
: IntersectionHandler(node_based_graph,
node_data_container,
coordinates,
@@ -42,8 +41,7 @@ RoundaboutHandler::RoundaboutHandler(
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator),
street_name_suffix_table),
coordinate_extractor(node_based_graph, compressed_geometries, coordinates)
{
}
+2 -4
View File
@@ -22,8 +22,7 @@ namespace extractor
namespace guidance
{
SliproadHandler::SliproadHandler(const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
SliproadHandler::SliproadHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
const std::vector<util::Coordinate> &node_coordinates,
const extractor::CompressedEdgeContainer &compressed_geometries,
@@ -40,8 +39,7 @@ SliproadHandler::SliproadHandler(const IntersectionGenerator &intersection_gener
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator),
street_name_suffix_table),
coordinate_extractor(node_based_graph, compressed_geometries, node_coordinates)
{
}
@@ -12,7 +12,6 @@ namespace guidance
{
SuppressModeHandler::SuppressModeHandler(
const IntersectionGenerator &intersection_generator,
const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
const std::vector<util::Coordinate> &coordinates,
@@ -30,8 +29,7 @@ SuppressModeHandler::SuppressModeHandler(
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator)
street_name_suffix_table)
{
}
+15 -28
View File
@@ -30,22 +30,15 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table)
: node_based_graph(node_based_graph), intersection_generator(node_based_graph,
node_data_container,
restriction_map,
barrier_nodes,
node_coordinates,
compressed_edge_container),
roundabout_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
restriction_map,
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator),
: node_based_graph(node_based_graph), roundabout_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
restriction_map,
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table),
motorway_handler(node_based_graph,
node_data_container,
node_coordinates,
@@ -54,8 +47,7 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator),
street_name_suffix_table),
turn_handler(node_based_graph,
node_data_container,
node_coordinates,
@@ -64,10 +56,8 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator),
sliproad_handler(intersection_generator,
node_based_graph,
street_name_suffix_table),
sliproad_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
@@ -76,8 +66,7 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
turn_lanes_data,
name_table,
street_name_suffix_table),
suppress_mode_handler(intersection_generator,
node_based_graph,
suppress_mode_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
@@ -86,8 +75,7 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
turn_lanes_data,
name_table,
street_name_suffix_table),
driveway_handler(intersection_generator,
node_based_graph,
driveway_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
@@ -96,8 +84,7 @@ TurnAnalysis::TurnAnalysis(const util::NodeBasedDynamicGraph &node_based_graph,
turn_lanes_data,
name_table,
street_name_suffix_table),
statistics_handler(intersection_generator,
node_based_graph,
statistics_handler(node_based_graph,
node_data_container,
node_coordinates,
compressed_edge_container,
@@ -1,5 +1,6 @@
#include "extractor/guidance/turn_discovery.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/coordinate_extractor.hpp"
#include "extractor/intersection/intersection_analysis.hpp"
#include "util/bearing.hpp"
#include "util/coordinate_calculation.hpp"
+2 -4
View File
@@ -118,8 +118,7 @@ TurnHandler::TurnHandler(const util::NodeBasedDynamicGraph &node_based_graph,
const std::unordered_set<NodeID> &barrier_nodes,
const guidance::TurnLanesIndexedArray &turn_lanes_data,
const util::NameTable &name_table,
const SuffixTable &street_name_suffix_table,
const IntersectionGenerator &intersection_generator)
const SuffixTable &street_name_suffix_table)
: IntersectionHandler(node_based_graph,
node_data_container,
coordinates,
@@ -128,8 +127,7 @@ TurnHandler::TurnHandler(const util::NodeBasedDynamicGraph &node_based_graph,
barrier_nodes,
turn_lanes_data,
name_table,
street_name_suffix_table,
intersection_generator)
street_name_suffix_table)
{
}
@@ -783,6 +783,27 @@ getConnectedRoads(const util::NodeBasedDynamicGraph &graph,
outgoing_edges,
std::unordered_set<EdgeID>());
}
IntersectionEdge skipDegreeTwoNodes(const util::NodeBasedDynamicGraph &graph, IntersectionEdge road)
{
std::unordered_set<NodeID> visited_nodes;
(void)visited_nodes;
// Skip trivial nodes without generating the intersection in between, stop at the very first
// intersection of degree > 2
const auto starting_node = road.node;
auto next_node = graph.GetTarget(road.edge);
while (graph.GetOutDegree(next_node) == 2 && next_node != starting_node)
{
BOOST_ASSERT(visited_nodes.insert(next_node).second);
const auto next_edge = graph.BeginEdges(next_node);
road.edge = graph.GetTarget(next_edge) == road.node ? next_edge + 1 : next_edge;
road.node = next_node;
next_node = graph.GetTarget(road.edge);
}
return road;
}
}
}
}