blob: aefa55b929ab6371bb233d0b780fdebfb925616c (
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
|
#include <mbgl/algorithm/generate_clip_ids_impl.hpp>
#include <mbgl/algorithm/covered_by_children.hpp>
#include <mbgl/util/std.hpp>
#include <list>
#include <vector>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <iterator>
namespace mbgl {
namespace algorithm {
ClipIDGenerator::Leaf::Leaf(ClipID& clip_) : clip(clip_) {
}
void ClipIDGenerator::Leaf::add(const CanonicalTileID& p) {
// Ensure that no already present child is a parent of the new p.
for (const auto& child : children) {
if (p.isChildOf(child)) {
return;
}
}
children.emplace(p);
}
bool ClipIDGenerator::Leaf::operator==(const Leaf& other) const {
return children == other.children;
}
std::map<UnwrappedTileID, ClipID> ClipIDGenerator::getClipIDs() const {
std::map<UnwrappedTileID, ClipID> clipIDs;
// Merge everything.
for (auto& pair : pool) {
auto& id = pair.first;
auto& leaf = pair.second;
auto res = clipIDs.emplace(id, leaf.clip);
if (!res.second) {
// Merge with the existing ClipID when there was already an element with the
// same tile ID.
res.first->second |= leaf.clip;
}
}
for (auto it = clipIDs.begin(); it != clipIDs.end(); ++it) {
auto& childId = it->first;
auto& childClip = it->second;
// Loop through all preceding stencils, and find all parents.
for (auto parentIt = std::reverse_iterator<decltype(it)>(it);
parentIt != clipIDs.rend(); ++parentIt) {
auto& parentId = parentIt->first;
if (childId.isChildOf(parentId)) {
// Once we have a parent, we add the bits that this ID hasn't set yet.
const auto& parentClip = parentIt->second;
const auto mask = ~(childClip.mask & parentClip.mask);
childClip.reference |= mask & parentClip.reference;
childClip.mask |= parentClip.mask;
}
}
}
// Remove tiles that are entirely covered by children.
util::erase_if(clipIDs, [&](const auto& stencil) {
return algorithm::coveredByChildren(stencil.first, clipIDs);
});
return clipIDs;
}
} // namespace algorithm
} // namespace mbgl
|