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
|
#pragma once
#include "generator/collector_interface.hpp"
#include "generator/intermediate_elements.hpp"
#include "generator/osm_element.hpp"
#include "routing/road_access.hpp"
#include "routing/vehicle_mask.hpp"
#include <array>
#include <cstdint>
#include <fstream>
#include <map>
#include <ostream>
#include <set>
#include <string>
#include <vector>
struct OsmElement;
class FeatureParams;
// The road accessibility information is collected in the same manner
// as the restrictions are.
// See generator/restriction_generator.hpp for details.
namespace routing
{
class RoadAccessTagProcessor
{
public:
using TagMapping = std::map<OsmElement::Tag, RoadAccess::Type>;
explicit RoadAccessTagProcessor(VehicleType vehicleType);
void Process(OsmElement const & elem, std::ofstream & oss);
private:
bool ShouldIgnoreBarrierWithoutAccess(OsmElement const & osmElement) const;
RoadAccess::Type GetAccessType(OsmElement const & elem) const;
VehicleType m_vehicleType;
std::vector<TagMapping const *> m_barrierMappings;
// Order of tag mappings in m_tagMappings is from more to less specific.
// e.g. for car: motorcar, motorvehicle, vehicle, general access tags.
std::vector<TagMapping const *> m_accessMappings;
// We decided to ignore some barriers without access on some type of highways
// because we almost always do not need to add penalty for passes through such nodes.
std::set<OsmElement::Tag> const * m_hwIgnoreBarriersWithoutAccess;
std::map<uint64_t, RoadAccess::Type> m_barriers;
};
class RoadAccessWriter : public generator::CollectorInterface
{
public:
RoadAccessWriter(std::string const & filePath);
// CollectorInterface overrides:
void CollectFeature(feature::FeatureBuilder const &, OsmElement const & elem) override;
void Save() override {}
private:
void Open(std::string const & filePath);
bool IsOpened() const;
std::ofstream m_stream;
std::vector<RoadAccessTagProcessor> m_tagProcessors;
};
class RoadAccessCollector
{
public:
using RoadAccessByVehicleType = std::array<RoadAccess, static_cast<size_t>(VehicleType::Count)>;
RoadAccessCollector(std::string const & dataFilePath, std::string const & roadAccessPath,
std::string const & osmIdsToFeatureIdsPath);
RoadAccessByVehicleType const & GetRoadAccessAllTypes() const
{
return m_roadAccessByVehicleType;
}
bool IsValid() const { return m_valid; }
private:
RoadAccessByVehicleType m_roadAccessByVehicleType;
bool m_valid = true;
};
// The generator tool's interface to writing the section with
// road accessibility information for one mwm file.
void BuildRoadAccessInfo(std::string const & dataFilePath, std::string const & roadAccessPath,
std::string const & osmIdsToFeatureIdsPath);
} // namespace routing
|