QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
TerrainTileManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QMutex>
4#include <QtCore/QObject>
5#include <QtCore/QPointer>
6#include <QtCore/QQueue>
7#include <QtPositioning/QGeoCoordinate>
8
10
11class TerrainTile;
12class QNetworkAccessManager;
13
14class TerrainTileManager : public QObject
15{
16 Q_OBJECT
17public:
18 explicit TerrainTileManager(QObject *parent = nullptr);
20
22
26 bool getAltitudesForCoordinates(const QList<QGeoCoordinate> &coordinates, QList<double> &altitudes, bool &error);
27
28 void addCoordinateQuery(TerrainQueryInterface *terrainQueryInterface, const QList<QGeoCoordinate> &coordinates);
29 void addPathQuery(TerrainQueryInterface *terrainQueryInterface, const QGeoCoordinate &startPoint, const QGeoCoordinate &endPoint);
30 void addCarpetQuery(TerrainQueryInterface *terrainQueryInterface, const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord, bool statsOnly);
31
32private slots:
33 void _terrainDone();
34
35private:
37 static QList<QGeoCoordinate> _pathQueryToCoords(const QGeoCoordinate &fromCoord, const QGeoCoordinate &toCoord, double &distanceBetween, double &finalDistanceBetween);
38 void _tileFailed();
39 void _cacheTile(const QByteArray &data, const QString &hash);
40 TerrainTile *_getCachedTile(const QString &hash);
41 bool _isFailedTile(const QString &hash);
42 bool _recordFailedTile(const QString &hash);
43 void _clearFailedTile(const QString &hash);
44 static void _processCarpetResults(const QList<double> &altitudes, int gridSizeLat, int gridSizeLon,
45 bool statsOnly, double &minHeight, double &maxHeight, QList<QList<double>> &carpet);
46
47 struct QueuedRequestInfo_t {
48 QPointer<TerrainQueryInterface> terrainQueryInterface;
50 double distanceBetween;
51 double finalDistanceBetween;
52 QList<QGeoCoordinate> coordinates;
53 bool carpetStatsOnly;
54 int carpetGridSizeLat;
55 int carpetGridSizeLon;
56 };
57
58 QQueue<QueuedRequestInfo_t> _requestQueue;
60
61 QMutex _tilesMutex;
62 QHash<QString, TerrainTile*> _tiles;
63 QHash<QString, qint64> _failedTiles;
64 qint64 _lastFailedTileSweepMs = 0;
65
66 QNetworkAccessManager *_networkManager = nullptr;
67
68 static constexpr qint64 kFailedTileBackoffMs = 5000;
69};
Error error
Base class for offline/online terrain queries.
bool getAltitudesForCoordinates(const QList< QGeoCoordinate > &coordinates, QList< double > &altitudes, bool &error)
void addPathQuery(TerrainQueryInterface *terrainQueryInterface, const QGeoCoordinate &startPoint, const QGeoCoordinate &endPoint)
void addCarpetQuery(TerrainQueryInterface *terrainQueryInterface, const QGeoCoordinate &swCoord, const QGeoCoordinate &neCoord, bool statsOnly)
static TerrainTileManager * instance()
void addCoordinateQuery(TerrainQueryInterface *terrainQueryInterface, const QList< QGeoCoordinate > &coordinates)