QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "moc_qgsdemterraingenerator.cpp"
18
20
21#include "qgs3dutils.h"
22#include "qgsrasterlayer.h"
24
29
31{
32 delete mHeightMapGenerator;
33}
34
36{
37 mLayer = layer;
38 updateGenerator();
39}
40
42{
43 return mLayer;
44}
45
47{
48 mCrs = crs;
49 mTransformContext = context;
50 updateGenerator();
51}
52
54{
56 cloned->setTerrain( mTerrain );
57 cloned->mCrs = mCrs;
58 cloned->mLayer = mLayer;
59 cloned->mResolution = mResolution;
60 cloned->mSkirtHeight = mSkirtHeight;
61 cloned->mExtent = mExtent;
62 cloned->updateGenerator();
63 return cloned;
64}
65
70
75
76float QgsDemTerrainGenerator::heightAt( double x, double y, const Qgs3DRenderContext &context ) const
77{
78 Q_UNUSED( context )
79 if ( mHeightMapGenerator )
80 return mHeightMapGenerator->heightAt( x, y );
81 else
82 return 0;
83}
84
85QgsChunkLoader *QgsDemTerrainGenerator::createChunkLoader( QgsChunkNode *node ) const
86{
87 // A bit of a hack to make cloning terrain generator work properly
88 return new QgsDemTerrainTileLoader( mTerrain, node, const_cast<QgsDemTerrainGenerator *>( this ) );
89}
90
92{
93 mExtent = extent;
94 updateGenerator();
95}
96
97void QgsDemTerrainGenerator::updateGenerator()
98{
99 QgsRasterLayer *dem = layer();
100 if ( dem && mCrs.isValid() )
101 {
102 QgsRectangle layerExtent = Qgs3DUtils::tryReprojectExtent2D( mLayer->extent(), mLayer->crs(), mCrs, mTransformContext );
103 // no need to have an mExtent larger than the actual layer's extent
104 const QgsRectangle intersectExtent = mExtent.intersect( layerExtent );
105
106 mTerrainTilingScheme = QgsTilingScheme( intersectExtent, mCrs );
107 delete mHeightMapGenerator;
108 mHeightMapGenerator = new QgsDemHeightMapGenerator( dem, mTerrainTilingScheme, mResolution, mTransformContext );
109 mIsValid = true;
110 }
111 else
112 {
114 delete mHeightMapGenerator;
115 mHeightMapGenerator = nullptr;
116 mIsValid = false;
117 }
118}
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.
This class 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.
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.
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
virtual void setTerrain(QgsTerrainEntity *t)
Sets terrain entity for the generator (does not transfer ownership)
QgsRectangle tileToExtent(int x, int y, int z) const
Returns map coordinates of the extent of a tile.
const QgsCoordinateReferenceSystem & crs