QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsterraingenerator.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsterraingenerator.cpp
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#include "qgsterraingenerator.h"
17
18#include "qgsaabb.h"
19#include "qgs3dmapsettings.h"
20#include "qgs3dutils.h"
22
24{
26
27 float hMin, hMax;
28 rootChunkHeightRange( hMin, hMax );
29 return Qgs3DUtils::mapToWorldExtent( te, hMin * map.terrainVerticalScale(), hMax * map.terrainVerticalScale(), map.origin() );
30}
31
33{
35
36 // use texel size as the error
37 return te.width() / map.mapTileResolution();
38}
39
40void QgsTerrainGenerator::rootChunkHeightRange( float &hMin, float &hMax ) const
41{
42 // TODO: makes sense to have kind of default implementation?
43 hMin = 0;
44 hMax = 400;
45}
46
47float QgsTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings &map ) const
48{
49 Q_UNUSED( x )
50 Q_UNUSED( y )
51 Q_UNUSED( map )
52 return 0.f;
53}
54
56{
57 switch ( type )
58 {
60 return QStringLiteral( "mesh" );
62 return QStringLiteral( "flat" );
64 return QStringLiteral( "dem" );
66 return QStringLiteral( "online" );
67 }
68 return QString();
69}
70
72{
73 return mIsValid;
74}
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
Definition: qgs3dutils.cpp:602
static QgsRectangle tryReprojectExtent2D(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Reprojects extent from crs1 to crs2 coordinate reference system with context context.
Definition: qgs3dutils.cpp:569
3
Definition: qgsaabb.h:34
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
Type
Enumeration of the available terrain generators.
@ Dem
Terrain is built from raster layer with digital elevation model.
@ Online
Terrain is built from downloaded tiles with digital elevation model.
@ Mesh
Terrain is built from mesh layer with z value on vertices.
@ Flat
The whole terrain is flat area.
virtual Type type() const =0
What texture generator implementation is this.
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
virtual float heightAt(double x, double y, const Qgs3DMapSettings &map) const
Returns height at (x,y) in terrain's CRS.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
virtual QgsAABB rootChunkBbox(const Qgs3DMapSettings &map) const
Returns bounding box of the root chunk.
virtual QgsRectangle rootChunkExtent() const =0
extent of the terrain's root chunk in terrain's CRS
virtual void rootChunkHeightRange(float &hMin, float &hMax) const
Returns height range of the root chunk in world coordinates.
bool isValid() const
Returns whether the terrain generator is valid.