QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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#include <Qt3DRender/QCamera>
25
27#include "qgsmaplayerref.h"
29#include "qgsterraingenerator.h"
30#include "qgsvector3d.h"
31#include "qgs3daxissettings.h"
32#include "qgsskyboxsettings.h"
33#include "qgsshadowsettings.h"
36
37class QgsMapLayer;
38class QgsRasterLayer;
39class QgsLightSource;
42class QgsProject;
43
44class QDomElement;
45
51class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObject
52{
53 Q_OBJECT
54 public:
58 Qgs3DMapSettings( const Qgs3DMapSettings &other );
59 ~Qgs3DMapSettings() override;
60
62
64 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
66 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
68 void resolveReferences( const QgsProject &project );
69
74 QgsRectangle extent() const { return mExtent; }
75
84 void setExtent( const QgsRectangle &extent );
85
97 void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
99 QgsVector3D origin() const { return mOrigin; }
100
102 QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
104 QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
105
107 void setCrs( const QgsCoordinateReferenceSystem &crs );
109 QgsCoordinateReferenceSystem crs() const { return mCrs; }
110
118 QgsCoordinateTransformContext transformContext() const;
119
127 void setTransformContext( const QgsCoordinateTransformContext &context );
128
135 const QgsPathResolver &pathResolver() const { return mPathResolver; }
136
143 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
144
151 QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
152
158 void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
159
161 void setBackgroundColor( const QColor &color );
163 QColor backgroundColor() const;
164
166 void setSelectionColor( const QColor &color );
168 QColor selectionColor() const;
169
178 void setLayers( const QList<QgsMapLayer *> &layers );
179
188 QList<QgsMapLayer *> layers() const;
189
190 //
191 // terrain related config
192 //
193
199 void configureTerrainFromProject( QgsProjectElevationProperties *properties, const QgsRectangle &fullExtent ) SIP_SKIP;
200
205 void setTerrainVerticalScale( double zScale );
207 double terrainVerticalScale() const;
208
213 void setMapTileResolution( int res );
214
219 int mapTileResolution() const;
220
225 void setMaxTerrainScreenError( float error );
226
234 float maxTerrainScreenError() const;
235
240 void setMaxTerrainGroundError( float error );
241
248 float maxTerrainGroundError() const;
249
255 void setTerrainElevationOffset( float offset );
256
260 float terrainElevationOffset() const { return mTerrainElevationOffset; }
261
274 void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
275
287 {
288 return mTerrainGenerator.get();
289 }
290
296 void setTerrainShadingEnabled( bool enabled );
297
304 bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
305
311 void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
312
318 QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
319
325 void setTerrainMapTheme( const QString &theme );
326
333 QString terrainMapTheme() const { return mTerrainMapTheme; }
334
335 //
336 // misc configuration
337 //
338
340 void setShowTerrainBoundingBoxes( bool enabled );
342 bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
344 void setShowTerrainTilesInfo( bool enabled );
346 bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
347
352 void setShowCameraViewCenter( bool enabled );
353
358 bool showCameraViewCenter() const { return mShowCameraViewCenter; }
359
364 void setShowCameraRotationCenter( bool enabled );
365
370 bool showCameraRotationCenter() const { return mShowCameraRotationCenter; }
371
376 void setShowLightSourceOrigins( bool enabled );
377
382 bool showLightSourceOrigins() const { return mShowLightSources; }
383
385 void setShowLabels( bool enabled );
387 bool showLabels() const { return mShowLabels; }
388
394 void setEyeDomeLightingEnabled( bool enabled );
396 bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
397
403 void setEyeDomeLightingStrength( double strength );
405 double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
406
412 void setEyeDomeLightingDistance( int distance );
414 int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
415
421 void setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size );
423 bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
425 Qt::Corner debugShadowMapCorner() const { return mDebugShadowMapCorner; }
427 double debugShadowMapSize() const { return mDebugShadowMapSize; }
428
434 void setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size );
436 bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
438 Qt::Corner debugDepthMapCorner() const { return mDebugDepthMapCorner; }
440 double debugDepthMapSize() const { return mDebugDepthMapSize; }
441
447 QList<QgsLightSource *> lightSources() const;
448
457 void setLightSources( const QList<QgsLightSource *> &lights SIP_TRANSFER );
458
463 float fieldOfView() const { return mFieldOfView; }
464
469 void setFieldOfView( const float fieldOfView );
470
475 Qt3DRender::QCameraLens::ProjectionType projectionType() const SIP_SKIP { return mProjectionType; }
476
481 void setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType ) SIP_SKIP;
482
483#ifndef SIP_RUN
484
489 Qgis::NavigationMode cameraNavigationMode() const { return mCameraNavigationMode; }
490
495 void setCameraNavigationMode( Qgis::NavigationMode navigationMode );
496#endif
497
502 double cameraMovementSpeed() const { return mCameraMovementSpeed; }
503
508 void setCameraMovementSpeed( double movementSpeed );
509
515 void setOutputDpi( const double dpi ) {mDpi = dpi;}
516
517
523 double outputDpi() const { return mDpi; }
524
529 QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
530
535 QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
536
541 QgsAmbientOcclusionSettings ambientOcclusionSettings() const SIP_SKIP { return mAmbientOcclusionSettings; }
542
547 void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
548
553 void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
554
559 void setAmbientOcclusionSettings( const QgsAmbientOcclusionSettings &ambientOcclusionSettings ) SIP_SKIP;
560
566 bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
567
573 void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
574
580 bool isFpsCounterEnabled() const { return mIsFpsCounterEnabled; }
581
587 void setIsFpsCounterEnabled( bool fpsCounterEnabled );
588
594 bool terrainRenderingEnabled() const { return mTerrainRenderingEnabled; }
595
601 void setTerrainRenderingEnabled( bool terrainRenderingEnabled );
602
609 Qgis::RendererUsage rendererUsage() const;
610
617 void setRendererUsage( Qgis::RendererUsage rendererUsage );
618
624 Qgis::ViewSyncModeFlags viewSyncMode() const { return mViewSyncMode; }
625
631 void setViewSyncMode( Qgis::ViewSyncModeFlags mode );
632
638 bool viewFrustumVisualizationEnabled() const { return mVisualizeViewFrustum; }
639
645 void setViewFrustumVisualizationEnabled( bool enabled );
646
651 Qgs3DAxisSettings get3DAxisSettings() const SIP_SKIP { return m3dAxisSettings; }
652
657 void set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force = false ) SIP_SKIP;
658
664 bool isDebugOverlayEnabled() const { return mIsDebugOverlayEnabled; }
665
674 void setIsDebugOverlayEnabled( bool debugOverlayEnabled );
675
681 bool showExtentIn2DView() const { return mShowExtentIn2DView; }
682
687 void setShowExtentIn2DView( bool show );
688
689 signals:
690
697
702
710
721
726 void terrainElevationOffsetChanged( float newElevation );
727
733
739
745
750
756
762
768
771
777
783
789
795
801
807
813
819
825
831
837
843
849
855
856
862
867 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
868
875
881
886 void debugOverlayEnabledChanged( bool debugOverlayEnabled );
887
894
901
902 private:
903#ifdef SIP_RUN
904 Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
905#endif
906
907 private:
909 void connectChangedSignalsToSettingsChanged();
910
911 private:
913 QgsVector3D mOrigin;
915 QColor mBackgroundColor = Qt::black;
916 QColor mSelectionColor;
917 double mTerrainVerticalScale = 1;
918 std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
919 int mMapTileResolution = 512;
920 float mMaxTerrainScreenError = 3.f;
921 float mMaxTerrainGroundError = 1.f;
922 float mTerrainElevationOffset = 0.0f;
923 bool mTerrainShadingEnabled = false;
924 QgsPhongMaterialSettings mTerrainShadingMaterial;
925 QString mTerrainMapTheme;
926 bool mShowTerrainBoundingBoxes = false;
927 bool mShowTerrainTileInfo = false;
928 bool mShowCameraViewCenter = false;
929 bool mShowCameraRotationCenter = false;
930 bool mShowLightSources = false;
931 bool mShowLabels = false;
932 QList< QgsLightSource * > mLightSources;
933 float mFieldOfView = 45.0f; //<! Camera lens field of view value
934 Qt3DRender::QCameraLens::ProjectionType mProjectionType = Qt3DRender::QCameraLens::PerspectiveProjection; //<! Camera lens projection type
936 double mCameraMovementSpeed = 5.0;
937 QList<QgsMapLayerRef> mLayers;
939 QgsCoordinateTransformContext mTransformContext;
940 QgsPathResolver mPathResolver;
941 QgsMapThemeCollection *mMapThemes = nullptr;
942 double mDpi = 96;
943 bool mIsFpsCounterEnabled = false;
944
945 bool mIsSkyboxEnabled = false;
946 QgsSkyboxSettings mSkyboxSettings;
947 QgsShadowSettings mShadowSettings;
948 QgsAmbientOcclusionSettings mAmbientOcclusionSettings;
949
950 bool mEyeDomeLightingEnabled = false;
951 double mEyeDomeLightingStrength = 1000.0;
952 int mEyeDomeLightingDistance = 1;
953
954 Qgis::ViewSyncModeFlags mViewSyncMode;
955 bool mVisualizeViewFrustum = false;
956
957 bool mDebugShadowMapEnabled = false;
958 Qt::Corner mDebugShadowMapCorner = Qt::Corner::TopLeftCorner;
959 double mDebugShadowMapSize = 0.2;
960
961 bool mDebugDepthMapEnabled = false;
962 Qt::Corner mDebugDepthMapCorner = Qt::Corner::TopRightCorner;
963 double mDebugDepthMapSize = 0.2;
964
965 bool mTerrainRenderingEnabled = true;
966
967 Qgis::RendererUsage mRendererUsage;
968
969 Qgs3DAxisSettings m3dAxisSettings;
970
971 bool mIsDebugOverlayEnabled = false;
972
973 QgsRectangle mExtent;
974
975 bool mShowExtentIn2DView = false;
976
977};
978
979
980#endif // QGS3DMAPSETTINGS_H
QFlags< ViewSyncModeFlag > ViewSyncModeFlags
Definition: qgis.h:2821
NavigationMode
The navigation mode used by 3D cameras.
Definition: qgis.h:3410
@ TerrainBased
The default navigation based on the terrain.
RendererUsage
Usage of the renderer.
Definition: qgis.h:2803
Contains the configuration of a 3d axis.
void extentChanged()
Emitted when the 3d view's 2d extent has changed.
void mapTileResolutionChanged()
Emitted when the map tile resoulution has changed.
void terrainVerticalScaleChanged()
Emitted when the vertical scale of the terrain has changed.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
void settingsChanged()
Emitted when one of the configuration settings has changed.
void renderersChanged()
Emitted when the list of map's extra renderers have been modified.
void eyeDomeLightingDistanceChanged()
Emitted when the eye dome lighting distance has changed.
void terrainShadingChanged()
Emitted when terrain shading enabled flag or terrain shading material has changed.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
bool showExtentIn2DView() const
Returns whether the extent is displayed on the main 2D map canvas.
double cameraMovementSpeed() const
Returns the camera movement speed.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens' projection type.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
void debugDepthMapSettingsChanged()
Emitted when depth map debugging has changed.
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Qgis::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
void backgroundColorChanged()
Emitted when the background color has changed.
void showTerrainBoundingBoxesChanged()
Emitted when the flag whether terrain's bounding boxes are shown has changed.
Qt::Corner debugShadowMapCorner() const
Returns the corner where the shadow map preview is displayed.
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
bool showCameraViewCenter() const
Returns whether to show camera's view center as a sphere (for debugging)
void showCameraRotationCenterChanged()
Emitted when the flag whether camera's rotation center is shown has changed.
void directionalLightsChanged()
Emitted when the list of directional lights changes.
void cameraNavigationModeChanged()
Emitted when the camera navigation mode was changed.
void shadowSettingsChanged()
Emitted when shadow rendering settings are changed.
void eyeDomeLightingEnabledChanged()
Emitted when the flag whether eye dome lighting is used has changed.
void debugOverlayEnabledChanged(bool debugOverlayEnabled)
Emitted when the debug overaly is enabled or disabled.
void setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
void setIsSkyboxEnabled(bool enabled)
Sets whether the skybox is enabled.
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
void skyboxSettingsChanged()
Emitted when skybox settings are changed.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
void terrainMapThemeChanged()
Emitted when terrain's map theme has changed.
void pointLightsChanged()
Emitted when the list of point lights changes.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
Qgs3DAxisSettings get3DAxisSettings() const
Returns the current configuration of 3d axis.
bool viewFrustumVisualizationEnabled() const
Returns whether the camera's view frustum is visualized on the 2D map canvas.
void projectionTypeChanged()
Emitted when the camera lens projection type changes.
float fieldOfView() const
Returns the camera lens' field of view.
void selectionColorChanged()
Emitted when the selection color has changed.
QgsAmbientOcclusionSettings ambientOcclusionSettings() const
Returns the current configuration of screen space ambient occlusion.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in project's CRS.
Qgis::ViewSyncModeFlags viewSyncMode() const
Returns the view sync mode (used to synchronize the 2D main map canvas and the 3D camera navigation)
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down)
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image)
void lightSourcesChanged()
Emitted when any of the light source settings in the map changes.
void showLightSourceOriginsChanged()
Emitted when the flag whether light source origins are shown has changed.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
double debugShadowMapSize() const
Returns the size of the shadow map preview.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
void showLabelsChanged()
Emitted when the flag whether labels are displayed on terrain tiles has changed.
Qgs3DMapSettings & operator=(Qgs3DMapSettings const &)=delete
void maxTerrainScreenErrorChanged()
Emitted when the maximum terrain screen error has changed.
bool showLabels() const
Returns whether to display labels on terrain tiles.
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool terrainRenderingEnabled() const
Returns whether the 2D terrain surface will be rendered.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter is enabled or disabled.
void axisSettingsChanged()
Emitted when 3d axis rendering settings are changed.
void viewFrustumVisualizationEnabledChanged()
Emitted when the camera's view frustum visualization on the main 2D map canvas is enabled or disabled...
void ambientOcclusionSettingsChanged()
Emitted when ambient occlusion rendering settings are changed.
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging)
void showExtentIn2DViewChanged()
Emitted when the parameter to display 3d view's extent in the 2D canvas has changed.
void layersChanged()
Emitted when the list of map layers for 3d rendering has changed.
void showTerrainTilesInfoChanged()
Emitted when the flag whether terrain's tile info is shown has changed.
void eyeDomeLightingStrengthChanged()
Emitted when the eye dome lighting strength has changed.
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
void cameraMovementSpeedChanged()
Emitted when the camera movement speed was changed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
bool isFpsCounterEnabled() const
Returns whether FPS counter label is enabled.
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain's texture.
void fieldOfViewChanged()
Emitted when the camera lens field of view changes.
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
void terrainGeneratorChanged()
Emitted when the terrain generator has changed.
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
void debugShadowMapSettingsChanged()
Emitted when shadow map debugging has changed.
void showCameraViewCenterChanged()
Emitted when the flag whether camera's view center is shown has changed.
void maxTerrainGroundErrorChanged()
Emitted when the maximum terrain ground error has changed.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
bool showCameraRotationCenter() const
Returns whether to show camera's rotation center as a sphere (for debugging)
Base class for all renderers that may to participate in 3D view.
class containing the configuration of ambient occlusion rendering 3
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Base class for all map layer types.
Definition: qgsmaplayer.h:75
Container class that allows storage of map themes consisting of visible map layers and layer styles.
Resolves relative paths into absolute paths and vice versa.
Contains elevation properties for a QgsProject.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:107
Represents a raster layer.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
class containing the configuration of shadows rendering 3
Contains the configuration of a skybox entity.
Base class for objects with an associated (optional) temporal range.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
Definition: qgsvector3d.h:31
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
const QgsCoordinateReferenceSystem & crs