QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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"
21
23{
24 QgsRectangle te = extent();
25 QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
26 terrainToMapTransform.setBallparkTransformsAreAppropriate( true );
27 te = terrainToMapTransform.transformBoundingBox( te );
28
29 float hMin, hMax;
30 rootChunkHeightRange( hMin, hMax );
31 return QgsAABB( te.xMinimum() - map.origin().x(), hMin * map.terrainVerticalScale(), -te.yMaximum() + map.origin().y(),
32 te.xMaximum() - map.origin().x(), hMax * map.terrainVerticalScale(), -te.yMinimum() + map.origin().y() );
33}
34
36{
37 QgsRectangle te = extent();
38 QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
39 terrainToMapTransform.setBallparkTransformsAreAppropriate( true );
40 te = terrainToMapTransform.transformBoundingBox( te );
41
42 // use texel size as the error
43 return te.width() / map.mapTileResolution();
44}
45
46void QgsTerrainGenerator::rootChunkHeightRange( float &hMin, float &hMax ) const
47{
48 // TODO: makes sense to have kind of default implementation?
49 hMin = 0;
50 hMax = 400;
51}
52
53float QgsTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings &map ) const
54{
55 Q_UNUSED( x )
56 Q_UNUSED( y )
57 Q_UNUSED( map )
58 return 0.f;
59}
60
62{
63 switch ( type )
64 {
66 return QStringLiteral( "mesh" );
68 return QStringLiteral( "flat" );
70 return QStringLiteral( "dem" );
72 return QStringLiteral( "online" );
73 }
74 return QString();
75}
76
78{
79 return mIsValid;
80}
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)
3
Definition: qgsaabb.h:34
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
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 QgsRectangle extent() const =0
extent of the terrain in terrain's CRS
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 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.
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49