QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsdemterraintileloader_p.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdemterraintileloader_p.h
3  --------------------------------------
4  Date : July 2017
5  Copyright : (C) 2017 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSDEMTERRAINTILELOADER_P_H
17 #define QGSDEMTERRAINTILELOADER_P_H
18 
20 
21 //
22 // W A R N I N G
23 // -------------
24 //
25 // This file is not part of the QGIS API. It exists purely as an
26 // implementation detail. This header file may change from version to
27 // version without notice, or even be removed.
28 //
29 
30 #define SIP_NO_FILE
31 
32 #include <QtConcurrent/QtConcurrentRun>
33 #include <QFutureWatcher>
34 #include <QElapsedTimer>
35 #include <QMutex>
36 
37 #include "qgschunknode_p.h"
38 #include "qgsrectangle.h"
39 #include "qgsterraintileloader_p.h"
40 #include "qgstilingscheme.h"
41 
43 class QgsRasterLayer;
46 
52 class QgsDemTerrainTileLoader : public QgsTerrainTileLoader
53 {
54  Q_OBJECT
55  public:
57  QgsDemTerrainTileLoader( QgsTerrainEntity *terrain, QgsChunkNode *node, QgsTerrainGenerator *terrainGenerator );
58 
59  Qt3DCore::QEntity *createEntity( Qt3DCore::QEntity *parent ) override;
60 
61  private slots:
62  void onHeightMapReady( int jobId, const QByteArray &heightMap );
63 
64  private:
65 
66  int mHeightMapJobId;
67  QByteArray mHeightMap;
68  int mResolution;
69  float mSkirtHeight;
70 };
71 
72 
74 
80 class QgsDemHeightMapGenerator : public QObject
81 {
82  Q_OBJECT
83  public:
84 
89  QgsDemHeightMapGenerator( QgsRasterLayer *dtm, const QgsTilingScheme &tilingScheme, int resolution, const QgsCoordinateTransformContext &transformContext );
90  ~QgsDemHeightMapGenerator() override;
91 
93  int render( int x, int y, int z );
94 
96  void waitForFinished();
97 
99  int resolution() const { return mResolution; }
100 
102  float heightAt( double x, double y );
103 
104  signals:
106  void heightMapReady( int jobId, const QByteArray &heightMap );
107 
108  private slots:
109  void onFutureFinished();
110 
111  private:
113  QgsRasterLayer *mDtm = nullptr;
114 
116  QgsRasterDataProvider *mClonedProvider = nullptr;
117 
118  QgsTilingScheme mTilingScheme;
119 
120  int mResolution;
121 
122  int mLastJobId;
123 
124  std::unique_ptr<QgsTerrainDownloader> mDownloader;
125 
126  struct JobData
127  {
128  int jobId;
129  QgsChunkNodeId tileId;
130  QgsRectangle extent;
131  QFuture<QByteArray> future;
132  QElapsedTimer timer;
133  };
134 
135  QHash<QFutureWatcher<QByteArray>*, JobData> mJobs;
136 
137  void lazyLoadDtmCoarseData( int res, const QgsRectangle &rect );
138  mutable QMutex mLazyLoadDtmCoarseDataMutex;
140  QByteArray mDtmCoarseData;
141 };
142 
144 
145 #endif // QGSDEMTERRAINTILELOADER_P_H
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
qgsrectangle.h
QgsTerrainDownloader
3 Takes care of downloading terrain data from a publicly available data source.
Definition: qgsterraindownloader.h:49
qgschunknode_p.h
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsTerrainGenerator
3 Base class for generators of terrain.
Definition: qgsterraingenerator.h:48
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
qgsterraintileloader_p.h
QgsTilingScheme
3 The class encapsulates tiling scheme (just like with WMTS / TMS / XYZ layers).
Definition: qgstilingscheme.h:36
qgstilingscheme.h
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89