|
22 | 22 |
|
23 | 23 | namespace nucleus::tile::drawing {
|
24 | 24 |
|
25 |
| -std::vector<TileBounds> generate_list(const camera::Definition& camera, utils::AabbDecoratorPtr aabb_decorator, unsigned int max_zoom_level) |
| 25 | +std::vector<tile::Id> generate_list(const camera::Definition& camera, utils::AabbDecoratorPtr aabb_decorator, unsigned int max_zoom_level) |
26 | 26 | {
|
27 | 27 | const auto tile_refine_functor = tile::utils::refineFunctor(camera, aabb_decorator, 1, 256, max_zoom_level);
|
| 28 | + return radix::quad_tree::onTheFlyTraverse(tile::Id { 0, { 0, 0 } }, tile_refine_functor, [](const tile::Id& v) { return v.children(); }); |
| 29 | +} |
| 30 | + |
| 31 | +std::vector<TileBounds> compute_bounds(const std::vector<Id>& tiles, utils::AabbDecoratorPtr aabb_decorator) |
| 32 | +{ |
| 33 | + std::vector<TileBounds> bounded_tiles; |
| 34 | + bounded_tiles.reserve(tiles.size()); |
| 35 | + for (const auto& t : tiles) { |
| 36 | + bounded_tiles.emplace_back(t, aabb_decorator->aabb(t)); |
| 37 | + } |
| 38 | + return bounded_tiles; |
| 39 | +} |
28 | 40 |
|
29 |
| - auto tiles = radix::quad_tree::onTheFlyTraverse(tile::Id { 0, { 0, 0 } }, tile_refine_functor, [](const tile::Id& v) { return v.children(); }); |
| 41 | +std::vector<tile::Id> limit(std::vector<tile::Id> tiles, uint max_n_tiles) |
| 42 | +{ |
| 43 | + if (tiles.size() < max_n_tiles) |
| 44 | + return tiles; |
30 | 45 |
|
31 |
| - if (tiles.size() > max_n_tiles) { |
32 |
| - std::sort(tiles.begin(), tiles.end(), [&](const tile::Id& a, const tile::Id& b) { return a.zoom_level > b.zoom_level; }); |
33 |
| - std::unordered_set<tile::Id, tile::Id::Hasher> id_set; |
34 |
| - id_set.reserve(tiles.size()); |
35 |
| - for (const auto t : tiles) { |
36 |
| - id_set.insert(t); |
| 46 | + std::sort(tiles.begin(), tiles.end(), [&](const tile::Id& a, const tile::Id& b) { return a.zoom_level > b.zoom_level; }); |
| 47 | + std::unordered_set<tile::Id, tile::Id::Hasher> id_set; |
| 48 | + id_set.reserve(tiles.size()); |
| 49 | + for (const auto t : tiles) { |
| 50 | + id_set.insert(t); |
| 51 | + } |
| 52 | + const auto all_in_set = [&](const std::array<Id, 4>& siblings) { |
| 53 | + for (const auto& s : siblings) { |
| 54 | + if (!id_set.contains(s)) |
| 55 | + return false; |
37 | 56 | }
|
38 |
| - const auto all_in_set = [&](const std::array<Id, 4>& siblings) { |
39 |
| - for (const auto& s : siblings) { |
40 |
| - if (!id_set.contains(s)) |
41 |
| - return false; |
42 |
| - } |
43 |
| - return true; |
44 |
| - }; |
45 |
| - const auto remove = [&](const std::array<Id, 4>& siblings) { |
46 |
| - for (const auto& s : siblings) { |
47 |
| - const auto pos = std::find(tiles.crbegin(), tiles.crend(), s); |
48 |
| - tiles.erase(std::next(pos).base()); |
49 |
| - id_set.erase(s); |
50 |
| - } |
51 |
| - return true; |
52 |
| - }; |
| 57 | + return true; |
| 58 | + }; |
| 59 | + const auto remove = [&](const std::array<Id, 4>& siblings) { |
| 60 | + for (const auto& s : siblings) { |
| 61 | + const auto pos = std::find(tiles.crbegin(), tiles.crend(), s); |
| 62 | + tiles.erase(std::next(pos).base()); |
| 63 | + id_set.erase(s); |
| 64 | + } |
| 65 | + return true; |
| 66 | + }; |
53 | 67 |
|
54 |
| - while (tiles.size() > max_n_tiles) { |
55 |
| - for (auto it = tiles.crbegin(); it != tiles.crend(); ++it) { |
56 |
| - const auto parent = (*it).parent(); |
57 |
| - const auto siblings = parent.children(); |
58 |
| - if (all_in_set(siblings)) { |
59 |
| - remove(siblings); |
60 |
| - tiles.push_back(parent); |
61 |
| - id_set.insert(parent); |
62 |
| - break; |
63 |
| - } |
| 68 | + while (tiles.size() > max_n_tiles) { |
| 69 | + for (auto it = tiles.crbegin(); it != tiles.crend(); ++it) { |
| 70 | + const auto parent = (*it).parent(); |
| 71 | + const auto siblings = parent.children(); |
| 72 | + if (all_in_set(siblings)) { |
| 73 | + remove(siblings); |
| 74 | + tiles.push_back(parent); |
| 75 | + id_set.insert(parent); |
| 76 | + break; |
64 | 77 | }
|
65 | 78 | }
|
66 | 79 | }
|
| 80 | + return tiles; |
| 81 | +} |
| 82 | + |
| 83 | +std::vector<TileBounds> cull(std::vector<TileBounds> tiles, const camera::Definition& camera) |
| 84 | +{ |
| 85 | + std::vector<TileBounds> culled_tiles; |
| 86 | + culled_tiles.reserve(tiles.size()); |
| 87 | + const auto frustum = camera.frustum(); |
67 | 88 |
|
68 |
| - std::vector<TileBounds> bounded_tiles; |
69 |
| - bounded_tiles.reserve(tiles.size()); |
70 | 89 | for (const auto& t : tiles) {
|
71 |
| - bounded_tiles.emplace_back(t, aabb_decorator->aabb(t)); |
| 90 | + if (tile::utils::camera_frustum_contains_tile(frustum, t.bounds)) |
| 91 | + culled_tiles.push_back(t); |
72 | 92 | }
|
73 |
| - return bounded_tiles; |
| 93 | + |
| 94 | + return culled_tiles; |
74 | 95 | }
|
75 | 96 |
|
76 | 97 | std::vector<TileBounds> sort(std::vector<TileBounds> list, const glm::dvec3& camera_position)
|
|
0 commit comments