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: 59bcc98567eca126b566ee831fe08298f1064874 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once

#include "routing/road_graph.hpp"

#include "routing_common/vehicle_model.hpp"

#include "indexer/altitude_loader.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 DataSourceBase;
class FeatureType;

namespace routing
{

class FeaturesRoadGraph : public IRoadGraph
{
private:
  class CrossCountryVehicleModel : public VehicleModelInterface
  {
  public:
    CrossCountryVehicleModel(shared_ptr<VehicleModelFactoryInterface> vehicleModelFactory);

    // VehicleModelInterface overrides:
    double GetSpeed(FeatureType const & f) const override;
    double GetMaxSpeed() const override;
    double GetOffroadSpeed() const override;
    bool IsOneWay(FeatureType const & f) const override;
    bool IsRoad(FeatureType const & f) const override;
    bool IsPassThroughAllowed(FeatureType const & f) const override;

    void Clear();

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

    shared_ptr<VehicleModelFactoryInterface> const m_vehicleModelFactory;
    double const m_maxSpeedKMPH;
    double const m_offroadSpeedKMPH;

    mutable map<MwmSet::MwmId, shared_ptr<VehicleModelInterface>> 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(DataSourceBase const & dataSource, IRoadGraph::Mode mode,
                    shared_ptr<VehicleModelFactoryInterface> vehicleModelFactory);

  static int 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, Junction>> & 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;

  bool IsRoad(FeatureType const & ft) const;

private:
  friend class CrossFeaturesLoader;

  struct Value
  {
    Value() = default;
    Value(DataSourceBase const & dataSource, MwmSet::MwmHandle handle);

    bool IsAlive() const { return m_mwmHandle.IsAlive(); }

    MwmSet::MwmHandle m_mwmHandle;
    unique_ptr<feature::AltitudeLoader> m_altitudeLoader;
  };

  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 const & ft,
                                     double speedKMPH) const;
  void ExtractRoadInfo(FeatureID const & featureId, FeatureType const & ft, double speedKMPH,
                       RoadInfo & ri) const;

  Value const & LockMwm(MwmSet::MwmId const & mwmId) const;

  DataSourceBase const & m_dataSource;
  IRoadGraph::Mode const m_mode;
  mutable RoadInfoCache m_cache;
  mutable CrossCountryVehicleModel m_vehicleModel;
  mutable map<MwmSet::MwmId, Value> m_mwmLocks;
};

// @returns a distance d such as that for a given point p any edge
// with start point s such as that |s - p| < d, and edge is considered outgouing from p.
// Symmetrically for ingoing edges.
double GetRoadCrossingRadiusMeters();

}  // namespace routing