QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
21 
23 {
24  QgsRectangle te = extent();
25  QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
26  te = terrainToMapTransform.transformBoundingBox( te );
27 
28  float hMin, hMax;
29  rootChunkHeightRange( hMin, hMax );
30  return QgsAABB( te.xMinimum() - map.origin().x(), hMin * map.terrainVerticalScale(), -te.yMaximum() + map.origin().y(),
31  te.xMaximum() - map.origin().x(), hMax * map.terrainVerticalScale(), -te.yMinimum() + map.origin().y() );
32 }
33 
35 {
36  QgsRectangle te = extent();
37  QgsCoordinateTransform terrainToMapTransform( crs(), map.crs(), map.transformContext() );
38  te = terrainToMapTransform.transformBoundingBox( te );
39 
40  // use texel size as the error
41  return te.width() / map.mapTileResolution();
42 }
43 
44 void QgsTerrainGenerator::rootChunkHeightRange( float &hMin, float &hMax ) const
45 {
46  // TODO: makes sense to have kind of default implementation?
47  hMin = 0;
48  hMax = 400;
49 }
50 
51 float QgsTerrainGenerator::heightAt( double x, double y, const Qgs3DMapSettings &map ) const
52 {
53  Q_UNUSED( x )
54  Q_UNUSED( y )
55  Q_UNUSED( map )
56  return 0.f;
57 }
58 
60 {
61  switch ( type )
62  {
64  return QStringLiteral( "mesh" );
66  return QStringLiteral( "flat" );
68  return QStringLiteral( "dem" );
70  return QStringLiteral( "online" );
71  }
72  return QString();
73 }
74 
76 {
77  return mIsValid;
78 }
Qgs3DMapSettings::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.h:94
QgsTerrainGenerator::Dem
@ Dem
Terrain is built from raster layer with digital elevation model.
Definition: qgsterraingenerator.h:55
QgsTerrainGenerator::crs
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
Definition: qgsterraingenerator.h:100
QgsTerrainGenerator::type
virtual Type type() const =0
What texture generator implementation is this.
QgsVector3D::y
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:64
qgsaabb.h
Qgs3DMapSettings::mapTileResolution
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
Definition: qgs3dmapsettings.cpp:418
QgsRectangle::xMaximum
double xMaximum() const
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
Qgs3DMapSettings::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Definition: qgs3dmapsettings.cpp:329
QgsRectangle
Definition: qgsrectangle.h:41
QgsCoordinateTransform::transformBoundingBox
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:511
QgsTerrainGenerator::rootChunkHeightRange
virtual void rootChunkHeightRange(float &hMin, float &hMax) const
Returns height range of the root chunk in world coordinates.
Definition: qgsterraingenerator.cpp:44
QgsTerrainGenerator::heightAt
virtual float heightAt(double x, double y, const Qgs3DMapSettings &map) const
Returns height at (x,y) in terrain's CRS.
Definition: qgsterraingenerator.cpp:51
qgsterraingenerator.h
QgsTerrainGenerator::Flat
@ Flat
The whole terrain is flat area.
Definition: qgsterraingenerator.h:54
QgsTerrainGenerator::typeToString
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
Definition: qgsterraingenerator.cpp:59
QgsTerrainGenerator::isValid
bool isValid() const
Returns whether the terrain generator is valid.
Definition: qgsterraingenerator.cpp:75
QgsAABB
Definition: qgsaabb.h:33
QgsTerrainGenerator::Type
Type
Enumeration of the available terrain generators.
Definition: qgsterraingenerator.h:52
Qgs3DMapSettings
Definition: qgs3dmapsettings.h:51
Qgs3DMapSettings::origin
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Definition: qgs3dmapsettings.h:84
QgsRectangle::yMaximum
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:172
QgsTerrainGenerator::rootChunkError
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
Definition: qgsterraingenerator.cpp:34
qgs3dmapsettings.h
QgsTerrainGenerator::Online
@ Online
Terrain is built from downloaded tiles with digital elevation model.
Definition: qgsterraingenerator.h:56
QgsRectangle::yMinimum
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsTerrainGenerator::mIsValid
bool mIsValid
Definition: qgsterraingenerator.h:109
QgsTerrainGenerator::extent
virtual QgsRectangle extent() const =0
extent of the terrain in terrain's CRS
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
QgsTerrainGenerator::rootChunkBbox
virtual QgsAABB rootChunkBbox(const Qgs3DMapSettings &map) const
Returns bounding box of the root chunk.
Definition: qgsterraingenerator.cpp:22
QgsVector3D::x
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:62
QgsTerrainGenerator::Mesh
@ Mesh
Terrain is built from mesh layer with z value on vertices.
Definition: qgsterraingenerator.h:57
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
Qgs3DMapSettings::terrainVerticalScale
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
Definition: qgs3dmapsettings.cpp:376