QGIS API Documentation  3.17.0-Master (a035f434f4)
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 
37 class QgsMapLayer;
38 class QgsRasterLayer;
39 
41 
42 
44 class QgsProject;
45 
46 class QDomElement;
47 
54 class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObject
55 {
56  Q_OBJECT
57  public:
58 
60  Qgs3DMapSettings() = default;
62  Qgs3DMapSettings( const Qgs3DMapSettings &other );
63  ~Qgs3DMapSettings() override;
64 
65  Qgs3DMapSettings &operator=( Qgs3DMapSettings const & ) = delete;
66 
68  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
70  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
72  void resolveReferences( const QgsProject &project );
73 
85  void setOrigin( const QgsVector3D &origin ) { mOrigin = origin; }
87  QgsVector3D origin() const { return mOrigin; }
88 
90  QgsVector3D mapToWorldCoordinates( const QgsVector3D &mapCoords ) const;
92  QgsVector3D worldToMapCoordinates( const QgsVector3D &worldCoords ) const;
93 
95  void setCrs( const QgsCoordinateReferenceSystem &crs );
97  QgsCoordinateReferenceSystem crs() const { return mCrs; }
98 
106  QgsCoordinateTransformContext transformContext() const;
107 
115  void setTransformContext( const QgsCoordinateTransformContext &context );
116 
124  const QgsPathResolver &pathResolver() const { return mPathResolver; }
125 
133  void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }
134 
141  QgsMapThemeCollection *mapThemeCollection() const { return mMapThemes; }
142 
148  void setMapThemeCollection( QgsMapThemeCollection *mapThemes ) { mMapThemes = mapThemes; }
149 
151  void setBackgroundColor( const QColor &color );
153  QColor backgroundColor() const;
154 
156  void setSelectionColor( const QColor &color );
158  QColor selectionColor() const;
159 
171  void setLayers( const QList<QgsMapLayer *> &layers );
172 
184  QList<QgsMapLayer *> layers() const;
185 
186  //
187  // terrain related config
188  //
189 
202  void setTerrainLayers( const QList<QgsMapLayer *> &layers );
203 
216  QList<QgsMapLayer *> terrainLayers() const;
217 
222  void setTerrainVerticalScale( double zScale );
224  double terrainVerticalScale() const;
225 
230  void setMapTileResolution( int res );
231 
236  int mapTileResolution() const;
237 
242  void setMaxTerrainScreenError( float error );
243 
251  float maxTerrainScreenError() const;
252 
257  void setMaxTerrainGroundError( float error );
258 
265  float maxTerrainGroundError() const;
266 
272  void setTerrainElevationOffset( float offset );
273 
277  float terrainElevationOffset() const { return mTerrainElevationOffset; }
278 
283  void setTerrainGenerator( QgsTerrainGenerator *gen SIP_TRANSFER ) SIP_SKIP;
285  QgsTerrainGenerator *terrainGenerator() const SIP_SKIP { return mTerrainGenerator.get(); }
286 
292  void setTerrainShadingEnabled( bool enabled );
293 
300  bool isTerrainShadingEnabled() const { return mTerrainShadingEnabled; }
301 
307  void setTerrainShadingMaterial( const QgsPhongMaterialSettings &material );
308 
314  QgsPhongMaterialSettings terrainShadingMaterial() const { return mTerrainShadingMaterial; }
315 
321  void setTerrainMapTheme( const QString &theme );
322 
329  QString terrainMapTheme() const { return mTerrainMapTheme; }
330 
331  //
332  // misc configuration
333  //
334 
336  void setRenderers( const QList<QgsAbstract3DRenderer *> &renderers SIP_TRANSFER );
338  QList<QgsAbstract3DRenderer *> renderers() const { return mRenderers; }
339 
341  void setShowTerrainBoundingBoxes( bool enabled );
343  bool showTerrainBoundingBoxes() const { return mShowTerrainBoundingBoxes; }
345  void setShowTerrainTilesInfo( bool enabled );
347  bool showTerrainTilesInfo() const { return mShowTerrainTileInfo; }
348 
353  void setShowCameraViewCenter( bool enabled );
354 
359  bool showCameraViewCenter() const { return mShowCameraViewCenter; }
360 
365  void setShowLightSourceOrigins( bool enabled );
366 
371  bool showLightSourceOrigins() const { return mShowLightSources; }
372 
374  void setShowLabels( bool enabled );
376  bool showLabels() const { return mShowLabels; }
377 
383  void setEyeDomeLightingEnabled( bool enabled );
385  bool eyeDomeLightingEnabled() const { return mEyeDomeLightingEnabled; }
386 
392  void setEyeDomeLightingStrength( double strength );
394  double eyeDomeLightingStrength() const { return mEyeDomeLightingStrength; }
395 
401  void setEyeDomeLightingDistance( int distance );
403  int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }
404 
410  void setDebugShadowMapSettings( bool enabled, Qt::Corner corner, double size );
412  bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
414  Qt::Corner debugShadowMapCorner() const { return mDebugShadowMapCorner; }
416  double debugShadowMapSize() const { return mDebugShadowMapSize; }
417 
423  void setDebugDepthMapSettings( bool enabled, Qt::Corner corner, double size );
425  bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
427  Qt::Corner debugDepthMapCorner() const { return mDebugDepthMapCorner; }
429  double debugDepthMapSize() const { return mDebugDepthMapSize; }
430 
435  QList<QgsPointLightSettings> pointLights() const { return mPointLights; }
436 
441  QList<QgsDirectionalLightSettings> directionalLights() const { return mDirectionalLights; }
442 
447  void setPointLights( const QList<QgsPointLightSettings> &pointLights );
448 
453  void setDirectionalLights( const QList<QgsDirectionalLightSettings> &directionalLights );
454 
459  float fieldOfView() const { return mFieldOfView; }
460 
465  void setFieldOfView( const float fieldOfView );
466 
471  Qt3DRender::QCameraLens::ProjectionType projectionType() const SIP_SKIP { return mProjectionType; }
472 
477  void setProjectionType( const Qt3DRender::QCameraLens::ProjectionType projectionType ) SIP_SKIP;
478 
484  void setOutputDpi( const double dpi ) {mDpi = dpi;}
485 
486 
492  double outputDpi() const { return mDpi; }
493 
498  QgsSkyboxSettings skyboxSettings() const SIP_SKIP { return mSkyboxSettings; }
499 
504  QgsShadowSettings shadowSettings() const SIP_SKIP { return mShadowSettings; }
505 
510  void setSkyboxSettings( const QgsSkyboxSettings &skyboxSettings ) SIP_SKIP;
511 
516  void setShadowSettings( const QgsShadowSettings &shadowSettings ) SIP_SKIP;
517 
523  bool isSkyboxEnabled() const { return mIsSkyboxEnabled; }
524 
530  void setIsSkyboxEnabled( bool enabled ) { mIsSkyboxEnabled = enabled; }
531 
532  signals:
534  void backgroundColorChanged();
536  void selectionColorChanged();
537 
545  void layersChanged();
546 
556  void terrainLayersChanged();
557 
559  void terrainGeneratorChanged();
561  void terrainVerticalScaleChanged();
563  void mapTileResolutionChanged();
565  void maxTerrainScreenErrorChanged();
567  void maxTerrainGroundErrorChanged();
568 
573  void terrainElevationOffsetChanged( float newElevation );
574 
579  void terrainShadingChanged();
580 
585  void terrainMapThemeChanged();
586 
591  void renderersChanged();
592 
594  void showTerrainBoundingBoxesChanged();
596  void showTerrainTilesInfoChanged();
597 
602  void showCameraViewCenterChanged();
603 
608  void showLightSourceOriginsChanged();
609 
611  void showLabelsChanged();
612 
617  void eyeDomeLightingEnabledChanged();
618 
623  void eyeDomeLightingStrengthChanged();
624 
629  void eyeDomeLightingDistanceChanged();
630 
635  void debugShadowMapSettingsChanged();
636 
641  void debugDepthMapSettingsChanged();
642 
647  void pointLightsChanged();
648 
653  void directionalLightsChanged();
654 
659  void fieldOfViewChanged();
660 
665  void projectionTypeChanged();
666 
671  void skyboxSettingsChanged();
672 
677  void shadowSettingsChanged();
678 
679  private:
680 #ifdef SIP_RUN
681  Qgs3DMapSettings &operator=( const Qgs3DMapSettings & );
682 #endif
683 
684  private:
686  QgsVector3D mOrigin;
688  QColor mBackgroundColor = Qt::black;
689  QColor mSelectionColor;
690  double mTerrainVerticalScale = 1;
691  std::unique_ptr<QgsTerrainGenerator> mTerrainGenerator;
692  int mMapTileResolution = 512;
693  float mMaxTerrainScreenError = 3.f;
694  float mMaxTerrainGroundError = 1.f;
695  float mTerrainElevationOffset = 0.0f;
696  bool mTerrainShadingEnabled = false;
697  QgsPhongMaterialSettings mTerrainShadingMaterial;
698  QString mTerrainMapTheme;
699  bool mShowTerrainBoundingBoxes = false;
700  bool mShowTerrainTileInfo = false;
701  bool mShowCameraViewCenter = false;
702  bool mShowLightSources = false;
703  bool mShowLabels = false;
704  QList<QgsPointLightSettings> mPointLights;
705  QList<QgsDirectionalLightSettings> mDirectionalLights;
706  float mFieldOfView = 45.0f; //<! Camera lens field of view value
707  Qt3DRender::QCameraLens::ProjectionType mProjectionType = Qt3DRender::QCameraLens::PerspectiveProjection; //<! Camera lens projection type
708  QList<QgsMapLayerRef> mLayers;
709  QList<QgsMapLayerRef> mTerrainLayers;
710  QList<QgsAbstract3DRenderer *> mRenderers;
711  QgsCoordinateTransformContext mTransformContext;
713  QgsPathResolver mPathResolver;
714  QgsMapThemeCollection *mMapThemes = nullptr;
715  double mDpi = 96;
716 
717  bool mIsSkyboxEnabled = false;
718  QgsSkyboxSettings mSkyboxSettings;
719  QgsShadowSettings mShadowSettings;
720 
721  bool mEyeDomeLightingEnabled = false;
722  double mEyeDomeLightingStrength = 1000.0;
723  int mEyeDomeLightingDistance = 1;
724 
725  bool mDebugShadowMapEnabled = false;
726  Qt::Corner mDebugShadowMapCorner = Qt::Corner::TopLeftCorner;
727  double mDebugShadowMapSize = 0.2;
728 
729  bool mDebugDepthMapEnabled = false;
730  Qt::Corner mDebugDepthMapCorner = Qt::Corner::TopRightCorner;
731  double mDebugDepthMapSize = 0.2;
732 };
733 
734 
735 #endif // QGS3DMAPSETTINGS_H
double debugShadowMapSize() const
Returns the size of the shadow map preview.
Qt3DRender::QCameraLens::ProjectionType projectionType() const
Returns the camera lens&#39; projection type.
The class is used as a container of context for various read/write operations on other objects...
3 Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double preci...
Definition: qgsvector3d.h:31
Base class for all map layer types.
Definition: qgsmaplayer.h:83
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
bool showTerrainBoundingBoxes() const
Returns whether to display bounding boxes of terrain tiles (for debugging)
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
Qt::Corner debugShadowMapCorner() const
Returns the corner where the shadow map preview is displayed.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsMapThemeCollection * mapThemeCollection() const
Returns pointer to the collection of map themes.
bool isTerrainShadingEnabled() const
Returns whether terrain shading is enabled.
Base class for all renderers that may to participate in 3D view.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
void setOutputDpi(const double dpi)
Sets DPI used for conversion between real world units (e.g.
QgsPhongMaterialSettings terrainShadingMaterial() const
Returns terrain shading material.
bool showCameraViewCenter() const
Returns whether to show camera&#39;s view center as a sphere (for debugging)
class containing the configuration of a skybox entity 3
Represents a raster layer.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
QList< QgsPointLightSettings > pointLights() const
Returns list of point lights defined in the scene.
const QgsCoordinateReferenceSystem & crs
3 Basic shading material used for rendering based on the Phong shading model with three color compone...
3 Definition of the world
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
bool showLightSourceOrigins() const
Returns whether to show light source origins as a sphere (for debugging)
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
QString terrainMapTheme() const
Returns name of the map theme (from the active project) that will be used for terrain&#39;s texture...
QList< QgsDirectionalLightSettings > directionalLights() const
Returns list of directional lights defined in the scene.
class containing the configuration of shadows rendering 3
#define SIP_SKIP
Definition: qgis_sip.h:126
bool showTerrainTilesInfo() const
Returns whether to display extra tile info on top of terrain tiles (for debugging) ...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
Definition: qgsproject.h:94
bool isSkyboxEnabled() const
Returns whether the skybox is enabled.
Contains information about the context in which a coordinate transform is executed.
void setOrigin(const QgsVector3D &origin)
Sets coordinates in map CRS at which our 3D world has origin (0,0,0)
void setMapThemeCollection(QgsMapThemeCollection *mapThemes)
Sets pointer to the collection of map themes.
bool showLabels() const
Returns whether to display labels on terrain tiles.
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down) ...
QgsSkyboxSettings skyboxSettings() const
Returns the current configuration of the skybox.
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
Base class for objects with an associated (optional) temporal range.
3 Base class for generators of terrain.
QList< QgsAbstract3DRenderer * > renderers() const
Returns list of extra 3D renderers.
void setIsSkyboxEnabled(bool enabled)
Sets whether the skybox is enabled.
This class represents a coordinate reference system (CRS).
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
float fieldOfView() const
Returns the camera lens&#39; field of view.
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.
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image) ...
bool debugShadowMapEnabled() const
Returns whether the shadow map debugging is enabled.
QgsTerrainGenerator * terrainGenerator() const
Returns terrain generator. It takes care of producing terrain tiles from the input data...