QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgscoordinatetransform.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 
46 void 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 
53 float 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 }
Qgs3DMapSettings::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
Definition: qgs3dmapsettings.h:99
QgsTerrainGenerator::Dem
@ Dem
Terrain is built from raster layer with digital elevation model.
Definition: qgsterraingenerator.h:58
QgsTerrainGenerator::crs
QgsCoordinateReferenceSystem crs() const
Returns CRS of the terrain.
Definition: qgsterraingenerator.h:106
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:630
QgsRectangle::yMinimum
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsCoordinateTransform::transformBoundingBox
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.
Definition: qgscoordinatetransform.cpp:560
Qgs3DMapSettings::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Definition: qgs3dmapsettings.cpp:494
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsRectangle::xMaximum
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
QgsTerrainGenerator::rootChunkHeightRange
virtual void rootChunkHeightRange(float &hMin, float &hMax) const
Returns height range of the root chunk in world coordinates.
Definition: qgsterraingenerator.cpp:46
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:53
QgsCoordinateTransform::setBallparkTransformsAreAppropriate
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
Definition: qgscoordinatetransform.cpp:939
qgsterraingenerator.h
QgsTerrainGenerator::Flat
@ Flat
The whole terrain is flat area.
Definition: qgsterraingenerator.h:57
QgsTerrainGenerator::typeToString
static QString typeToString(Type type)
Converts terrain generator type enumeration into a string.
Definition: qgsterraingenerator.cpp:61
QgsTerrainGenerator::isValid
bool isValid() const
Returns whether the terrain generator is valid.
Definition: qgsterraingenerator.cpp:77
QgsAABB
Axis-aligned bounding box - in world coords.
Definition: qgsaabb.h:33
QgsTerrainGenerator::Type
Type
Enumeration of the available terrain generators.
Definition: qgsterraingenerator.h:55
qgscoordinatetransform.h
Qgs3DMapSettings
Definition of the world.
Definition: qgs3dmapsettings.h:57
QgsRectangle::xMinimum
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
Qgs3DMapSettings::origin
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
Definition: qgs3dmapsettings.h:89
QgsTerrainGenerator::rootChunkError
virtual float rootChunkError(const Qgs3DMapSettings &map) const
Returns error of the root chunk in world coordinates.
Definition: qgsterraingenerator.cpp:35
qgs3dmapsettings.h
QgsRectangle::yMaximum
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
QgsTerrainGenerator::Online
@ Online
Terrain is built from downloaded tiles with digital elevation model.
Definition: qgsterraingenerator.h:59
QgsRectangle::width
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
QgsTerrainGenerator::mIsValid
bool mIsValid
Definition: qgsterraingenerator.h:124
QgsTerrainGenerator::extent
virtual QgsRectangle extent() const =0
extent of the terrain in terrain's CRS
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
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:60
Qgs3DMapSettings::terrainVerticalScale
double terrainVerticalScale() const
Returns vertical scale (exaggeration) of terrain.
Definition: qgs3dmapsettings.cpp:541