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

collector_camera.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2fc5d783aed8517300615f066c0cff06b613fcbb (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
#pragma once

#include "generator/collector_interface.hpp"

#include "coding/file_writer.hpp"

#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace generator_tests
{
class TestCameraCollector;
}  // namespace generator_tests

struct OsmElement;
class FeatureBuilder1;

// TODO (@gmoryes) move members of m_routingTagsProcessor to generator
namespace routing
{
/// \brief Gets text with speed, returns formatted speed string in km per hour.
/// \param maxSpeedString - text with speed. Possible format:
///                         "130" - means 130 km per hour.
///                         "130 mph" - means 130 miles per hour.
///                         "130 kmh" - means 130 km per hour.
/// See https://wiki.openstreetmap.org/wiki/Key:maxspeed
/// for more details about input string.
std::string ValidateMaxSpeedString(std::string const & maxSpeedString);

class CameraProcessor
{
public:
  struct CameraInfo;
  using Fn = std::function<void (CameraInfo const &, std::vector<uint64_t> const &)>;

  struct CameraInfo
  {
    CameraInfo(const OsmElement & element);

    uint64_t m_id = 0;
    double m_lon = 0.0;
    double m_lat = 0.0;
    std::string m_speed;
    std::vector<uint64_t> m_ways;
  };

  static size_t const kMaxSpeedSpeedStringLength;

  void ForEachCamera(Fn && toDo) const;
  void ProcessNode(OsmElement const & element);
  void ProcessWay(OsmElement const & element);

private:
  std::unordered_map<uint64_t, CameraInfo> m_speedCameras;
  std::unordered_map<uint64_t, std::vector<uint64_t>> m_cameraToWays;
};

class CameraCollector : public generator::CollectorInterface
{
public:
  friend class generator_tests::TestCameraCollector;

  explicit CameraCollector(std::string const & writerFile);

  // generator::CollectorInterface overrides:
  // We will process all nodes before ways because of o5m format:
  // all nodes are first, then all ways, then all relations.
  void CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) override;
  void Save() override;

private:
  void Write(CameraProcessor::CameraInfo const & camera, std::vector<uint64_t> const & ways);

  FileWriter m_fileWriter;
  CameraProcessor m_processor;
};
}  // namespace routing