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

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

#include "generator/intermediate_data.hpp"
#include "generator/intermediate_elements.hpp"

#include "geometry/point2d.hpp"

#include <cstdint>
#include <map>
#include <memory>
#include <utility>
#include <vector>

namespace generator
{
class AreaWayMerger
{
  using PointSeq = std::vector<m2::PointD>;
  using WayMap = std::multimap<uint64_t, std::shared_ptr<WayElement>>;
  using WayMapIterator = WayMap::iterator;

public:
  explicit AreaWayMerger(cache::IntermediateDataReader & cache);

  void AddWay(uint64_t id);

  template <class ToDo>
  void ForEachArea(bool collectID, ToDo toDo)
  {
    while (!m_map.empty())
    {
      // start
      WayMapIterator i = m_map.begin();
      uint64_t id = i->first;

      std::vector<uint64_t> ids;
      PointSeq points;

      do
      {
        // process way points
        std::shared_ptr<WayElement> e = i->second;
        if (collectID)
          ids.push_back(e->m_wayOsmId);

        e->ForEachPointOrdered(id, [this, &points](uint64_t id)
        {
          m2::PointD pt;
          if (m_cache.GetNode(id, pt.y, pt.x))
            points.push_back(pt);
        });

        m_map.erase(i);

        // next 'id' to process
        id = e->GetOtherEndPoint(id);
        std::pair<WayMapIterator, WayMapIterator> r = m_map.equal_range(id);

        // finally erase element 'e' and find next way in chain
        i = r.second;
        while (r.first != r.second)
        {
          if (r.first->second == e)
            m_map.erase(r.first++);
          else
            i = r.first++;
        }

        if (i == r.second)
          break;
      } while (true);

      if (points.size() > 2 && points.front() == points.back())
        toDo(points, ids);
    }
  }

private:
  cache::IntermediateDataReader & m_cache;
  WayMap m_map;
};
}  // namespace generator