QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TerrariumTileFetcher.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/QElapsedTimer>
13#include <QtCore/QHash>
14#include <QtCore/QRectF>
15#include <QtCore/QSet>
16
18#include "HeightSource.h"
19
20class HeightField;
21class QImage;
22class QNetworkAccessManager;
23class QNetworkReply;
24
42{
43 Q_OBJECT
44
45public:
47 explicit TerrariumTileFetcher(QObject* parent = nullptr, QNetworkAccessManager* networkManager = nullptr);
48
50 static constexpr int kMaxTileZoom = 15;
51
55 static constexpr int kAnchorZoom = 10;
56
58 static constexpr int kMaxGridSize = 256;
59
60 int requestPatchHeights(const TileMath::TileKey& key, int gridSize) final;
61 void cancelRequest(int requestId) final;
62
67 bool requestTile(const TileMath::TileKey& key) override;
68
69 int pendingCount() const { return _pending.count(); }
70
73 TileMath::TileKey lastFetchKey() const { return _lastFetchKey; }
74
75private:
76 struct PendingRequest
77 {
78 TileMath::TileKey fetchKey;
79 QRectF subWindow;
80 int gridSize = 0;
81 };
82
83 struct HeldTile
84 {
86 QSet<TileMath::TileKey> anchors;
87 };
88
89 void _insertIntoField(const TileMath::TileKey& fetchKey, ElevationTilePyramid::Grid grid);
92 int _releaseHeld(const TileMath::TileKey& anchor);
93 void _failAsync(int requestId);
94 bool _fetchInFlight(const TileMath::TileKey& fetchKey) const;
95 bool _startFetch(const TileMath::TileKey& fetchKey);
96 void _fetchFromNetwork(const TileMath::TileKey& fetchKey);
97 void _deliverAll(const TileMath::TileKey& fetchKey, const QImage& image);
98 void _failAll(const TileMath::TileKey& fetchKey, const QString& reason);
99 void _deliver(int requestId, const QImage& image);
100 void _finishFailed(int requestId);
101 bool _shouldWarnFailure();
102
103 static constexpr int kFailureWarnIntervalMs = 10000;
104
105 QNetworkAccessManager* _networkManager = nullptr;
106 const int _mapId;
107 QHash<int, PendingRequest> _pending;
108 QHash<TileMath::TileKey, QList<int>> _waiters;
109 QSet<TileMath::TileKey> _fieldRequests;
110 QHash<TileMath::TileKey, HeldTile> _held;
111 QHash<TileMath::TileKey, QNetworkReply*> _activeReplies;
112 TileMath::TileKey _lastFetchKey;
113 QElapsedTimer _failureWarnTimer;
114};
static constexpr int kAnchorZoom
static constexpr int kMaxGridSize
Largest supported patch grid (matches PatchGeometry::kMaxGridSize)
static constexpr int kMaxTileZoom
Highest zoom the terrarium dataset serves (deeper patches sample the ancestor)
TileMath::TileKey lastFetchKey() const
bool requestTile(const TileMath::TileKey &key) override
void cancelRequest(int requestId) final
Cancel a pending request. No signal is emitted for a cancelled request.
int requestPatchHeights(const TileMath::TileKey &key, int gridSize) final
Decoded elevation samples for one tile, row-major from the NW corner.