diff options
author | Sergey Magidovich <mgsergio@mapswithme.com> | 2016-10-24 15:15:36 +0300 |
---|---|---|
committer | Sergey Magidovich <mgsergio@mapswithme.com> | 2017-01-31 10:43:14 +0300 |
commit | 3e6df70ac10b8e10dd15199fa16bfdd54c6ee1f4 (patch) | |
tree | b8e1d157a64a02d6f304cd4e1eb6ba9eda7b2667 /routing | |
parent | 13090e8c57c6191e64eb85c72be5315af46cabba (diff) |
OpenLR decoding, markup tool.
Diffstat (limited to 'routing')
-rw-r--r-- | routing/features_road_graph.hpp | 3 | ||||
-rw-r--r-- | routing/road_graph.cpp | 49 | ||||
-rw-r--r-- | routing/road_graph.hpp | 15 | ||||
-rw-r--r-- | routing/router.cpp | 4 | ||||
-rw-r--r-- | routing/router.hpp | 12 |
5 files changed, 54 insertions, 29 deletions
diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index 7657e7dc6f..9634a1b307 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -76,6 +76,8 @@ public: IRoadGraph::Mode GetMode() const override; void ClearState() override; + bool IsRoad(FeatureType const & ft) const; + private: friend class CrossFeaturesLoader; @@ -90,7 +92,6 @@ private: unique_ptr<feature::AltitudeLoader> m_altitudeLoader; }; - bool IsRoad(FeatureType const & ft) const; bool IsOneWay(FeatureType const & ft) const; double GetSpeedKMPHFromFt(FeatureType const & ft) const; diff --git a/routing/road_graph.cpp b/routing/road_graph.cpp index db72d0bb2c..52597f86b8 100644 --- a/routing/road_graph.cpp +++ b/routing/road_graph.cpp @@ -12,6 +12,7 @@ #include "base/math.hpp" #include "base/stl_helpers.hpp" +#include "std/algorithm.hpp" #include "std/limits.hpp" #include "std/sstream.hpp" @@ -23,15 +24,16 @@ bool OnEdge(Junction const & p, Edge const & ab) { auto const & a = ab.GetStartJunction(); auto const & b = ab.GetEndJunction(); - return m2::IsPointOnSegment(p.GetPoint(), a.GetPoint(), b.GetPoint()); + return m2::IsPointOnSegmentEps(p.GetPoint(), a.GetPoint(), b.GetPoint(), 1e-9); } void SplitEdge(Edge const & ab, Junction const & p, vector<Edge> & edges) { auto const & a = ab.GetStartJunction(); auto const & b = ab.GetEndJunction(); - edges.push_back(Edge::MakeFake(a, p)); - edges.push_back(Edge::MakeFake(p, b)); + bool const partOfReal = ab.IsPartOfReal(); + edges.push_back(Edge::MakeFake(a, p, partOfReal)); + edges.push_back(Edge::MakeFake(p, b, partOfReal)); } } // namespace @@ -51,20 +53,33 @@ string DebugPrint(Junction const & r) // Edge ------------------------------------------------------------------------ -Edge Edge::MakeFake(Junction const & startJunction, Junction const & endJunction) +Edge Edge::MakeFake(Junction const & startJunction, Junction const & endJunction, bool partOfReal) { - return Edge(FeatureID(), true /* forward */, 0 /* segId */, startJunction, endJunction); + Edge edge(FeatureID(), true /* forward */, 0 /* segId */, startJunction, endJunction); + edge.m_partOfReal = partOfReal; + return edge; } -Edge::Edge(FeatureID const & featureId, bool forward, uint32_t segId, Junction const & startJunction, Junction const & endJunction) - : m_featureId(featureId), m_forward(forward), m_segId(segId), m_startJunction(startJunction), m_endJunction(endJunction) +Edge::Edge() : m_forward(true), m_segId(0) { m_partOfReal = !IsFake(); } + +Edge::Edge(FeatureID const & featureId, bool forward, uint32_t segId, + Junction const & startJunction, Junction const & endJunction) + : m_featureId(featureId) + , m_forward(forward) + , m_segId(segId) + , m_startJunction(startJunction) + , m_endJunction(endJunction) { ASSERT_LESS(segId, numeric_limits<uint32_t>::max(), ()); + m_partOfReal = !IsFake(); } Edge Edge::GetReverseEdge() const { - return Edge(m_featureId, !m_forward, m_segId, m_endJunction, m_startJunction); + Edge edge = *this; + edge.m_forward = !edge.m_forward; + swap(edge.m_startJunction, edge.m_endJunction); + return edge; } bool Edge::SameRoadSegmentAndDirection(Edge const & r) const @@ -76,11 +91,9 @@ bool Edge::SameRoadSegmentAndDirection(Edge const & r) const bool Edge::operator==(Edge const & r) const { - return m_featureId == r.m_featureId && - m_forward == r.m_forward && - m_segId == r.m_segId && - m_startJunction == r.m_startJunction && - m_endJunction == r.m_endJunction; + return m_featureId == r.m_featureId && m_forward == r.m_forward && + m_partOfReal == r.m_partOfReal && m_segId == r.m_segId && + m_startJunction == r.m_startJunction && m_endJunction == r.m_endJunction; } bool Edge::operator<(Edge const & r) const @@ -89,6 +102,8 @@ bool Edge::operator<(Edge const & r) const return m_featureId < r.m_featureId; if (m_forward != r.m_forward) return (m_forward == false); + if (m_partOfReal != r.m_partOfReal) + return (m_partOfReal == false); if (m_segId != r.m_segId) return m_segId < r.m_segId; if (!(m_startJunction == r.m_startJunction)) @@ -102,7 +117,8 @@ string DebugPrint(Edge const & r) { ostringstream ss; ss << "Edge{featureId: " << DebugPrint(r.GetFeatureId()) << ", isForward:" << r.IsForward() - << ", segId:" << r.m_segId << ", startJunction:" << DebugPrint(r.m_startJunction) + << ", partOfReal:" << r.IsPartOfReal() << ", segId:" << r.m_segId + << ", startJunction:" << DebugPrint(r.m_startJunction) << ", endJunction:" << DebugPrint(r.m_endJunction) << "}"; return ss.str(); } @@ -198,8 +214,9 @@ void IRoadGraph::AddFakeEdges(Junction const & junction, vector<Edge> edges; SplitEdge(ab, p, edges); - edges.push_back(Edge::MakeFake(junction, p)); - edges.push_back(Edge::MakeFake(p, junction)); + + edges.push_back(Edge::MakeFake(junction, p, false /* partOfReal */)); + edges.push_back(Edge::MakeFake(p, junction, false /* partOfReal */)); ForEachFakeEdge([&](Edge const & uv) { diff --git a/routing/road_graph.hpp b/routing/road_graph.hpp index 1d0f1118cf..6fcc21a6c9 100644 --- a/routing/road_graph.hpp +++ b/routing/road_graph.hpp @@ -25,6 +25,7 @@ public: Junction & operator=(Junction const &) = default; inline bool operator==(Junction const & r) const { return m_point == r.m_point; } + inline bool operator!=(Junction const & r) const { return !(*this == r); } inline bool operator<(Junction const & r) const { return m_point < r.m_point; } inline m2::PointD const & GetPoint() const { return m_point; } @@ -52,10 +53,12 @@ inline bool AlmostEqualAbs(Junction const & lhs, Junction const & rhs) class Edge { public: - static Edge MakeFake(Junction const & startJunction, Junction const & endJunction); + static Edge MakeFake(Junction const & startJunction, Junction const & endJunction, + bool partOfReal); - Edge() : m_forward(true), m_segId(0) {} - Edge(FeatureID const & featureId, bool forward, uint32_t segId, Junction const & startJunction, Junction const & endJunction); + Edge(); + Edge(FeatureID const & featureId, bool forward, uint32_t segId, Junction const & startJunction, + Junction const & endJunction); Edge(Edge const &) = default; Edge & operator=(Edge const &) = default; @@ -65,6 +68,7 @@ public: inline Junction const & GetStartJunction() const { return m_startJunction; } inline Junction const & GetEndJunction() const { return m_endJunction; } inline bool IsFake() const { return !m_featureId.IsValid(); } + inline bool IsPartOfReal() const { return m_partOfReal; } Edge GetReverseEdge() const; @@ -82,6 +86,9 @@ private: // Is the feature along the road. bool m_forward; + // This flag is set for edges that are parts of some real edges. + bool m_partOfReal; + // Ordinal number of the segment on the road. uint32_t m_segId; @@ -261,7 +268,6 @@ public: /// Clear all temporary buffers. virtual void ClearState() {} -private: /// \brief Finds all outgoing regular (non-fake) edges for junction. void GetRegularOutgoingEdges(Junction const & junction, TEdgeVector & edges) const; /// \brief Finds all ingoing regular (non-fake) edges for junction. @@ -271,6 +277,7 @@ private: /// \brief Finds all ingoing fake edges for junction. void GetFakeIngoingEdges(Junction const & junction, TEdgeVector & edges) const; +private: template <typename Fn> void ForEachFakeEdge(Fn && fn) { diff --git a/routing/router.cpp b/routing/router.cpp index eb3dc93e79..bd6e5af5ff 100644 --- a/routing/router.cpp +++ b/routing/router.cpp @@ -3,7 +3,7 @@ namespace routing { -string ToString(RouterType type) +std::string ToString(RouterType type) { switch(type) { @@ -16,7 +16,7 @@ string ToString(RouterType type) return "Error"; } -RouterType FromString(string const & str) +RouterType FromString(std::string const & str) { if (str == "vehicle") return RouterType::Vehicle; diff --git a/routing/router.hpp b/routing/router.hpp index 1e8e0da7d9..31fe361ad1 100644 --- a/routing/router.hpp +++ b/routing/router.hpp @@ -6,13 +6,13 @@ #include "base/cancellable.hpp" -#include "std/function.hpp" -#include "std/string.hpp" +#include <functional> +#include <string> namespace routing { -using TCountryFileFn = function<string(m2::PointD const &)>; +using TCountryFileFn = std::function<std::string(m2::PointD const &)>; class Route; @@ -26,8 +26,8 @@ enum class RouterType Taxi, /// For taxi route calculation Vehicle routing is used. }; -string ToString(RouterType type); -RouterType FromString(string const & str); +std::string ToString(RouterType type); +RouterType FromString(std::string const & str); class IRouter { @@ -55,7 +55,7 @@ public: virtual ~IRouter() {} /// Return unique name of a router implementation. - virtual string GetName() const = 0; + virtual std::string GetName() const = 0; /// Clear all temporary buffers. virtual void ClearState() {} |