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
36 virtual int requestPatchHeights(const TileMath::TileKey& key, int gridSize) = 0;
37
39 virtual void cancelRequest(int requestId) = 0;
40
42 void setHeightField(HeightField* field) { _heightField = field; }
43
47 virtual bool requestTile(const TileMath::TileKey& key)
48 {
49 Q_UNUSED(key);
50 return false;
51 }
52
53signals:
55 void patchHeightsReady(int requestId, const QList<float>& heights);
56 void patchHeightsFailed(int requestId);
57
58protected:
59 int _nextRequestId();
60
62
63private:
64 int _requestIdCounter = 0;
65};
66
70{
71 Q_OBJECT
72
73public:
75
76 static constexpr int kSynthGridSize = 33;
77
78 int requestPatchHeights(const TileMath::TileKey& key, int gridSize) final;
79 void cancelRequest(int requestId) final;
80
83 bool requestTile(const TileMath::TileKey& key) override;
84
85protected:
87 virtual float heightAtWorld(const QPointF& world) const = 0;
88
89private:
90 void _deliver(int requestId);
91
92 QHash<int, QList<float>> _pending;
93};
94
97{
98 Q_OBJECT
99
100public:
101 using ProceduralHeightSource::ProceduralHeightSource;
102
105 bool requestTile(const TileMath::TileKey& key) override
106 {
107 Q_UNUSED(key);
108 return false;
109 }
110
111protected:
112 float heightAtWorld(const QPointF& world) const override;
113};
114
118{
119 Q_OBJECT
120
121public:
122 using ProceduralHeightSource::ProceduralHeightSource;
123
124 static constexpr double kAmplitude = 200.0;
125 static constexpr double kWavelength = 4000.0;
126
127protected:
128 float heightAtWorld(const QPointF& world) const override;
129};
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
Request the vertex height grid for a patch. Returns a request id (> 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
Request the vertex height grid for a patch. Returns a request id (> 0).
bool requestTile(const TileMath::TileKey &key) override