QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
HeightSource.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
16#include "TileMath.h"
17
18class HeightField;
19
28class HeightSource : public QObject
29{
30 Q_OBJECT
31
32public:
33 explicit HeightSource(QObject* parent = nullptr);
34
37 virtual int requestPatchHeights(const TileMath::TileKey& key, int gridSize) = 0;
38
40 virtual void cancelRequest(int requestId) = 0;
41
43 void setHeightField(HeightField* field) { _heightField = field; }
44
48 virtual bool requestTile(const TileMath::TileKey& key)
49 {
50 Q_UNUSED(key);
51 return false;
52 }
53
54signals:
56 void patchHeightsReady(int requestId, const QList<float>& heights);
57 void patchHeightsFailed(int requestId);
58
59protected:
60 int _nextRequestId();
61
63
64private:
65 int _requestIdCounter = 0;
66};
67
71{
72 Q_OBJECT
73
74public:
76
77 static constexpr int kSynthGridSize = 33;
78
79 int requestPatchHeights(const TileMath::TileKey& key, int gridSize) final;
80 void cancelRequest(int requestId) final;
81
84 bool requestTile(const TileMath::TileKey& key) override;
85
86protected:
88 virtual float heightAtWorld(const QPointF& world) const = 0;
89
90private:
91 void _deliver(int requestId);
92
93 QHash<int, QList<float>> _pending;
94};
95
98{
99 Q_OBJECT
100
101public:
102 using ProceduralHeightSource::ProceduralHeightSource;
103
106 bool requestTile(const TileMath::TileKey& key) override
107 {
108 Q_UNUSED(key);
109 return false;
110 }
111
112protected:
113 float heightAtWorld(const QPointF& world) const override;
114};
115
119{
120 Q_OBJECT
121
122public:
123 using ProceduralHeightSource::ProceduralHeightSource;
124
125 static constexpr double kAmplitude = 200.0;
126 static constexpr double kWavelength = 4000.0;
127
128protected:
129 float heightAtWorld(const QPointF& world) const override;
130};
float heightAtWorld(const QPointF &world) const override
Height in meters at a world-space ground position.
static constexpr double kWavelength
hill spacing (world m)
static constexpr double kAmplitude
peak height (m)
z=0 everywhere (Milestone 1 default)
bool requestTile(const TileMath::TileKey &key) override
float heightAtWorld(const QPointF &world) const override
Height in meters at a world-space ground position.
void patchHeightsReady(int requestId, const QList< float > &heights)
heights has (gridSize+1)^2 entries, row-major from the north-west corner
virtual void cancelRequest(int requestId)=0
Cancel a pending request. No signal is emitted for a cancelled request.
void patchHeightsFailed(int requestId)
virtual int requestPatchHeights(const TileMath::TileKey &key, int gridSize)=0
virtual bool requestTile(const TileMath::TileKey &key)
HeightField * _heightField
tile delivery target for requestTile (not owned)
void setHeightField(HeightField *field)
Field that receives whole tiles requested via requestTile (not owned)
HeightSource(QObject *parent=nullptr)
int _nextRequestId()
static constexpr int kSynthGridSize
samples per edge of a synthesized tile
void cancelRequest(int requestId) final
Cancel a pending request. No signal is emitted for a cancelled request.
virtual float heightAtWorld(const QPointF &world) const =0
Height in meters at a world-space ground position.
int requestPatchHeights(const TileMath::TileKey &key, int gridSize) final
bool requestTile(const TileMath::TileKey &key) override