Welcome to mirror list, hosted at ThFree Co, Russian Federation.

features_road_graph.hpp « routing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: af61afd11f1367c7974e5f9e6e5bc3786a7535cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include "routing/road_graph.hpp"
#include "routing/vehicle_model.hpp"

#include "indexer/feature_data.hpp"
#include "indexer/mwm_set.hpp"

#include "geometry/point2d.hpp"

#include "base/cache.hpp"

#include "std/map.hpp"
#include "std/unique_ptr.hpp"
#include "std/vector.hpp"

class Index;
class FeatureType;

namespace routing
{

class FeaturesRoadGraph : public IRoadGraph
{
private:
  class CrossCountryVehicleModel : public IVehicleModel
  {
  public:
    CrossCountryVehicleModel(unique_ptr<IVehicleModelFactory> && vehicleModelFactory);

    // IVehicleModel overrides:
    double GetSpeed(FeatureType const & f) const override;
    double GetMaxSpeed() const override;
    bool IsOneWay(FeatureType const & f) const override;

    void Clear();

  private:
    IVehicleModel * GetVehicleModel(FeatureID const & featureId) const;

    unique_ptr<IVehicleModelFactory> const m_vehicleModelFactory;
    double const m_maxSpeedKMPH;

    mutable map<MwmSet::MwmId, shared_ptr<IVehicleModel>> m_cache;
  };

  class RoadInfoCache
  {
  public:
    RoadInfo & Find(FeatureID const & featureId, bool & found);

    void Clear();

  private:
    using TMwmFeatureCache = my::Cache<uint32_t, RoadInfo>;
    map<MwmSet::MwmId, TMwmFeatureCache> m_cache;
  };

public:
  FeaturesRoadGraph(Index const & index, IRoadGraph::Mode mode,
                    unique_ptr<IVehicleModelFactory> && vehicleModelFactory);

  static uint32_t GetStreetReadScale();

  // IRoadGraph overrides:
  RoadInfo GetRoadInfo(FeatureID const & featureId) const override;
  double GetSpeedKMPH(FeatureID const & featureId) const override;
  double GetMaxSpeedKMPH() const override;
  void ForEachFeatureClosestToCross(m2::PointD const & cross,
                                    ICrossEdgesLoader & edgesLoader) const override;
  void FindClosestEdges(m2::PointD const & point, uint32_t count,
                        vector<pair<Edge, m2::PointD>> & vicinities) const override;
  void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override;
  void GetJunctionTypes(Junction const & junction, feature::TypesHolder & types) const override;
  IRoadGraph::Mode GetMode() const override;
  void ClearState() override;

private:
  friend class CrossFeaturesLoader;

  bool IsOneWay(FeatureType const & ft) const;
  double GetSpeedKMPHFromFt(FeatureType const & ft) const;

  // Searches a feature RoadInfo in the cache, and if does not find then
  // loads feature from the index and takes speed for the feature from the vehicle model.
  RoadInfo const & GetCachedRoadInfo(FeatureID const & featureId) const;
  // Searches a feature RoadInfo in the cache, and if does not find then takes passed feature and speed.
  // This version is used to prevent redundant feature loading when feature speed is known.
  RoadInfo const & GetCachedRoadInfo(FeatureID const & featureId,
                                     FeatureType & ft,
                                     double speedKMPH) const;

  void LockFeatureMwm(FeatureID const & featureId) const;

  Index const & m_index;
  IRoadGraph::Mode const m_mode;
  mutable RoadInfoCache m_cache;
  mutable CrossCountryVehicleModel m_vehicleModel;
  mutable map<MwmSet::MwmId, MwmSet::MwmHandle> m_mwmLocks;
};

}  // namespace routing