/
qgs3dmapsettings.h
303 lines (261 loc) · 13.2 KB
/
qgs3dmapsettings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/***************************************************************************
qgs3dmapsettings.h
--------------------------------------
Date : July 2017
Copyright : (C) 2017 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGS3DMAPSETTINGS_H
#define QGS3DMAPSETTINGS_H
#include "qgis_3d.h"
#include <memory>
#include <QColor>
#include <QMatrix4x4>
#include "qgscoordinatereferencesystem.h"
#include "qgsmaplayerref.h"
#include "qgsterraingenerator.h"
#include "qgsvector3d.h"
class QgsMapLayer;
class QgsRasterLayer;
class QgsAbstract3DRenderer;
class QgsReadWriteContext;
class QgsProject;
class QDomElement;
/**
* \ingroup 3d
* Definition of the world
*
* \since QGIS 3.0
*/
class _3D_EXPORT Qgs3DMapSettings : public QObject
{
Q_OBJECT
public:
//! Constructor for Qgs3DMapSettings
Qgs3DMapSettings() = default;
//! Copy constructor
Qgs3DMapSettings( const Qgs3DMapSettings &other );
~Qgs3DMapSettings() override;
//! Reads configuration from a DOM element previously written by writeXml()
void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
//! Writes configuration to a DOM element, to be used later with readXml()
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
//! Resolves references to other objects (map layers) after the call to readXml()
void resolveReferences( const QgsProject &project );
/**
* Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
*
* We move the 3D world origin to the center of the extent of our terrain: this is done
* to minimize the impact of numerical errors when operating with 32-bit floats.
* Unfortunately this is not enough when working with a large area (still results in jitter
* with scenes spanning hundreds of kilometers and zooming in a lot).
*
* Need to look into more advanced techniques like "relative to center" or "relative to eye"
* to improve the precision.
*/
void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
//! Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QgsVector3D origin() const { return mOrigin; }
//! Converts map coordinates to 3D world coordinates (applies offset and turns (x,y,z) into (x,-z,y))
QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
//! Converts 3D world coordinates to map coordinates (applies offset and turns (x,y,z) into (x,-z,y))
QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
//! Sets coordinate reference system used in the 3D scene
void setCrs( const QgsCoordinateReferenceSystem &crs );
//! Returns coordinate reference system used in the 3D scene
QgsCoordinateReferenceSystem crs() const { return mCrs; }
/**
* Returns the coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \see setTransformContext()
*/
QgsCoordinateTransformContext transformContext() const;
/**
* Sets the coordinate transform \a context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \see transformContext()
*/
void setTransformContext( const QgsCoordinateTransformContext &context );
/**
* Returns the path resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \see setPathResolver()
* \since QGIS 3.0
*/
const QgsPathResolver &pathResolver() const { return mPathResolver; }
/**
* Sets the path \a resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \see pathResolver()
* \since QGIS 3.0
*/
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
//! Sets background color of the 3D map view
void setBackgroundColor( const QColor &color );
//! Returns background color of the 3D map view
QColor backgroundColor() const;
//! Sets color used for selected features
void setSelectionColor( const QColor &color );
//! Returns color used for selected features
QColor selectionColor() const;
//
// terrain related config
//
/**
* Sets vertical scale (exaggeration) of terrain
* (1 = true scale, > 1 = hills get more pronounced)
*/
void setTerrainVerticalScale( double zScale );
//! Returns vertical scale (exaggeration) of terrain
double terrainVerticalScale() const;
//! Sets the list of map layers to be rendered as a texture of the terrain
void setLayers( const QList<QgsMapLayer *> &layers );
//! Returns the list of map layers to be rendered as a texture of the terrain
QList<QgsMapLayer *> layers() const;
/**
* Sets resolution (in pixels) of the texture of a terrain tile
* \sa mapTileResolution()
*/
void setMapTileResolution( int res );
/**
* Returns resolution (in pixels) of the texture of a terrain tile. This parameter influences
* how many zoom levels for terrain tiles there will be (together with maxTerrainGroundError())
*/
int mapTileResolution() const;
/**
* Sets maximum allowed screen error of terrain tiles in pixels.
* \sa maxTerrainScreenError()
*/
void setMaxTerrainScreenError( float error );
/**
* Returns maximum allowed screen error of terrain tiles in pixels. This parameter decides
* how aggressively less detailed terrain tiles are swapped to more detailed ones as camera gets closer.
* Each tile has its error defined in world units - this error gets projected to screen pixels
* according to camera view and if the tile's error is greater than the allowed error, it will
* be swapped by more detailed tiles with lower error.
*/
float maxTerrainScreenError() const;
/**
* Returns maximum ground error of terrain tiles in world units.
* \sa maxTerrainGroundError()
*/
void setMaxTerrainGroundError( float error );
/**
* Returns maximum ground error of terrain tiles in world units. This parameter influences
* how many zoom levels there will be (together with mapTileResolution()).
* This value tells that when the given ground error is reached (e.g. 10 meters), it makes no sense
* to further split terrain tiles into finer ones because they will not add extra details anymore.
*/
float maxTerrainGroundError() const;
/**
* Sets terrain generator. It takes care of producing terrain tiles from the input data.
* Takes ownership of the generator
*/
void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER );
//! Returns terrain generator. It takes care of producing terrain tiles from the input data.
QgsTerrainGenerator *terrainGenerator() const { return mTerrainGenerator.get(); }
//! Sets list of extra 3D renderers to use in the scene. Takes ownership of the objects.
void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
//! Returns list of extra 3D renderers
QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
/**
* Sets skybox configuration. When enabled, map scene will try to load six texture files
* using the following syntax of filenames: "[base]_[side][extension]" where [side] is one
* of the following: posx/posy/posz/negx/negy/negz and [base] and [extension] are the arguments
* passed this method.
*/
void setSkybox( bool enabled, const QString &fileBase = QString(), const QString &fileExtension = QString() );
//! Returns whether skybox is enabled
bool hasSkyboxEnabled() const { return mSkyboxEnabled; }
//! Returns base part of filenames of skybox (see setSkybox())
QString skyboxFileBase() const { return mSkyboxFileBase; }
//! Returns extension part of filenames of skybox (see setSkybox())
QString skyboxFileExtension() const { return mSkyboxFileExtension; }
//! Sets whether to display bounding boxes of terrain tiles (for debugging)
void setShowTerrainBoundingBoxes( bool enabled );
//! Returns whether to display bounding boxes of terrain tiles (for debugging)
bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
//! Sets whether to display extra tile info on top of terrain tiles (for debugging)
void setShowTerrainTilesInfo( bool enabled );
//! Returns whether to display extra tile info on top of terrain tiles (for debugging)
bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
/**
* Sets whether to show camera's view center as a sphere (for debugging)
* \since QGIS 3.4
*/
void setShowCameraViewCenter( bool enabled );
/**
* Returns whether to show camera's view center as a sphere (for debugging)
* \since QGIS 3.4
*/
bool showCameraViewCenter() const { return mShowCameraViewCenter; }
//! Sets whether to display labels on terrain tiles
void setShowLabels( bool enabled );
//! Returns whether to display labels on terrain tiles
bool showLabels() const { return mShowLabels; }
signals:
//! Emitted when the background color has changed
void backgroundColorChanged();
//! Emitted when the selection color has changed
void selectionColorChanged();
//! Emitted when the list of map layers for terrain texture has changed
void layersChanged();
//! Emitted when the terrain generator has changed
void terrainGeneratorChanged();
//! Emitted when the vertical scale of the terrain has changed
void terrainVerticalScaleChanged();
//! Emitted when the map tile resoulution has changed
void mapTileResolutionChanged();
//! Emitted when the maximum terrain screen error has changed
void maxTerrainScreenErrorChanged();
//! Emitted when the maximum terrain ground error has changed
void maxTerrainGroundErrorChanged();
//! Emitted when the flag whether terrain's bounding boxes are shown has changed
void showTerrainBoundingBoxesChanged();
//! Emitted when the flag whether terrain's tile info is shown has changed
void showTerrainTilesInfoChanged();
/**
* Emitted when the flag whether camera's view center is shown has changed
* \since QGIS 3.4
*/
void showCameraViewCenterChanged();
//! Emitted when the flag whether labels are displayed on terrain tiles has changed
void showLabelsChanged();
private:
//! Offset in map CRS coordinates at which our 3D world has origin (0,0,0)
QgsVector3D mOrigin;
QgsCoordinateReferenceSystem mCrs; //!< Destination coordinate system of the world
QColor mBackgroundColor = Qt::black; //!< Background color of the scene
QColor mSelectionColor; //!< Color to be used for selected map features
double mTerrainVerticalScale = 1; //!< Multiplier of terrain heights to make the terrain shape more pronounced
std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator; //!< Implementation of the terrain generation
int mMapTileResolution = 512; //!< Size of map textures of tiles in pixels (width/height)
float mMaxTerrainScreenError = 3.f; //!< Maximum allowed terrain error in pixels (determines when tiles are switched to more detailed ones)
float mMaxTerrainGroundError = 1.f; //!< Maximum allowed horizontal map error in map units (determines how many zoom levels will be used)
bool mShowTerrainBoundingBoxes = false; //!< Whether to show bounding boxes of entities - useful for debugging
bool mShowTerrainTileInfo = false; //!< Whether to draw extra information about terrain tiles to the textures - useful for debugging
bool mShowCameraViewCenter = false; //!< Whether to show camera view center as a sphere - useful for debugging
bool mShowLabels = false; //!< Whether to display labels on terrain tiles
QList<QgsMapLayerRef> mLayers; //!< Layers to be rendered
QList<QgsAbstract3DRenderer *> mRenderers; //!< Extra stuff to render as 3D object
bool mSkyboxEnabled = false; //!< Whether to render skybox
QString mSkyboxFileBase; //!< Base part of the files with skybox textures
QString mSkyboxFileExtension; //!< Extension part of the files with skybox textures
//! Coordinate transform context
QgsCoordinateTransformContext mTransformContext;
QgsPathResolver mPathResolver;
};
#endif // QGS3DMAPSETTINGS_H