QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 }
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.
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.
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:172
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:162
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
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