17#include "moc_qgsrulebasedchunkloader_p.cpp"
34#include <QtConcurrent>
35#include <Qt3DCore/QTransform>
40QgsRuleBasedChunkLoader::QgsRuleBasedChunkLoader(
const QgsRuleBasedChunkLoaderFactory *factory, QgsChunkNode *node )
41 : QgsChunkLoader( node )
43 , mContext( factory->mRenderContext )
46 if ( node->level() < mFactory->mLeafLevel )
48 QTimer::singleShot( 0,
this, &QgsRuleBasedChunkLoader::finished );
61 exprContext.setFields( layer->
fields() );
62 mContext.setExpressionContext( exprContext );
68 mRootRule.reset( mFactory->mRootRule->clone() );
70 mRootRule->createHandlers( layer, mHandlers );
72 QSet<QString> attributeNames;
73 mRootRule->prepare( mContext, attributeNames, chunkOrigin, mHandlers );
84 mFutureWatcher =
new QFutureWatcher<void>(
this );
85 connect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
87 const QFuture<void> future = QtConcurrent::run( [req,
this]
89 const QgsEventTracing::ScopedEvent e( QStringLiteral(
"3D" ), QStringLiteral(
"RB chunk load" ) );
97 mContext.expressionContext().setFeature( f );
98 mRootRule->registerFeature( f, mContext, mHandlers );
103 mFutureWatcher->setFuture( future );
106QgsRuleBasedChunkLoader::~QgsRuleBasedChunkLoader()
108 if ( mFutureWatcher && !mFutureWatcher->isFinished() )
110 disconnect( mFutureWatcher, &QFutureWatcher<void>::finished,
this, &QgsChunkQueueJob::finished );
111 mFutureWatcher->waitForFinished();
114 qDeleteAll( mHandlers );
118void QgsRuleBasedChunkLoader::cancel()
123Qt3DCore::QEntity *QgsRuleBasedChunkLoader::createEntity( Qt3DCore::QEntity *parent )
125 if ( mNode->level() < mFactory->mLeafLevel )
127 return new Qt3DCore::QEntity( parent );
130 long long featureCount = 0;
131 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
133 featureCount += it.value()->featureCount();
135 if ( featureCount == 0 )
141 Qt3DCore::QEntity *entity =
new Qt3DCore::QEntity( parent );
142 float zMin = std::numeric_limits<float>::max();
143 float zMax = std::numeric_limits<float>::lowest();
144 for (
auto it = mHandlers.constBegin(); it != mHandlers.constEnd(); ++it )
146 QgsFeature3DHandler *handler = it.value();
147 handler->finalize( entity, mContext );
148 if ( handler->zMinimum() < zMin )
149 zMin = handler->zMinimum();
150 if ( handler->zMaximum() > zMax )
151 zMax = handler->zMaximum();
155 if ( zMin != std::numeric_limits<float>::max() && zMax != std::numeric_limits<float>::lowest() )
160 mNode->setExactBox3D( box );
161 mNode->updateParentBoundingBoxesRecursively();
172 : mRenderContext( context )
174 , mRootRule( rootRule->clone() )
175 , mLeafLevel( leafLevel )
178 setupQuadtree( rootBox3D, -1, leafLevel );
181QgsRuleBasedChunkLoaderFactory::~QgsRuleBasedChunkLoaderFactory() =
default;
183QgsChunkLoader *QgsRuleBasedChunkLoaderFactory::createChunkLoader( QgsChunkNode *node )
const
185 return new QgsRuleBasedChunkLoader(
this, node );
192 : QgsChunkedEntity( map,
194 new QgsRuleBasedChunkLoaderFactory(
Qgs3DRenderContext::fromMapSettings( map ), vl, rootRule, tilingSettings.zoomLevelsCount() - 1, zMin, zMax ), true )
196 mTransform =
new Qt3DCore::QTransform;
197 if ( applyTerrainOffset() )
201 this->addComponent( mTransform );
207QgsRuleBasedChunkedEntity::~QgsRuleBasedChunkedEntity()
214bool QgsRuleBasedChunkedEntity::applyTerrainOffset()
const
216 QgsRuleBasedChunkLoaderFactory *loaderFactory =
static_cast<QgsRuleBasedChunkLoaderFactory *
>( mChunkLoaderFactory );
223 if ( symbolType ==
"line" )
231 else if ( symbolType ==
"point" )
239 else if ( symbolType ==
"polygon" )
249 QgsDebugMsgLevel( QStringLiteral(
"QgsRuleBasedChunkedEntityChunkedEntity::applyTerrainOffset, unhandled symbol type %1" ).arg( symbolType ), 2 );
257void QgsRuleBasedChunkedEntity::onTerrainElevationOffsetChanged(
float newOffset )
259 float previousOffset = mTransform->translation()[1];
260 if ( !applyTerrainOffset() )
265 if ( newOffset != previousOffset )
267 mTransform->setTranslation( QVector3D( 0.0f, newOffset, 0.0f ) );
271QVector<QgsRayCastingUtils::RayHit> QgsRuleBasedChunkedEntity::rayIntersection(
const QgsRayCastingUtils::Ray3D &ray,
const QgsRayCastingUtils::RayCastContext &context )
const
273 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...
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.
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
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.
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.
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.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
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.