diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index ed51985d67..e9f346a005 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -1,5 +1,6 @@ #include "features_road_graph.hpp" #include "route.hpp" +#include "vehicle_model.hpp" #include "../indexer/index.hpp" #include "../indexer/classificator.hpp" @@ -19,7 +20,7 @@ double const DEFAULT_SPEED_MS = 15.0; FeaturesRoadGraph::FeaturesRoadGraph(Index const * pIndex, size_t mwmID) - : m_pIndex(pIndex), m_mwmID(mwmID) + : m_pIndex(pIndex), m_mwmID(mwmID), m_vehicleModel(new CarModel()) { } @@ -60,7 +61,7 @@ public: ft.ParseGeometry(FeatureType::BEST_GEOMETRY); - bool const isOneWay = m_graph.IsOneway(types); + bool const isOneWay = m_graph.IsOneWay(ft); size_t const count = ft.GetPointsCount(); PossibleTurn t; @@ -114,9 +115,14 @@ void FeaturesRoadGraph::GetPossibleTurns(RoadPos const & pos, vector(ft.GetPointsCount()); bool const isForward = pos.IsForward(); - bool const isOneWay = IsOneway(ft); + bool const isOneWay = IsOneWay(ft); int const inc = isForward ? -1 : 1; int startID = pos.GetPointId(); @@ -137,7 +143,7 @@ void FeaturesRoadGraph::GetPossibleTurns(RoadPos const & pos, vectorIsOneWay(ft); } +double FeaturesRoadGraph::GetSpeed(FeatureType const & ft) const +{ + return m_vehicleModel->GetSpeed(ft); +} + + } // namespace routing diff --git a/routing/features_road_graph.hpp b/routing/features_road_graph.hpp index 3d9f2fa3d4..d478bc5a7e 100644 --- a/routing/features_road_graph.hpp +++ b/routing/features_road_graph.hpp @@ -1,6 +1,7 @@ #pragma once #include "road_graph.hpp" +#include "../std/scoped_ptr.hpp" class Index; class FeatureType; @@ -13,6 +14,8 @@ namespace feature namespace routing { +class IVehicleModel; + class FeaturesRoadGraph : public IRoadGraph { public: @@ -29,13 +32,14 @@ private: friend class CrossFeaturesLoader; bool IsStreet(feature::TypesHolder const & types) const; - bool IsOneway(feature::TypesHolder const & types) const; - + bool IsOneWay(FeatureType const & ft) const; + double GetSpeed(FeatureType const & ft) const; void LoadFeature(uint32_t id, FeatureType & ft); private: Index const * m_pIndex; size_t m_mwmID; + scoped_ptr m_vehicleModel; }; } // namespace routing diff --git a/routing/road_graph_router.cpp b/routing/road_graph_router.cpp index 1acc0f1db4..9398df14ac 100644 --- a/routing/road_graph_router.cpp +++ b/routing/road_graph_router.cpp @@ -1,6 +1,7 @@ #include "road_graph_router.hpp" #include "features_road_graph.hpp" #include "route.hpp" +#include "vehicle_model.hpp" #include "../indexer/feature.hpp" #include "../indexer/ftypes_matcher.hpp" @@ -19,17 +20,19 @@ class Point2RoadPos size_t m_segIdx; bool m_isOneway; FeatureID m_fID; + IVehicleModel const * m_vehicleModel; public: - Point2RoadPos(m2::PointD const & pt) - : m_point(pt), m_minDist(numeric_limits::max()) + Point2RoadPos(m2::PointD const & pt, IVehicleModel const * vehicleModel) + : m_point(pt), m_minDist(numeric_limits::max()), m_vehicleModel(vehicleModel) { } void operator() (FeatureType const & ft) { - if (ft.GetFeatureType() != feature::GEOM_LINE || - !ftypes::IsStreetChecker::Instance()(ft)) + double const speed = m_vehicleModel->GetSpeed(ft); + + if (ft.GetFeatureType() != feature::GEOM_LINE || speed <= 0.0) return; ft.ParseGeometry(FeatureType::BEST_GEOMETRY); @@ -45,7 +48,7 @@ public: m_minDist = d; m_segIdx = i; m_fID = ft.GetID(); - m_isOneway = ftypes::IsStreetChecker::Instance().IsOneway(ft); + m_isOneway = m_vehicleModel->IsOneWay(ft); } } } @@ -66,9 +69,19 @@ public: } }; +RoadGraphRouter::~RoadGraphRouter() +{ +} + +RoadGraphRouter::RoadGraphRouter(Index const * pIndex) : + m_vehicleModel(new CarModel()), m_pIndex(pIndex) +{ + +} + size_t RoadGraphRouter::GetRoadPos(m2::PointD const & pt, vector & pos) { - Point2RoadPos getter(pt); + Point2RoadPos getter(pt, m_vehicleModel.get()); m_pIndex->ForEachInRect(getter, MercatorBounds::RectByCenterXYAndSizeInMeters(pt, 100.0), FeaturesRoadGraph::GetStreetReadScale()); diff --git a/routing/road_graph_router.hpp b/routing/road_graph_router.hpp index 0fcdf76561..6380cea2d8 100644 --- a/routing/road_graph_router.hpp +++ b/routing/road_graph_router.hpp @@ -14,10 +14,13 @@ class Index; namespace routing { +class IVehicleModel; + class RoadGraphRouter : public IRouter { public: - RoadGraphRouter(Index const * pIndex) : m_pIndex(pIndex) {} + RoadGraphRouter(Index const * pIndex); + ~RoadGraphRouter(); virtual void SetFinalPoint(m2::PointD const & finalPt); virtual void CalculateRoute(m2::PointD const & startPt, ReadyCallback const & callback); @@ -31,6 +34,7 @@ protected: bool IsMyMWM(size_t mwmID) const; scoped_ptr m_pRoadGraph; + scoped_ptr m_vehicleModel; Index const * m_pIndex; };