blob: 66b41972344600489f14fb17331211060cb6f6e4 (
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
|
#pragma once
#include "generator/intermediate_elements.hpp"
#include "geometry/point2d.hpp"
#include "std/map.hpp"
#include "std/vector.hpp"
#include "std/shared_ptr.hpp"
template <class THolder>
class AreaWayMerger
{
using TPointSeq = vector<m2::PointD>;
using TWayMap = multimap<uint64_t, shared_ptr<WayElement>>;
using TWayMapIterator = TWayMap::iterator;
THolder & m_holder;
TWayMap m_map;
public:
AreaWayMerger(THolder & holder) : m_holder(holder) {}
void AddWay(uint64_t id)
{
shared_ptr<WayElement> e(new WayElement(id));
if (m_holder.GetWay(id, *e) && e->IsValid())
{
m_map.insert(make_pair(e->nodes.front(), e));
m_map.insert(make_pair(e->nodes.back(), e));
}
}
template <class ToDo>
void ForEachArea(bool collectID, ToDo toDo)
{
while (!m_map.empty())
{
// start
TWayMapIterator i = m_map.begin();
uint64_t id = i->first;
vector<uint64_t> ids;
TPointSeq points;
do
{
// process way points
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_holder.GetNode(id, pt.y, pt.x))
points.push_back(pt);
});
m_map.erase(i);
// next 'id' to process
id = e->GetOtherEndPoint(id);
pair<TWayMapIterator, TWayMapIterator> 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);
}
}
};
|