33#include <QtConcurrent>
34#include <Qt3DCore/QTransform>
39QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
40 : QgsChunkLoader( node )
42 , mContext( factory->mRenderContext )
45 if ( node->level() < mFactory->mLeafLevel )
47 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
54 exprContext.setFields( layer->
fields() );
55 mContext.setExpressionContext( exprContext );
61 mRootRule.reset( mFactory->mRootRule->clone() );
63 mRootRule->createHandlers( layer, mHandlers );
65 QSet<QString> attributeNames;
66 mRootRule->prepare( mContext, attributeNames, mHandlers );
80 mFutureWatcher =
new QFutureWatcher<void>(
this );
81 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
83 const QFuture<void> future = QtConcurrent::run( [req,
this]
85 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
93 mContext.expressionContext().setFeature( f );
94 mRootRule->registerFeature( f, mContext, mHandlers );
99 mFutureWatcher->setFuture( future );
102QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
104 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
106 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
107 mFutureWatcher->waitForFinished();
110 qDeleteAll( mHandlers );
114void QgsRuleBasedChunkLoader::cancel()
119Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
121 if ( mNode->level() < mFactory->mLeafLevel )
123 return new Qt3DCore::QEntity( parent );
126 long long featureCount = 0;
127 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
129 featureCount += it.value()->featureCount();
131 if ( featureCount == 0 )
137 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
138 float zMin = std::numeric_limits<float>::max();
139 float zMax = std::numeric_limits<float>::lowest();
140 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
142 QgsFeature3DHandler *handler = it.value();
143 handler->finalize( entity, mContext );
144 if ( handler->zMinimum() < zMin )
145 zMin = handler->zMinimum();
146 if ( handler->zMaximum() > zMax )
147 zMax = handler->zMaximum();
151 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::lowest() )
156 mNode->setExactBbox( box );
157 mNode->updateParentBoundingBoxesRecursively();
168 : mRenderContext( context )
170 , mRootRule( rootRule->clone() )
171 , mLeafLevel( leafLevel )
174 setupQuadtree( rootBbox, -1, leafLevel );
177QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
179QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
181 return new QgsRuleBasedChunkLoader(
this, node );
188 : QgsChunkedEntity( map,
190 new QgsRuleBasedChunkLoaderFactory(
Qgs3DRenderContext::fromMapSettings( map ), vl, rootRule, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
192 mTransform =
new Qt3DCore::QTransform;
193 if ( applyTerrainOffset() )
197 this->addComponent( mTransform );
203QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
210bool QgsRuleBasedChunkedEntity::applyTerrainOffset()
const
212 QgsRuleBasedChunkLoaderFactory *loaderFactory =
static_cast<QgsRuleBasedChunkLoaderFactory *
>( mChunkLoaderFactory );
219 if ( symbolType ==
"line" )
227 else if ( symbolType ==
"point" )
235 else if ( symbolType ==
"polygon" )
245 QgsDebugMsgLevel( QStringLiteral(
"QgsRuleBasedChunkedEntityChunkedEntity::applyTerrainOffset, unhandled symbol type %1" ).arg( symbolType ), 2 );
253void QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged(
float newOffset )
255 float previousOffset = mTransform->translation()[1];
256 if ( !applyTerrainOffset() )
261 if ( newOffset != previousOffset )
263 mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
267QVector<QgsRayCastingUtils::RayHit> QgsRuleBasedChunkedEntity::rayIntersection(
const QgsRayCastingUtils::Ray3D &ray,
const QgsRayCastingUtils::RayCastContext &context )
const
269 return QgsVectorLayerChunkedEntity::rayIntersection( activeNodes(), mTransform->matrix(), ray, context );
@ Absolute
Elevation is taken directly from feature and is independent of terrain height (final elevation = feat...
float terrainElevationOffset() const
Returns the elevation offset of the terrain (used to move the terrain up or down)
void terrainElevationOffsetChanged(float newElevation)
Emitted when the terrain elevation offset is changed.
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
static QgsRectangle worldToMapExtent(const QgsAABB &bbox, const QgsVector3D &mapOrigin)
Converts axis aligned bounding box in 3D world coordinates to extent in map coordinates.
static QgsAABB mapToWorldExtent(const QgsRectangle &extent, double zMin, double zMax, const QgsVector3D &mapOrigin)
Converts map extent to axis aligned bounding box in 3D world coordinates.
static QgsExpressionContext globalProjectLayerExpressionContext(QgsVectorLayer *layer)
Returns expression context for use in preparation of 3D data of a layer.
virtual QString type() const =0
Returns identifier of symbol type. Each 3D symbol implementation should return a different type.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
This class 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...
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
Qgis::AltitudeClamping altitudeClamping() const
Returns method that determines altitude (whether to clamp to feature to terrain)
A rectangle specified with double values.
QgsAbstract3DSymbol * symbol() const
Returns the labeling settings.
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 data sets.
#define QgsDebugMsgLevel(str, level)
Helper struct to store ray casting parameters.