32#include <Qt3DCore/QTransform>
33#include <QtConcurrent>
35#include "moc_qgsrulebasedchunkloader_p.cpp"
40QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
41 : QgsChunkLoader( node )
43 , mContext( factory->mRenderContext )
48void QgsRuleBasedChunkLoader::start()
50 QgsChunkNode *node = chunk();
51 if ( node->level() < mFactory->mLeafLevel )
53 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
68 mContext.setExpressionContext( exprContext );
74 mRootRule.reset( mFactory->mRootRule->clone() );
76 mRootRule->createHandlers( layer, mHandlers );
78 QSet<QString> attributeNames;
79 mRootRule->prepare( mContext, attributeNames, chunkOrigin, mHandlers );
90 mFutureWatcher =
new QFutureWatcher<void>(
this );
91 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
93 const QFuture<void> future = QtConcurrent::run( [req = std::move( req ),
this] {
94 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
102 mContext.expressionContext().setFeature( f );
103 mRootRule->registerFeature( f, mContext, mHandlers );
108 mFutureWatcher->setFuture( future );
111QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
113 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
115 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
116 mFutureWatcher->waitForFinished();
119 qDeleteAll( mHandlers );
123void QgsRuleBasedChunkLoader::cancel()
128Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
130 if ( mNode->level() < mFactory->mLeafLevel )
132 return new Qt3DCore::QEntity( parent );
135 long long featureCount = 0;
136 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
138 featureCount += it.value()->featureCount();
140 if ( featureCount == 0 )
146 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
147 float zMin = std::numeric_limits<float>::max();
148 float zMax = std::numeric_limits<float>::lowest();
149 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
151 QgsFeature3DHandler *handler = it.value();
152 handler->finalize( entity, mContext );
153 if ( handler->zMinimum() < zMin )
154 zMin = handler->zMinimum();
155 if ( handler->zMaximum() > zMax )
156 zMax = handler->zMaximum();
160 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::lowest() )
165 mNode->setExactBox3D( box );
166 mNode->updateParentBoundingBoxesRecursively();
177 : mRenderContext( context )
179 , mRootRule( rootRule->clone() )
180 , mLeafLevel( leafLevel )
183 setupQuadtree( rootBox3D, -1, leafLevel );
186QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
188QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
190 return new QgsRuleBasedChunkLoader(
this, node );
197 : QgsChunkedEntity( map,
199 new QgsRuleBasedChunkLoaderFactory(
Qgs3DRenderContext::fromMapSettings( map ), vl, rootRule, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
201 mTransform =
new Qt3DCore::QTransform;
202 if ( applyTerrainOffset() )
206 this->addComponent( mTransform );
212QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
219bool QgsRuleBasedChunkedEntity::applyTerrainOffset()
const
221 QgsRuleBasedChunkLoaderFactory *loaderFactory =
static_cast<QgsRuleBasedChunkLoaderFactory *
>( mChunkLoaderFactory );
226 for (
const auto &rule : rules )
228 if ( rule->symbol() )
230 QString symbolType = rule->symbol()->type();
231 if ( symbolType ==
"line" )
239 else if ( symbolType ==
"point" )
247 else if ( symbolType ==
"polygon" )
257 QgsDebugMsgLevel( QStringLiteral(
"QgsRuleBasedChunkedEntityChunkedEntity::applyTerrainOffset, unhandled symbol type %1" ).arg( symbolType ), 2 );
266void QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged()
268 const float previousOffset = mTransform->translation()[1];
269 float newOffset =
static_cast<float>( qobject_cast<Qgs3DMapSettings *>( sender() )->terrainSettings()->elevationOffset() );
270 if ( !applyTerrainOffset() )
275 if ( newOffset != previousOffset )
277 mTransform->setTranslation( QVector3D( 0.0f, 0.0f, newOffset ) );
281QList<QgsRayCastHit> QgsRuleBasedChunkedEntity::rayIntersection(
const QgsRay3D &ray,
const QgsRayCastContext &context )
const
283 return QgsVectorLayerChunkedEntity::rayIntersection( activeNodes(), mTransform->matrix(), ray, context, mMapSettings->origin() );
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
const QgsAbstractTerrainSettings * terrainSettings() const
Returns the terrain settings.
void terrainSettingsChanged()
Emitted when the terrain settings are changed.
Rendering context for preparation of 3D entities.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
double elevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down).
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.
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 & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setDestinationCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets the destination crs for feature's geometries.
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).
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 representation of a ray in 3D.
Responsible for defining parameters of the ray casting operations in 3D map canvases.
A rectangle specified with double values.
A child rule for a QgsRuleBased3DRenderer.
const QgsRuleBased3DRenderer::RuleList & children() const
Returns all children rules of this rule.
QList< QgsRuleBased3DRenderer::Rule * > RuleList
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
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).
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)