QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
Viewer3DTerrainTexture.cc
Go to the documentation of this file.
2
3#include "Fact.h"
4#include "FlightMapSettings.h"
6#include "QGCMapEngine.h"
7#include "QGCMapUrlEngine.h"
8#include "SettingsManager.h"
10#include "Viewer3DTileQuery.h"
12
13QGC_LOGGING_CATEGORY(Viewer3DTerrainTextureLog, "Viewer3d.Viewer3DTerrainTexture")
14
16 : _flightMapSettings(SettingsManager::instance()->flightMapSettings())
17{
18 _onMapTypeChanged();
19
20 connect(_flightMapSettings->mapType(), &Fact::rawValueChanged, this, &Viewer3DTerrainTexture::_onMapTypeChanged);
21}
22
24{
25 _setTextureLoaded(false);
28
29 if (!_mapProvider || !_mapProvider->mapLoaded()) {
30 qCDebug(Viewer3DTerrainTextureLog) << "loadTexture: no map provider or map not loaded";
31 return;
32 }
33
34 if (!_terrainTileLoader) {
35 _terrainTileLoader = new Viewer3DTileQuery(this);
36 }
37
38 connect(_terrainTileLoader, &Viewer3DTileQuery::loadingMapCompleted, this, &Viewer3DTerrainTexture::_updateTexture, Qt::UniqueConnection);
39 connect(_terrainTileLoader, &Viewer3DTileQuery::textureGeometryReady, this, &Viewer3DTerrainTexture::setTextureGeometry, Qt::UniqueConnection);
40 connect(_terrainTileLoader, &Viewer3DTileQuery::mapTileDownloaded, this, &Viewer3DTerrainTexture::setTextureDownloadProgress, Qt::UniqueConnection);
41
42 const auto [bbMin, bbMax] = _mapProvider->mapBoundingBox();
43 _terrainTileLoader->adaptiveMapTilesLoader(_mapType, _mapId, bbMin, bbMax);
44}
45
46void Viewer3DTerrainTexture::_updateTexture()
47{
48 qCDebug(Viewer3DTerrainTextureLog) << "Texture loaded:" << _terrainTileLoader->mapSize();
49 setSize(_terrainTileLoader->mapSize());
50 setFormat(QQuick3DTextureData::RGBA32F);
51 setHasTransparency(false);
52
53 setTextureData(_terrainTileLoader->mapData());
54 _setTextureLoaded(true);
57 disconnect(_terrainTileLoader, &Viewer3DTileQuery::loadingMapCompleted, this, &Viewer3DTerrainTexture::_updateTexture);
58
59 _terrainTileLoader->deleteLater();
60 _terrainTileLoader = nullptr;
62}
63
64void Viewer3DTerrainTexture::_onMapTypeChanged()
65{
66 _mapType = _flightMapSettings->mapProvider()->rawValue().toString()
67 + QStringLiteral(" ")
68 + _flightMapSettings->mapType()->rawValue().toString();
69
70 const int mapId = UrlFactory::getQtMapIdFromProviderType(_mapType);
71
72 if (mapId == _mapId) {
73 return;
74 }
75
76 qCDebug(Viewer3DTerrainTextureLog) << "Map type changed:" << _mapType << "mapId:" << mapId;
77 _mapId = mapId;
79}
80
81void Viewer3DTerrainTexture::setRoiMinCoordinate(const QGeoCoordinate &newRoiMinCoordinate)
82{
83 if (_roiMinCoordinate == newRoiMinCoordinate) {
84 return;
85 }
86 _roiMinCoordinate = newRoiMinCoordinate;
88}
89
90void Viewer3DTerrainTexture::setRoiMaxCoordinate(const QGeoCoordinate &newRoiMaxCoordinate)
91{
92 if (_roiMaxCoordinate == newRoiMaxCoordinate) {
93 return;
94 }
95 _roiMaxCoordinate = newRoiMaxCoordinate;
97}
98
100{
101 if (_mapProvider == newMapProvider) {
102 return;
103 }
104
105 if (_mapProvider) {
107 }
108
109 _mapProvider = newMapProvider;
110
111 if (_mapProvider) {
113 // Handle late binding: provider may already have a loaded map before this object is wired.
114 loadTexture();
115 }
116
117 emit mapProviderChanged();
118}
119
120void Viewer3DTerrainTexture::setTileCount(const QSize &newTileCount)
121{
122 if (_tileCount == newTileCount) {
123 return;
124 }
125 _tileCount = newTileCount;
126 emit tileCountChanged();
127}
128
129void Viewer3DTerrainTexture::setTextureGeometryDone(bool newTextureGeometryDone)
130{
131 if (_textureGeometryDone == newTextureGeometryDone) {
132 return;
133 }
134 _textureGeometryDone = newTextureGeometryDone;
136}
137
138void Viewer3DTerrainTexture::setTextureDownloadProgress(float newTextureDownloadProgress)
139{
140 if (qFuzzyCompare(_textureDownloadProgress, newTextureDownloadProgress)) {
141 return;
142 }
143 _textureDownloadProgress = newTextureDownloadProgress;
145}
146
#define QGC_LOGGING_CATEGORY(name, categoryStr)
void rawValueChanged(const QVariant &value)
Provides access to all app settings.
static int getQtMapIdFromProviderType(QStringView type)
virtual std::pair< QGeoCoordinate, QGeoCoordinate > mapBoundingBox() const =0
virtual bool mapLoaded() const =0
void setRoiMinCoordinate(const QGeoCoordinate &newRoiMinCoordinate)
void setTextureGeometryDone(bool newTextureGeometryDone)
void setRoiMaxCoordinate(const QGeoCoordinate &newRoiMaxCoordinate)
void setTextureGeometry(const Viewer3DTileStatistics &tileInfo)
void textureDownloadProgressChanged()
void setTextureDownloadProgress(float newTextureDownloadProgress)
void setTileCount(const QSize &newTileCount)
void setMapProvider(Viewer3DMapProvider *newMapProvider)
void textureGeometryReady(TileStatistics_t tileInfo)
void mapTileDownloaded(float progress)
void adaptiveMapTilesLoader(const QString &mapType, int mapId, const QGeoCoordinate &coordinateMin, const QGeoCoordinate &coordinateMax)
QByteArray mapData() const
QSize mapSize() const
void loadingMapCompleted()