26#include "moc_qgsterraintexturegenerator_p.cpp"
30QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
32 , mTextureSize( QSize( mMap.terrainSettings()->mapTileResolution(), mMap.terrainSettings()->mapTileResolution() ) )
36int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
39 mapSettings.setExtent( extent );
40 QSize size = QSize( mTextureSize );
47 clippedExtent = extent.
intersect( mMap.extent() );
48 mapSettings.setExtent( clippedExtent );
52 if ( clippedExtent.
height() > clippedExtent.
width() )
53 size.setWidth(
static_cast< int >( std::round( size.width() * clippedExtent.
width() / clippedExtent.
height() ) ) );
54 else if ( clippedExtent.
height() < clippedExtent.
width() )
55 size.setHeight(
static_cast< int >( std::round( size.height() * clippedExtent.
height() / clippedExtent.
width() ) ) );
57 mapSettings.setOutputSize( size );
59 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), tileId.text() );
65 jobData.jobId = ++mLastJobId;
66 jobData.tileId = tileId;
68 jobData.extent = extent;
69 jobData.debugText = debugText;
71 mJobs.insert( job, jobData );
78void QgsTerrainTextureGenerator::cancelJob(
int jobId )
80 for (
const JobData &jd : std::as_const( mJobs ) )
82 if ( jd.jobId == jobId )
87 jd.job->cancelWithoutBlocking();
88 mJobs.remove( jd.job );
92 Q_ASSERT(
false &&
"requested job ID does not exist!" );
95void QgsTerrainTextureGenerator::waitForFinished()
97 for (
auto it = mJobs.keyBegin(); it != mJobs.keyEnd(); it++ )
99 QVector<QgsMapRendererSequentialJob *> toBeDeleted;
100 for (
auto it = mJobs.constBegin(); it != mJobs.constEnd(); it++ )
104 JobData jobData = it.value();
105 toBeDeleted.push_back( mapJob );
109 if ( mMap.showTerrainTilesInfo() )
114 p.setBackgroundMode( Qt::OpaqueMode );
115 QFont font = p.font();
116 font.setPixelSize( std::max( 30, mMap.terrainSettings()->mapTileResolution() / 6 ) );
118 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
119 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
124 emit tileReady( jobData.jobId, img );
129 mJobs.remove( mapJob );
130 mapJob->deleteLater();
134void QgsTerrainTextureGenerator::onRenderingFinished()
138 Q_ASSERT( mJobs.contains( mapJob ) );
139 JobData jobData = mJobs.value( mapJob );
143 if ( mMap.showTerrainTilesInfo() )
148 p.setBackgroundMode( Qt::OpaqueMode );
149 QFont font = p.font();
150 font.setPixelSize( std::max( 30, mMap.terrainSettings()->mapTileResolution() / 6 ) );
152 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
153 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
157 mapJob->deleteLater();
158 mJobs.remove( mapJob );
162 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), jobData.tileId.text() );
165 emit tileReady( jobData.jobId, img );
181 QList<QgsMapLayer *> layers;
183 QString mapThemeName = mMap.terrainMapTheme();
184 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )
186 layers = mMap.layers();
193 layers.erase( std::remove_if( layers.begin(), layers.end(), [](
const QgsMapLayer *layer ) { return layer->renderer3D(); } ), layers.end() );
@ 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.
void waitForFinished() override
Block until the job has finished.
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).