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 "PatchSampler.h"
20#include "TileMath.h"
21
35class HeightField : public QObject
36{
37 Q_OBJECT
38 // Passed through QML as an opaque pointer (PatchGeometry.heightField)
39 QML_ANONYMOUS
40
41public:
42 explicit HeightField(QObject* parent = nullptr);
43
45 static constexpr int kMaxGridSize = 4096;
46
52
55 void setPinnedKeys(QSet<TileMath::TileKey> keys) { _pyramid.setPinnedKeys(std::move(keys)); }
56
59 double heightAt(const QPointF& world) const;
60
70 QList<float> samplePatch(const TileMath::TileKey& key, int gridSize,
71 PatchSampler::EdgeStep* edgeStep = nullptr) const;
72
73 int tileCount() const { return _pyramid.tileCount(); }
74
76 bool hasTile(const TileMath::TileKey& key) const { return _pyramid.hasTile(key); }
77
81 {
82 const ElevationTilePyramid::View view = _pyramid.bestTileFor(key);
83 return view.isValid() ? view.key : TileMath::TileKey{0, 0, -1};
84 }
85
89 qint64 lookupCountForTest() const { return _pyramid.lookupCountForTest(); }
90
91signals:
97 void regionChanged(const QRectF& worldRect);
98
99private:
100 ElevationTilePyramid _pyramid;
101
102 // Memoized last resolved view: adjacent sample positions almost always
103 // resolve to the same stored tile, so heightAt reuses it when the query
104 // key resolves to it (same arithmetic as the full lookup). Only populated
105 // when the tile has no stored descendant (nothing finer could override
106 // it), and invalidated on every insert (the view's grid pointer is only
107 // valid until then).
108 mutable ElevationTilePyramid::View _memoView;
109 mutable double _memoMinX = 0.0;
110 mutable double _memoMaxY = 0.0;
111 mutable double _memoSpan = 0.0;
112};
std::array< MsgOutKey, 4 > keys
Definition UBXPlan.cc:13
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)
QList< float > samplePatch(const TileMath::TileKey &key, int gridSize, PatchSampler::EdgeStep *edgeStep=nullptr) const
void setPinnedKeys(QSet< TileMath::TileKey > keys)
Definition HeightField.h:55
qint64 lookupCountForTest() const
Definition HeightField.h:89
bool hasTile(const TileMath::TileKey &key) const
True when the backing pyramid holds this exact tile.
Definition HeightField.h:76
int tileCount() const
Definition HeightField.h:73
double heightAt(const QPointF &world) const
static constexpr int kMaxGridSize
Sanity cap on patch density: rejects absurd sizes before allocation.
Definition HeightField.h:45
void regionChanged(const QRectF &worldRect)
TileMath::TileKey backingKeyFor(const TileMath::TileKey &key) const
Definition HeightField.h:80
Decoded elevation samples for one tile, row-major from the NW corner.
TileMath::TileKey key
stored tile the view samples