33#include <QtConcurrent>
34#include <Qt3DCore/QTransform>
39QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
40 : QgsChunkLoader( node )
42 , mContext( factory->mMap )
45 if ( node->level() < mFactory->mLeafLevel )
47 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
55 exprContext.setFields( layer->
fields() );
56 mContext.setExpressionContext( exprContext );
62 mRootRule.reset( mFactory->mRootRule->clone() );
64 mRootRule->createHandlers( layer, mHandlers );
66 QSet<QString> attributeNames;
67 mRootRule->prepare( mContext, attributeNames, mHandlers );
81 mFutureWatcher =
new QFutureWatcher<void>(
this );
82 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
84 const QFuture<void> future = QtConcurrent::run( [req,
this]
86 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
94 mContext.expressionContext().setFeature( f );
95 mRootRule->registerFeature( f, mContext, mHandlers );
100 mFutureWatcher->setFuture( future );
103QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
105 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
107 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
108 mFutureWatcher->waitForFinished();
111 qDeleteAll( mHandlers );
115void QgsRuleBasedChunkLoader::cancel()
120Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
122 if ( mNode->level() < mFactory->mLeafLevel )
124 return new Qt3DCore::QEntity( parent );
127 long long featureCount = 0;
128 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
130 featureCount += it.value()->featureCount();
132 if ( featureCount == 0 )
138 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
139 float zMin = std::numeric_limits<float>::max();
140 float zMax = std::numeric_limits<float>::lowest();
141 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
143 QgsFeature3DHandler *handler = it.value();
144 handler->finalize( entity, mContext );
145 if ( handler->zMinimum() < zMin )
146 zMin = handler->zMinimum();
147 if ( handler->zMaximum() > zMax )
148 zMax = handler->zMaximum();
152 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::lowest() )
157 mNode->setExactBbox( box );
158 mNode->updateParentBoundingBoxesRecursively();
171 , mRootRule( rootRule->clone() )
172 , mLeafLevel( leafLevel )
175 setupQuadtree( rootBbox, -1, leafLevel );
178QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
180QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
182 return new QgsRuleBasedChunkLoader(
this, node );
189 : QgsChunkedEntity( -1,
190 new QgsRuleBasedChunkLoaderFactory( 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...
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
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.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used in the 3D scene.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsVector3D origin() const
Returns coordinates in map CRS at which 3D scene has origin (0,0,0)
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.