QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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( "flat" );
66  return QStringLiteral( "dem" );
68  return QStringLiteral( "quantized-mesh" );
69  }
70  return QString();
71 }
3 Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:30
A rectangle specified with double values.
Definition: qgsrectangle.h:40
virtual float heightAt(double x, double y, const Qgs3DMapSettings &map) const
Returns height at (x,y) in terrain's CRS.
virtual Type type() const =0
What texture generator implementation is this.
3 Definition of the world
virtual void rootChunkHeightRange(float &hMin, float &hMax) const
Returns height range of the root chunk in world coordinates.
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
Terrain is built from raster layer with digital elevation model.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
int mapTileResolution() const
Returns resolution (in pixels) of the texture of a terrain tile.
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
Type
Enumeration of the available terrain generators.
virtual QgsAABB rootChunkBbox(const Qgs3DMapSettings &map) const
Returns bounding box of the root chunk.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Class for doing transforms between two map coordinate systems.
virtual QgsRectangle extent() const =0
extent of the terrain in terrain's CRS
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
Terrain is built from downloaded tiles in quantized mesh format.
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:201
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
The whole terrain is flat area.