QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgs3dterrainregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs3dterrainregistry.cpp
3 --------------------------------------
4 Date : November 2024
5 Copyright : (C) 2024 by Nyall Dawson
6 Email : nyall dot dawson 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
17#include "qgis.h"
18
27#include "qgsmeshterraingenerator.h"
30#include "qgsterrainprovider.h"
31
32#include <QDomElement>
33
34
36{
37 addType( new Qgs3DTerrainMetadata( QStringLiteral( "flat" ), QObject::tr( "Flat Terrain" ), &QgsFlatTerrainSettings::create, &QgsFlatTerrainGenerator::create ) );
38 addType( new Qgs3DTerrainMetadata( QStringLiteral( "dem" ), QObject::tr( "DEM (Raster Layer)" ), &QgsDemTerrainSettings::create, &QgsDemTerrainGenerator::create ) );
39 addType( new Qgs3DTerrainMetadata( QStringLiteral( "online" ), QObject::tr( "Online" ), &QgsOnlineDemTerrainSettings::create, &QgsOnlineTerrainGenerator::create ) );
40 addType( new Qgs3DTerrainMetadata( QStringLiteral( "mesh" ), QObject::tr( "Mesh" ), &QgsMeshTerrainSettings::create, &QgsMeshTerrainGenerator::create ) );
41 addType( new Qgs3DTerrainMetadata( QStringLiteral( "quantizedmesh" ), QObject::tr( "Quantized Mesh" ), &QgsQuantizedMeshTerrainSettings::create, &QgsQuantizedMeshTerrainGenerator::create ) );
42}
43
45{
46 qDeleteAll( mMetadata );
47}
48
50{
51 if ( !metadata || mMetadata.contains( metadata->type() ) )
52 return false;
53
54 mMetadata[metadata->type()] = metadata;
55 mTerrainOrder << metadata->type();
56 return true;
57}
58
60{
61 if ( !mMetadata.contains( type ) )
62 return nullptr;
63
64 return mMetadata[type]->createTerrainSettings();
65}
66
68{
69 if ( !mMetadata.contains( type ) )
70 return nullptr;
71
72 return mMetadata[type]->createTerrainGenerator();
73}
74
76{
77 if ( properties->terrainProvider()->type() == QLatin1String( "flat" ) )
78 {
79 std::unique_ptr<QgsFlatTerrainSettings> flatTerrain = std::make_unique<QgsFlatTerrainSettings>();
80 flatTerrain->setElevationOffset( properties->terrainProvider()->offset() );
81 return flatTerrain.release();
82 }
83 else if ( properties->terrainProvider()->type() == QLatin1String( "raster" ) )
84 {
85 QgsRasterDemTerrainProvider *rasterProvider = qgis::down_cast<QgsRasterDemTerrainProvider *>( properties->terrainProvider() );
86
87 std::unique_ptr<QgsDemTerrainSettings> demTerrain = std::make_unique<QgsDemTerrainSettings>();
88 demTerrain->setLayer( rasterProvider->layer() );
89 demTerrain->setElevationOffset( properties->terrainProvider()->offset() );
90 demTerrain->setVerticalScale( properties->terrainProvider()->scale() );
91 return demTerrain.release();
92 }
93 else if ( properties->terrainProvider()->type() == QLatin1String( "mesh" ) )
94 {
95 QgsMeshTerrainProvider *meshProvider = qgis::down_cast<QgsMeshTerrainProvider *>( properties->terrainProvider() );
96
97 std::unique_ptr<QgsMeshTerrainSettings> meshTerrain = std::make_unique<QgsMeshTerrainSettings>();
98 meshTerrain->setLayer( meshProvider->layer() );
99 meshTerrain->setElevationOffset( properties->terrainProvider()->offset() );
100 meshTerrain->setVerticalScale( properties->terrainProvider()->scale() );
101 return meshTerrain.release();
102 }
103 else
104 {
105 std::unique_ptr<QgsFlatTerrainSettings> flatTerrain = std::make_unique<QgsFlatTerrainSettings>();
106 return flatTerrain.release();
107 }
108}
109
111{
112 return mMetadata.value( type );
113}
114
116{
117 QStringList types;
118 for ( const QString &type : mTerrainOrder )
119 {
120 if ( mMetadata.value( type ) )
121 types << type;
122 }
123 return types;
124}
Stores metadata about one 3D terrain class.
QString type() const
Returns the unique terrain type string.
Convenience metadata class that uses static functions to create 3D terrain objects.
QgsAbstractTerrainSettings * configureTerrainFromProject(QgsProjectElevationProperties *properties)
Create terrain settings directly from a project's elevation properties.
QgsAbstractTerrainSettings * createTerrainSettings(const QString &type) const
Creates a new instance of the terrain settings of the specified type.
QgsTerrainGenerator * createTerrainGenerator(const QString &type) const
Creates a new instance of the terrain generator of the specified type.
Qgs3DTerrainAbstractMetadata * terrainMetadata(const QString &type) const
Returns metadata for specified terrain type. Returns nullptr if not found.
QStringList types() const
Returns a list of all available terrain types.
bool addType(Qgs3DTerrainAbstractMetadata *metadata)
Registers a new terrain type. Takes ownership of the metadata instance.
virtual QString type() const =0
Returns the unique type ID string for the provider.
double offset() const
Returns the vertical offset value, used for adjusting the heights from the terrain provider.
double scale() const
Returns the vertical scale factor, which can be used to exaggerate vertical heights.
static QgsTerrainGenerator * create()
Creates a new instance of a QgsDemTerrainGenerator object.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsDemTerrainSettings object.
static QgsTerrainGenerator * create() SIP_FACTORY
Creates a new instance of a QgsFlatTerrainGenerator object.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsFlatTerrainSettings object.
A terrain provider that uses the Z values of a mesh layer to build a terrain surface.
QgsMeshLayer * layer() const
Returns the mesh layer to be used as the terrain source.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsMeshTerrainSettings object.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsOnlineDemTerrainSettings object.
static QgsTerrainGenerator * create() SIP_FACTORY
Creates a new instance of a QgsOnlineTerrainGenerator object.
Contains elevation properties for a QgsProject.
QgsAbstractTerrainProvider * terrainProvider()
Returns the project's terrain provider.
static QgsTerrainGenerator * create()
Creates a new instance of a QgsQuantizedMeshTerrainGenerator object.
static QgsAbstractTerrainSettings * create()
Creates a new instance of a QgsQuantizedMeshTerrainSettings object.
A terrain provider where the terrain source is a raster DEM layer.
QgsRasterLayer * layer() const
Returns the raster layer with elevation model to be used as the terrain source.