QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ElevationTilePyramid.h
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10#pragma once
11
12#include <QtCore/QHash>
13#include <QtCore/QList>
14#include <QtCore/QRectF>
15#include <QtCore/QSet>
16
17#include <utility>
18
19#include "TileMath.h"
20
36{
37public:
40 static constexpr int kMaxTiles = 128;
41
43 struct Grid
44 {
45 int width = 0;
46 int height = 0;
47 QList<float> heights;
48
49 bool isValid() const { return (width > 0) && (height > 0) && (heights.size() == qsizetype(width) * height); }
50 };
51
54 struct View
55 {
56 const Grid* grid = nullptr;
58 QRectF subWindow;
59
60 bool isValid() const { return grid != nullptr; }
61 };
62
66 bool insertTile(const TileMath::TileKey& key, Grid grid, TileMath::TileKey* evictedKey = nullptr);
67
68 bool hasTile(const TileMath::TileKey& key) const { return _tiles.contains(key); }
69
72 View bestTileFor(const TileMath::TileKey& key) const;
73
74 int tileCount() const { return static_cast<int>(_tiles.count()); }
75
79 void setPinnedKeys(QSet<TileMath::TileKey> keys) { _pinnedKeys = std::move(keys); }
80
83 bool hasDescendant(const TileMath::TileKey& key) const { return _descendantCounts.value(key, 0) > 0; }
84
87 qint64 lookupCountForTest() const { return _lookupCount; }
88
89private:
90 TileMath::TileKey _evictLeastRecentlyUsed();
91
92 QHash<TileMath::TileKey, Grid> _tiles;
93 QHash<TileMath::TileKey, int> _descendantCounts;
94 QSet<TileMath::TileKey> _pinnedKeys;
95 mutable QHash<TileMath::TileKey, qint64> _lastUsed;
96 mutable qint64 _useTick = 0;
97 mutable qint64 _lookupCount = 0;
98};
View bestTileFor(const TileMath::TileKey &key) const
bool hasTile(const TileMath::TileKey &key) const
bool insertTile(const TileMath::TileKey &key, Grid grid, TileMath::TileKey *evictedKey=nullptr)
static constexpr int kMaxTiles
void setPinnedKeys(QSet< TileMath::TileKey > keys)
bool hasDescendant(const TileMath::TileKey &key) const
qint64 lookupCountForTest() const
Decoded elevation samples for one tile, row-major from the NW corner.
const Grid * grid
null when nothing stored covers the query
TileMath::TileKey key
stored tile the view samples