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
|
#include "routing/pedestrian_directions.hpp"
#include "routing/road_graph.hpp"
#include "routing/routing_helpers.hpp"
#include "indexer/classificator.hpp"
#include "indexer/feature.hpp"
#include "indexer/ftypes_matcher.hpp"
#include "base/assert.hpp"
#include "base/logging.hpp"
#include <utility>
using namespace std;
namespace
{
bool HasType(uint32_t type, feature::TypesHolder const & types)
{
for (uint32_t t : types)
{
t = ftypes::BaseChecker::PrepareToMatch(t, 2);
if (type == t)
return true;
}
return false;
}
} // namespace
namespace routing
{
PedestrianDirectionsEngine::PedestrianDirectionsEngine(shared_ptr<NumMwmIds> numMwmIds)
: m_typeSteps(classif().GetTypeByPath({"highway", "steps"}))
, m_typeLiftGate(classif().GetTypeByPath({"barrier", "lift_gate"}))
, m_typeGate(classif().GetTypeByPath({"barrier", "gate"}))
, m_numMwmIds(move(numMwmIds))
{
}
bool PedestrianDirectionsEngine::Generate(RoadGraphBase const & graph,
vector<Junction> const & path,
my::Cancellable const & cancellable,
Route::TTurns & turns, Route::TStreets & streetNames,
vector<Junction> & routeGeometry,
vector<Segment> & segments)
{
turns.clear();
streetNames.clear();
segments.clear();
routeGeometry = path;
// Note. According to Route::IsValid() method route of zero or one point is invalid.
if (path.size() < 1)
return false;
vector<Edge> routeEdges;
if (!ReconstructPath(graph, path, routeEdges, cancellable))
{
LOG(LWARNING, ("Can't reconstruct path."));
return false;
}
CalculateTurns(graph, routeEdges, turns, cancellable);
if (graph.IsRouteSegmentsImplemented())
{
graph.GetRouteSegments(segments);
}
else
{
segments.reserve(routeEdges.size());
for (Edge const & e : routeEdges)
segments.push_back(ConvertEdgeToSegment(*m_numMwmIds, e));
}
return true;
}
void PedestrianDirectionsEngine::CalculateTurns(RoadGraphBase const & graph,
vector<Edge> const & routeEdges,
Route::TTurns & turns,
my::Cancellable const & cancellable) const
{
for (size_t i = 0; i < routeEdges.size(); ++i)
{
if (cancellable.IsCancelled())
return;
Edge const & edge = routeEdges[i];
feature::TypesHolder types;
graph.GetEdgeTypes(edge, types);
if (HasType(m_typeSteps, types))
{
if (edge.IsForward())
turns.emplace_back(i, turns::PedestrianDirection::Upstairs);
else
turns.emplace_back(i, turns::PedestrianDirection::Downstairs);
}
else
{
graph.GetJunctionTypes(edge.GetStartJunction(), types);
if (HasType(m_typeLiftGate, types))
turns.emplace_back(i, turns::PedestrianDirection::LiftGate);
else if (HasType(m_typeGate, types))
turns.emplace_back(i, turns::PedestrianDirection::Gate);
}
}
// direction "arrival"
// (index of last junction is the same as number of edges)
turns.emplace_back(routeEdges.size(), turns::PedestrianDirection::ReachedYourDestination);
}
} // namespace routing
|