36#include <Qt3DCore/QTransform>
37#include <Qt3DRender/QGeometryRenderer>
38#include <QtConcurrentRun>
40#include "moc_qgsvectorlayerchunkloader_p.cpp"
42using namespace Qt::StringLiterals;
47QgsVectorLayerChunkLoader::QgsVectorLayerChunkLoader(
const QgsVectorLayerChunkLoaderFactory *factory, QgsChunkNode *node )
48 : QgsChunkLoader( node )
50 , mRenderContext( factory->mRenderContext )
54void QgsVectorLayerChunkLoader::start()
56 QgsChunkNode *node = chunk();
59 mLayerName = mFactory->mLayer->
name();
64 QgsDebugError( u
"Unknown 3D symbol type for vector layer: "_s + mFactory->mSymbol->type() );
67 mHandler.reset( handler );
72 mRenderContext.setExpressionContext( exprContext );
74 QSet<QString> attributeNames;
75 if ( !mHandler->prepare( mRenderContext, attributeNames, node->box3D() ) )
92 mFutureWatcher =
new QFutureWatcher<void>(
this );
94 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, [
this] {
96 mFactory->mNodesAreLeafs[mNode->tileId().text()] = mNodeIsLeaf;
99 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
101 const QFuture<void> future = QtConcurrent::run( [req = std::move( req ),
this] {
102 const QgsEventTracing::ScopedEvent e( u
"3D"_s, u
"VL chunk load"_s );
106 int featureCount = 0;
107 bool featureLimitReached =
false;
113 if ( ++featureCount > mFactory->mMaxFeatures )
115 featureLimitReached =
true;
119 mRenderContext.expressionContext().setFeature( f );
120 mHandler->processFeature( f, mRenderContext );
123 if ( !featureLimitReached )
125 QgsDebugMsgLevel( u
"All features fetched for node: %1"_s.arg( mNode->tileId().text() ), 3 );
133 mFutureWatcher->setFuture( future );
136QgsVectorLayerChunkLoader::~QgsVectorLayerChunkLoader()
138 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
140 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
141 mFutureWatcher->waitForFinished();
145void QgsVectorLayerChunkLoader::cancel()
150Qt3DCore::QEntity *QgsVectorLayerChunkLoader::createEntity( Qt3DCore::QEntity *parent )
152 if ( mHandler->featureCount() == 0 )
157 mNode->updateParentBoundingBoxesRecursively();
161 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
162 entity->setObjectName( mLayerName +
"_" + mNode->tileId().text() );
163 mHandler->finalize( entity, mRenderContext );
166 if ( mHandler->zMinimum() != std::numeric_limits<float>::max() && mHandler->zMaximum() != std::numeric_limits<float>::lowest() )
171 mNode->setExactBox3D( box );
172 mNode->updateParentBoundingBoxesRecursively();
183 : mRenderContext( context )
185 , mSymbol( symbol->clone() )
186 , mMaxFeatures( maxFeatures )
192 QgsDebugError( u
"Vector layers in globe scenes are not supported yet!"_s );
193 setupQuadtree( QgsBox3D( -7e6, -7e6, -7e6, 7e6, 7e6, 7e6 ), -1, 3 );
200 if ( layerExtentInMapCrs.isValid() )
202 extent = context.extent().intersect( layerExtentInMapCrs );
204 if ( extent.isValid() )
206 QgsBox3D rootBox3D( extent, zMin, zMax );
208 rootBox3D.grow( 1.0 );
210 const float rootError = static_cast<float>( std::max<double>( rootBox3D.width(), rootBox3D.height() ) * QgsVectorLayer3DTilingSettings::tileGeometryErrorRatio() );
211 setupQuadtree( rootBox3D, rootError );
215QgsChunkLoader *QgsVectorLayerChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
217 return new QgsVectorLayerChunkLoader(
this, node );
220bool QgsVectorLayerChunkLoaderFactory::canCreateChildren( QgsChunkNode *node )
222 return mNodesAreLeafs.contains( node->tileId().text() );
225QVector<QgsChunkNode *> QgsVectorLayerChunkLoaderFactory::createChildren( QgsChunkNode *node )
const
227 if ( mNodesAreLeafs.value( node->tileId().text(),
false ) )
230 return QgsQuadtreeChunkLoaderFactory::createChildren( node );
237QgsVectorLayerChunkedEntity::QgsVectorLayerChunkedEntity(
240 : QgsAbstractFeatureBasedChunkedEntity( map, 3, new QgsVectorLayerChunkLoaderFactory(
Qgs3DRenderContext::fromMapSettings( map ), vl, symbol, zMin, zMax, tilingSettings.maximumChunkFeatures() ), true )
242 onTerrainElevationOffsetChanged();
246QgsVectorLayerChunkedEntity::~QgsVectorLayerChunkedEntity()
253bool QgsVectorLayerChunkedEntity::applyTerrainOffset()
const
255 QgsVectorLayerChunkLoaderFactory *loaderFactory =
static_cast<QgsVectorLayerChunkLoaderFactory *
>( mChunkLoaderFactory );
258 QString symbolType = loaderFactory->mSymbol.get()->type();
259 if ( symbolType ==
"line" )
267 else if ( symbolType ==
"point" )
275 else if ( symbolType ==
"polygon" )
285 QgsDebugMsgLevel( u
"QgsVectorLayerChunkedEntity::applyTerrainOffset, unhandled symbol type %1"_s.arg( symbolType ), 2 );
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
@ Geocentric
Geocentric CRS.
Rendering context for preparation of 3D entities.
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system used in the 3D scene.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsFeature3DHandler * createHandlerForSymbol(QgsVectorLayer *layer, const QgsAbstract3DSymbol *symbol)
Creates a feature handler for a symbol, for the specified vector layer.
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.
Abstract base class for 3D symbols that are used by VectorLayer3DRenderer objects.
static Qgs3DSymbolRegistry * symbol3DRegistry()
Returns registry of available 3D symbols.
A 3-dimensional box composed of x, y, z coordinates.
void setZMinimum(double z)
Sets the minimum z value.
void setZMaximum(double z)
Sets the maximum z value.
Qgis::CrsType type() const
Returns the type of the CRS.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform which will be used to transform the feature's geometries.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
3D symbol that draws linestring geometries as planar polygons (created from lines using a buffer with...
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain).
QgsCoordinateReferenceSystem crs3D
3D symbol that draws point geometries as 3D objects using one of the predefined shapes.
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain).
3D symbol that draws polygon geometries as planar polygons, optionally extruded (with added walls).
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain).
A rectangle specified with double values.
Defines configuration of how a vector layer gets tiled for 3D rendering.
bool showBoundingBoxes() const
Returns whether to display bounding boxes of entity's tiles (for debugging).
static double maximumLeafExtent()
This is the maximum width or height a tile can have and still be considered a leaf node.
Partial snapshot of vector layer's state (only the members necessary for access to features).
Represents a vector layer which manages a vector based dataset.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)