QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PatchGeometry.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/QList>
13#include <QtQuick3D/QQuick3DGeometry>
14
15#include <array>
16
17#include "TileMath.h"
18
19class HeightField;
20
21Q_MOC_INCLUDE("HeightField.h")
22
23
38class PatchGeometry : public QQuick3DGeometry
39{
40 Q_OBJECT
41 QML_ELEMENT
42 Q_PROPERTY(int gridSize READ gridSize WRITE setGridSize NOTIFY gridSizeChanged)
43 Q_PROPERTY(qreal span READ span WRITE setSpan NOTIFY spanChanged)
44 Q_PROPERTY(QList<float> heights READ heights WRITE setHeights NOTIFY heightsChanged)
45 Q_PROPERTY(QList<int> edgeLodDeltas READ edgeLodDeltas WRITE setEdgeLodDeltas NOTIFY edgeLodDeltasChanged)
46 Q_PROPERTY(HeightField* heightField READ heightField WRITE setHeightField NOTIFY heightFieldChanged)
47
48public:
49 explicit PatchGeometry(QQuick3DObject* parent = nullptr);
50
51 static constexpr int kMinGridSize = 1;
52 static constexpr int kMaxGridSize = 256;
53 static constexpr double kSkirtDepthFraction =
54 0.05;
55
56 int gridSize() const { return _gridSize; }
57
58 void setGridSize(int gridSize);
59
60 qreal span() const { return _span; }
61
62 void setSpan(qreal span);
63
65 QList<float> heights() const { return _heights; }
66
67 void setHeights(const QList<float>& heights);
68
70 HeightField* heightField() const { return _heightField; }
71
72 void setHeightField(HeightField* heightField);
73
77 bool sampleFromField(const TileMath::TileKey& key);
78
84 void setEdgeLodDeltas(int north, int south, int west, int east);
85
87 QList<int> edgeLodDeltas() const
88 {
89 return {_lodDelta[kNorth], _lodDelta[kSouth], _lodDelta[kWest], _lodDelta[kEast]};
90 }
91
92 void setEdgeLodDeltas(const QList<int>& deltas);
93
94signals:
100
101protected:
102 void componentComplete() override;
103
104private:
106 enum Edge
107 {
108 kNorth,
109 kSouth,
110 kWest,
111 kEast,
112 kEdgeCount
113 };
114
115 void _rebuild();
118 void _requestRebuild();
119 float _heightAt(int row, int col) const;
120 float _rawHeightAt(int row, int col) const;
121
122 int _gridSize = 16;
123 qreal _span = 1000.0;
124 QList<float> _heights;
125 HeightField* _heightField = nullptr;
126 std::array<int, kEdgeCount> _lodDelta{};
127};
static constexpr int kMaxGridSize
Sanity cap on patch density: rejects absurd sizes before allocation.
Definition HeightField.h:44
QList< int > edgeLodDeltas() const
QML-bindable form of the deltas: {north, south, west, east}.
void spanChanged()
HeightField * heightField() const
Field for sampleFromField to sample from; not owned, may be null.
void heightsChanged()
QList< float > heights() const
(gridSize+1)^2 heights row-major from the north-west corner; empty = flat
void gridSizeChanged()
qreal span() const
int gridSize() const
void edgeLodDeltasChanged()
void heightFieldChanged()