Big Restructuring / Cleanup

This commit is contained in:
Patrick Niklaus
2016-03-01 22:30:31 +01:00
parent adb8d0e845
commit b08b360f38
40 changed files with 419 additions and 511 deletions
+8 -12
View File
@@ -10,9 +10,9 @@
#include "extractor/edge_based_node.hpp"
#include "extractor/original_edge_data.hpp"
#include "extractor/query_node.hpp"
#include "extractor/turn_analysis.hpp"
#include "extractor/guidance/turn_analysis.hpp"
#include "engine/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp"
@@ -71,12 +71,12 @@ class EdgeBasedGraphFactory
// with known angle.
// Handles special cases like u-turns and roundabouts
// For basic turns, the turn based on the angle-classification is returned
engine::guidance::TurnInstruction AnalyzeTurn(const NodeID u,
const EdgeID e1,
const NodeID v,
const EdgeID e2,
const NodeID w,
const double angle) const;
guidance::TurnInstruction AnalyzeTurn(const NodeID u,
const EdgeID e1,
const NodeID v,
const EdgeID e2,
const NodeID w,
const double angle) const;
std::int32_t GetTurnPenalty(double angle, lua_State *lua_state) const;
@@ -129,10 +129,6 @@ class EdgeBasedGraphFactory
void FlushVectorToStream(std::ofstream &edge_data_file,
std::vector<OriginalEdgeData> &original_edge_data_vector) const;
// Use In Order to generate base turns
std::vector<TurnCandidate> getTurns(const NodeID from, const EdgeID via_edge);
// cannot be const due to the counters...
std::size_t restricted_turns_counter;
std::size_t skipped_uturns_counter;
std::size_t skipped_barrier_turns_counter;
-3
View File
@@ -3,7 +3,6 @@
#include "extractor/travel_mode.hpp"
#include "util/typedefs.hpp"
#include "engine/guidance/classification_data.hpp"
#include <string>
#include <vector>
@@ -34,7 +33,6 @@ struct ExtractionWay
name.clear();
forward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
backward_travel_mode = TRAVEL_MODE_INACCESSIBLE;
road_classification_data.invalidate();
}
// These accessors exists because it's not possible to take the address of a bitfield,
@@ -53,7 +51,6 @@ struct ExtractionWay
bool is_startpoint;
TravelMode forward_travel_mode : 4;
TravelMode backward_travel_mode : 4;
engine::guidance::RoadClassificationData road_classification_data;
};
}
}
@@ -0,0 +1,107 @@
#ifndef OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#define OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
#include "util/simple_logger.hpp"
#include <string>
#include <unordered_map>
// Forward Declaration to allow usage of external osmium::Way
namespace osmium
{
class Way;
}
namespace osrm
{
namespace extractor
{
namespace guidance
{
enum class FunctionalRoadClass : short
{
UNKNOWN = 0,
MOTORWAY,
MOTORWAY_LINK,
TRUNK,
TRUNK_LINK,
PRIMARY,
PRIMARY_LINK,
SECONDARY,
SECONDARY_LINK,
TERTIARY,
TERTIARY_LINK,
UNCLASSIFIED,
RESIDENTIAL,
SERVICE,
LIVING_STREET,
LOW_PRIORITY_ROAD // a road simply included for connectivity. Should be avoided at all cost
};
inline FunctionalRoadClass functionalRoadClassFromTag(std::string const &value)
{
//FIXME at some point this should be part of the profiles
const static auto initializeClassHash = []()
{
std::unordered_map<std::string, FunctionalRoadClass> hash;
hash["motorway"] = FunctionalRoadClass::MOTORWAY;
hash["motorway_link"] = FunctionalRoadClass::MOTORWAY_LINK;
hash["trunk"] = FunctionalRoadClass::TRUNK;
hash["trunk_link"] = FunctionalRoadClass::TRUNK_LINK;
hash["primary"] = FunctionalRoadClass::PRIMARY;
hash["primary_link"] = FunctionalRoadClass::PRIMARY_LINK;
hash["secondary"] = FunctionalRoadClass::SECONDARY;
hash["secondary_link"] = FunctionalRoadClass::SECONDARY_LINK;
hash["tertiary"] = FunctionalRoadClass::TERTIARY;
hash["tertiary_link"] = FunctionalRoadClass::TERTIARY_LINK;
hash["unclassified"] = FunctionalRoadClass::UNCLASSIFIED;
hash["residential"] = FunctionalRoadClass::RESIDENTIAL;
hash["service"] = FunctionalRoadClass::SERVICE;
hash["living_street"] = FunctionalRoadClass::LIVING_STREET;
hash["track"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["road"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["path"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
hash["driveway"] = FunctionalRoadClass::LOW_PRIORITY_ROAD;
return hash;
};
static const std::unordered_map<std::string, FunctionalRoadClass> class_hash =
initializeClassHash();
if (class_hash.find(value) != class_hash.end())
{
return class_hash.find(value)->second;
}
else
{
util::SimpleLogger().Write(logDEBUG) << "Unknown road class encountered: " << value;
return FunctionalRoadClass::UNKNOWN;
}
}
inline bool isRampClass(const FunctionalRoadClass road_class)
{
// Primary Roads and down are usually too small to announce their links as ramps
return road_class == FunctionalRoadClass::MOTORWAY_LINK ||
road_class == FunctionalRoadClass::TRUNK_LINK;
}
// TODO augment this with all data required for guidance generation
struct RoadClassificationData
{
FunctionalRoadClass road_class = FunctionalRoadClass::UNKNOWN;
void augment(const osmium::Way &way);
};
inline bool operator==(const RoadClassificationData lhs, const RoadClassificationData rhs)
{
return lhs.road_class == rhs.road_class;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif // OSRM_EXTRACTOR_CLASSIFICATION_DATA_HPP_
@@ -0,0 +1,16 @@
#ifndef OSRM_EXTRACTOR_GUIDANCE_DISCRETE_ANGLE
#define OSRM_EXTRACTOR_GUIDANCE_DISCRETE_ANGLE
namespace osrm
{
namespace extractor
{
namespace guidance
{
typedef uint8_t DiscreteAngle;
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif /* OSRM_EXTRACTOR_GUIDANCE_DISCRETE_ANGLE */
+339
View File
@@ -0,0 +1,339 @@
#ifndef OSRM_GUIDANCE_TOOLKIT_HPP_
#define OSRM_GUIDANCE_TOOLKIT_HPP_
#include "util/bearing.hpp"
#include "util/coordinate.hpp"
#include "util/coordinate_calculation.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/query_node.hpp"
#include "extractor/guidance/discrete_angle.hpp"
#include "extractor/guidance/classification_data.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include <map>
#include <cmath>
namespace osrm
{
namespace extractor
{
namespace guidance
{
namespace detail
{
const constexpr double DESIRED_SEGMENT_LENGTH = 10.0;
const constexpr bool shiftable_ccw[] = {false, true, true, false, false, true, true, false};
const constexpr bool shiftable_cw[] = {false, false, true, true, false, false, true, true};
const constexpr uint8_t modifier_bounds[detail::num_direction_modifiers] = {
0, 36, 93, 121, 136, 163, 220, 255};
const constexpr double discrete_angle_step_size = 360. / 256.;
template <typename IteratorType>
util::Coordinate
getCoordinateFromCompressedRange(util::Coordinate current_coordinate,
IteratorType compressed_geometry_begin,
const IteratorType compressed_geometry_end,
const util::Coordinate final_coordinate,
const std::vector<extractor::QueryNode> &query_nodes)
{
const auto extractCoordinateFromNode = [](const extractor::QueryNode &node) -> util::Coordinate
{
return {node.lon, node.lat};
};
double distance_to_current_coordinate = 0;
double distance_to_next_coordinate = 0;
// get the length that is missing from the current segment to reach DESIRED_SEGMENT_LENGTH
const auto getFactor = [](const double first_distance, const double second_distance)
{
BOOST_ASSERT(first_distance < detail::DESIRED_SEGMENT_LENGTH);
double segment_length = second_distance - first_distance;
BOOST_ASSERT(segment_length > 0);
BOOST_ASSERT(second_distance >= detail::DESIRED_SEGMENT_LENGTH);
double missing_distance = detail::DESIRED_SEGMENT_LENGTH - first_distance;
return missing_distance / segment_length;
};
for (auto compressed_geometry_itr = compressed_geometry_begin;
compressed_geometry_itr != compressed_geometry_end; ++compressed_geometry_itr)
{
const auto next_coordinate =
extractCoordinateFromNode(query_nodes[compressed_geometry_itr->node_id]);
distance_to_next_coordinate =
distance_to_current_coordinate +
util::coordinate_calculation::haversineDistance(current_coordinate, next_coordinate);
// reached point where coordinates switch between
if (distance_to_next_coordinate >= detail::DESIRED_SEGMENT_LENGTH)
return util::coordinate_calculation::interpolateLinear(
getFactor(distance_to_current_coordinate, distance_to_next_coordinate),
current_coordinate, next_coordinate);
// prepare for next iteration
current_coordinate = next_coordinate;
distance_to_current_coordinate = distance_to_next_coordinate;
}
distance_to_next_coordinate =
distance_to_current_coordinate +
util::coordinate_calculation::haversineDistance(current_coordinate, final_coordinate);
// reached point where coordinates switch between
if (distance_to_next_coordinate >= detail::DESIRED_SEGMENT_LENGTH)
return util::coordinate_calculation::interpolateLinear(
getFactor(distance_to_current_coordinate, distance_to_next_coordinate),
current_coordinate, final_coordinate);
else
return final_coordinate;
}
} // namespace detail
// Finds a (potentially inteprolated) coordinate that is DESIRED_SEGMENT_LENGTH away
// from the start of an edge
inline util::Coordinate
getRepresentativeCoordinate(const NodeID from_node,
const NodeID to_node,
const EdgeID via_edge_id,
const bool traverse_in_reverse,
const extractor::CompressedEdgeContainer &compressed_geometries,
const std::vector<extractor::QueryNode> &query_nodes)
{
const auto extractCoordinateFromNode = [](const extractor::QueryNode &node) -> util::Coordinate
{
return {node.lon, node.lat};
};
// Uncompressed roads are simple, return the coordinate at the end
if (!compressed_geometries.HasEntryForID(via_edge_id))
{
return extractCoordinateFromNode(traverse_in_reverse ? query_nodes[from_node]
: query_nodes[to_node]);
}
else
{
const auto &geometry = compressed_geometries.GetBucketReference(via_edge_id);
const auto base_node_id = (traverse_in_reverse) ? to_node : from_node;
const auto base_coordinate = extractCoordinateFromNode(query_nodes[base_node_id]);
const auto final_node = (traverse_in_reverse) ? from_node : to_node;
const auto final_coordinate = extractCoordinateFromNode(query_nodes[final_node]);
if (traverse_in_reverse)
return detail::getCoordinateFromCompressedRange(
base_coordinate, geometry.rbegin(), geometry.rend(), final_coordinate, query_nodes);
else
return detail::getCoordinateFromCompressedRange(
base_coordinate, geometry.begin(), geometry.end(), final_coordinate, query_nodes);
}
}
// shift an instruction around the degree circle in CCW order
inline DirectionModifier
forcedShiftCCW(const DirectionModifier modifier)
{
return static_cast<DirectionModifier>(
(static_cast<uint32_t>(modifier) + 1) % detail::num_direction_modifiers);
}
inline DirectionModifier
shiftCCW(const DirectionModifier modifier)
{
if (detail::shiftable_ccw[static_cast<int>(modifier)])
return forcedShiftCCW(modifier);
else
return modifier;
}
// shift an instruction around the degree circle in CW order
inline DirectionModifier
forcedShiftCW(const DirectionModifier modifier)
{
return static_cast<DirectionModifier>(
(static_cast<uint32_t>(modifier) + detail::num_direction_modifiers - 1) %
detail::num_direction_modifiers);
}
inline DirectionModifier
shiftCW(const DirectionModifier modifier)
{
if (detail::shiftable_cw[static_cast<int>(modifier)])
return forcedShiftCW(modifier);
else
return modifier;
}
inline bool isBasic(const TurnType type)
{
return type == TurnType::Turn ||
type == TurnType::EndOfRoad;
}
inline bool isUturn(const TurnInstruction instruction)
{
return isBasic(instruction.type) &&
instruction.direction_modifier == DirectionModifier::UTurn;
}
inline bool resolve(TurnInstruction &to_resolve,
const TurnInstruction neighbor,
bool resolve_cw)
{
const auto shifted_turn = resolve_cw ? shiftCW(to_resolve.direction_modifier)
: shiftCCW(to_resolve.direction_modifier);
if (shifted_turn == neighbor.direction_modifier ||
shifted_turn == to_resolve.direction_modifier)
return false;
to_resolve.direction_modifier = shifted_turn;
return true;
}
inline bool resolveTransitive(TurnInstruction &first,
TurnInstruction &second,
const TurnInstruction third,
bool resolve_cw)
{
if (resolve(second, third, resolve_cw))
{
first.direction_modifier =
resolve_cw ? shiftCW(first.direction_modifier) : shiftCCW(first.direction_modifier);
return true;
}
return false;
}
inline bool isSlightTurn(const TurnInstruction turn)
{
return (isBasic(turn.type) || turn.type == TurnType::NoTurn) &&
(turn.direction_modifier == DirectionModifier::Straight ||
turn.direction_modifier == DirectionModifier::SlightRight ||
turn.direction_modifier == DirectionModifier::SlightLeft);
}
inline bool isSlightModifier(const DirectionModifier direction_modifier)
{
return (direction_modifier == DirectionModifier::Straight ||
direction_modifier == DirectionModifier::SlightRight ||
direction_modifier == DirectionModifier::SlightLeft);
}
inline bool isSharpTurn(const TurnInstruction turn)
{
return isBasic(turn.type) &&
(turn.direction_modifier == DirectionModifier::SharpLeft ||
turn.direction_modifier == DirectionModifier::SharpRight);
}
inline bool isStraight(const TurnInstruction turn)
{
return (isBasic(turn.type) || turn.type == TurnType::NoTurn) &&
turn.direction_modifier == DirectionModifier::Straight;
}
inline bool isConflict(const TurnInstruction first,
const TurnInstruction second)
{
return (first.type == second.type && first.direction_modifier == second.direction_modifier) ||
(isStraight(first) && isStraight(second));
}
inline DiscreteAngle discretizeAngle(const double angle)
{
BOOST_ASSERT(angle >= 0. && angle <= 360.);
return DiscreteAngle(
static_cast<uint8_t>(angle / detail::discrete_angle_step_size));
}
inline double angleFromDiscreteAngle(const DiscreteAngle angle)
{
return static_cast<double>(angle) * detail::discrete_angle_step_size;
}
inline double angularDeviation(const double angle, const double from)
{
const double deviation = std::abs(angle - from);
return std::min(360 - deviation, deviation);
}
inline double getAngularPenalty(const double angle, TurnInstruction instruction)
{
const double center[] = {0, 45, 90, 135, 180, 225, 270, 315};
return angularDeviation(center[static_cast<int>(instruction.direction_modifier)], angle);
}
inline double getTurnConfidence(const double angle, TurnInstruction instruction)
{
// special handling of U-Turns and Roundabout
if (!isBasic(instruction.type) ||
instruction.direction_modifier == DirectionModifier::UTurn)
return 1.0;
const double deviations[] = {0, 45, 50, 35, 10, 35, 50, 45};
const double difference = getAngularPenalty(angle, instruction);
const double max_deviation = deviations[static_cast<int>(instruction.direction_modifier)];
return 1.0 - (difference / max_deviation) * (difference / max_deviation);
}
// Translates between angles and their human-friendly directional representation
inline DirectionModifier getTurnDirection(const double angle)
{
// An angle of zero is a u-turn
// 180 goes perfectly straight
// 0-180 are right turns
// 180-360 are left turns
if (angle > 0 && angle < 60)
return DirectionModifier::SharpRight;
if (angle >= 60 && angle < 140)
return DirectionModifier::Right;
if (angle >= 140 && angle < 170)
return DirectionModifier::SlightRight;
if (angle >= 170 && angle <= 190)
return DirectionModifier::Straight;
if (angle > 190 && angle <= 220)
return DirectionModifier::SlightLeft;
if (angle > 220 && angle <= 300)
return DirectionModifier::Left;
if (angle > 300 && angle < 360)
return DirectionModifier::SharpLeft;
return DirectionModifier::UTurn;
}
// swaps left <-> right modifier types
inline DirectionModifier
mirrorDirectionModifier(const DirectionModifier modifier)
{
const constexpr DirectionModifier results[] = {
DirectionModifier::UTurn,
DirectionModifier::SharpLeft,
DirectionModifier::Left,
DirectionModifier::SlightLeft,
DirectionModifier::Straight,
DirectionModifier::SlightRight,
DirectionModifier::Right,
DirectionModifier::SharpRight};
return results[modifier];
}
inline bool canBeSuppressed(const TurnType type)
{
if (type == TurnType::Turn)
return true;
return false;
}
inline bool isLowPriorityRoadClass(const FunctionalRoadClass road_class)
{
return road_class == FunctionalRoadClass::LOW_PRIORITY_ROAD ||
road_class == FunctionalRoadClass::SERVICE;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif // OSRM_GUIDANCE_TOOLKIT_HPP_
@@ -1,9 +1,8 @@
#ifndef OSRM_EXTRACTOR_TURN_ANALYSIS
#define OSRM_EXTRACTOR_TURN_ANALYSIS
#include "engine/guidance/turn_classification.hpp"
#include "engine/guidance/guidance_toolkit.hpp"
#include "extractor/guidance/turn_classification.hpp"
#include "extractor/guidance/toolkit.hpp"
#include "extractor/restriction_map.hpp"
#include "extractor/compressed_edge_container.hpp"
@@ -13,14 +12,16 @@ namespace osrm
{
namespace extractor
{
namespace guidance
{
struct TurnCandidate
{
EdgeID eid; // the id of the arc
bool valid; // a turn may be relevant to good instructions, even if we cannot take the road
double angle; // the approximated angle of the turn
engine::guidance::TurnInstruction instruction; // a proposed instruction
double confidence; // how close to the border is the turn?
TurnInstruction instruction; // a proposed instruction
double confidence; // how close to the border is the turn?
std::string toString() const
{
@@ -38,8 +39,6 @@ struct TurnCandidate
return result;
}
};
namespace turn_analysis
{
// the entry into the turn analysis
std::vector<TurnCandidate>
@@ -57,6 +56,7 @@ namespace detail
// Check for restrictions/barriers and generate a list of valid and invalid turns present at the
// node reached
// from `from_node` via `via_eid`
// The resulting candidates have to be analysed for their actual instructions later on.
std::vector<TurnCandidate>
getTurnCandidates(const NodeID from_node,
const EdgeID via_eid,
@@ -66,16 +66,27 @@ getTurnCandidates(const NodeID from_node,
const std::unordered_set<NodeID> &barrier_nodes,
const CompressedEdgeContainer &compressed_edge_container);
// merge segregated roads to omit invalid turns in favor of treating segregated roads as one
// Merge segregated roads to omit invalid turns in favor of treating segregated roads as one.
// This function combines roads the following way:
//
// * *
// * is converted to *
// v ^ +
// v ^ +
//
// The treatment results in a straight turn angle of 180º rather than a turn angle of approx 160
std::vector<TurnCandidate>
mergeSegregatedRoads(const NodeID from_node,
const EdgeID via_eid,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// handle roundabouts
// TODO distinguish roundabouts and rotaries
// TODO handle bike/walk cases that allow crossing a roundabout!
// Processing of roundabouts
// Produces instructions to enter/exit a roundabout or to stay on it.
// Performs the distinction between roundabout and rotaries.
std::vector<TurnCandidate>
handleRoundabouts(const NodeID from,
const EdgeID via_edge,
@@ -85,79 +96,100 @@ handleRoundabouts(const NodeID from,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// A Basic junction is a junction not requiring special treatment. It cannot contain anything
// but streets of lesser priority than trunks and ramps (of any type). No roundabouts or motorway
// like types.
bool isBasicJunction(const NodeID from,
const EdgeID via_edge,
const std::vector<TurnCandidate> &turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Indicates a Junction containing a motoryway
bool isMotorwayJunction(const NodeID from,
const EdgeID via_edge,
const std::vector<TurnCandidate> &turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Decide whether a turn is a turn or a ramp access
engine::guidance::TurnType
turnOrRamp(const NodeID from,
const EdgeID via_edge,
const TurnCandidate &candidate,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
TurnType turnOrRamp(const NodeID from,
const EdgeID via_edge,
const TurnCandidate &candidate,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Get the Instruction for an obvious turn
engine::guidance::TurnInstruction
// Instruction will be a silent instruction
TurnInstruction
getInstructionForObvious(const NodeID from,
const EdgeID via_edge,
const TurnCandidate &candidate,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
engine::guidance::TurnInstruction
// Helper Function that decides between NoTurn or NewName
TurnInstruction
noTurnOrNewName(const NodeID from,
const EdgeID via_edge,
const TurnCandidate &candidate,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// handle basic intersections
// Basic Turn Handling
// Dead end.
std::vector<TurnCandidate>
handleOneWayTurn(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Mode Changes, new names...
std::vector<TurnCandidate>
handleTwoWayTurn(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Forks, T intersections and similar
std::vector<TurnCandidate>
handleThreeWayTurn(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Normal Intersection. Can still contain forks...
std::vector<TurnCandidate>
handleFourWayTurn(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Fallback for turns of high complexion
std::vector<TurnCandidate>
handleComplexTurn(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Any Junction containing motorways
std::vector<TurnCandidate>
handleMotorwayJunction(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Utility function, setting basic turn types. Prepares for normal turn handling.
std::vector<TurnCandidate>
setTurnTypes(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Utility function to handle direction modifier conflicts if reasonably possible
std::vector<TurnCandidate>
handleConflicts(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// Old fallbacks, to be removed
std::vector<TurnCandidate>
optimizeRamps(const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
@@ -180,7 +212,7 @@ suppressTurns(const EdgeID via_eid,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
// node_u -- (edge_1) --> node_v -- (edge_2) --> node_w
engine::guidance::TurnInstruction
TurnInstruction
AnalyzeTurn(const NodeID node_u,
const EdgeID edge1,
const NodeID node_v,
@@ -189,13 +221,8 @@ AnalyzeTurn(const NodeID node_u,
const double angle,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
std::vector<TurnCandidate>
handleConflicts(const NodeID from,
const EdgeID via_edge,
std::vector<TurnCandidate> turn_candidates,
const std::shared_ptr<const util::NodeBasedDynamicGraph> node_based_graph);
} // namespace detail
} // namespace turn_analysis
} // namespace guidance
} // namespace extractor
} // namespace osrm
@@ -0,0 +1,123 @@
#ifndef OSRM_GUIDANCE_TURN_CLASSIFICATION_HPP_
#define OSRM_GUIDANCE_TURN_CLASSIFICATION_HPP_
#include "extractor/guidance/toolkit.hpp"
#include "util/typedefs.hpp"
#include "util/coordinate.hpp"
#include "util/node_based_graph.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/query_node.hpp"
#include <algorithm>
#include <cstddef>
#include <vector>
namespace osrm
{
namespace extractor
{
namespace guidance
{
struct TurnPossibility
{
TurnPossibility(DiscreteAngle angle, EdgeID edge_id)
: angle(std::move(angle)), edge_id(std::move(edge_id))
{
}
TurnPossibility() : angle(0), edge_id(SPECIAL_EDGEID) {}
DiscreteAngle angle;
EdgeID edge_id;
};
struct CompareTurnPossibilities
{
bool operator()(const std::vector<TurnPossibility> &left,
const std::vector<TurnPossibility> &right) const
{
if (left.size() < right.size())
return true;
if (left.size() > right.size())
return false;
for (std::size_t i = 0; i < left.size(); ++i)
{
if ((((int)left[i].angle + 16) % 256) / 32 < (((int)right[i].angle + 16) % 256) / 32)
return true;
if ((((int)left[i].angle + 16) % 256) / 32 > (((int)right[i].angle + 16) % 256) / 32)
return false;
}
return false;
}
};
inline std::vector<TurnPossibility>
classifyIntersection(NodeID nid,
const util::NodeBasedDynamicGraph &graph,
const extractor::CompressedEdgeContainer &compressed_geometries,
const std::vector<extractor::QueryNode> &query_nodes)
{
std::vector<TurnPossibility> turns;
if (graph.BeginEdges(nid) == graph.EndEdges(nid))
return std::vector<TurnPossibility>();
const EdgeID base_id = graph.BeginEdges(nid);
const auto base_coordinate = getRepresentativeCoordinate(nid, graph.GetTarget(base_id), base_id,
graph.GetEdgeData(base_id).reversed,
compressed_geometries, query_nodes);
const auto node_coordinate = util::Coordinate(query_nodes[nid].lon, query_nodes[nid].lat);
// generate a list of all turn angles between a base edge, the node and a current edge
for (const EdgeID eid : graph.GetAdjacentEdgeRange(nid))
{
const auto edge_coordinate = getRepresentativeCoordinate(
nid, graph.GetTarget(eid), eid, false, compressed_geometries, query_nodes);
double angle = util::coordinate_calculation::computeAngle(base_coordinate, node_coordinate,
edge_coordinate);
turns.emplace_back(discretizeAngle(angle), eid);
}
std::sort(turns.begin(), turns.end(),
[](const TurnPossibility left, const TurnPossibility right)
{
return left.angle < right.angle;
});
turns.push_back(turns.front()); // sentinel
for (std::size_t turn_nr = 0; turn_nr + 1 < turns.size(); ++turn_nr)
{
turns[turn_nr].angle = (256 + static_cast<uint32_t>(turns[turn_nr + 1].angle) -
static_cast<uint32_t>(turns[turn_nr].angle)) %
256; // calculate the difference to the right
}
turns.pop_back(); // remove sentinel again
// find largest:
std::size_t best_id = 0;
DiscreteAngle largest_turn_angle = turns.front().angle;
for (std::size_t current_turn_id = 1; current_turn_id < turns.size(); ++current_turn_id)
{
if (turns[current_turn_id].angle > largest_turn_angle)
{
largest_turn_angle = turns[current_turn_id].angle;
best_id = current_turn_id;
}
}
// rotate all angles so the largest angle comes first
std::rotate(turns.begin(), turns.begin() + best_id, turns.end());
return turns;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif // OSRM_GUIDANCE_TURN_CLASSIFICATION_HPP_
@@ -0,0 +1,120 @@
#ifndef OSRM_GUIDANCE_TURN_INSTRUCTION_HPP_
#define OSRM_GUIDANCE_TURN_INSTRUCTION_HPP_
#include <cstdint>
#include <boost/assert.hpp>
namespace osrm
{
namespace extractor
{
namespace guidance
{
namespace detail
{
// inclusive bounds for turn modifiers
const constexpr uint8_t num_direction_modifiers = 8;
} // detail
// direction modifiers based on angle
// Would be nice to have
// enum class DirectionModifier : unsigned char
enum DirectionModifier
{
UTurn,
SharpRight,
Right,
SlightRight,
Straight,
SlightLeft,
Left,
SharpLeft
};
// enum class TurnType : unsigned char
enum TurnType // at the moment we can support 32 turn types, without increasing memory consumption
{
Invalid, // no valid turn instruction
NoTurn, // end of segment without turn
Location, // start,end,via
Suppressed, // location that suppresses a turn
NewName, // no turn, but name changes
Continue, // remain on a street
Turn, // basic turn
Merge, // merge onto a street
Ramp, // special turn (highway ramp exits)
Fork, // fork road splitting up
EndOfRoad, // T intersection
EnterRoundabout, // Entering a small Roundabout
EnterRoundaboutAtExit, // Entering a small Roundabout at a countable exit
EnterAndExitRoundabout, // Touching a roundabout
ExitRoundabout, // Exiting a small Roundabout
EnterRotary, // Enter a rotary
EnterRotaryAtExit, // Enter A Rotary at a countable exit
EnterAndExitRotary, // Touching a rotary
ExitRotary, // Exit a rotary
StayOnRoundabout, // Continue on Either a small or a large Roundabout
Restriction, // Cross a Barrier, requires barrier penalties instead of full block
Notification // Travel Mode Changes`
};
// turn angle in 1.40625 degree -> 128 == 180 degree
struct TurnInstruction
{
TurnInstruction(const TurnType type = TurnType::Invalid,
const DirectionModifier direction_modifier = DirectionModifier::Straight)
: type(type), direction_modifier(direction_modifier)
{
}
TurnType type : 5;
DirectionModifier direction_modifier : 3;
static TurnInstruction INVALID()
{
return TurnInstruction(TurnType::Invalid, DirectionModifier::UTurn);
}
static TurnInstruction NO_TURN()
{
return TurnInstruction(TurnType::NoTurn, DirectionModifier::UTurn);
}
static TurnInstruction REMAIN_ROUNDABOUT(const DirectionModifier modifier)
{
return TurnInstruction(TurnType::StayOnRoundabout, modifier);
}
static TurnInstruction ENTER_ROUNDABOUT(const DirectionModifier modifier)
{
return TurnInstruction(TurnType::EnterRoundabout, modifier);
}
static TurnInstruction EXIT_ROUNDABOUT(const DirectionModifier modifier)
{
return TurnInstruction(TurnType::ExitRoundabout, modifier);
}
static TurnInstruction SUPPRESSED(const DirectionModifier modifier)
{
return TurnInstruction{TurnType::Suppressed, modifier};
}
};
inline bool operator!=(const TurnInstruction lhs, const TurnInstruction rhs)
{
return lhs.type != rhs.type || lhs.direction_modifier != rhs.direction_modifier;
}
inline bool operator==(const TurnInstruction lhs, const TurnInstruction rhs)
{
return lhs.type == rhs.type && lhs.direction_modifier == rhs.direction_modifier;
}
} // namespace guidance
} // namespace extractor
} // namespace osrm
#endif // OSRM_GUIDANCE_TURN_INSTRUCTION_HPP_
@@ -9,7 +9,7 @@
#include "osrm/coordinate.hpp"
#include <utility>
#include "engine/guidance/classification_data.hpp"
#include "extractor/guidance/classification_data.hpp"
namespace osrm
{
@@ -52,7 +52,7 @@ struct InternalExtractorEdge
true,
TRAVEL_MODE_INACCESSIBLE,
false,
engine::guidance::RoadClassificationData::INVALID())
guidance::RoadClassificationData())
{
}
@@ -67,7 +67,7 @@ struct InternalExtractorEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
engine::guidance::RoadClassificationData road_classification)
guidance::RoadClassificationData road_classification)
: result(OSMNodeID(source),
OSMNodeID(target),
name_id,
@@ -96,13 +96,13 @@ struct InternalExtractorEdge
{
return InternalExtractorEdge(MIN_OSM_NODEID, MIN_OSM_NODEID, 0, WeightData(), false, false,
false, false, true, TRAVEL_MODE_INACCESSIBLE, false,
engine::guidance::RoadClassificationData::INVALID());
guidance::RoadClassificationData());
}
static InternalExtractorEdge max_osm_value()
{
return InternalExtractorEdge(MAX_OSM_NODEID, MAX_OSM_NODEID, 0, WeightData(), false, false,
false, false, true, TRAVEL_MODE_INACCESSIBLE, false,
engine::guidance::RoadClassificationData::INVALID());
guidance::RoadClassificationData());
}
static InternalExtractorEdge min_internal_value()
+6 -7
View File
@@ -4,7 +4,7 @@
#include "extractor/travel_mode.hpp"
#include "util/typedefs.hpp"
#include "engine/guidance/classification_data.hpp"
#include "extractor/guidance/classification_data.hpp"
namespace osrm
{
@@ -26,7 +26,7 @@ struct NodeBasedEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
engine::guidance::RoadClassificationData road_classification);
guidance::RoadClassificationData road_classification);
bool operator<(const NodeBasedEdge &other) const;
@@ -41,7 +41,7 @@ struct NodeBasedEdge
bool startpoint : 1;
bool is_split : 1;
TravelMode travel_mode : 4;
engine::guidance::RoadClassificationData road_classification;
guidance::RoadClassificationData road_classification;
};
struct NodeBasedEdgeWithOSM : NodeBasedEdge
@@ -57,7 +57,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge
bool startpoint,
TravelMode travel_mode,
bool is_split,
engine::guidance::RoadClassificationData road_classification);
guidance::RoadClassificationData road_classification);
OSMNodeID osm_source_id;
OSMNodeID osm_target_id;
@@ -70,7 +70,6 @@ inline NodeBasedEdge::NodeBasedEdge()
backward(false), roundabout(false), access_restricted(false), startpoint(true),
is_split(false), travel_mode(false)
{
road_classification.invalidate();
}
inline NodeBasedEdge::NodeBasedEdge(NodeID source,
@@ -84,7 +83,7 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source,
bool startpoint,
TravelMode travel_mode,
bool is_split,
engine::guidance::RoadClassificationData road_classification)
guidance::RoadClassificationData road_classification)
: source(source), target(target), name_id(name_id), weight(weight), forward(forward),
backward(backward), roundabout(roundabout), access_restricted(access_restricted),
startpoint(startpoint), is_split(is_split), travel_mode(travel_mode),
@@ -121,7 +120,7 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(
bool startpoint,
TravelMode travel_mode,
bool is_split,
engine::guidance::RoadClassificationData road_classification)
guidance::RoadClassificationData road_classification)
: NodeBasedEdge(SPECIAL_NODEID,
SPECIAL_NODEID,
name_id,
+4 -4
View File
@@ -2,7 +2,7 @@
#define ORIGINAL_EDGE_DATA_HPP
#include "extractor/travel_mode.hpp"
#include "engine/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "util/typedefs.hpp"
#include <limits>
@@ -16,7 +16,7 @@ struct OriginalEdgeData
{
explicit OriginalEdgeData(NodeID via_node,
unsigned name_id,
engine::guidance::TurnInstruction turn_instruction,
guidance::TurnInstruction turn_instruction,
TravelMode travel_mode)
: via_node(via_node), name_id(name_id), turn_instruction(turn_instruction),
travel_mode(travel_mode)
@@ -26,14 +26,14 @@ struct OriginalEdgeData
OriginalEdgeData()
: via_node(std::numeric_limits<unsigned>::max()),
name_id(std::numeric_limits<unsigned>::max()),
turn_instruction(engine::guidance::TurnInstruction::INVALID()),
turn_instruction(guidance::TurnInstruction::INVALID()),
travel_mode(TRAVEL_MODE_INACCESSIBLE)
{
}
NodeID via_node;
unsigned name_id;
engine::guidance::TurnInstruction turn_instruction;
guidance::TurnInstruction turn_instruction;
TravelMode travel_mode;
};
}