29#include "moc_qgsterraintexturegenerator_p.cpp"
31using namespace Qt::StringLiterals;
35QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
37 , mTextureSize( QSize( mMap.terrainSettings()->mapTileResolution(), mMap.terrainSettings()->mapTileResolution() ) )
40QFuture<QImage> QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
43 mapSettings.setExtent( extent );
44 QSize size = QSize( mTextureSize );
51 clippedExtent = extent.
intersect( mMap.extent() );
52 mapSettings.setExtent( clippedExtent );
56 if ( clippedExtent.
height() > clippedExtent.
width() )
57 size.setWidth(
static_cast< int >( std::round( size.width() * clippedExtent.
width() / clippedExtent.
height() ) ) );
58 else if ( clippedExtent.
height() < clippedExtent.
width() )
59 size.setHeight(
static_cast< int >( std::round( size.height() * clippedExtent.
height() / clippedExtent.
width() ) ) );
61 mapSettings.setOutputSize( size );
63 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, u
"3D"_s, u
"Texture"_s, tileId.text() );
68 auto jobData = std::make_unique<JobData>();
69 jobData->tileId = tileId;
71 jobData->extent = extent;
72 jobData->debugText = debugText;
74 connect( &jobData->watcher, &QFutureWatcher<QImage>::canceled,
this, [
this, &jobData = *jobData]() {
75 disconnect( jobData.job, &QgsMapRendererJob::finished, this, &QgsTerrainTextureGenerator::onRenderingFinished );
76 connect( jobData.job, &QgsMapRendererJob::finished, jobData.job, &QgsMapRendererSequentialJob::deleteLater );
77 jobData.job->cancelWithoutBlocking();
78 jobData.promise.finish();
79 mJobs.erase( jobData.job );
81 jobData->watcher.setFuture( jobData->promise.future() );
83 mJobs[job] = std::move( jobData );
87 return mJobs[job]->promise.future();
90void QgsTerrainTextureGenerator::onRenderingFinished()
94 Q_ASSERT( mJobs.contains( mapJob ) );
95 JobData &jobData = *mJobs[mapJob];
104 p.setBackgroundMode( Qt::OpaqueMode );
105 QFont font = p.font();
106 font.setPixelSize( std::max( 30, mMap.terrainSettings()->mapTileResolution() / 6 ) );
108 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
109 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
113 mapJob->deleteLater();
114 jobData.promise.addResult( img );
115 jobData.promise.finish();
116 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, u
"3D"_s, u
"Texture"_s, jobData.tileId.text() );
117 mJobs.erase( mapJob );
133 QList<QgsMapLayer *> layers;
135 QString mapThemeName = mMap.terrainMapTheme();
136 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )
138 layers = mMap.layers();
145 layers.erase( std::remove_if( layers.begin(), layers.end(), [](
const QgsMapLayer *layer ) { return layer->renderer3D(); } ), layers.end() );
@ ShowTerrainTileInfo
Displays extra tile info on top of terrain tiles.
@ Globe
Scene is represented as a globe using a geocentric CRS.
@ Local
Local scene based on a projected CRS.
@ DrawLabeling
Enable drawing of labels on top of the map.
@ Render3DMap
Render is for a 3D map.
Base class for all map layer types.
void finished()
emitted when asynchronous rendering is finished (or canceled).
void start()
Start the rendering job and immediately return.
Job implementation that renders everything sequentially in one thread.
QImage renderedImage() override
Gets a preview/resulting image.
Contains configuration for rendering maps.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
void setBackgroundColor(const QColor &color)
Sets the background color of the map.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
Container class that allows storage of map themes consisting of visible map layers and layer styles.
bool hasMapTheme(const QString &name) const
Returns whether a map theme with a matching name exists.
QList< QgsMapLayer * > mapThemeVisibleLayers(const QString &name) const
Returns the list of layers that are visible for the specified map theme.
QMap< QString, QString > mapThemeStyleOverrides(const QString &name)
Gets layer style overrides (for QgsMapSettings) of the visible layers for given map theme.
A rectangle specified with double values.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
@ Flat
The whole terrain is flat area.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).