17#include "moc_qgsvirtualpointcloudentity_p.cpp"
18#include "qgsvirtualpointcloudprovider.h"
26QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity(
31 float maximumScreenSpaceError,
32 bool showBoundingBoxes,
36 : Qgs3DMapSceneEntity( map, nullptr )
38 , mCoordinateTransform( coordinateTransform )
39 , mZValueScale( zValueScale )
40 , mZValueOffset( zValueOffset )
41 , mPointBudget( pointBudget )
42 , mMaximumScreenSpaceError( maximumScreenSpaceError )
43 , mShowBoundingBoxes( showBoundingBoxes )
45 mSymbol.reset( symbol );
46 mBboxesEntity =
new QgsChunkBoundsEntity(
this );
48 const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
49 for (
int i = 0; i < subIndexes.size(); ++i )
51 const QgsPointCloudSubIndex &si = subIndexes.at( i );
56 createChunkedEntityForSubIndex( i );
60 connect(
this, &QgsVirtualPointCloudEntity::subIndexNeedsLoading, provider(), &QgsVirtualPointCloudProvider::loadSubIndex, Qt::QueuedConnection );
61 connect( provider(), &QgsVirtualPointCloudProvider::subIndexLoaded,
this, &QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex );
65QList<QgsChunkedEntity *> QgsVirtualPointCloudEntity::chunkedEntities()
const
67 return mChunkedEntitiesMap.values();
70QgsVirtualPointCloudProvider *QgsVirtualPointCloudEntity::provider()
const
72 return qobject_cast<QgsVirtualPointCloudProvider *>( mLayer->dataProvider() );
75QgsAABB QgsVirtualPointCloudEntity::boundingBox(
int i )
const
77 return mBboxes.at( i );
80void QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex(
int i )
82 const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
83 const QgsPointCloudSubIndex &si = subIndexes.at( i );
86 if ( !si.index() || mBboxes.at( i ).isEmpty() )
89 QgsPointCloudLayerChunkedEntity *newChunkedEntity =
new QgsPointCloudLayerChunkedEntity(
94 mMaximumScreenSpaceError,
100 mChunkedEntitiesMap.insert( i, newChunkedEntity );
101 newChunkedEntity->setParent(
this );
102 connect( newChunkedEntity, &QgsChunkedEntity::pendingJobsCountChanged,
this, &Qgs3DMapSceneEntity::pendingJobsCountChanged );
103 emit newEntityCreated( newChunkedEntity );
106void QgsVirtualPointCloudEntity::handleSceneUpdate(
const SceneContext &sceneContext )
108 const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
109 for (
int i = 0; i < subIndexes.size(); ++i )
111 const QgsAABB &bbox = mBboxes.at( i );
117 constexpr int SPAN = 256;
118 const float epsilon = std::min( bbox.
xExtent(), bbox.
yExtent() ) / SPAN;
121 constexpr float THRESHOLD = .2;
125 const bool displayAsBbox = sceneContext.cameraPos.isNull() || sse < THRESHOLD;
126 if ( !displayAsBbox && !subIndexes.at( i ).index() )
127 emit subIndexNeedsLoading( i );
129 setRenderSubIndexAsBbox( i, displayAsBbox );
130 if ( !displayAsBbox && mChunkedEntitiesMap.contains( i ) )
131 mChunkedEntitiesMap[i]->handleSceneUpdate( sceneContext );
136QgsRange<float> QgsVirtualPointCloudEntity::getNearFarPlaneRange(
const QMatrix4x4 &viewMatrix )
const
141 for ( QgsChunkedEntity *entity : mChunkedEntitiesMap )
143 if ( entity->isEnabled() )
145 const QgsRange<float> range = entity->getNearFarPlaneRange( viewMatrix );
146 ffar = std::max( range.
upper(), ffar );
147 fnear = std::min( range.
lower(), fnear );
152 if ( fnear == 1e9 && ffar == 0 )
154 for (
const QgsAABB &bbox : mBboxes )
159 fnear = std::min( fnear, bboxfnear );
160 ffar = std::max( ffar, bboxffar );
167int QgsVirtualPointCloudEntity::pendingJobsCount()
const
170 for ( QgsChunkedEntity *entity : mChunkedEntitiesMap )
172 if ( entity->isEnabled() )
173 jobs += entity->pendingJobsCount();
178bool QgsVirtualPointCloudEntity::needsUpdate()
const
180 for ( QgsChunkedEntity *entity : mChunkedEntitiesMap )
182 if ( entity->isEnabled() && entity->needsUpdate() )
188void QgsVirtualPointCloudEntity::updateBboxEntity()
190 QList<QgsAABB> bboxes;
191 const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
192 for (
int i = 0; i < subIndexes.size(); ++i )
194 if ( mChunkedEntitiesMap.contains( i ) && mChunkedEntitiesMap[i]->isEnabled() )
197 if ( mBboxes.at( i ).isEmpty() )
200 bboxes << mBboxes.at( i );
203 mBboxesEntity->setBoxes( bboxes );
206void QgsVirtualPointCloudEntity::setRenderSubIndexAsBbox(
int i,
bool asBbox )
208 if ( !mChunkedEntitiesMap.contains( i ) )
211 mChunkedEntitiesMap[i]->setEnabled( !asBbox );
QgsRectangle extent() const
Returns the 3D scene's 2D extent in the 3D scene's CRS.
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 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 float screenSpaceError(float epsilon, float distance, int screenSize, float fov)
This routine approximately calculates how an error (epsilon) of an object in world coordinates at giv...
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.
static void computeBoundingBoxNearFarPlanes(const QgsAABB &bbox, const QMatrix4x4 &viewMatrix, float &fnear, float &ffar)
This routine computes nearPlane farPlane from the closest and farthest corners point of bounding box ...
float yExtent() const
Returns box width in Y axis.
float xExtent() const
Returns box width in X axis.
bool isEmpty() const
Returns true if xExtent(), yExtent() and zExtent() are all zero, false otherwise.
float distanceFromPoint(float x, float y, float z) const
Returns shortest distance from the box to a point.
QgsCoordinateReferenceSystem crs
Represents a map layer supporting display of point clouds.
A template based class for storing ranges (lower to upper values).
T lower() const
Returns the lower bound of the range.
T upper() const
Returns the upper bound of the range.
A rectangle specified with double values.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.