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

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

#include "generator/collector_interface.hpp"
#include "generator/feature_builder.hpp"
#include "generator/osm_element.hpp"

#include "coding/reader.hpp"
#include "coding/write_to_sink.hpp"
#include "coding/writer.hpp"

#include <cstdlib>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace generator
{
namespace cache
{
class IntermediateDataReaderInterface;
}  // namespace cache
}  // namespace generator

namespace feature
{
// A string of connected ways.
class LineString
{
public:
  using Ways = std::vector<int32_t>;

  explicit LineString(OsmElement const & way);

  bool Add(LineString & line);
  void Reverse();

  Ways const & GetWays() const { return m_ways; }
  uint64_t GetStart() const { return m_start; }
  uint64_t GetEnd() const { return m_end; }

  template <typename T>
  void Serialize(T & w)
  {
    WriteVarUint(w, m_start);
    WriteVarUint(w, m_end);
    WriteToSink(w, m_oneway);
    rw::WriteVectorOfPOD(w, m_ways);
  }

  template <typename T>
  static LineString Deserialize(T & r)
  {
    LineString ls;
    ls.m_start = ReadVarUint<uint64_t>(r);
    ls.m_end = ReadVarUint<uint64_t>(r);
    ReadPrimitiveFromSource(r, ls.m_oneway);
    rw::ReadVectorOfPOD(r, ls.m_ways);
    return ls;
  }

private:
  LineString() = default;

  uint64_t m_start;
  uint64_t m_end;
  bool m_oneway;
  Ways m_ways;
};

class LineStringMerger
{
public:
  using LinePtr = std::shared_ptr<LineString>;
  using InputData = std::unordered_multimap<size_t, LinePtr>;
  using OutputData = std::map<size_t, std::vector<LinePtr>>;

  static OutputData Merge(InputData const & data);

private:
  using Buffer = std::unordered_map<uint64_t, LinePtr>;

  static bool TryMerge(LinePtr const & lineString, Buffer & buffer);
  static bool TryMergeOne(LinePtr const & lineString, Buffer & buffer);
  static OutputData OrderData(InputData const & data);
};

// Merges road segments with similar name and ref values into groups called metalines.
class MetalinesBuilder : public generator::CollectorInterface
{
public:
  explicit MetalinesBuilder(std::string const & filename);

  // CollectorInterface overrides:
  std::shared_ptr<CollectorInterface> Clone(
      std::shared_ptr<generator::cache::IntermediateDataReaderInterface> const & = {})
      const override;

  /// Add a highway segment to the collection of metalines.
  void CollectFeature(FeatureBuilder const & feature, OsmElement const & element) override;

  void Finish() override;

  void Merge(generator::CollectorInterface const & collector) override;
  void MergeInto(MetalinesBuilder & collector) const override;

protected:
  void Save() override;
  void OrderCollectedData() override;

private:
  std::unique_ptr<FileWriter> m_writer;
};

// Read an intermediate file from MetalinesBuilder and convert it to an mwm section.
bool WriteMetalinesSection(std::string const & mwmPath, std::string const & metalinesPath,
                           std::string const & osmIdsToFeatureIdsPath);
}