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

feature_processing_layers.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5fd09139d3c8a11d2200e42fef7dc6ae611e144 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#pragma once

#include "generator/affiliation.hpp"
#include "generator/booking_dataset.hpp"
#include "generator/feature_builder.hpp"
#include "generator/feature_generator.hpp"
#include "generator/features_processing_helpers.hpp"
#include "generator/filter_world.hpp"
#include "generator/opentable_dataset.hpp"
#include "generator/processor_interface.hpp"
#include "generator/promo_catalog_cities.hpp"
#include "generator/world_map_generator.hpp"

#include <functional>
#include <memory>
#include <sstream>
#include <string>
#include <unordered_set>

class CoastlineFeaturesGenerator;

namespace feature
{
struct GenerateInfo;
}  // namespace feature

namespace generator
{
class ComplexFeaturesMixer;
// This is the base layer class. Inheriting from it allows you to create a chain of layers.
class LayerBase : public std::enable_shared_from_this<LayerBase>
{
public:
  LayerBase() = default;
  virtual ~LayerBase() = default;

  // The function works in linear time from the number of layers that exist after that.
  virtual void Handle(feature::FeatureBuilder & fb);

  size_t GetChainSize() const;

  void SetNext(std::shared_ptr<LayerBase> next);
  std::shared_ptr<LayerBase> Add(std::shared_ptr<LayerBase> next);

private:
  std::shared_ptr<LayerBase> m_next;
};

// Responsibility of class RepresentationLayer is converting features from one form to another for countries.
// Here we can use the knowledge of the rules for drawing objects.
// Osm object can be represented as feature of following geometry types: point, line, area depending on
// its types and geometry. Sometimes one osm object can be represented as two features e.g. object with
// closed geometry with types "leisure=playground" and "barrier=fence" splits into two objects: area object
// with type "leisure=playground" and line object with type "barrier=fence".
class RepresentationLayer : public LayerBase
{
public:
  explicit RepresentationLayer(std::shared_ptr<ComplexFeaturesMixer> const & complexFeaturesMixer = nullptr);

  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;

  static bool CanBeArea(FeatureParams const & params);
  static bool CanBePoint(FeatureParams const & params);
  static bool CanBeLine(FeatureParams const & params);

private:
  void HandleArea(feature::FeatureBuilder & fb, FeatureBuilderParams const & params);

  std::shared_ptr<ComplexFeaturesMixer> m_complexFeaturesMixer;
};

// Responsibility of class PrepareFeatureLayer is the removal of unused types and names,
// as well as the preparation of features for further processing for countries.
class PrepareFeatureLayer : public LayerBase
{
public:
  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;
};

// Responsibility of class RepresentationCoastlineLayer is converting features from one form to
// another for coastlines. Here we can use the knowledge of the rules for drawing objects.
class RepresentationCoastlineLayer : public LayerBase
{
public:
  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;
};

// Responsibility of class PrepareCoastlineFeatureLayer is the removal of unused types and names,
// as well as the preparation of features for further processing for coastlines.
class PrepareCoastlineFeatureLayer : public LayerBase
{
public:
  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;
};

class WorldLayer : public LayerBase
{
public:
  explicit WorldLayer(std::string const & popularityFilename);

  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;

private:
  FilterWorld m_filter;
};

class CountryLayer : public LayerBase
{
public:
  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;
};

class PreserializeLayer : public LayerBase
{
public:
  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override;
};

template <class SerializePolicy = feature::serialization_policy::MaxAccuracy>
class AffiliationsFeatureLayer : public LayerBase
{
public:
  AffiliationsFeatureLayer(size_t bufferSize, std::shared_ptr<feature::AffiliationInterface> const & affiliation,
                          std::shared_ptr<FeatureProcessorQueue> const & queue)
    : m_bufferSize(bufferSize)
    , m_affiliation(affiliation)
    , m_queue(queue)
  {
    m_buffer.reserve(m_bufferSize);
  }

  // LayerBase overrides:
  void Handle(feature::FeatureBuilder & fb) override
  {
    feature::FeatureBuilder::Buffer buffer;
    SerializePolicy::Serialize(fb, buffer);
    m_buffer.emplace_back(std::move(buffer), m_affiliation->GetAffiliations(fb));
    if (m_buffer.size() >= m_bufferSize)
      AddBufferToQueue();
  }

  bool AddBufferToQueue()
  {
    if (m_buffer.empty())
      return false;

    m_queue->Push(std::move(m_buffer));
    m_buffer.clear();
    m_buffer.reserve(m_bufferSize);
    return true;
  }

private:
  size_t const m_bufferSize;
  std::vector<ProcessedData> m_buffer;
  std::shared_ptr<feature::AffiliationInterface> m_affiliation;
  std::shared_ptr<FeatureProcessorQueue> m_queue;
};

class ComplexFeaturesMixer
{
public:
  explicit ComplexFeaturesMixer(std::unordered_set<CompositeId> const & hierarchyNodesSet);

  void Process(std::function<void(feature::FeatureBuilder &)> next,
               feature::FeatureBuilder const & fb);

  std::shared_ptr<ComplexFeaturesMixer> Clone();

private:
  feature::FeatureBuilder MakeComplexLineFrom(feature::FeatureBuilder const & fb);
  feature::FeatureBuilder MakeComplexAreaFrom(feature::FeatureBuilder const & fb);

  std::unordered_set<CompositeId> const & m_hierarchyNodesSet;
  uint32_t const m_complexEntryType;
};
}  // namespace generator