link ConnectedRoad and TurnOperation via class hierarchy
and empower intersection by adding basic functionality to pod type refactor extractor/toolkit into intersection
This commit is contained in:
@@ -75,6 +75,32 @@ template <typename Iter, typename Fn> inline Fn forEachRoundabout(Iter first, It
|
||||
return fn;
|
||||
}
|
||||
|
||||
LaneID inline numLanesToTheRight(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
return step.intersections.front().lanes.first_lane_from_the_right;
|
||||
}
|
||||
|
||||
LaneID inline numLanesToTheLeft(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
LaneID const total = step.intersections.front().lane_description.size();
|
||||
return total - (step.intersections.front().lanes.lanes_in_turn +
|
||||
step.intersections.front().lanes.first_lane_from_the_right);
|
||||
}
|
||||
|
||||
auto inline lanesToTheLeft(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
const auto &description = step.intersections.front().lane_description;
|
||||
LaneID num_lanes_left = numLanesToTheLeft(step);
|
||||
return boost::make_iterator_range(description.begin(), description.begin() + num_lanes_left);
|
||||
}
|
||||
|
||||
auto inline lanesToTheRight(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
const auto &description = step.intersections.front().lane_description;
|
||||
LaneID num_lanes_right = numLanesToTheRight(step);
|
||||
return boost::make_iterator_range(description.end() - num_lanes_right, description.end());
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
} // namespace engine
|
||||
} // namespace osrm
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "extractor/guidance/turn_instruction.hpp"
|
||||
#include "util/guidance/toolkit.hpp"
|
||||
#include "util/node_based_graph.hpp"
|
||||
#include "util/typedefs.hpp" // EdgeID
|
||||
|
||||
namespace osrm
|
||||
@@ -18,7 +19,7 @@ namespace guidance
|
||||
// Every Turn Operation describes a way of switching onto a segment, indicated by an EdgeID. The
|
||||
// associated turn is described by an angle and an instruction that is used to announce it.
|
||||
// The Turn Operation indicates what is exposed to the outside of the turn analysis.
|
||||
struct TurnOperation final
|
||||
struct TurnOperation
|
||||
{
|
||||
EdgeID eid;
|
||||
double angle;
|
||||
@@ -48,13 +49,23 @@ struct TurnOperation final
|
||||
// aaaaaaaa
|
||||
//
|
||||
// We would perceive a->c as a sharp turn, a->b as a slight turn, and b->c as a slight turn.
|
||||
struct ConnectedRoad final
|
||||
struct ConnectedRoad final : public TurnOperation
|
||||
{
|
||||
using Base = TurnOperation;
|
||||
|
||||
ConnectedRoad(const TurnOperation turn, const bool entry_allowed = false);
|
||||
|
||||
// a turn may be relevant to good instructions, even if we cannot enter the road
|
||||
bool entry_allowed;
|
||||
TurnOperation turn;
|
||||
|
||||
// used to sort the set of connected roads (we require sorting throughout turn handling)
|
||||
bool compareByAngle(const ConnectedRoad &other) const;
|
||||
|
||||
// make a left turn into an equivalent right turn and vice versa
|
||||
void mirror();
|
||||
|
||||
OSRM_ATTR_WARN_UNUSED
|
||||
ConnectedRoad getMirroredCopy() const;
|
||||
};
|
||||
|
||||
// small helper function to print the content of a connected road
|
||||
@@ -64,25 +75,24 @@ struct Intersection final : public std::vector<ConnectedRoad>
|
||||
{
|
||||
using Base = std::vector<ConnectedRoad>;
|
||||
|
||||
inline Base::iterator findClosestTurn(double angle)
|
||||
{
|
||||
return std::min_element(this->begin(),
|
||||
this->end(),
|
||||
[angle](const ConnectedRoad &lhs, const ConnectedRoad &rhs) {
|
||||
return util::guidance::angularDeviation(lhs.turn.angle, angle) <
|
||||
util::guidance::angularDeviation(rhs.turn.angle, angle);
|
||||
});
|
||||
}
|
||||
/*
|
||||
* find the turn whose angle offers the least angularDeviation to the specified angle
|
||||
* E.g. for turn angles [0,90,260] and a query of 180 we return the 260 degree turn (difference
|
||||
* 80 over the difference of 90 to the 90 degree turn)
|
||||
*/
|
||||
Base::iterator findClosestTurn(double angle);
|
||||
Base::const_iterator findClosestTurn(double angle) const;
|
||||
|
||||
inline Base::const_iterator findClosestTurn(double angle) const
|
||||
{
|
||||
return std::min_element(this->begin(),
|
||||
this->end(),
|
||||
[angle](const ConnectedRoad &lhs, const ConnectedRoad &rhs) {
|
||||
return util::guidance::angularDeviation(lhs.turn.angle, angle) <
|
||||
util::guidance::angularDeviation(rhs.turn.angle, angle);
|
||||
});
|
||||
}
|
||||
/*
|
||||
* Check validity of the intersection object. We assume a few basic properties every set of
|
||||
* connected roads should follow throughout guidance pre-processing. This utility function
|
||||
* allows checking intersections for validity
|
||||
*/
|
||||
bool valid() const;
|
||||
|
||||
// given all possible turns, which is the highest connected number of lanes per turn. This value
|
||||
// is used, for example, during generation of intersections.
|
||||
std::uint8_t getHighestConnectedLaneCount(const util::NodeBasedDynamicGraph &) const;
|
||||
};
|
||||
|
||||
Intersection::const_iterator findClosestTurn(const Intersection &intersection, const double angle);
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
#include "extractor/guidance/road_classification.hpp"
|
||||
#include "extractor/guidance/turn_instruction.hpp"
|
||||
|
||||
#include "engine/guidance/route_step.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
@@ -51,26 +48,6 @@ using util::guidance::leavesRoundabout;
|
||||
// To simplify handling of Left/Right hand turns, we can mirror turns and write an intersection
|
||||
// handler only for one side. The mirror function turns a left-hand turn in a equivalent right-hand
|
||||
// turn and vice versa.
|
||||
OSRM_ATTR_WARN_UNUSED
|
||||
inline ConnectedRoad mirror(ConnectedRoad road)
|
||||
{
|
||||
const constexpr DirectionModifier::Enum mirrored_modifiers[] = {DirectionModifier::UTurn,
|
||||
DirectionModifier::SharpLeft,
|
||||
DirectionModifier::Left,
|
||||
DirectionModifier::SlightLeft,
|
||||
DirectionModifier::Straight,
|
||||
DirectionModifier::SlightRight,
|
||||
DirectionModifier::Right,
|
||||
DirectionModifier::SharpRight};
|
||||
|
||||
if (angularDeviation(road.turn.angle, 0) > std::numeric_limits<double>::epsilon())
|
||||
{
|
||||
road.turn.angle = 360 - road.turn.angle;
|
||||
road.turn.instruction.direction_modifier =
|
||||
mirrored_modifiers[road.turn.instruction.direction_modifier];
|
||||
}
|
||||
return road;
|
||||
}
|
||||
|
||||
inline bool hasRoundaboutType(const TurnInstruction instruction)
|
||||
{
|
||||
@@ -184,42 +161,6 @@ inline std::string applyAccessTokens(std::string lane_string, const std::string
|
||||
return result_string;
|
||||
}
|
||||
|
||||
LaneID inline numLanesToTheRight(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
return step.intersections.front().lanes.first_lane_from_the_right;
|
||||
}
|
||||
|
||||
LaneID inline numLanesToTheLeft(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
LaneID const total = step.intersections.front().lane_description.size();
|
||||
return total - (step.intersections.front().lanes.lanes_in_turn +
|
||||
step.intersections.front().lanes.first_lane_from_the_right);
|
||||
}
|
||||
|
||||
auto inline lanesToTheLeft(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
const auto &description = step.intersections.front().lane_description;
|
||||
LaneID num_lanes_left = numLanesToTheLeft(step);
|
||||
return boost::make_iterator_range(description.begin(), description.begin() + num_lanes_left);
|
||||
}
|
||||
|
||||
auto inline lanesToTheRight(const engine::guidance::RouteStep &step)
|
||||
{
|
||||
const auto &description = step.intersections.front().lane_description;
|
||||
LaneID num_lanes_right = numLanesToTheRight(step);
|
||||
return boost::make_iterator_range(description.end() - num_lanes_right, description.end());
|
||||
}
|
||||
|
||||
inline std::uint8_t getLaneCountAtIntersection(const NodeID intersection_node,
|
||||
const util::NodeBasedDynamicGraph &node_based_graph)
|
||||
{
|
||||
std::uint8_t lanes = 0;
|
||||
for (const EdgeID onto_edge : node_based_graph.GetAdjacentEdgeRange(intersection_node))
|
||||
lanes = std::max(
|
||||
lanes, node_based_graph.GetEdgeData(onto_edge).road_classification.GetNumberOfLanes());
|
||||
return lanes;
|
||||
}
|
||||
|
||||
inline bool obviousByRoadClass(const RoadClassification in_classification,
|
||||
const RoadClassification obvious_candidate,
|
||||
const RoadClassification compare_candidate)
|
||||
@@ -282,6 +223,16 @@ leastSquareRegression(const std::vector<util::Coordinate> &coordinates)
|
||||
return {regression_first, regression_end};
|
||||
}
|
||||
|
||||
inline std::uint8_t getLaneCountAtIntersection(const NodeID intersection_node,
|
||||
const util::NodeBasedDynamicGraph &node_based_graph)
|
||||
{
|
||||
std::uint8_t lanes = 0;
|
||||
for (const EdgeID onto_edge : node_based_graph.GetAdjacentEdgeRange(intersection_node))
|
||||
lanes = std::max(
|
||||
lanes, node_based_graph.GetEdgeData(onto_edge).road_classification.GetNumberOfLanes());
|
||||
return lanes;
|
||||
}
|
||||
|
||||
} // namespace guidance
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace api
|
||||
struct ParsedURL;
|
||||
}
|
||||
|
||||
|
||||
class ServiceHandlerInterface
|
||||
{
|
||||
public:
|
||||
public:
|
||||
virtual ~ServiceHandlerInterface() {}
|
||||
virtual engine::Status RunQuery(api::ParsedURL parsed_url, service::BaseService::ResultT & result) = 0;
|
||||
virtual engine::Status RunQuery(api::ParsedURL parsed_url,
|
||||
service::BaseService::ResultT &result) = 0;
|
||||
};
|
||||
|
||||
class ServiceHandler final : public ServiceHandlerInterface
|
||||
|
||||
@@ -73,8 +73,7 @@ inline void print(const NodeBasedDynamicGraph &node_based_graph,
|
||||
for (const auto &road : intersection)
|
||||
{
|
||||
std::cout << "\t" << toString(road) << "\n";
|
||||
std::cout << "\t\t"
|
||||
<< node_based_graph.GetEdgeData(road.turn.eid).road_classification.ToString()
|
||||
std::cout << "\t\t" << node_based_graph.GetEdgeData(road.eid).road_classification.ToString()
|
||||
<< "\n";
|
||||
}
|
||||
std::cout << std::flush;
|
||||
|
||||
Reference in New Issue
Block a user