QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
qgsdemterraingenerator.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdemterraingenerator.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
17
18#include <limits>
19
20#include "qgs3dutils.h"
23#include "qgsrasterlayer.h"
24
25#include "moc_qgsdemterraingenerator.cpp"
26
31
33{
34 delete mHeightMapGenerator;
35}
36
38{
39 mLayer = layer;
40 updateGenerator();
41}
42
44{
45 return mLayer;
46}
47
49{
50 mCrs = crs;
51 mTransformContext = context;
52 updateGenerator();
53}
54
56{
58 cloned->setTerrain( mTerrain );
59 cloned->mCrs = mCrs;
60 cloned->mLayer = mLayer;
61 cloned->mResolution = mResolution;
62 cloned->mSkirtHeight = mSkirtHeight;
63 cloned->mExtent = mExtent;
64 cloned->updateGenerator();
65 return cloned;
66}
67
72
74{
75 return mTerrainTilingScheme.tileToExtent( 0, 0, 0 );
76}
77
78float QgsDemTerrainGenerator::heightAt( double x, double y, const Qgs3DRenderContext &context ) const
79{
80 Q_UNUSED( context )
81 if ( mHeightMapGenerator )
82 return mHeightMapGenerator->heightAt( x, y );
83 else
84 return std::numeric_limits<float>::quiet_NaN();
85}
86
87QgsChunkLoader *QgsDemTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
88{
89 // A bit of a hack to make cloning terrain generator work properly
90 return new QgsDemTerrainTileLoader( mTerrain, node, const_cast<QgsDemTerrainGenerator *>( this ) );
91}
92
94{
95 mExtent = extent;
96 updateGenerator();
97}
98
99void QgsDemTerrainGenerator::updateGenerator()
100{
101 QgsRasterLayer *dem = layer();
102 if ( dem && mCrs.isValid() )
103 {
104 QgsRectangle layerExtent = Qgs3DUtils::tryReprojectExtent2D( mLayer->extent(), mLayer->crs(), mCrs, mTransformContext );
105 // no need to have an mExtent larger than the actual layer's extent
106 const QgsRectangle intersectExtent = mExtent.intersect( layerExtent );
107
108 mTerrainTilingScheme = QgsTilingScheme( intersectExtent, mCrs );
109 delete mHeightMapGenerator;
110 mHeightMapGenerator = new QgsDemHeightMapGenerator( dem, mTerrainTilingScheme, mResolution, mTransformContext );
111 mIsValid = true;
112 }
113 else
114 {
115 mTerrainTilingScheme = QgsTilingScheme();
116 delete mHeightMapGenerator;
117 mHeightMapGenerator = nullptr;
118 mIsValid = false;
119 }
120}
121
Rendering context for preparation of 3D entities.
static QgsRectangle tryReprojectExtent2D(const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs1, const QgsCoordinateReferenceSystem &crs2, const QgsCoordinateTransformContext &context)
Reprojects extent from crs1 to crs2 coordinate reference system with context context.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Contains information about the context in which a coordinate transform is executed.
QgsRectangle rootChunkExtent() const override
extent of the terrain's root chunk in terrain's CRS
static QgsTerrainGenerator * create()
Creates a new instance of a QgsDemTerrainGenerator object.
float heightAt(double x, double y, const Qgs3DRenderContext &context) const override
Returns height at (x,y) in map's CRS.
Type type() const override
What texture generator implementation is this.
QgsTerrainGenerator * clone() const override
Makes a copy of the current instance.
QgsTerrainGenerator::Capabilities capabilities() const override
Returns flags containing the supported capabilities.
void setCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context) override
Sets the CRS associated with the terrain.
QgsRasterLayer * layer() const
Returns raster layer with elevation model to be used for terrain generation.
void setExtent(const QgsRectangle &extent) override
sets the extent of the terrain in terrain's CRS
QgsCoordinateReferenceSystem crs() const override
Returns CRS of the terrain.
QgsChunkLoader * createChunkLoader(QgsChunkNode *node) const override
void setLayer(QgsRasterLayer *layer)
Sets raster layer with elevation model to be used for terrain generation.
QgsDemTerrainGenerator()=default
Represents a raster layer.
A rectangle specified with double values.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
Base class for generators of terrain.
Type
Enumeration of the available terrain generators.
@ Dem
Terrain is built from raster layer with digital elevation model.
QgsTilingScheme mTerrainTilingScheme
Tiling scheme of the terrain.
QgsTerrainEntity * mTerrain
QFlags< Capability > Capabilities
@ SupportsTileResolution
Supports tile resolution.
virtual void setTerrain(QgsTerrainEntity *t)
Sets terrain entity for the generator (does not transfer ownership).
Encapsulates tiling schemes (just like with WMTS / TMS / XYZ layers).