clean-up guidance code/code in general

removes duplicated includes
removes unused includes
eliminates dedicated toolkits that resulted in circular dependencies
moves functionality close to data, where possible
This commit is contained in:
Moritz Kobitzsch
2016-12-02 10:53:22 +01:00
parent a28a20a1ba
commit df3c39cef5
54 changed files with 607 additions and 692 deletions
+1 -2
View File
@@ -10,7 +10,6 @@
#include "util/percent.hpp"
#include "util/timing_util.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "extractor/guidance/turn_analysis.hpp"
#include "extractor/guidance/turn_lane_handler.hpp"
#include "extractor/scripting_environment.hpp"
@@ -354,7 +353,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
street_name_suffix_table,
profile_properties);
guidance::LaneDataIdMap lane_data_map;
util::guidance::LaneDataIdMap lane_data_map;
guidance::lanes::TurnLaneHandler turn_lane_handler(*m_node_based_graph,
turn_lane_offsets,
turn_lane_masks,
-2
View File
@@ -10,7 +10,6 @@
#include "extractor/raster_source.hpp"
#include "storage/io.hpp"
#include "storage/io.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/graph_loader.hpp"
@@ -45,7 +44,6 @@
#include <atomic>
#include <bitset>
#include <chrono>
#include <chrono>
#include <fstream>
#include <iostream>
#include <iterator>
@@ -1,17 +1,17 @@
#include "extractor/guidance/coordinate_extractor.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <limits>
#include <numeric>
#include <tuple>
#include <utility>
#include <boost/range/algorithm/transform.hpp>
#include "util/bearing.hpp"
#include "util/coordinate_calculation.hpp"
using osrm::util::angularDeviation;
namespace osrm
{
@@ -1153,7 +1153,8 @@ CoordinateExtractor::RegressionLine(const std::vector<util::Coordinate> &coordin
return {coordinates.front(), coordinates.back()};
// compute the regression vector based on the sum of least squares
const auto regression_line = leastSquareRegression(sampled_coordinates);
const auto regression_line =
util::coordinate_calculation::leastSquareRegression(sampled_coordinates);
const auto coord_between_front =
util::coordinate_calculation::projectPointOnSegment(
regression_line.first, regression_line.second, coordinates.front())
+2 -1
View File
@@ -1,5 +1,4 @@
#include "extractor/guidance/intersection.hpp"
#include "extractor/guidance/toolkit.hpp"
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/algorithm/find_if.hpp>
@@ -10,6 +9,8 @@
#include <functional>
#include <limits>
using osrm::util::angularDeviation;
namespace osrm
{
namespace extractor
@@ -1,16 +1,12 @@
#include "extractor/guidance/intersection_generator.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/coordinate_calculation.hpp"
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iterator>
#include <functional> // mem_fn
#include <limits>
#include <unordered_set>
#include <numeric>
#include <utility>
#include <boost/range/algorithm/count_if.hpp>
@@ -58,8 +54,16 @@ IntersectionGenerator::ComputeIntersectionShape(const NodeID node_at_center_of_i
const util::Coordinate turn_coordinate = node_info_list[node_at_center_of_intersection];
// number of lanes at the intersection changes how far we look down the road
const auto intersection_lanes =
getLaneCountAtIntersection(node_at_center_of_intersection, node_based_graph);
const auto edge_range = node_based_graph.GetAdjacentEdgeRange(node_at_center_of_intersection);
const auto max_lanes_intersection = std::accumulate(
edge_range.begin(),
edge_range.end(),
std::uint8_t{0},
[this](const auto current_max, const auto current_eid) {
return std::max(
current_max,
node_based_graph.GetEdgeData(current_eid).road_classification.GetNumberOfLanes());
});
for (const EdgeID edge_connected_to_intersection :
node_based_graph.GetAdjacentEdgeRange(node_at_center_of_intersection))
@@ -86,7 +90,7 @@ IntersectionGenerator::ComputeIntersectionShape(const NodeID node_at_center_of_i
via_eid,
traversed_in_reverse,
to_node,
intersection_lanes,
max_lanes_intersection,
std::move(coordinates));
};
@@ -112,9 +116,9 @@ IntersectionGenerator::ComputeIntersectionShape(const NodeID node_at_center_of_i
return node_based_graph.GetTarget(data.eid) == *sorting_base;
});
if (itr != intersection.end())
return util::bearing::reverseBearing(itr->bearing);
return util::reverseBearing(itr->bearing);
}
return util::bearing::reverseBearing(intersection.begin()->bearing);
return util::reverseBearing(intersection.begin()->bearing);
}();
std::sort(
intersection.begin(), intersection.end(), makeCompareShapeDataByBearing(base_bearing));
@@ -150,11 +154,8 @@ IntersectionView IntersectionGenerator::GetConnectedRoads(const NodeID from_node
return TransformIntersectionShapeIntoView(from_node, via_eid, std::move(intersection));
}
IntersectionView
IntersectionGenerator::GetActualNextIntersection(const NodeID starting_node,
const EdgeID via_edge,
NodeID *resulting_from_node = nullptr,
EdgeID *resulting_via_edge = nullptr) const
std::pair<NodeID, EdgeID> IntersectionGenerator::SkipDegreeTwoNodes(const NodeID starting_node,
const EdgeID via_edge) const
{
NodeID query_node = starting_node;
EdgeID query_edge = via_edge;
@@ -185,12 +186,7 @@ IntersectionGenerator::GetActualNextIntersection(const NodeID starting_node,
query_edge = next_edge;
}
if (resulting_from_node)
*resulting_from_node = query_node;
if (resulting_via_edge)
*resulting_via_edge = query_edge;
return GetConnectedRoads(query_node, query_edge);
return std::make_pair(query_node, query_edge);
}
IntersectionView IntersectionGenerator::TransformIntersectionShapeIntoView(
@@ -273,7 +269,7 @@ IntersectionView IntersectionGenerator::TransformIntersectionShapeIntoView(
normalised_intersection.end(),
[&](const IntersectionShapeData &road) { return road.eid == merged_into_id; });
BOOST_ASSERT(merged_u_turn != normalised_intersection.end());
return util::bearing::reverseBearing(merged_u_turn->bearing);
return util::reverseBearing(merged_u_turn->bearing);
}
else
{
@@ -283,8 +279,7 @@ IntersectionView IntersectionGenerator::TransformIntersectionShapeIntoView(
connect_to_previous_node);
BOOST_ASSERT(uturn_edge_at_normalised_intersection_itr !=
normalised_intersection.end());
return util::bearing::reverseBearing(
uturn_edge_at_normalised_intersection_itr->bearing);
return util::reverseBearing(uturn_edge_at_normalised_intersection_itr->bearing);
}
}();
@@ -297,7 +292,7 @@ IntersectionView IntersectionGenerator::TransformIntersectionShapeIntoView(
return IntersectionViewData(
road,
is_allowed_turn(road),
util::bearing::angleBetweenBearings(uturn_bearing, road.bearing));
util::angleBetweenBearings(uturn_bearing, road.bearing));
});
const auto uturn_edge_at_intersection_view_itr =
@@ -1,16 +1,15 @@
#include "extractor/guidance/intersection_handler.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/log.hpp"
#include "util/guidance/name_announcements.hpp"
#include <algorithm>
#include <cstddef>
using EdgeData = osrm::util::NodeBasedDynamicGraph::EdgeData;
using osrm::util::guidance::getTurnDirection;
using osrm::util::angularDeviation;
namespace osrm
{
@@ -759,8 +758,12 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge,
// try to find whether there is a turn going to the opposite direction of our obvious
// turn, this should be alright.
NodeID new_node;
const auto previous_intersection = intersection_generator.GetActualNextIntersection(
node_at_intersection, intersection[0].eid, &new_node, nullptr);
const auto previous_intersection = [&]() {
EdgeID turn_edge;
std::tie(new_node, turn_edge) = intersection_generator.SkipDegreeTwoNodes(
node_at_intersection, intersection[0].eid);
return intersection_generator.GetConnectedRoads(new_node, turn_edge);
}();
if (new_node != node_at_intersection)
{
@@ -1,7 +1,12 @@
#include "extractor/guidance/intersection_normalizer.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/name_announcements.hpp"
#include <tuple>
#include <utility>
using osrm::util::angularDeviation;
namespace osrm
{
@@ -115,10 +120,10 @@ bool IntersectionNormalizer::InnerCanMerge(const NodeID node_at_intersection,
const auto isValidYArm = [this, intersection, coordinate_at_intersection, node_at_intersection](
const std::size_t index, const std::size_t other_index) {
const auto GetActualTarget = [&](const std::size_t index) {
EdgeID last_in_edge_id;
intersection_generator.GetActualNextIntersection(
node_at_intersection, intersection[index].eid, nullptr, &last_in_edge_id);
return node_based_graph.GetTarget(last_in_edge_id);
EdgeID edge_id;
std::tie(std::ignore, edge_id) = intersection_generator.SkipDegreeTwoNodes(
node_at_intersection, intersection[index].eid);
return node_based_graph.GetTarget(edge_id);
};
const auto target_id = GetActualTarget(index);
+5 -14
View File
@@ -1,18 +1,17 @@
#include "extractor/guidance/motorway_handler.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/road_classification.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/log.hpp"
#include "util/bearing.hpp"
#include "util/guidance/name_announcements.hpp"
#include <limits>
#include <utility>
#include <boost/assert.hpp>
using osrm::util::guidance::angularDeviation;
using osrm::util::guidance::getTurnDirection;
using osrm::util::angularDeviation;
using osrm::extractor::guidance::getTurnDirection;
namespace osrm
{
@@ -197,9 +196,6 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in
else if (countValid(intersection) > 0) // check whether turns exist at all
{
// FALLBACK, this should hopefully never be reached
util::Log(logDEBUG) << "Fallback reached from motorway, no continue angle, "
<< intersection.size() << " roads, " << countValid(intersection)
<< " valid ones.";
return fallback(std::move(intersection));
}
}
@@ -275,7 +271,6 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in
via_eid,
isThroughStreet(1, intersection),
intersection[1]);
util::Log(logDEBUG) << "Disabled U-Turn on a freeway";
intersection[0].entry_allowed = false; // UTURN on the freeway
}
else if (exiting_motorways == 2)
@@ -334,8 +329,6 @@ Intersection MotorwayHandler::fromMotorway(const EdgeID via_eid, Intersection in
}
else
{
util::Log(logDEBUG) << "Found motorway junction with more than "
"2 exiting motorways or additional ramps";
return fallback(std::move(intersection));
}
} // done for more than one highway exit
@@ -488,9 +481,7 @@ Intersection MotorwayHandler::fromRamp(const EdgeID via_eid, Intersection inters
}
}
else
{ // FALLBACK, hopefully this should never been reached
util::Log(logDEBUG) << "Reached fallback on motorway ramp with " << intersection.size()
<< " roads and " << countValid(intersection) << " valid turns.";
{
return fallback(std::move(intersection));
}
return intersection;
@@ -1,5 +1,8 @@
#include "extractor/guidance/node_based_graph_walker.hpp"
#include "util/coordinate_calculation.hpp"
#include <utility>
using osrm::util::angularDeviation;
namespace osrm
{
+22 -9
View File
@@ -1,17 +1,19 @@
#include "extractor/guidance/roundabout_handler.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/log.hpp"
#include "util/guidance/name_announcements.hpp"
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <boost/assert.hpp>
using osrm::util::guidance::getTurnDirection;
using osrm::extractor::guidance::getTurnDirection;
namespace osrm
{
@@ -182,12 +184,23 @@ bool RoundaboutHandler::qualifiesAsRoundaboutIntersection(
// there is a single non-roundabout edge
const auto src_coordinate = getCoordinate(node);
const auto next_coordinate = coordinate_extractor.GetCoordinateAlongRoad(
node,
edge,
edge_data.reversed,
node_based_graph.GetTarget(edge),
getLaneCountAtIntersection(node, node_based_graph));
const auto edge_range = node_based_graph.GetAdjacentEdgeRange(node);
const auto number_of_lanes_at_intersection = std::accumulate(
edge_range.begin(),
edge_range.end(),
std::uint8_t{0},
[this](const auto current_max, const auto current_eid) {
return std::max(current_max,
node_based_graph.GetEdgeData(current_eid)
.road_classification.GetNumberOfLanes());
});
const auto next_coordinate =
coordinate_extractor.GetCoordinateAlongRoad(node,
edge,
false,
node_based_graph.GetTarget(edge),
number_of_lanes_at_intersection);
result.push_back(
util::coordinate_calculation::bearing(src_coordinate, next_coordinate));
+5 -6
View File
@@ -1,17 +1,16 @@
#include "extractor/guidance/sliproad_handler.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/name_announcements.hpp"
#include <limits>
#include <utility>
#include <boost/assert.hpp>
using EdgeData = osrm::util::NodeBasedDynamicGraph::EdgeData;
using osrm::util::guidance::getTurnDirection;
using osrm::util::guidance::angularDeviation;
using osrm::extractor::guidance::getTurnDirection;
using osrm::util::angularDeviation;
namespace osrm
{
+2 -8
View File
@@ -4,19 +4,13 @@
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/log.hpp"
#include <cstddef>
#include <iomanip>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
using osrm::util::guidance::getTurnDirection;
using osrm::extractor::guidance::getTurnDirection;
namespace osrm
{
@@ -1,10 +1,8 @@
#include "extractor/guidance/turn_classification.hpp"
#include "util/log.hpp"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iomanip>
namespace osrm
{
+3 -3
View File
@@ -1,7 +1,8 @@
#include "extractor/guidance/turn_discovery.hpp"
#include "extractor/guidance/constants.hpp"
#include "util/coordinate_calculation.hpp"
#include "util/guidance/toolkit.hpp"
using osrm::util::angularDeviation;
namespace osrm
{
@@ -73,8 +74,7 @@ bool findPreviousIntersection(const NodeID node_v,
// TODO evaluate if narrow turn is the right criterion here... Might be that other angles are
// valid
if (util::guidance::angularDeviation(straightmost_at_v_in_reverse->angle, STRAIGHT_ANGLE) >
GROUP_ANGLE)
if (angularDeviation(straightmost_at_v_in_reverse->angle, STRAIGHT_ANGLE) > GROUP_ANGLE)
return false;
const auto node_u = node_based_graph.GetTarget(straightmost_at_v_in_reverse->eid);
+4 -4
View File
@@ -1,8 +1,8 @@
#include "extractor/guidance/turn_handler.hpp"
#include "extractor/guidance/constants.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include "util/guidance/name_announcements.hpp"
#include <algorithm>
#include <limits>
@@ -11,8 +11,8 @@
#include <boost/assert.hpp>
using EdgeData = osrm::util::NodeBasedDynamicGraph::EdgeData;
using osrm::util::guidance::getTurnDirection;
using osrm::util::guidance::angularDeviation;
using osrm::extractor::guidance::getTurnDirection;
using osrm::util::angularDeviation;
namespace osrm
{
@@ -5,7 +5,6 @@
#include <algorithm>
#include <cstddef>
#include <string>
#include <unordered_map>
#include <utility>
+4 -2
View File
@@ -4,14 +4,16 @@
#include "extractor/guidance/turn_lane_augmentation.hpp"
#include "extractor/guidance/turn_lane_matcher.hpp"
#include "util/log.hpp"
#include "util/bearing.hpp"
#include "util/typedefs.hpp"
#include <cstddef>
#include <cstdint>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/numeric/conversion/cast.hpp>
using osrm::util::angularDeviation;
namespace osrm
{
namespace extractor
@@ -36,7 +38,7 @@ TurnLaneHandler::TurnLaneHandler(const util::NodeBasedDynamicGraph &node_based_g
std::vector<TurnLaneType::Mask> &turn_lane_masks,
LaneDescriptionMap &lane_description_map,
const TurnAnalysis &turn_analysis,
LaneDataIdMap &id_map)
util::guidance::LaneDataIdMap &id_map)
: node_based_graph(node_based_graph), turn_lane_offsets(turn_lane_offsets),
turn_lane_masks(turn_lane_masks), lane_description_map(lane_description_map),
turn_analysis(turn_analysis), id_map(id_map)
+8 -6
View File
@@ -1,12 +1,13 @@
#include "extractor/guidance/turn_lane_matcher.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "util/guidance/toolkit.hpp"
#include "util/bearing.hpp"
#include <boost/assert.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <functional>
using osrm::util::angularDeviation;
namespace osrm
{
namespace extractor
@@ -53,8 +54,8 @@ DirectionModifier::Enum getMatchingModifier(const TurnLaneType::Mask tag)
// check whether a match of a given tag and a turn instruction can be seen as valid
bool isValidMatch(const TurnLaneType::Mask tag, const TurnInstruction instruction)
{
using util::guidance::hasLeftModifier;
using util::guidance::hasRightModifier;
using extractor::guidance::hasLeftModifier;
using extractor::guidance::hasRightModifier;
const auto isMirroredModifier = [](const TurnInstruction instruction) {
return instruction.type == TurnType::Merge;
};
@@ -200,12 +201,13 @@ Intersection triviallyMatchLanesToTurns(Intersection intersection,
const LaneDataVector &lane_data,
const util::NodeBasedDynamicGraph &node_based_graph,
const LaneDescriptionID lane_string_id,
LaneDataIdMap &lane_data_to_id)
util::guidance::LaneDataIdMap &lane_data_to_id)
{
std::size_t road_index = 1, lane = 0;
const auto matchRoad = [&](ConnectedRoad &road, const TurnLaneData &data) {
LaneTupleIdPair key{{LaneID(data.to - data.from + 1), data.from}, lane_string_id};
util::guidance::LaneTupleIdPair key{{LaneID(data.to - data.from + 1), data.from},
lane_string_id};
auto lane_data_id = boost::numeric_cast<LaneDataID>(lane_data_to_id.size());
const auto it = lane_data_to_id.find(key);