28#include "moc_qgsterraintexturegenerator_p.cpp"
30using namespace Qt::StringLiterals;
34QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
36 , mTextureSize( QSize( mMap.terrainSettings()->mapTileResolution(), mMap.terrainSettings()->mapTileResolution() ) )
39int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
42 mapSettings.setExtent( extent );
43 QSize size = QSize( mTextureSize );
50 clippedExtent = extent.
intersect( mMap.extent() );
51 mapSettings.setExtent( clippedExtent );
55 if ( clippedExtent.
height() > clippedExtent.
width() )
56 size.setWidth(
static_cast< int >( std::round( size.width() * clippedExtent.
width() / clippedExtent.
height() ) ) );
57 else if ( clippedExtent.
height() < clippedExtent.
width() )
58 size.setHeight(
static_cast< int >( std::round( size.height() * clippedExtent.
height() / clippedExtent.
width() ) ) );
60 mapSettings.setOutputSize( size );
62 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, u
"3D"_s, u
"Texture"_s, tileId.text() );
68 jobData.jobId = ++mLastJobId;
69 jobData.tileId = tileId;
71 jobData.extent = extent;
72 jobData.debugText = debugText;
74 mJobs.insert( job, jobData );
81void QgsTerrainTextureGenerator::cancelJob(
int jobId )
83 for (
const JobData &jd : std::as_const( mJobs ) )
85 if ( jd.jobId == jobId )
90 jd.job->cancelWithoutBlocking();
91 mJobs.remove( jd.job );
95 Q_ASSERT(
false &&
"requested job ID does not exist!" );
98void QgsTerrainTextureGenerator::waitForFinished()
100 for (
auto it = mJobs.keyBegin(); it != mJobs.keyEnd(); it++ )
102 QVector<QgsMapRendererSequentialJob *> toBeDeleted;
103 for (
auto it = mJobs.constBegin(); it != mJobs.constEnd(); it++ )
107 JobData jobData = it.value();
108 toBeDeleted.push_back( mapJob );
112 if ( mMap.showTerrainTilesInfo() )
117 p.setBackgroundMode( Qt::OpaqueMode );
118 QFont font = p.font();
119 font.setPixelSize( std::max( 30, mMap.terrainSettings()->mapTileResolution() / 6 ) );
121 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
122 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
127 emit tileReady( jobData.jobId, img );
132 mJobs.remove( mapJob );
133 mapJob->deleteLater();
137void QgsTerrainTextureGenerator::onRenderingFinished()
141 Q_ASSERT( mJobs.contains( mapJob ) );
142 JobData jobData = mJobs.value( mapJob );
146 if ( mMap.showTerrainTilesInfo() )
151 p.setBackgroundMode( Qt::OpaqueMode );
152 QFont font = p.font();
153 font.setPixelSize( std::max( 30, mMap.terrainSettings()->mapTileResolution() / 6 ) );
155 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
156 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
160 mapJob->deleteLater();
161 mJobs.remove( mapJob );
165 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, u
"3D"_s, u
"Texture"_s, jobData.tileId.text() );
168 emit tileReady( jobData.jobId, img );
184 QList<QgsMapLayer *> layers;
186 QString mapThemeName = mMap.terrainMapTheme();
187 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )
189 layers = mMap.layers();
196 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).