QGIS API Documentation  3.25.0-Master (10b47c2603)
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"
30 #include "qgspointlightsettings.h"
32 #include "qgsterraingenerator.h"
33 #include "qgsvector3d.h"
34 #include "qgsskyboxsettings.h"
35 #include "qgsshadowsettings.h"
36 #include "qgscameracontroller.h"
37 #include "qgstemporalrangeobject.h"
38 
39 class QgsMapLayer;
40 class QgsRasterLayer;
41 
43 
44 
46 class QgsProject;
47 
48 class QDomElement;
49 
56 class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObject
57 {
58  Q_OBJECT
59  public:
63  Qgs3DMapSettings( const Qgs3DMapSettings &other );
64  ~Qgs3DMapSettings() override;
65 
67 
69  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
71  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
73  void resolveReferences( const QgsProject &project );
74 
86  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
88  QgsVector3D origin() const { return mOrigin; }
89 
91  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
93  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
94 
96  void setCrs( const QgsCoordinateReferenceSystem &crs );
98  QgsCoordinateReferenceSystem crs() const { return mCrs; }
99 
107  QgsCoordinateTransformContext transformContext() const;
108 
116  void setTransformContext( const QgsCoordinateTransformContext &context );
117 
125  const QgsPathResolver &pathResolver() const { return mPathResolver; }
126 
134  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
135 
142  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
143 
149  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
150 
152  void setBackgroundColor( const QColor &color );
154  QColor backgroundColor() const;
155 
157  void setSelectionColor( const QColor &color );
159  QColor selectionColor() const;
160 
169  void setLayers( const QList<QgsMapLayer *> &layers );
170 
179  QList<QgsMapLayer *> layers() const;
180 
181  //
182  // terrain related config
183  //
184 
190  void configureTerrainFromProject( QgsProjectElevationProperties *properties, const QgsRectangle &fullExtent ) SIP_SKIP;
191 
196  void setTerrainVerticalScale( double zScale );
198  double terrainVerticalScale() const;
199 
204  void setMapTileResolution( int res );
205 
210  int mapTileResolution() const;
211 
216  void setMaxTerrainScreenError( float error );
217 
225  float maxTerrainScreenError() const;
226 
231  void setMaxTerrainGroundError( float error );
232 
239  float maxTerrainGroundError() const;
240 
246  void setTerrainElevationOffset( float offset );
247 
251  float terrainElevationOffset() const { return mTerrainElevationOffset; }
252 
264  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
265 
277  {
278  return mTerrainGenerator.get();
279  }
280 
286  void setTerrainShadingEnabled( bool enabled );
287 
294  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
295 
301  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
302 
308  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
309 
315  void setTerrainMapTheme( const QString &theme );
316 
323  QString terrainMapTheme() const { return mTerrainMapTheme; }
324 
325  //
326  // misc configuration
327  //
328 
330  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
332  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
333 
335  void setShowTerrainBoundingBoxes( bool enabled );
337  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
339  void setShowTerrainTilesInfo( bool enabled );
341  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
342 
347  void setShowCameraViewCenter( bool enabled );
348 
353  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
354 
359  void setShowCameraRotationCenter( bool enabled );
360 
365  bool showCameraRotationCenter() const { return mShowCameraRotationCenter; }
366 
371  void setShowLightSourceOrigins( bool enabled );
372 
377  bool showLightSourceOrigins() const { return mShowLightSources; }
378 
380  void setShowLabels( bool enabled );
382  bool showLabels() const { return mShowLabels; }
383 
389  void setEyeDomeLightingEnabled( bool enabled );
391  bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
392 
398  void setEyeDomeLightingStrength( double strength );
400  double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
401 
407  void setEyeDomeLightingDistance( int distance );
409  int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
410 
416  void setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size );
418  bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
420  Qt::Corner debugShadowMapCorner() const { return mDebugShadowMapCorner; }
422  double debugShadowMapSize() const { return mDebugShadowMapSize; }
423 
429  void setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size );
431  bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
433  Qt::Corner debugDepthMapCorner() const { return mDebugDepthMapCorner; }
435  double debugDepthMapSize() const { return mDebugDepthMapSize; }
436 
442  QList<QgsLightSource *> lightSources() const;
443 
452  void setLightSources( const QList<QgsLightSource *> &lights SIP_TRANSFER );
453 
458  float fieldOfView() const { return mFieldOfView; }
459 
464  void setFieldOfView( const float fieldOfView );
465 
470  Qt3DRender::QCameraLens::ProjectionType projectionType() const SIP_SKIP { return mProjectionType; }
471 
476  void setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType ) SIP_SKIP;
477 
478 #ifndef SIP_RUN
479 
484  QgsCameraController::NavigationMode cameraNavigationMode() const { return mCameraNavigationMode; }
485 
490  void setCameraNavigationMode( QgsCameraController::NavigationMode navigationMode );
491 #endif
492 
497  double cameraMovementSpeed() const { return mCameraMovementSpeed; }
498 
503  void setCameraMovementSpeed( double movementSpeed );
504 
510  void setOutputDpi( const double dpi ) {mDpi = dpi;}
511 
512 
518  double outputDpi() const { return mDpi; }
519 
524  QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
525 
530  QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
531 
536  void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
537 
542  void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
543 
549  bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
550 
556  void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
557 
563  bool isFpsCounterEnabled() const { return mIsFpsCounterEnabled; }
564 
570  void setIsFpsCounterEnabled( bool fpsCounterEnabled );
571 
577  bool terrainRenderingEnabled() const { return mTerrainRenderingEnabled; }
578 
584  void setTerrainRenderingEnabled( bool terrainRenderingEnabled );
585 
592  Qgis::RendererUsage rendererUsage() const;
593 
600  void setRendererUsage( Qgis::RendererUsage rendererUsage );
601 
607  Qgis::ViewSyncModeFlags viewSyncMode() const { return mViewSyncMode; }
608 
614  void setViewSyncMode( Qgis::ViewSyncModeFlags mode );
615 
621  bool viewFrustumVisualizationEnabled() const { return mVisualizeViewFrustum; }
622 
628  void setViewFrustumVisualizationEnabled( bool enabled );
629 
630  signals:
631 
638 
643 
651 
662 
667  void terrainElevationOffsetChanged( float newElevation );
668 
674 
680 
686 
691 
697 
703 
709 
712 
718 
724 
730 
736 
742 
748 
754 
760 
766 
772 
778 
784 
790 
796 
801  void fpsCounterEnabledChanged( bool fpsCounterEnabled );
802 
809 
810  private:
811 #ifdef SIP_RUN
812  Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
813 #endif
814 
815  private:
817  void connectChangedSignalsToSettingsChanged();
818 
819  private:
821  QgsVector3D mOrigin;
823  QColor mBackgroundColor = Qt::black;
824  QColor mSelectionColor;
825  double mTerrainVerticalScale = 1;
826  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
827  int mMapTileResolution = 512;
828  float mMaxTerrainScreenError = 3.f;
829  float mMaxTerrainGroundError = 1.f;
830  float mTerrainElevationOffset = 0.0f;
831  bool mTerrainShadingEnabled = false;
832  QgsPhongMaterialSettings mTerrainShadingMaterial;
833  QString mTerrainMapTheme;
834  bool mShowTerrainBoundingBoxes = false;
835  bool mShowTerrainTileInfo = false;
836  bool mShowCameraViewCenter = false;
837  bool mShowCameraRotationCenter = false;
838  bool mShowLightSources = false;
839  bool mShowLabels = false;
840  QList< QgsLightSource * > mLightSources;
841  float mFieldOfView = 45.0f; //<! Camera lens field of view value
842  Qt3DRender::QCameraLens::ProjectionType mProjectionType = Qt3DRender::QCameraLens::PerspectiveProjection; //<! Camera lens projection type
843  QgsCameraController::NavigationMode mCameraNavigationMode = QgsCameraController::NavigationMode::TerrainBasedNavigation;
844  double mCameraMovementSpeed = 5.0;
845  QList<QgsMapLayerRef> mLayers;
846  QList<QgsAbstract3DRenderer *> mRenderers;
848  QgsCoordinateTransformContext mTransformContext;
849  QgsPathResolver mPathResolver;
850  QgsMapThemeCollection *mMapThemes = nullptr;
851  double mDpi = 96;
852  bool mIsFpsCounterEnabled = false;
853 
854  bool mIsSkyboxEnabled = false;
855  QgsSkyboxSettings mSkyboxSettings;
856  QgsShadowSettings mShadowSettings;
857 
858  bool mEyeDomeLightingEnabled = false;
859  double mEyeDomeLightingStrength = 1000.0;
860  int mEyeDomeLightingDistance = 1;
861 
862  Qgis::ViewSyncModeFlags mViewSyncMode;
863  bool mVisualizeViewFrustum = false;
864 
865  bool mDebugShadowMapEnabled = false;
866  Qt::Corner mDebugShadowMapCorner = Qt::Corner::TopLeftCorner;
867  double mDebugShadowMapSize = 0.2;
868 
869  bool mDebugDepthMapEnabled = false;
870  Qt::Corner mDebugDepthMapCorner = Qt::Corner::TopRightCorner;
871  double mDebugDepthMapSize = 0.2;
872 
873  bool mTerrainRenderingEnabled = true;
874 
875  Qgis::RendererUsage mRendererUsage;
876 };
877 
878 
879 #endif // QGS3DMAPSETTINGS_H
RendererUsage
Usage of the renderer.
Definition: qgis.h:1483
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.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
QgsTerrainGenerator * terrainGenerator() const
Returns the terrain generator.
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.
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 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.
Qgs3DMapSettings & operator=(Qgs3DMapSettings const &)=delete
void pointLightsChanged()
Emitted when the list of point lights changes.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
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.
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)
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
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.
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.
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 viewFrustumVisualizationEnabledChanged()
Emitted when the camera's view frustum visualization on the main 2D map canvas is enabled or disabled...
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.
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
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.
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.
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