Merge IntersectionShapeData and IntersectionEdgeGeometry

This commit is contained in:
Michael Krasnyk
2018-02-16 09:39:38 +01:00
parent 0f93a7dd05
commit 0fc8b6289c
14 changed files with 103 additions and 106 deletions
@@ -26,14 +26,19 @@ struct IntersectionEdge
using IntersectionEdges = std::vector<IntersectionEdge>;
// The extracted geometry of an intersection edge only knows about edge IDs and bearings
// Bearing is the direction in clockwise angle from true north after taking the turn:
// 0 = heading north, 90 = east, 180 = south, 270 = west
// `initial_bearing` is the original OSM edge bearing
// `perceived_bearing` is the edge bearing after line fitting and edges merging
struct IntersectionEdgeGeometry
{
EdgeID edge;
EdgeID eid;
double initial_bearing;
double perceived_bearing;
double length;
double segment_length;
bool operator<(const IntersectionEdgeGeometry &other) const { return edge < other.edge; }
bool operator<(const IntersectionEdgeGeometry &other) const { return eid < other.eid; }
};
using IntersectionEdgeGeometries = std::vector<IntersectionEdgeGeometry>;
@@ -1,6 +1,19 @@
#ifndef OSRM_EXTRACTOR_INTERSECTION_INTERSECTION_VIEW_HPP_
#define OSRM_EXTRACTOR_INTERSECTION_INTERSECTION_VIEW_HPP_
#include "extractor/intersection/intersection_edge.hpp"
#include "guidance/turn_instruction.hpp"
#include "util/bearing.hpp"
#include "util/log.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp" // EdgeID
#include <boost/range/algorithm/count_if.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/min_element.hpp>
#include <algorithm>
#include <functional>
#include <limits>
@@ -8,17 +21,6 @@
#include <type_traits>
#include <vector>
#include "util/bearing.hpp"
#include "util/log.hpp"
#include "util/node_based_graph.hpp"
#include "util/typedefs.hpp" // EdgeID
#include "guidance/turn_instruction.hpp"
#include <boost/range/algorithm/count_if.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/min_element.hpp>
namespace osrm
{
namespace extractor
@@ -26,24 +28,6 @@ namespace extractor
namespace intersection
{
// the shape of an intersection only knows about edge IDs and bearings
// `bearing` is the direction in clockwise angle from true north after taking the turn:
// 0 = heading north, 90 = east, 180 = south, 270 = west
struct IntersectionShapeData
{
EdgeID eid;
double bearing;
double segment_length;
};
inline auto makeCompareShapeDataByBearing(const double base_bearing)
{
return [base_bearing](const auto &lhs, const auto &rhs) {
return util::angularDeviation(lhs.bearing, base_bearing) <
util::angularDeviation(rhs.bearing, base_bearing);
};
}
inline auto makeCompareAngularDeviation(const double angle)
{
return [angle](const auto &lhs, const auto &rhs) {
@@ -60,12 +44,12 @@ inline auto makeExtractLanesForRoad(const util::NodeBasedDynamicGraph &node_base
// When viewing an intersection from an incoming edge, we can transform a shape into a view which
// gives additional information on angles and whether a turn is allowed
struct IntersectionViewData : IntersectionShapeData
struct IntersectionViewData : IntersectionEdgeGeometry
{
IntersectionViewData(const IntersectionShapeData &shape,
IntersectionViewData(const IntersectionEdgeGeometry &geometry,
const bool entry_allowed,
const double angle)
: IntersectionShapeData(shape), entry_allowed(entry_allowed), angle(angle)
: IntersectionEdgeGeometry(geometry), entry_allowed(entry_allowed), angle(angle)
{
}
@@ -80,10 +64,13 @@ struct IntersectionViewData : IntersectionShapeData
template <typename Self> struct EnableShapeOps
{
// same as closest turn, but for bearings
auto FindClosestBearing(double bearing) const
auto FindClosestBearing(double base_bearing) const
{
auto comp = makeCompareShapeDataByBearing(bearing);
return std::min_element(self()->begin(), self()->end(), comp);
return std::min_element(
self()->begin(), self()->end(), [base_bearing](const auto &lhs, const auto &rhs) {
return util::angularDeviation(lhs.perceived_bearing, base_bearing) <
util::angularDeviation(rhs.perceived_bearing, base_bearing);
});
}
// search a given eid in the intersection
@@ -119,10 +106,10 @@ template <typename Self> struct EnableShapeOps
auto self() const { return static_cast<const Self *>(this); }
};
struct IntersectionShape final : std::vector<IntersectionShapeData>, //
EnableShapeOps<IntersectionShape> //
struct IntersectionShape final : std::vector<IntersectionEdgeGeometry>, //
EnableShapeOps<IntersectionShape> //
{
using Base = std::vector<IntersectionShapeData>;
using Base = std::vector<IntersectionEdgeGeometry>;
};
// Common operations shared among IntersectionView and Intersections.
@@ -40,7 +40,7 @@ class MergableRoadDetector
{
public:
// in case we have to change the mode we are operating on
using MergableRoadData = IntersectionShapeData;
using MergableRoadData = IntersectionEdgeGeometry;
MergableRoadDetector(const util::NodeBasedDynamicGraph &node_based_graph,
const EdgeBasedNodeDataContainer &node_data_container,
+1 -1
View File
@@ -114,7 +114,7 @@ inline std::string toString(const ConnectedRoad &road)
result += " angle: ";
result += std::to_string(road.angle);
result += " bearing: ";
result += std::to_string(road.bearing);
result += std::to_string(road.perceived_bearing);
result += " instruction: ";
result += std::to_string(static_cast<std::int32_t>(road.instruction.type)) + " " +
std::to_string(static_cast<std::int32_t>(road.instruction.direction_modifier)) + " " +
+1 -1
View File
@@ -348,7 +348,7 @@ std::size_t IntersectionHandler::findObviousTurn(const EdgeID via_edge,
const auto turns_onto_through_street = [&](const auto &road) {
// find edge opposite to the one we are checking (in-road)
const auto in_through_candidate =
intersection.FindClosestBearing(util::bearing::reverse(road.bearing));
intersection.FindClosestBearing(util::bearing::reverse(road.perceived_bearing));
const auto &in_edge = node_based_graph.GetEdgeData(in_through_candidate->eid);
const auto &out_edge = node_based_graph.GetEdgeData(road.eid);
+5 -4
View File
@@ -68,7 +68,7 @@ namespace guidance
inline std::ostream &operator<<(std::ostream &out, const ConnectedRoad &road)
{
out << "ConnectedRoad {" << road.eid << " allows entry: " << road.entry_allowed
<< " angle: " << road.angle << " bearing: " << road.bearing
<< " angle: " << road.angle << " bearing: " << road.perceived_bearing
<< " instruction: " << static_cast<std::int32_t>(road.instruction.type) << " "
<< static_cast<std::int32_t>(road.instruction.direction_modifier) << " "
<< static_cast<std::int32_t>(road.lane_data_id) << "}";
@@ -80,16 +80,17 @@ namespace extractor
{
namespace intersection
{
inline std::ostream &operator<<(std::ostream &out, const IntersectionShapeData &shape)
inline std::ostream &operator<<(std::ostream &out, const IntersectionEdgeGeometry &shape)
{
out << "IntersectionShapeData { " << shape.eid << " bearing: " << shape.bearing << "}";
out << "IntersectionEdgeGeometry { " << shape.eid << " bearing: " << shape.perceived_bearing
<< "}";
return out;
}
inline std::ostream &operator<<(std::ostream &out, const IntersectionViewData &view)
{
out << "IntersectionViewData {" << view.eid << " allows entry: " << view.entry_allowed
<< " angle: " << view.angle << " bearing: " << view.bearing << "}";
<< " angle: " << view.angle << " bearing: " << view.perceived_bearing << "}";
return out;
}
}