QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgs3dmapsettings.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgs3dmapsettings.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 QGS3DMAPSETTINGS_H
17 #define QGS3DMAPSETTINGS_H
18 
19 #include "qgis_3d.h"
20 
21 #include <memory>
22 #include <QColor>
23 #include <QMatrix4x4>
24 
26 #include "qgsmaplayerref.h"
27 #include "qgsmesh3dsymbol.h"
29 #include "qgspointlightsettings.h"
31 #include "qgsterraingenerator.h"
32 #include "qgsvector3d.h"
33 #include "qgsskyboxsettings.h"
34 #include "qgsshadowsettings.h"
35 
36 class QgsMapLayer;
37 class QgsRasterLayer;
38 
40 
41 
43 class QgsProject;
44 
45 class QDomElement;
46 
53 class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObject
54 {
55  Q_OBJECT
56  public:
57 
59  Qgs3DMapSettings() = default;
61  Qgs3DMapSettings( const Qgs3DMapSettings &other );
62  ~Qgs3DMapSettings() override;
63 
65 
67  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
69  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
71  void resolveReferences( const QgsProject &project );
72 
84  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
86  QgsVector3D origin() const { return mOrigin; }
87 
89  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
91  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
92 
94  void setCrs( const QgsCoordinateReferenceSystem &crs );
96  QgsCoordinateReferenceSystem crs() const { return mCrs; }
97 
105  QgsCoordinateTransformContext transformContext() const;
106 
114  void setTransformContext( const QgsCoordinateTransformContext &context );
115 
123  const QgsPathResolver &pathResolver() const { return mPathResolver; }
124 
132  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
133 
140  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
141 
147  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
148 
150  void setBackgroundColor( const QColor &color );
152  QColor backgroundColor() const;
153 
155  void setSelectionColor( const QColor &color );
157  QColor selectionColor() const;
158 
170  void setLayers( const QList<QgsMapLayer *> &layers );
171 
183  QList<QgsMapLayer *> layers() const;
184 
185  //
186  // terrain related config
187  //
188 
201  void setTerrainLayers( const QList<QgsMapLayer *> &layers );
202 
215  QList<QgsMapLayer *> terrainLayers() const;
216 
221  void setTerrainVerticalScale( double zScale );
223  double terrainVerticalScale() const;
224 
229  void setMapTileResolution( int res );
230 
235  int mapTileResolution() const;
236 
241  void setMaxTerrainScreenError( float error );
242 
250  float maxTerrainScreenError() const;
251 
256  void setMaxTerrainGroundError( float error );
257 
264  float maxTerrainGroundError() const;
265 
270  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
272  QgsTerrainGenerator *terrainGenerator() const SIP_SKIP { return mTerrainGenerator.get(); }
273 
279  void setTerrainShadingEnabled( bool enabled );
280 
287  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
288 
294  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
295 
301  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
302 
308  void setTerrainMapTheme( const QString &theme );
309 
316  QString terrainMapTheme() const { return mTerrainMapTheme; }
317 
318  //
319  // misc configuration
320  //
321 
323  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
325  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
326 
328  void setShowTerrainBoundingBoxes( bool enabled );
330  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
332  void setShowTerrainTilesInfo( bool enabled );
334  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
335 
340  void setShowCameraViewCenter( bool enabled );
341 
346  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
347 
352  void setShowLightSourceOrigins( bool enabled );
353 
358  bool showLightSourceOrigins() const { return mShowLightSources; }
359 
361  void setShowLabels( bool enabled );
363  bool showLabels() const { return mShowLabels; }
364 
369  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
370 
375  QList<QgsDirectionalLightSettings> directionalLights() const { return mDirectionalLights; }
376 
381  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
382 
387  void setDirectionalLights( const QList<QgsDirectionalLightSettings> &directionalLights );
388 
393  float fieldOfView() const { return mFieldOfView; }
394 
399  void setFieldOfView( const float fieldOfView );
400 
406  void setOutputDpi( const double dpi ) {mDpi = dpi;}
407 
408 
414  double outputDpi() const { return mDpi; }
415 
420  QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
421 
426  QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
427 
432  void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
433 
438  void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
439 
445  bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
446 
452  void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
453 
454  signals:
459 
468 
479 
490 
496 
502 
508 
513 
519 
525 
528 
534 
540 
546 
552 
558 
559  private:
560 #ifdef SIP_RUN
561  Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
562 #endif
563 
564  private:
566  QgsVector3D mOrigin;
568  QColor mBackgroundColor = Qt::black;
569  QColor mSelectionColor;
570  double mTerrainVerticalScale = 1;
571  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
572  int mMapTileResolution = 512;
573  float mMaxTerrainScreenError = 3.f;
574  float mMaxTerrainGroundError = 1.f;
575  bool mTerrainShadingEnabled = false;
576  QgsPhongMaterialSettings mTerrainShadingMaterial;
577  QString mTerrainMapTheme;
578  bool mShowTerrainBoundingBoxes = false;
579  bool mShowTerrainTileInfo = false;
580  bool mShowCameraViewCenter = false;
581  bool mShowLightSources = false;
582  bool mShowLabels = false;
583  QList<QgsPointLightSettings> mPointLights;
584  QList<QgsDirectionalLightSettings> mDirectionalLights;
585  float mFieldOfView = 45.0f; //<! Camera lens field of view value
586  QList<QgsMapLayerRef> mLayers;
587  QList<QgsMapLayerRef> mTerrainLayers;
588  QList<QgsAbstract3DRenderer *> mRenderers;
589  QgsCoordinateTransformContext mTransformContext;
591  QgsPathResolver mPathResolver;
592  QgsMapThemeCollection *mMapThemes = nullptr;
593  double mDpi = 96;
594 
595  bool mIsSkyboxEnabled = false;
596  QgsSkyboxSettings mSkyboxSettings;
597  QgsShadowSettings mShadowSettings;
598 };
599 
600 
601 #endif // QGS3DMAPSETTINGS_H
Qgs3DMapSettings::backgroundColorChanged
void backgroundColorChanged()
Emitted when the background color has changed.
Qgs3DMapSettings::showLightSourceOrigins
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
Definition: qgs3dmapsettings.h:358
Qgs3DMapSettings::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.h:96
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:58
Qgs3DMapSettings::directionalLightsChanged
void directionalLightsChanged()
Emitted when the list of directional lights changes.
Qgs3DMapSettings::terrainShadingMaterial
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
Definition: qgs3dmapsettings.h:301
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
Qgs3DMapSettings::outputDpi
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Definition: qgs3dmapsettings.h:414
Qgs3DMapSettings::mapThemeCollection
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
Definition: qgs3dmapsettings.h:140
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:49
QgsVector3D
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:32
Qgs3DMapSettings::showLightSourceOriginsChanged
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
Qgs3DMapSettings::showCameraViewCenterChanged
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
qgsmesh3dsymbol.h
QgsSkyboxSettings
class containing the configuration of a skybox entity 3
Definition: qgsskyboxsettings.h:36
Qgs3DMapSettings::mapTileResolutionChanged
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
qgsskyboxsettings.h
Qgs3DMapSettings::terrainGeneratorChanged
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
Qgs3DMapSettings::operator=
Qgs3DMapSettings & operator=(Qgs3DMapSettings const &)=delete
Qgs3DMapSettings::skyboxSettingsChanged
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
Qgs3DMapSettings::renderersChanged
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
Qgs3DMapSettings::terrainMapTheme
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain's texture.
Definition: qgs3dmapsettings.h:316
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
Qgs3DMapSettings::showLabels
bool showLabels() const
Returns whether to display labels on terrain tiles.
Definition: qgs3dmapsettings.h:363
qgspointlightsettings.h
QgsPhongMaterialSettings
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
Definition: qgsphongmaterialsettings.h:37
Qgs3DMapSettings::maxTerrainScreenErrorChanged
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsTerrainGenerator
3 Base class for generators of terrain.
Definition: qgsterraingenerator.h:48
Qgs3DMapSettings::pathResolver
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Definition: qgs3dmapsettings.h:123
Qgs3DMapSettings::setOutputDpi
void setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
Definition: qgs3dmapsettings.h:406
qgsterraingenerator.h
Qgs3DMapSettings::terrainLayersChanged
void terrainLayersChanged()
Emitted when the list of map layers for terrain texture has changed.
Qgs3DMapSettings::setIsSkyboxEnabled
void setIsSkyboxEnabled(bool enabled)
Sets whether the skybox is enabled.
Definition: qgs3dmapsettings.h:452
Qgs3DMapSettings::terrainVerticalScaleChanged
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Qgs3DMapSettings::setOrigin
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
Definition: qgs3dmapsettings.h:84
qgsshadowsettings.h
Qgs3DMapSettings
3 Definition of the world
Definition: qgs3dmapsettings.h:54
Qgs3DMapSettings::fieldOfView
float fieldOfView() const
Returns the camera lens' field of view.
Definition: qgs3dmapsettings.h:393
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
Qgs3DMapSettings::origin
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Definition: qgs3dmapsettings.h:86
Qgs3DMapSettings::fieldOfViewChanged
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
Qgs3DMapSettings::pointLightsChanged
void pointLightsChanged()
Emitted when the list of point lights changes.
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
Qgs3DMapSettings::shadowSettingsChanged
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
Qgs3DMapSettings::terrainGenerator
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data.
Definition: qgs3dmapsettings.h:272
Qgs3DMapSettings::terrainShadingChanged
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
Qgs3DMapSettings::Qgs3DMapSettings
Qgs3DMapSettings()=default
Constructor for Qgs3DMapSettings.
Qgs3DMapSettings::setPathResolver
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Definition: qgs3dmapsettings.h:132
Qgs3DMapSettings::showTerrainBoundingBoxesChanged
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
Qgs3DMapSettings::setMapThemeCollection
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
Definition: qgs3dmapsettings.h:147
Qgs3DMapSettings::shadowSettings
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
Definition: qgs3dmapsettings.h:426
Qgs3DMapSettings::directionalLights
QList< QgsDirectionalLightSettings > directionalLights() const
Returns list of directional lights defined in the scene.
Definition: qgs3dmapsettings.h:375
qgsvector3d.h
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Qgs3DMapSettings::renderers
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
Definition: qgs3dmapsettings.h:325
Qgs3DMapSettings::selectionColorChanged
void selectionColorChanged()
Emitted when the selection color has changed.
QgsShadowSettings
class containing the configuration of shadows rendering 3
Definition: qgsshadowsettings.h:35
Qgs3DMapSettings::showTerrainBoundingBoxes
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
Definition: qgs3dmapsettings.h:330
qgsmaplayerref.h
Qgs3DMapSettings::showTerrainTilesInfo
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging)
Definition: qgs3dmapsettings.h:334
Qgs3DMapSettings::terrainMapThemeChanged
void terrainMapThemeChanged()
Emitted when terrain's map theme has changed.
QgsMapThemeCollection
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Definition: qgsmapthemecollection.h:45
Qgs3DMapSettings::showCameraViewCenter
bool showCameraViewCenter() const
Returns whether to show camera's view center as a sphere (for debugging)
Definition: qgs3dmapsettings.h:346
qgsphongmaterialsettings.h
Qgs3DMapSettings::skyboxSettings
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
Definition: qgs3dmapsettings.h:420
Qgs3DMapSettings::isSkyboxEnabled
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
Definition: qgs3dmapsettings.h:445
qgscoordinatereferencesystem.h
Qgs3DMapSettings::maxTerrainGroundErrorChanged
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsPathResolver
Resolves relative paths into absolute paths and vice versa.
Definition: qgspathresolver.h:32
QgsTemporalRangeObject
Base class for objects with an associated (optional) temporal range.
Definition: qgstemporalrangeobject.h:34
qgsdirectionallightsettings.h
Qgs3DMapSettings::pointLights
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
Definition: qgs3dmapsettings.h:369
Qgs3DMapSettings::isTerrainShadingEnabled
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
Definition: qgs3dmapsettings.h:287
Qgs3DMapSettings::showLabelsChanged
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
Qgs3DMapSettings::layersChanged
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
Qgs3DMapSettings::showTerrainTilesInfoChanged
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.