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
17#include "HeightSource.h"
18
19class HeightField;
20class QImage;
21class QNetworkAccessManager;
22class QNetworkReply;
23
41{
42 Q_OBJECT
43
44public:
46 explicit TerrariumTileFetcher(QObject* parent = nullptr, QNetworkAccessManager* networkManager = nullptr);
47
49 static constexpr int kMaxTileZoom = 15;
50
52 static constexpr int kMaxGridSize = 256;
53
54 int requestPatchHeights(const TileMath::TileKey& key, int gridSize) final;
55 void cancelRequest(int requestId) final;
56
61 bool requestTile(const TileMath::TileKey& key) override;
62
63 int pendingCount() const { return _pending.count(); }
64
67 TileMath::TileKey lastFetchKey() const { return _lastFetchKey; }
68
69private:
70 struct PendingRequest
71 {
72 TileMath::TileKey fetchKey;
73 QRectF subWindow;
74 int gridSize = 0;
75 };
76
77 void _failAsync(int requestId);
78 bool _fetchInFlight(const TileMath::TileKey& fetchKey) const;
79 bool _startFetch(const TileMath::TileKey& fetchKey);
80 void _fetchFromNetwork(const TileMath::TileKey& fetchKey);
81 void _deliverAll(const TileMath::TileKey& fetchKey, const QImage& image);
82 void _failAll(const TileMath::TileKey& fetchKey, const QString& reason);
83 void _deliver(int requestId, const QImage& image);
84 void _finishFailed(int requestId);
85 bool _shouldWarnFailure();
86
87 static constexpr int kFailureWarnIntervalMs = 10000;
88
89 QNetworkAccessManager* _networkManager = nullptr;
90 const int _mapId;
91 QHash<int, PendingRequest> _pending;
92 QHash<TileMath::TileKey, QList<int>> _waiters;
93 QSet<TileMath::TileKey> _fieldRequests;
94 QHash<TileMath::TileKey, QNetworkReply*> _activeReplies;
95 TileMath::TileKey _lastFetchKey;
96 QElapsedTimer _failureWarnTimer;
97};
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
Request the vertex height grid for a patch. Returns a request id (> 0).