Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Address reviews
Tune includes
  • Loading branch information
uclaros authored and wonder-sk committed May 11, 2023
1 parent 0276a33 commit 1bfa5ea
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
50 changes: 31 additions & 19 deletions src/3d/qgsvirtualpointcloudentity_p.cpp
Expand Up @@ -52,22 +52,7 @@ QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity( QgsPointCloudLayer *laye

mBboxes << Qgs3DUtils::mapToWorldExtent( intersection, si.zRange().lower(), si.zRange().upper(), mMap.origin() );

if ( !si.index() || intersection.isEmpty() )
continue;

QgsPointCloudLayerChunkedEntity *entity = new QgsPointCloudLayerChunkedEntity( si.index(),
mMap,
mCoordinateTransform,
static_cast< QgsPointCloud3DSymbol * >( mSymbol->clone() ),
mMaximumScreenSpaceError,
mShowBoundingBoxes,
mZValueScale,
mZValueOffset,
mPointBudget );

mChunkedEntitiesMap.insert( i, entity );
entity->setParent( this );
connect( entity, &QgsChunkedEntity::pendingJobsCountChanged, this, &Qgs3DMapSceneEntity::pendingJobsCountChanged );
createChunkedEntityForSubIndex( i );
}

updateBboxEntity();
Expand All @@ -92,7 +77,13 @@ QgsAABB QgsVirtualPointCloudEntity::boundingBox( int i ) const
void QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex( int i )
{
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
QgsPointCloudLayerChunkedEntity *newChunkedEntity = new QgsPointCloudLayerChunkedEntity( subIndexes.at( i ).index(),
const QgsPointCloudSubIndex &si = subIndexes.at( i );

// Skip if Index is not yet loaded or is outside the map extents
if ( !si.index() || mBboxes.at( i ).isEmpty() )
return;

QgsPointCloudLayerChunkedEntity *newChunkedEntity = new QgsPointCloudLayerChunkedEntity( si.index(),
mMap,
mCoordinateTransform,
static_cast< QgsPointCloud3DSymbol * >( mSymbol->clone() ),
Expand All @@ -108,7 +99,7 @@ void QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex( int i )
emit newEntityCreated( newChunkedEntity );
}

void QgsVirtualPointCloudEntity::handleSceneUpdate( const QgsChunkedEntity::SceneState &state )
void QgsVirtualPointCloudEntity::handleSceneUpdate( const SceneState &state )
{
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
for ( int i = 0; i < subIndexes.size(); ++i )
Expand Down Expand Up @@ -149,6 +140,27 @@ QgsRange<float> QgsVirtualPointCloudEntity::getNearFarPlaneRange( const QMatrix4
fnear = std::min( range.lower(), fnear );
}
}

// if there were no chunked entities available, we will iterate the bboxes as a fallback instead
if ( fnear == 1e9 && ffar == 0 )
{
for ( const QgsAABB &bbox : mBboxes )
{
for ( int i = 0; i < 8; ++i )
{
const QVector4D p( ( ( i >> 0 ) & 1 ) ? bbox.xMin : bbox.xMax,
( ( i >> 1 ) & 1 ) ? bbox.yMin : bbox.yMax,
( ( i >> 2 ) & 1 ) ? bbox.zMin : bbox.zMax, 1 );

const QVector4D pc = viewMatrix * p;

const float dst = -pc.z(); // in camera coordinates, x grows right, y grows down, z grows to the back
fnear = std::min( fnear, dst );
ffar = std::max( ffar, dst );
}
}
}

return QgsRange<float>( fnear, ffar );
}

Expand Down Expand Up @@ -191,7 +203,7 @@ void QgsVirtualPointCloudEntity::updateBboxEntity()
mBboxesEntity->setBoxes( bboxes );
}

void QgsVirtualPointCloudEntity::setRenderSubIndexAsBbox( const int i, const bool asBbox )
void QgsVirtualPointCloudEntity::setRenderSubIndexAsBbox( int i, bool asBbox )
{
if ( !mChunkedEntitiesMap.contains( i ) )
return;
Expand Down
8 changes: 2 additions & 6 deletions src/3d/qgsvirtualpointcloudentity_p.h
Expand Up @@ -29,13 +29,13 @@
//

#include "qgscoordinatetransform.h"
#include "qgspointcloudsubindex.h"
#include "qgschunkedentity_p.h"
#include "qgs3dmapsceneentity_p.h"

class QgsAABB;
class QgsChunkBoundsEntity;
class QgsPointCloudLayer;
class QgsPointCloudIndex;
class QgsVirtualPointCloudProvider;
class QgsPointCloud3DSymbol;
class Qgs3DMapSettings;
Expand Down Expand Up @@ -68,16 +68,12 @@ class QgsVirtualPointCloudEntity : public Qgs3DMapSceneEntity

bool needsUpdate() const override;

signals:
//! Emitted when a new point cloud chunked entity has been created for a sub index
void newEntityCreated( QgsChunkedEntity *entity );

public slots:
//! Creates a child QgsPointCloudLayerChunkedEntity for the \a i th sub index
void createChunkedEntityForSubIndex( int i );

//! If \a asBbox is TRUE only the bounding box will be rendered for the sub index \a i. If it is FALSE, the sub index will be rendered as a chunked entity.
void setRenderSubIndexAsBbox( const int i, const bool asBbox );
void setRenderSubIndexAsBbox( int i, bool asBbox );

private:
//! Updates the Bbox child entity to display the sub indexes set with setRenderSubIndexAsBbox()
Expand Down
3 changes: 2 additions & 1 deletion src/core/pointcloud/qgspointcloudsubindex.h
Expand Up @@ -20,13 +20,14 @@

#include <memory>
#include <QString>

#include "qgspointcloudindex.h"
#include "qgsgeometry.h"
#include "qgsrange.h"

///@cond PRIVATE
#define SIP_NO_FILE

class QgsPointCloudIndex;

/**
* \brief Represents an individual index and metadata for the virtual point cloud data provider.
Expand Down

0 comments on commit 1bfa5ea

Please sign in to comment.