QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SurfaceModel.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/QObject>
15#include <QtCore/QRectF>
16
17#include <optional>
18
19#include "TileMath.h"
20
21class GeoMapCamera;
22class HeightField;
23class HeightSource;
24
43class SurfaceModel : public QObject
44{
45 Q_OBJECT
46
47public:
48 SurfaceModel(GeoMapCamera* camera, HeightSource* heightSource, HeightField* field, QObject* parent = nullptr);
49
50 static constexpr int kGridSize = 16;
54 static constexpr int kMaxPatches = 256;
60 static constexpr int kMaxPatchAddsPerUpdate = 2;
65 static constexpr int kMaxPatchRemovalsPerUpdate = 4;
66 static constexpr double kRefinePixelThreshold = 384.0;
67 static constexpr double kMaxRangeMultiplier = 40.0;
68 static constexpr int kVisibleSampleGrid = 5;
71 static constexpr double kRecullHeightMargin = 25.0;
72
73 struct Patch
74 {
76 QList<float> heights;
79 bool ready = true;
80 bool covered = false;
81 };
82
87 void update();
88
90 bool updateSettled() const { return !_updatePending && !_addsDeferred && !_removalsDeferred; }
91
92 QList<Patch> patches() const;
93
95 std::optional<Patch> patch(const TileMath::TileKey& key) const;
96
100 QList<int> edgeLodDeltas(const TileMath::TileKey& key) const;
101
104 {
105 int updates = 0;
106 qint64 totalUs = 0;
107 qint64 maxUs = 0;
108 };
109
112
114 QRectF visibleGroundRect() const { return _visibleGroundRect(_maxTerrainZ()); }
115
116 int patchCount() const { return _patches.count(); }
117
120 int pendingCount() const { return 0; }
121
122#ifdef QGC_UNITTEST_BUILD
125 void drainUpdates()
126 {
127 int guard = kMaxPatches;
128 do {
129 update();
130 } while ((_addsDeferred || _removalsDeferred) && (--guard > 0));
131 }
132#endif
133
134signals:
142
143private slots:
144 void _fieldRegionChanged(const QRectF& worldRect);
145
146private:
147 struct PatchData
148 {
149 QList<float> heights;
150 float maxHeight = 0.0f;
151 };
152
153 double _projectedPixels(const TileMath::TileKey& key, const QPointF& cameraGround, double cameraHeight) const;
154 QList<TileMath::TileKey> _desiredPatches(const QRectF& visible, const QPointF& cameraGround,
155 double cameraHeight) const;
156 QRectF _visibleGroundRect(double terrainZ) const;
157 double _maxTerrainZ() const;
158 int _edgeDelta(const TileMath::TileKey& key, int dx, int dy) const;
159 void _scheduleUpdate();
160
161 GeoMapCamera* const _camera;
162 HeightSource* const _heightSource;
163 HeightField* const _field;
164 QHash<TileMath::TileKey, PatchData> _patches;
165 UpdateStats _updateStats;
166 bool _updatePending = false;
167 bool _addsDeferred = false;
168 bool _removalsDeferred = false;
169 int _removalsThisPass = 0;
170 double _culledTerrainZ = 0.0;
171};
static constexpr double kRecullHeightMargin
static constexpr int kMaxPatchAddsPerUpdate
static constexpr double kMaxRangeMultiplier
visible-range cap in camera distances
std::optional< Patch > patch(const TileMath::TileKey &key) const
Single-patch lookup; std::nullopt when the key is not resident.
static constexpr int kMaxPatchRemovalsPerUpdate
static constexpr int kGridSize
QList< Patch > patches() const
bool updateSettled() const
False while a scheduled update pass or deferred patch churn is outstanding.
void patchEdgeDeltasChanged(const TileMath::TileKey &key)
QList< int > edgeLodDeltas(const TileMath::TileKey &key) const
void patchRemoved(const TileMath::TileKey &key)
int pendingCount() const
static constexpr int kVisibleSampleGrid
int patchCount() const
void patchAdded(const TileMath::TileKey &key)
static constexpr double kRefinePixelThreshold
subdivide above this projected size
void patchMeshChanged(const TileMath::TileKey &key)
The patch's mesh content changed (heights re-sampled): consumers must re-pull heights.
QRectF visibleGroundRect() const
Estimated visible ground region in world meters (see class comment)
UpdateStats takeUpdateStats()
Returns the counters accumulated since the previous call and resets them.
static constexpr int kMaxPatches
TileMath::TileKey key
bool covered
always false (see ready)
QList< float > heights
update() call/duration counters for the perf overlay