QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
HeightField.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 <QtCore/QObject>
14#include <QtCore/QPointF>
15#include <QtCore/QRectF>
16#include <QtQmlIntegration/QtQmlIntegration>
17
19#include "TileMath.h"
20
34class HeightField : public QObject
35{
36 Q_OBJECT
37 // Passed through QML as an opaque pointer (PatchGeometry.heightField)
38 QML_ANONYMOUS
39
40public:
41 explicit HeightField(QObject* parent = nullptr);
42
44 static constexpr int kMaxGridSize = 4096;
45
51
54 void setPinnedKeys(QSet<TileMath::TileKey> keys) { _pyramid.setPinnedKeys(std::move(keys)); }
55
58 double heightAt(const QPointF& world) const;
59
66 QList<float> samplePatch(const TileMath::TileKey& key, int gridSize) const;
67
68 int tileCount() const { return _pyramid.tileCount(); }
69
71 bool hasTile(const TileMath::TileKey& key) const { return _pyramid.hasTile(key); }
72
76 {
77 const ElevationTilePyramid::View view = _pyramid.bestTileFor(key);
78 return view.isValid() ? view.key : TileMath::TileKey{0, 0, -1};
79 }
80
84 qint64 lookupCountForTest() const { return _pyramid.lookupCountForTest(); }
85
86signals:
92 void regionChanged(const QRectF& worldRect);
93
94private:
95 ElevationTilePyramid _pyramid;
96
97 // Memoized last resolved view: adjacent sample positions almost always
98 // resolve to the same stored tile, so heightAt reuses it when the query
99 // key resolves to it (same arithmetic as the full lookup). Only populated
100 // when the tile has no stored descendant (nothing finer could override
101 // it), and invalidated on every insert (the view's grid pointer is only
102 // valid until then).
103 mutable ElevationTilePyramid::View _memoView;
104 mutable double _memoMinX = 0.0;
105 mutable double _memoMaxY = 0.0;
106 mutable double _memoSpan = 0.0;
107};
View bestTileFor(const TileMath::TileKey &key) const
bool hasTile(const TileMath::TileKey &key) const
void setPinnedKeys(QSet< TileMath::TileKey > keys)
qint64 lookupCountForTest() const
bool insertTile(const TileMath::TileKey &key, ElevationTilePyramid::Grid grid)
void setPinnedKeys(QSet< TileMath::TileKey > keys)
Definition HeightField.h:54
qint64 lookupCountForTest() const
Definition HeightField.h:84
bool hasTile(const TileMath::TileKey &key) const
True when the backing pyramid holds this exact tile.
Definition HeightField.h:71
int tileCount() const
Definition HeightField.h:68
QList< float > samplePatch(const TileMath::TileKey &key, int gridSize) const
double heightAt(const QPointF &world) const
static constexpr int kMaxGridSize
Sanity cap on patch density: rejects absurd sizes before allocation.
Definition HeightField.h:44
void regionChanged(const QRectF &worldRect)
TileMath::TileKey backingKeyFor(const TileMath::TileKey &key) const
Definition HeightField.h:75
Decoded elevation samples for one tile, row-major from the NW corner.
TileMath::TileKey key
stored tile the view samples