Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
revert changes to provider subIndexes
  • Loading branch information
uclaros authored and wonder-sk committed May 11, 2023
1 parent 452b320 commit a6e1f6e
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -372,7 +372,7 @@ void Qgs3DMapScene::updateScene()
{
QgsVirtualPointCloudProvider *provider = entity->provider();

const QList<QgsPointCloudSubIndex *> subIndexes = provider->subIndexes();
const QVector<QgsPointCloudSubIndex> subIndexes = provider->subIndexes();
for ( int i = 0; i < subIndexes.size(); ++i )
{
const QgsAABB &bbox = entity->boundingBox( i );
Expand All @@ -383,7 +383,7 @@ void Qgs3DMapScene::updateScene()
const float sse = Qgs3DUtils::screenSpaceError( epsilon, distance, screenSize, fov );
constexpr float THRESHOLD = .2;
const bool displayAsBbox = sse < THRESHOLD;
if ( !displayAsBbox && !subIndexes.at( i )->index() )
if ( !displayAsBbox && !subIndexes.at( i ).index() )
provider->loadSubIndex( i );

entity->setRenderSubIndexAsBbox( i, displayAsBbox );
Expand Down
2 changes: 1 addition & 1 deletion src/3d/qgspointcloudlayer3drenderer.cpp
Expand Up @@ -169,7 +169,7 @@ Qt3DCore::QEntity *QgsPointCloudLayer3DRenderer::createEntity( const Qgs3DMapSet
}
else
{
entity = new QgsVirtualPointCloudEntity( pcl, pcl->dataProvider()->subIndexes(), map, coordinateTransform, dynamic_cast<QgsPointCloud3DSymbol *>( mSymbol->clone() ), maximumScreenError(), showBoundingBoxes(),
entity = new QgsVirtualPointCloudEntity( pcl, map, coordinateTransform, dynamic_cast<QgsPointCloud3DSymbol *>( mSymbol->clone() ), maximumScreenError(), showBoundingBoxes(),
static_cast< const QgsPointCloudLayerElevationProperties * >( pcl->elevationProperties() )->zScale(),
static_cast< const QgsPointCloudLayerElevationProperties * >( pcl->elevationProperties() )->zOffset(), mPointBudget );
}
Expand Down
23 changes: 13 additions & 10 deletions src/3d/qgsvirtualpointcloudentity_p.cpp
Expand Up @@ -22,7 +22,7 @@
///@cond PRIVATE


QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity( QgsPointCloudLayer *layer, const QList<QgsPointCloudSubIndex *> subIndexes,
QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity( QgsPointCloudLayer *layer,
const Qgs3DMapSettings &map,
const QgsCoordinateTransform &coordinateTransform,
QgsPointCloud3DSymbol *symbol,
Expand All @@ -33,7 +33,6 @@ QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity( QgsPointCloudLayer *laye
int pointBudget )
: Qt3DCore::QEntity( nullptr )
, mLayer( layer )
, mSubIndexes( subIndexes )
, mMap( map )
, mCoordinateTransform( coordinateTransform )
, mZValueScale( zValueScale )
Expand All @@ -44,9 +43,10 @@ QgsVirtualPointCloudEntity::QgsVirtualPointCloudEntity( QgsPointCloudLayer *laye
{
mSymbol.reset( symbol );
mBboxesEntity = new QgsChunkBoundsEntity( this );
for ( int i = 0; i < mSubIndexes.size(); ++i )
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
for ( const auto &si : subIndexes )
{
mBboxes << Qgs3DUtils::mapToWorldExtent( mSubIndexes.at( i )->extent(), mSubIndexes.at( i )->zRange().lower(), mSubIndexes.at( i )->zRange().upper(), mMap.origin() );
mBboxes << Qgs3DUtils::mapToWorldExtent( si.extent(), si.zRange().lower(), si.zRange().upper(), mMap.origin() );
}
updateBboxEntity();
}
Expand All @@ -71,13 +71,14 @@ void QgsVirtualPointCloudEntity::createChunkedEntitiesForLoadedSubIndexes()
if ( !mChunkedEntities.isEmpty() )
return;

for ( int i = 0; i < mSubIndexes.size(); ++i )
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
for ( int i = 0; i < subIndexes.size(); ++i )
{
QgsPointCloudSubIndex *si = mSubIndexes.at( i );
if ( !si->index() )
const QgsPointCloudSubIndex &si = subIndexes.at( i );
if ( !si.index() )
continue;

QgsPointCloudLayerChunkedEntity *entity = new QgsPointCloudLayerChunkedEntity( si->index(),
QgsPointCloudLayerChunkedEntity *entity = new QgsPointCloudLayerChunkedEntity( si.index(),
mMap,
mCoordinateTransform,
static_cast< QgsPointCloud3DSymbol * >( mSymbol->clone() ),
Expand All @@ -93,7 +94,8 @@ void QgsVirtualPointCloudEntity::createChunkedEntitiesForLoadedSubIndexes()

void QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex( int i )
{
QgsPointCloudLayerChunkedEntity *newChunkedEntity = new QgsPointCloudLayerChunkedEntity( mSubIndexes.at( i )->index(),
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
QgsPointCloudLayerChunkedEntity *newChunkedEntity = new QgsPointCloudLayerChunkedEntity( subIndexes.at( i ).index(),
mMap,
mCoordinateTransform,
static_cast< QgsPointCloud3DSymbol * >( mSymbol->clone() ),
Expand All @@ -110,7 +112,8 @@ void QgsVirtualPointCloudEntity::createChunkedEntityForSubIndex( int i )
void QgsVirtualPointCloudEntity::updateBboxEntity()
{
QList<QgsAABB> bboxes;
for ( int i = 0; i < mSubIndexes.size(); ++i )
const QVector<QgsPointCloudSubIndex> subIndexes = provider()->subIndexes();
for ( int i = 0; i < subIndexes.size(); ++i )
{
if ( mChunkedEntitiesMap.contains( i ) && mChunkedEntitiesMap[i]->isEnabled() )
continue;
Expand Down
3 changes: 1 addition & 2 deletions src/3d/qgsvirtualpointcloudentity_p.h
Expand Up @@ -56,7 +56,7 @@ class QgsVirtualPointCloudEntity : public Qt3DCore::QEntity
Q_OBJECT
public:
//! Constructs
QgsVirtualPointCloudEntity( QgsPointCloudLayer *layer, const QList<QgsPointCloudSubIndex *> subIndexes, const Qgs3DMapSettings &map, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maxScreenError, bool showBoundingBoxes,
QgsVirtualPointCloudEntity( QgsPointCloudLayer *layer, const Qgs3DMapSettings &map, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maxScreenError, bool showBoundingBoxes,
double zValueScale, double zValueOffset, int pointBudget );

//! creates a child QgsPointCloudLayerChunkedEntity for each of the already loaded sub indexes
Expand Down Expand Up @@ -89,7 +89,6 @@ class QgsVirtualPointCloudEntity : public Qt3DCore::QEntity
QgsPointCloudLayer *mLayer = nullptr;
QList<QgsChunkedEntity *> mChunkedEntities;
QMap<int, QgsChunkedEntity *> mChunkedEntitiesMap;
const QList<QgsPointCloudSubIndex *> mSubIndexes;
QgsChunkBoundsEntity *mBboxesEntity = nullptr;
QList<QgsAABB> mBboxes;
const Qgs3DMapSettings &mMap;
Expand Down
6 changes: 3 additions & 3 deletions src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -166,14 +166,14 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
virtual QgsPointCloudIndex *index() const SIP_SKIP {return nullptr;}

/**
* Returns a list of pointers to sub indexes available if the provider supports multiple indexes, empty list otherwise.
* Returns a list of sub indexes available if the provider supports multiple indexes, empty list otherwise.
*
* Each sub index contain a pointer to the individual point cloud index which may be nullptr if not loaded yet.
* The sub indexes contain a pointer to the individual indexes which may be nullptr if not yet loaded.
*
* \note Not available in Python bindings
* \since QGIS 3.32
*/
virtual QList<QgsPointCloudSubIndex *> subIndexes() SIP_SKIP { return QList<QgsPointCloudSubIndex *>(); }
virtual QVector<QgsPointCloudSubIndex> subIndexes() SIP_SKIP { return QVector<QgsPointCloudSubIndex>(); }

/**
* Triggers loading of the point cloud index for the \a n th sub index
Expand Down
11 changes: 5 additions & 6 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -968,16 +968,15 @@ void QgsPointCloudLayer::loadIndexesForRenderContext( QgsRenderContext &renderer
QgsDebugMsg( QStringLiteral( "Transformation of extent failed!" ) );
}

const QList<QgsPointCloudSubIndex *> subIndexes = mDataProvider->subIndexes();
for ( int i = 0; i < subIndexes.size(); ++i )
const QVector<QgsPointCloudSubIndex> subIndex = mDataProvider->subIndexes();
for ( int i = 0; i < subIndex.size(); ++i )
{
QgsPointCloudSubIndex *si = subIndexes.at( i );
// no need to load as it's there
if ( si->index() )
if ( subIndex.at( i ).index() )
continue;

if ( si->extent().intersects( renderExtent ) &&
renderExtent.width() < si->extent().width() )
if ( subIndex.at( i ).extent().intersects( renderExtent ) &&
renderExtent.width() < subIndex.at( i ).extent().width() )
{
mDataProvider->loadSubIndex( i );
}
Expand Down
12 changes: 6 additions & 6 deletions src/core/pointcloud/qgspointcloudlayerrenderer.cpp
Expand Up @@ -38,7 +38,7 @@ QgsPointCloudLayerRenderer::QgsPointCloudLayerRenderer( QgsPointCloudLayer *laye
: QgsMapLayerRenderer( layer->id(), &context )
, mLayer( layer )
, mLayerAttributes( layer->attributes() )
, mSubIndexes( layer && layer->dataProvider() ? layer->dataProvider()->subIndexes() : QList<QgsPointCloudSubIndex *>() )
, mSubIndexes( layer && layer->dataProvider() ? layer->dataProvider()->subIndexes() : QVector<QgsPointCloudSubIndex>() )
, mFeedback( new QgsFeedback )
{
// TODO: we must not keep pointer to mLayer (it's dangerous) - we must copy anything we need for rendering
Expand Down Expand Up @@ -162,21 +162,21 @@ bool QgsPointCloudLayerRenderer::render()
else
{
mSubIndexExtentRenderer->startRender( context );
for ( QgsPointCloudSubIndex *si : mSubIndexes )
for ( const auto &si : mSubIndexes )
{
if ( canceled )
break;

QgsPointCloudIndex *pc = si->index();
QgsPointCloudIndex *pc = si.index();

if ( !renderExtent.intersects( si->extent() ) )
if ( !renderExtent.intersects( si.extent() ) )
continue;

if ( !pc || !pc->isValid() || renderExtent.width() > si->extent().width() )
if ( !pc || !pc->isValid() || renderExtent.width() > si.extent().width() )
{
// when dealing with virtual point clouds, we want to render the individual extents when zoomed out
// and only use the selected renderer when zoomed in
mSubIndexExtentRenderer->renderExtent( si->polygonBounds(), context );
mSubIndexExtentRenderer->renderExtent( si.polygonBounds(), context );
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudlayerrenderer.h
Expand Up @@ -91,7 +91,7 @@ class CORE_EXPORT QgsPointCloudLayerRenderer: public QgsMapLayerRenderer
QgsPointCloudAttributeCollection mAttributes;
QgsGeometry mCloudExtent;
QList< QgsMapClippingRegion > mClippingRegions;
const QList<QgsPointCloudSubIndex *> mSubIndexes;
const QVector< QgsPointCloudSubIndex > mSubIndexes;

int mRenderTimeHint = 0;
bool mBlockRenderUpdates = false;
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgspointcloudsubindex.h
Expand Up @@ -73,7 +73,7 @@ class QgsPointCloudSubIndex
qint64 pointCount() const { return mPointCount; }

private:
std::unique_ptr<QgsPointCloudIndex> mIndex;
std::shared_ptr<QgsPointCloudIndex> mIndex;
QString mUri;
QgsRectangle mExtent;
QgsGeometry mGeometry;
Expand Down
52 changes: 24 additions & 28 deletions src/core/providers/vpc/qgsvirtualpointcloudprovider.cpp
Expand Up @@ -58,10 +58,7 @@ QgsVirtualPointCloudProvider::QgsVirtualPointCloudProvider(
parseFile();
}

QgsVirtualPointCloudProvider::~QgsVirtualPointCloudProvider()
{
qDeleteAll( mSubIndexes );
}
QgsVirtualPointCloudProvider::~QgsVirtualPointCloudProvider() = default;

QgsPointCloudDataProvider::Capabilities QgsVirtualPointCloudProvider::capabilities() const
{
Expand Down Expand Up @@ -96,7 +93,7 @@ bool QgsVirtualPointCloudProvider::isValid() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

return !mSubIndexes.isEmpty();
return !mSubLayers.isEmpty();
}

QString QgsVirtualPointCloudProvider::name() const
Expand Down Expand Up @@ -201,7 +198,6 @@ void QgsVirtualPointCloudProvider::parseFile()
QgsGeometry geometry;
QgsDoubleRange zRange;


for ( const auto &asset : f["assets"] )
{
if ( asset.contains( "href" ) )
Expand Down Expand Up @@ -366,8 +362,8 @@ void QgsVirtualPointCloudProvider::parseFile()

mPolygonBounds->addPart( geometry );
mPointCount += count;
QgsPointCloudSubIndex *si = new QgsPointCloudSubIndex( uri, geometry, extent, zRange, count );
mSubIndexes.push_back( si );
QgsPointCloudSubIndex si( uri, geometry, extent, zRange, count );
mSubLayers.push_back( si );
}
mExtent = mPolygonBounds->boundingBox();
populateAttributeCollection( attributeNames );
Expand All @@ -382,37 +378,37 @@ void QgsVirtualPointCloudProvider::loadSubIndex( int i )
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

if ( i >= mSubIndexes.size() || i < 0 )
if ( i >= mSubLayers.size() || i < 0 )
return;

QgsPointCloudSubIndex *sl = mSubIndexes[ i ];
QgsPointCloudSubIndex &sl = mSubLayers[ i ];
// Index already loaded -> no need to load
if ( sl->index() )
if ( sl.index() )
return;

if ( sl->uri().startsWith( QStringLiteral( "http" ), Qt::CaseSensitivity::CaseInsensitive ) )
if ( sl.uri().startsWith( QStringLiteral( "http" ), Qt::CaseSensitivity::CaseInsensitive ) )
{
if ( sl->uri().endsWith( QStringLiteral( "copc.laz" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl->setIndex( new QgsRemoteCopcPointCloudIndex() );
else if ( sl->uri().endsWith( QStringLiteral( "ept.json" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl->setIndex( new QgsRemoteEptPointCloudIndex() );
if ( sl.uri().endsWith( QStringLiteral( "copc.laz" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl.setIndex( new QgsRemoteCopcPointCloudIndex() );
else if ( sl.uri().endsWith( QStringLiteral( "ept.json" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl.setIndex( new QgsRemoteEptPointCloudIndex() );
}
else
{
if ( sl->uri().endsWith( QStringLiteral( "copc.laz" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl->setIndex( new QgsCopcPointCloudIndex() );
else if ( sl->uri().endsWith( QStringLiteral( "ept.json" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl->setIndex( new QgsEptPointCloudIndex() );
if ( sl.uri().endsWith( QStringLiteral( "copc.laz" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl.setIndex( new QgsCopcPointCloudIndex() );
else if ( sl.uri().endsWith( QStringLiteral( "ept.json" ), Qt::CaseSensitivity::CaseInsensitive ) )
sl.setIndex( new QgsEptPointCloudIndex() );
}

if ( !sl->index() )
if ( !sl.index() )
return;

sl->index()->load( sl->uri() );
sl.index()->load( sl.uri() );

// if expression is broken or index is missing a required field, set to "false" so it returns no points
if ( !sl->index()->setSubsetString( mSubsetString ) )
sl->index()->setSubsetString( QStringLiteral( "false" ) );
if ( !sl.index()->setSubsetString( mSubsetString ) )
sl.index()->setSubsetString( QStringLiteral( "false" ) );

emit subIndexLoaded( i );
}
Expand Down Expand Up @@ -484,14 +480,14 @@ bool QgsVirtualPointCloudProvider::setSubsetString( const QString &subset, bool

Q_UNUSED( updateFeatureCount )

for ( QgsPointCloudSubIndex *si : std::as_const( mSubIndexes ) )
for ( const auto &i : std::as_const( mSubLayers ) )
{
if ( !si->index() )
if ( !i.index() )
continue;

// if expression is broken or index is missing a required field, set to "false" so it returns no points
if ( !si->index()->setSubsetString( subset ) )
si->index()->setSubsetString( QStringLiteral( "false" ) );
if ( !i.index()->setSubsetString( subset ) )
i.index()->setSubsetString( QStringLiteral( "false" ) );
}

mSubsetString = subset;
Expand Down
4 changes: 2 additions & 2 deletions src/core/providers/vpc/qgsvirtualpointcloudprovider.h
Expand Up @@ -54,7 +54,7 @@ class CORE_EXPORT QgsVirtualPointCloudProvider: public QgsPointCloudDataProvider
void generateIndex( ) override;
PointCloudIndexGenerationState indexingState( ) override { return PointCloudIndexGenerationState::Indexed; }
QgsGeometry polygonBounds() const override;
QList<QgsPointCloudSubIndex *> subIndexes() override { return mSubIndexes; }
QVector<QgsPointCloudSubIndex> subIndexes() override { return mSubLayers; }
void loadSubIndex( int i ) override;
bool setSubsetString( const QString &subset, bool updateFeatureCount = false ) override;
QgsPointCloudRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const override SIP_FACTORY;
Expand All @@ -66,7 +66,7 @@ class CORE_EXPORT QgsVirtualPointCloudProvider: public QgsPointCloudDataProvider
private:
void parseFile();
void populateAttributeCollection( QSet<QString> names );
QList<QgsPointCloudSubIndex *> mSubIndexes;
QVector<QgsPointCloudSubIndex> mSubLayers;
std::unique_ptr<QgsGeometry> mPolygonBounds;
std::unique_ptr<QgsPointCloudIndex> mIndex;
QgsPointCloudAttributeCollection mAttributes;
Expand Down
11 changes: 6 additions & 5 deletions tests/src/providers/testqgsvirtualpointcloudprovider.cpp
Expand Up @@ -275,12 +275,12 @@ void TestQgsVirtualPointCloudProvider::testLazyLoading()
QgsPointCloudIndex *index = layer->dataProvider()->index();
QCOMPARE( index, nullptr );

QList<QgsPointCloudSubIndex *> subIndexes = layer->dataProvider()->subIndexes();
QVector< QgsPointCloudSubIndex > subIndexes = layer->dataProvider()->subIndexes();

QCOMPARE( subIndexes.size(), 18 );
int loadedIndexes = 0;
for ( QgsPointCloudSubIndex *si : subIndexes )
if ( si->index() )
for ( const auto &si : subIndexes )
if ( si.index() )
++loadedIndexes;

QCOMPARE( loadedIndexes, 0 );
Expand All @@ -289,8 +289,9 @@ void TestQgsVirtualPointCloudProvider::testLazyLoading()
QgsRenderContext ctx;
ctx.setMapExtent( QgsRectangle( -498160, -1205380, -498090, -1205330 ) );
layer->loadIndexesForRenderContext( ctx );
for ( QgsPointCloudSubIndex *si : subIndexes )
if ( si->index() )
subIndexes = layer->dataProvider()->subIndexes();
for ( const auto &si : subIndexes )
if ( si.index() )
++loadedIndexes;

QCOMPARE( loadedIndexes, 4 );
Expand Down

0 comments on commit a6e1f6e

Please sign in to comment.