QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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:
60 
64  Qgs3DMapSettings( const Qgs3DMapSettings &other );
65  ~Qgs3DMapSettings() override;
66 
68 
70  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
72  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
74  void resolveReferences( const QgsProject &project );
75 
87  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
89  QgsVector3D origin() const { return mOrigin; }
90 
92  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
94  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
95 
97  void setCrs( const QgsCoordinateReferenceSystem &crs );
99  QgsCoordinateReferenceSystem crs() const { return mCrs; }
100 
108  QgsCoordinateTransformContext transformContext() const;
109 
117  void setTransformContext( const QgsCoordinateTransformContext &context );
118 
126  const QgsPathResolver &pathResolver() const { return mPathResolver; }
127 
135  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
136 
143  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
144 
150  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
151 
153  void setBackgroundColor( const QColor &color );
155  QColor backgroundColor() const;
156 
158  void setSelectionColor( const QColor &color );
160  QColor selectionColor() const;
161 
170  void setLayers( const QList<QgsMapLayer *> &layers );
171 
180  QList<QgsMapLayer *> layers() const;
181 
182  //
183  // terrain related config
184  //
185 
190  void setTerrainVerticalScale( double zScale );
192  double terrainVerticalScale() const;
193 
198  void setMapTileResolution( int res );
199 
204  int mapTileResolution() const;
205 
210  void setMaxTerrainScreenError( float error );
211 
219  float maxTerrainScreenError() const;
220 
225  void setMaxTerrainGroundError( float error );
226 
233  float maxTerrainGroundError() const;
234 
240  void setTerrainElevationOffset( float offset );
241 
245  float terrainElevationOffset() const { return mTerrainElevationOffset; }
246 
251  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
254  {
255  if ( mTerrainRenderingEnabled )
256  return mTerrainGenerator.get();
257  return nullptr;
258  }
259 
265  void setTerrainShadingEnabled( bool enabled );
266 
273  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
274 
280  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
281 
287  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
288 
294  void setTerrainMapTheme( const QString &theme );
295 
302  QString terrainMapTheme() const { return mTerrainMapTheme; }
303 
304  //
305  // misc configuration
306  //
307 
309  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
311  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
312 
314  void setShowTerrainBoundingBoxes( bool enabled );
316  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
318  void setShowTerrainTilesInfo( bool enabled );
320  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
321 
326  void setShowCameraViewCenter( bool enabled );
327 
332  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
333 
338  void setShowCameraRotationCenter( bool enabled );
339 
344  bool showCameraRotationCenter() const { return mShowCameraRotationCenter; }
345 
350  void setShowLightSourceOrigins( bool enabled );
351 
356  bool showLightSourceOrigins() const { return mShowLightSources; }
357 
359  void setShowLabels( bool enabled );
361  bool showLabels() const { return mShowLabels; }
362 
368  void setEyeDomeLightingEnabled( bool enabled );
370  bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
371 
377  void setEyeDomeLightingStrength( double strength );
379  double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
380 
386  void setEyeDomeLightingDistance( int distance );
388  int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
389 
395  void setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size );
397  bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
399  Qt::Corner debugShadowMapCorner() const { return mDebugShadowMapCorner; }
401  double debugShadowMapSize() const { return mDebugShadowMapSize; }
402 
408  void setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size );
410  bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
412  Qt::Corner debugDepthMapCorner() const { return mDebugDepthMapCorner; }
414  double debugDepthMapSize() const { return mDebugDepthMapSize; }
415 
420  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
421 
426  QList<QgsDirectionalLightSettings> directionalLights() const { return mDirectionalLights; }
427 
432  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
433 
438  void setDirectionalLights( const QList<QgsDirectionalLightSettings> &directionalLights );
439 
444  float fieldOfView() const { return mFieldOfView; }
445 
450  void setFieldOfView( const float fieldOfView );
451 
456  Qt3DRender::QCameraLens::ProjectionType projectionType() const SIP_SKIP { return mProjectionType; }
457 
462  void setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType ) SIP_SKIP;
463 
464 #ifndef SIP_RUN
465 
470  QgsCameraController::NavigationMode cameraNavigationMode() const { return mCameraNavigationMode; }
471 
476  void setCameraNavigationMode( QgsCameraController::NavigationMode navigationMode );
477 #endif
478 
483  double cameraMovementSpeed() const { return mCameraMovementSpeed; }
484 
489  void setCameraMovementSpeed( double movementSpeed );
490 
496  void setOutputDpi( const double dpi ) {mDpi = dpi;}
497 
498 
504  double outputDpi() const { return mDpi; }
505 
510  QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
511 
516  QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
517 
522  void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
523 
528  void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
529 
535  bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
536 
542  void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
543 
549  bool isFpsCounterEnabled() const { return mIsFpsCounterEnabled; }
550 
556  void setIsFpsCounterEnabled( bool fpsCounterEnabled );
557 
563  bool terrainRenderingEnabled() { return mTerrainRenderingEnabled; }
564 
570  void setTerrainRenderingEnabled( bool terrainRenderingEnabled );
571 
578  Qgis::RendererUsage rendererUsage() const;
579 
586  void setRendererUsage( Qgis::RendererUsage rendererUsage );
587 
588  signals:
589 
596 
601 
609 
620 
625  void terrainElevationOffsetChanged( float newElevation );
626 
632 
638 
644 
649 
655 
661 
667 
670 
676 
682 
688 
694 
700 
706 
712 
718 
724 
730 
736 
742 
748 
753  void fpsCounterEnabledChanged( bool fpsCounterEnabled );
754 
755  private:
756 #ifdef SIP_RUN
757  Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
758 #endif
759 
760  private:
762  void connectChangedSignalsToSettingsChanged();
763 
764  private:
766  QgsVector3D mOrigin;
768  QColor mBackgroundColor = Qt::black;
769  QColor mSelectionColor;
770  double mTerrainVerticalScale = 1;
771  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
772  int mMapTileResolution = 512;
773  float mMaxTerrainScreenError = 3.f;
774  float mMaxTerrainGroundError = 1.f;
775  float mTerrainElevationOffset = 0.0f;
776  bool mTerrainShadingEnabled = false;
777  QgsPhongMaterialSettings mTerrainShadingMaterial;
778  QString mTerrainMapTheme;
779  bool mShowTerrainBoundingBoxes = false;
780  bool mShowTerrainTileInfo = false;
781  bool mShowCameraViewCenter = false;
782  bool mShowCameraRotationCenter = false;
783  bool mShowLightSources = false;
784  bool mShowLabels = false;
785  QList<QgsPointLightSettings> mPointLights;
786  QList<QgsDirectionalLightSettings> mDirectionalLights;
787  float mFieldOfView = 45.0f; //<! Camera lens field of view value
788  Qt3DRender::QCameraLens::ProjectionType mProjectionType = Qt3DRender::QCameraLens::PerspectiveProjection; //<! Camera lens projection type
789  QgsCameraController::NavigationMode mCameraNavigationMode = QgsCameraController::NavigationMode::TerrainBasedNavigation;
790  double mCameraMovementSpeed = 5.0;
791  QList<QgsMapLayerRef> mLayers;
792  QList<QgsAbstract3DRenderer *> mRenderers;
794  QgsCoordinateTransformContext mTransformContext;
795  QgsPathResolver mPathResolver;
796  QgsMapThemeCollection *mMapThemes = nullptr;
797  double mDpi = 96;
798  bool mIsFpsCounterEnabled = false;
799 
800  bool mIsSkyboxEnabled = false;
801  QgsSkyboxSettings mSkyboxSettings;
802  QgsShadowSettings mShadowSettings;
803 
804  bool mEyeDomeLightingEnabled = false;
805  double mEyeDomeLightingStrength = 1000.0;
806  int mEyeDomeLightingDistance = 1;
807 
808  bool mDebugShadowMapEnabled = false;
809  Qt::Corner mDebugShadowMapCorner = Qt::Corner::TopLeftCorner;
810  double mDebugShadowMapSize = 0.2;
811 
812  bool mDebugDepthMapEnabled = false;
813  Qt::Corner mDebugDepthMapCorner = Qt::Corner::TopRightCorner;
814  double mDebugDepthMapSize = 0.2;
815 
816  bool mTerrainRenderingEnabled = true;
817 
818  Qgis::RendererUsage mRendererUsage;
819 };
820 
821 
822 #endif // QGS3DMAPSETTINGS_H
RendererUsage
Usage of the renderer.
Definition: qgis.h:1291
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 terrain generator. It takes care of producing terrain tiles from the input data.
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.
QList< QgsDirectionalLightSettings > directionalLights() const
Returns list of directional lights defined in the scene.
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.
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.
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 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.
bool terrainRenderingEnabled()
Returns whether the 2D terrain surface will be rendered.
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
void fpsCounterEnabledChanged(bool fpsCounterEnabled)
Emitted when the FPS counter 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.
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:101
Represents a raster layer.
The class is used as a container of context for various read/write operations on other objects.
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