QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
28#include "qgsmesh3dsymbol.h"
32#include "qgsterraingenerator.h"
33#include "qgsvector3d.h"
34#include "qgs3daxissettings.h"
35#include "qgsskyboxsettings.h"
36#include "qgsshadowsettings.h"
37#include "qgscameracontroller.h"
40
41class QgsMapLayer;
42class QgsRasterLayer;
43
45
46
48class QgsProject;
49
50class QDomElement;
51
58class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObject
59{
60 Q_OBJECT
61 public:
65 Qgs3DMapSettings( const Qgs3DMapSettings &other );
66 ~Qgs3DMapSettings() override;
67
69
71 void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
73 QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
75 void resolveReferences( const QgsProject &project );
76
88 void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
90 QgsVector3D origin() const { return mOrigin; }
91
93 QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
95 QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
96
98 void setCrs( const QgsCoordinateReferenceSystem &crs );
100 QgsCoordinateReferenceSystem crs() const { return mCrs; }
101
109 QgsCoordinateTransformContext transformContext() const;
110
118 void setTransformContext( const QgsCoordinateTransformContext &context );
119
127 const QgsPathResolver &pathResolver() const { return mPathResolver; }
128
136 void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
137
144 QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
145
151 void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
152
154 void setBackgroundColor( const QColor &color );
156 QColor backgroundColor() const;
157
159 void setSelectionColor( const QColor &color );
161 QColor selectionColor() const;
162
171 void setLayers( const QList<QgsMapLayer *> &layers );
172
181 QList<QgsMapLayer *> layers() const;
182
183 //
184 // terrain related config
185 //
186
192 void configureTerrainFromProject( QgsProjectElevationProperties *properties, const QgsRectangle &fullExtent ) SIP_SKIP;
193
198 void setTerrainVerticalScale( double zScale );
200 double terrainVerticalScale() const;
201
206 void setMapTileResolution( int res );
207
212 int mapTileResolution() const;
213
218 void setMaxTerrainScreenError( float error );
219
227 float maxTerrainScreenError() const;
228
233 void setMaxTerrainGroundError( float error );
234
241 float maxTerrainGroundError() const;
242
248 void setTerrainElevationOffset( float offset );
249
253 float terrainElevationOffset() const { return mTerrainElevationOffset; }
254
266 void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
267
279 {
280 return mTerrainGenerator.get();
281 }
282
288 void setTerrainShadingEnabled( bool enabled );
289
296 bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
297
303 void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
304
310 QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
311
317 void setTerrainMapTheme( const QString &theme );
318
325 QString terrainMapTheme() const { return mTerrainMapTheme; }
326
327 //
328 // misc configuration
329 //
330
332 void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
334 QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
335
337 void setShowTerrainBoundingBoxes( bool enabled );
339 bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
341 void setShowTerrainTilesInfo( bool enabled );
343 bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
344
349 void setShowCameraViewCenter( bool enabled );
350
355 bool showCameraViewCenter() const { return mShowCameraViewCenter; }
356
361 void setShowCameraRotationCenter( bool enabled );
362
367 bool showCameraRotationCenter() const { return mShowCameraRotationCenter; }
368
373 void setShowLightSourceOrigins( bool enabled );
374
379 bool showLightSourceOrigins() const { return mShowLightSources; }
380
382 void setShowLabels( bool enabled );
384 bool showLabels() const { return mShowLabels; }
385
391 void setEyeDomeLightingEnabled( bool enabled );
393 bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
394
400 void setEyeDomeLightingStrength( double strength );
402 double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
403
409 void setEyeDomeLightingDistance( int distance );
411 int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
412
418 void setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size );
420 bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
422 Qt::Corner debugShadowMapCorner() const { return mDebugShadowMapCorner; }
424 double debugShadowMapSize() const { return mDebugShadowMapSize; }
425
431 void setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size );
433 bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
435 Qt::Corner debugDepthMapCorner() const { return mDebugDepthMapCorner; }
437 double debugDepthMapSize() const { return mDebugDepthMapSize; }
438
444 QList<QgsLightSource *> lightSources() const;
445
454 void setLightSources( const QList<QgsLightSource *> &lights SIP_TRANSFER );
455
460 float fieldOfView() const { return mFieldOfView; }
461
466 void setFieldOfView( const float fieldOfView );
467
472 Qt3DRender::QCameraLens::ProjectionType projectionType() const SIP_SKIP { return mProjectionType; }
473
478 void setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType ) SIP_SKIP;
479
480#ifndef SIP_RUN
481
486 QgsCameraController::NavigationMode cameraNavigationMode() const { return mCameraNavigationMode; }
487
492 void setCameraNavigationMode( QgsCameraController::NavigationMode navigationMode );
493#endif
494
499 double cameraMovementSpeed() const { return mCameraMovementSpeed; }
500
505 void setCameraMovementSpeed( double movementSpeed );
506
512 void setOutputDpi( const double dpi ) {mDpi = dpi;}
513
514
520 double outputDpi() const { return mDpi; }
521
526 QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
527
532 QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
533
538 QgsAmbientOcclusionSettings ambientOcclusionSettings() const SIP_SKIP { return mAmbientOcclusionSettings; }
539
544 void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
545
550 void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
551
556 void setAmbientOcclusionSettings( const QgsAmbientOcclusionSettings &ambientOcclusionSettings ) SIP_SKIP;
557
563 bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
564
570 void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
571
577 bool isFpsCounterEnabled() const { return mIsFpsCounterEnabled; }
578
584 void setIsFpsCounterEnabled( bool fpsCounterEnabled );
585
591 bool terrainRenderingEnabled() const { return mTerrainRenderingEnabled; }
592
598 void setTerrainRenderingEnabled( bool terrainRenderingEnabled );
599
606 Qgis::RendererUsage rendererUsage() const;
607
614 void setRendererUsage( Qgis::RendererUsage rendererUsage );
615
621 Qgis::ViewSyncModeFlags viewSyncMode() const { return mViewSyncMode; }
622
628 void setViewSyncMode( Qgis::ViewSyncModeFlags mode );
629
635 bool viewFrustumVisualizationEnabled() const { return mVisualizeViewFrustum; }
636
642 void setViewFrustumVisualizationEnabled( bool enabled );
643
648 Qgs3DAxisSettings get3DAxisSettings() const SIP_SKIP { return m3dAxisSettings; }
649
654 void set3DAxisSettings( const Qgs3DAxisSettings &axisSettings, bool force = false ) SIP_SKIP;
655
661 bool isDebugOverlayEnabled() const { return mIsDebugOverlayEnabled; }
662
671 void setIsDebugOverlayEnabled( bool debugOverlayEnabled );
672
673 signals:
674
681
686
694
705
710 void terrainElevationOffsetChanged( float newElevation );
711
717
723
729
734
740
746
752
755
761
767
773
779
785
791
797
803
809
815
821
827
833
839
840
846
851 void fpsCounterEnabledChanged( bool fpsCounterEnabled );
852
859
865
870 void debugOverlayEnabledChanged( bool debugOverlayEnabled );
871
872 private:
873#ifdef SIP_RUN
874 Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
875#endif
876
877 private:
879 void connectChangedSignalsToSettingsChanged();
880
881 private:
883 QgsVector3D mOrigin;
885 QColor mBackgroundColor = Qt::black;
886 QColor mSelectionColor;
887 double mTerrainVerticalScale = 1;
888 std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
889 int mMapTileResolution = 512;
890 float mMaxTerrainScreenError = 3.f;
891 float mMaxTerrainGroundError = 1.f;
892 float mTerrainElevationOffset = 0.0f;
893 bool mTerrainShadingEnabled = false;
894 QgsPhongMaterialSettings mTerrainShadingMaterial;
895 QString mTerrainMapTheme;
896 bool mShowTerrainBoundingBoxes = false;
897 bool mShowTerrainTileInfo = false;
898 bool mShowCameraViewCenter = false;
899 bool mShowCameraRotationCenter = false;
900 bool mShowLightSources = false;
901 bool mShowLabels = false;
902 QList< QgsLightSource * > mLightSources;
903 float mFieldOfView = 45.0f; //<! Camera lens field of view value
904 Qt3DRender::QCameraLens::ProjectionType mProjectionType = Qt3DRender::QCameraLens::PerspectiveProjection; //<! Camera lens projection type
905 QgsCameraController::NavigationMode mCameraNavigationMode = QgsCameraController::NavigationMode::TerrainBasedNavigation;
906 double mCameraMovementSpeed = 5.0;
907 QList<QgsMapLayerRef> mLayers;
908 QList<QgsAbstract3DRenderer *> mRenderers;
910 QgsCoordinateTransformContext mTransformContext;
911 QgsPathResolver mPathResolver;
912 QgsMapThemeCollection *mMapThemes = nullptr;
913 double mDpi = 96;
914 bool mIsFpsCounterEnabled = false;
915
916 bool mIsSkyboxEnabled = false;
917 QgsSkyboxSettings mSkyboxSettings;
918 QgsShadowSettings mShadowSettings;
919 QgsAmbientOcclusionSettings mAmbientOcclusionSettings;
920
921 bool mEyeDomeLightingEnabled = false;
922 double mEyeDomeLightingStrength = 1000.0;
923 int mEyeDomeLightingDistance = 1;
924
925 Qgis::ViewSyncModeFlags mViewSyncMode;
926 bool mVisualizeViewFrustum = false;
927
928 bool mDebugShadowMapEnabled = false;
929 Qt::Corner mDebugShadowMapCorner = Qt::Corner::TopLeftCorner;
930 double mDebugShadowMapSize = 0.2;
931
932 bool mDebugDepthMapEnabled = false;
933 Qt::Corner mDebugDepthMapCorner = Qt::Corner::TopRightCorner;
934 double mDebugDepthMapSize = 0.2;
935
936 bool mTerrainRenderingEnabled = true;
937
938 Qgis::RendererUsage mRendererUsage;
939
940 Qgs3DAxisSettings m3dAxisSettings;
941
942 bool mIsDebugOverlayEnabled = false;
943
944};
945
946
947#endif // QGS3DMAPSETTINGS_H
RendererUsage
Usage of the renderer.
Definition: qgis.h:1817
Contains the configuration of a 3d axis.
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...
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.
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.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
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.
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 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.
QgsCameraController::NavigationMode cameraNavigationMode() const
Returns the navigation mode used by the camera.
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
NavigationMode
The navigation mode used by the camera.
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:73
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:104
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.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
const QgsCoordinateReferenceSystem & crs