Skip to content

Commit

Permalink
Split point cloud index into implementation & wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon committed Dec 17, 2024
1 parent 98e89dc commit 9a58078
Show file tree
Hide file tree
Showing 38 changed files with 782 additions and 343 deletions.
34 changes: 17 additions & 17 deletions src/3d/qgspointcloudlayerchunkloader_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ QgsPointCloudLayerChunkLoader::QgsPointCloudLayerChunkLoader( const QgsPointClou
, mFactory( factory )
, mContext( factory->mRenderContext, coordinateTransform, std::move( symbol ), zValueScale, zValueOffset )
{
QgsPointCloudIndex *pc = mFactory->mPointCloudIndex;
mContext.setAttributes( pc->attributes() );
QgsPointCloudIndex pc = mFactory->mPointCloudIndex;
mContext.setAttributes( pc.attributes() );

const QgsChunkNodeId nodeId = node->tileId();
const QgsPointCloudNodeId pcNode( nodeId.d, nodeId.x, nodeId.y, nodeId.z );

Q_ASSERT( pc->hasNode( pcNode ) );
Q_ASSERT( pc.hasNode( pcNode ) );

QgsDebugMsgLevel( QStringLiteral( "loading entity %1" ).arg( node->tileId().text() ), 2 );

Expand Down Expand Up @@ -124,10 +124,10 @@ void QgsPointCloudLayerChunkLoader::cancel()

Qt3DCore::QEntity *QgsPointCloudLayerChunkLoader::createEntity( Qt3DCore::QEntity *parent )
{
QgsPointCloudIndex *pc = mFactory->mPointCloudIndex;
QgsPointCloudIndex pc = mFactory->mPointCloudIndex;
const QgsChunkNodeId nodeId = mNode->tileId();
const QgsPointCloudNodeId pcNode( nodeId.d, nodeId.x, nodeId.y, nodeId.z );
Q_ASSERT( pc->hasNode( pcNode ) );
Q_ASSERT( pc.hasNode( pcNode ) );

Qt3DCore::QEntity *entity = new Qt3DCore::QEntity( parent );
mHandler->finalize( entity, mContext );
Expand All @@ -137,7 +137,7 @@ Qt3DCore::QEntity *QgsPointCloudLayerChunkLoader::createEntity( Qt3DCore::QEntit
///////////////


QgsPointCloudLayerChunkLoaderFactory::QgsPointCloudLayerChunkLoaderFactory( const Qgs3DRenderContext &context, const QgsCoordinateTransform &coordinateTransform, QgsPointCloudIndex *pc, QgsPointCloud3DSymbol *symbol, double zValueScale, double zValueOffset, int pointBudget )
QgsPointCloudLayerChunkLoaderFactory::QgsPointCloudLayerChunkLoaderFactory( const Qgs3DRenderContext &context, const QgsCoordinateTransform &coordinateTransform, QgsPointCloudIndex pc, QgsPointCloud3DSymbol *symbol, double zValueScale, double zValueOffset, int pointBudget )
: mRenderContext( context )
, mCoordinateTransform( coordinateTransform )
, mPointCloudIndex( pc )
Expand All @@ -162,7 +162,7 @@ QgsChunkLoader *QgsPointCloudLayerChunkLoaderFactory::createChunkLoader( QgsChun
{
const QgsChunkNodeId id = node->tileId();

Q_ASSERT( mPointCloudIndex->hasNode( QgsPointCloudNodeId( id.d, id.x, id.y, id.z ) ) );
Q_ASSERT( mPointCloudIndex.hasNode( QgsPointCloudNodeId( id.d, id.x, id.y, id.z ) ) );
QgsPointCloud3DSymbol *symbol = static_cast<QgsPointCloud3DSymbol *>( mSymbol->clone() );
return new QgsPointCloudLayerChunkLoader( this, node, std::unique_ptr<QgsPointCloud3DSymbol>( symbol ), mCoordinateTransform, mZValueScale, mZValueOffset );
}
Expand All @@ -171,8 +171,8 @@ int QgsPointCloudLayerChunkLoaderFactory::primitivesCount( QgsChunkNode *node )
{
const QgsChunkNodeId id = node->tileId();
const QgsPointCloudNodeId n( id.d, id.x, id.y, id.z );
Q_ASSERT( mPointCloudIndex->hasNode( n ) );
return mPointCloudIndex->getNode( n ).pointCount();
Q_ASSERT( mPointCloudIndex.hasNode( n ) );
return mPointCloudIndex.getNode( n ).pointCount();
}


Expand All @@ -197,7 +197,7 @@ static QgsBox3D nodeBoundsToBox3D( QgsBox3D nodeBounds, const QgsCoordinateTrans

QgsChunkNode *QgsPointCloudLayerChunkLoaderFactory::createRootNode() const
{
const QgsPointCloudNode pcNode = mPointCloudIndex->getNode( mPointCloudIndex->root() );
const QgsPointCloudNode pcNode = mPointCloudIndex.getNode( mPointCloudIndex.root() );
const QgsBox3D rootNodeBounds = pcNode.bounds();
QgsBox3D rootNodeBox3D = nodeBoundsToBox3D( rootNodeBounds, mCoordinateTransform, mZValueOffset, mZValueScale );

Expand All @@ -218,9 +218,9 @@ QVector<QgsChunkNode *> QgsPointCloudLayerChunkLoaderFactory::createChildren( Qg
int dx = i & 1, dy = !!( i & 2 ), dz = !!( i & 4 );
const QgsChunkNodeId childId( nodeId.d + 1, nodeId.x * 2 + dx, nodeId.y * 2 + dy, nodeId.z * 2 + dz );
const QgsPointCloudNodeId childPcId( childId.d, childId.x, childId.y, childId.z );
if ( !mPointCloudIndex->hasNode( childPcId ) )
if ( !mPointCloudIndex.hasNode( childPcId ) )
continue;
const QgsPointCloudNode childNode = mPointCloudIndex->getNode( childPcId );
const QgsPointCloudNode childNode = mPointCloudIndex.getNode( childPcId );
const QgsBox3D childBounds = childNode.bounds();
if ( !mExtent.isEmpty() && !childBounds.intersects( mExtent ) )
continue;
Expand All @@ -237,7 +237,7 @@ QVector<QgsChunkNode *> QgsPointCloudLayerChunkLoaderFactory::createChildren( Qg
///////////////


QgsPointCloudLayerChunkedEntity::QgsPointCloudLayerChunkedEntity( Qgs3DMapSettings *map, QgsPointCloudIndex *pc, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maximumScreenSpaceError, bool showBoundingBoxes, double zValueScale, double zValueOffset, int pointBudget )
QgsPointCloudLayerChunkedEntity::QgsPointCloudLayerChunkedEntity( Qgs3DMapSettings *map, QgsPointCloudIndex pc, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maximumScreenSpaceError, bool showBoundingBoxes, double zValueScale, double zValueOffset, int pointBudget )
: QgsChunkedEntity( map, maximumScreenSpaceError, new QgsPointCloudLayerChunkLoaderFactory( Qgs3DRenderContext::fromMapSettings( map ), coordinateTransform, pc, symbol, zValueScale, zValueOffset, pointBudget ), true, pointBudget )
{
setShowBoundingBoxes( showBoundingBoxes );
Expand Down Expand Up @@ -278,9 +278,9 @@ QVector<QgsRayCastingUtils::RayHit> QgsPointCloudLayerChunkedEntity::rayIntersec
QgsVector3D adjustedRayDirection = QgsVector3D( rayDirectionMapCoords.x(), rayDirectionMapCoords.y(), rayDirectionMapCoords.z() / factory->mZValueScale );
adjustedRayDirection.normalize();

QgsPointCloudIndex *index = factory->mPointCloudIndex;
QgsPointCloudIndex index = factory->mPointCloudIndex;

const QgsPointCloudAttributeCollection attributeCollection = index->attributes();
const QgsPointCloudAttributeCollection attributeCollection = index.attributes();
QgsPointCloudRequest request;
request.setAttributes( attributeCollection );

Expand All @@ -291,14 +291,14 @@ QVector<QgsRayCastingUtils::RayHit> QgsPointCloudLayerChunkedEntity::rayIntersec
const QgsChunkNodeId id = node->tileId();
const QgsPointCloudNodeId n( id.d, id.x, id.y, id.z );

if ( !index->hasNode( n ) )
if ( !index.hasNode( n ) )
continue;

const QgsAABB nodeBbox = Qgs3DUtils::mapToWorldExtent( node->box3D(), mMapSettings->origin() );
if ( !QgsRayCastingUtils::rayBoxIntersection( ray, nodeBbox ) )
continue;

std::unique_ptr<QgsPointCloudBlock> block( index->nodeData( n, request ) );
std::unique_ptr<QgsPointCloudBlock> block( index.nodeData( n, request ) );
if ( !block )
continue;

Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgspointcloudlayerchunkloader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class QgsPointCloudLayerChunkLoaderFactory : public QgsChunkLoaderFactory
* Constructs the factory
* The factory takes ownership over the passed \a symbol
*/
QgsPointCloudLayerChunkLoaderFactory( const Qgs3DRenderContext &context, const QgsCoordinateTransform &coordinateTransform, QgsPointCloudIndex *pc, QgsPointCloud3DSymbol *symbol, double zValueScale, double zValueOffset, int pointBudget );
QgsPointCloudLayerChunkLoaderFactory( const Qgs3DRenderContext &context, const QgsCoordinateTransform &coordinateTransform, QgsPointCloudIndex pc, QgsPointCloud3DSymbol *symbol, double zValueScale, double zValueOffset, int pointBudget );

//! Creates loader for the given chunk node. Ownership of the returned is passed to the caller.
virtual QgsChunkLoader *createChunkLoader( QgsChunkNode *node ) const override;
Expand All @@ -72,7 +72,7 @@ class QgsPointCloudLayerChunkLoaderFactory : public QgsChunkLoaderFactory
virtual int primitivesCount( QgsChunkNode *node ) const override;
Qgs3DRenderContext mRenderContext;
QgsCoordinateTransform mCoordinateTransform;
QgsPointCloudIndex *mPointCloudIndex;
QgsPointCloudIndex mPointCloudIndex;
std::unique_ptr<QgsPointCloud3DSymbol> mSymbol;
double mZValueScale = 1.0;
double mZValueOffset = 0;
Expand Down Expand Up @@ -127,7 +127,7 @@ class QgsPointCloudLayerChunkedEntity : public QgsChunkedEntity
{
Q_OBJECT
public:
explicit QgsPointCloudLayerChunkedEntity( Qgs3DMapSettings *map, QgsPointCloudIndex *pc, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maxScreenError, bool showBoundingBoxes, double zValueScale, double zValueOffset, int pointBudget );
explicit QgsPointCloudLayerChunkedEntity( Qgs3DMapSettings *map, QgsPointCloudIndex pc, const QgsCoordinateTransform &coordinateTransform, QgsPointCloud3DSymbol *symbol, float maxScreenError, bool showBoundingBoxes, double zValueScale, double zValueOffset, int pointBudget );

QVector<QgsRayCastingUtils::RayHit> rayIntersection( const QgsRayCastingUtils::Ray3D &ray, const QgsRayCastingUtils::RayCastContext &context ) const override;

Expand Down
1 change: 0 additions & 1 deletion src/3d/qgsvirtualpointcloudentity_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
class QgsAABB;
class QgsChunkBoundsEntity;
class QgsPointCloudLayer;
class QgsPointCloudIndex;
class QgsVirtualPointCloudProvider;
class QgsPointCloud3DSymbol;
class Qgs3DMapSettings;
Expand Down
30 changes: 15 additions & 15 deletions src/3d/symbols/qgspointcloud3dsymbol_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ typedef Qt3DCore::QGeometry Qt3DQGeometry;
#include <delaunator.hpp>

// pick a point that we'll use as origin for coordinates for this node's points
static QgsVector3D originFromNodeBounds( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context )
static QgsVector3D originFromNodeBounds( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context )
{
QgsBox3D bounds = pc->getNode( n ).bounds();
QgsBox3D bounds = pc.getNode( n ).bounds();
double nodeOriginX = bounds.xMinimum();
double nodeOriginY = bounds.yMinimum();
double nodeOriginZ = bounds.zMinimum() * context.zValueScale() + context.zValueFixedOffset();
Expand Down Expand Up @@ -356,7 +356,7 @@ void QgsPointCloud3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const
}


std::vector<double> QgsPointCloud3DSymbolHandler::getVertices( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, const QgsBox3D &box3D )
std::vector<double> QgsPointCloud3DSymbolHandler::getVertices( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, const QgsBox3D &box3D )
{
bool hasColorData = !outNormal.colors.empty();
bool hasParameterData = !outNormal.parameter.empty();
Expand All @@ -374,7 +374,7 @@ std::vector<double> QgsPointCloud3DSymbolHandler::getVertices( QgsPointCloudInde
// next, we also need all points of all parents nodes to make the triangulation (also external points)
QgsPointCloudNodeId parentNode = n.parentNode();

double span = pc->span();
double span = pc.span();
//factor to take account of the density of the point to calculate extension of the bounding box
// with a usual value span = 128, bounding box is extended by 12.5 % on each side.
double extraBoxFactor = 16 / span;
Expand Down Expand Up @@ -516,7 +516,7 @@ void QgsPointCloud3DSymbolHandler::filterTriangles( const std::vector<size_t> &t
}
}

void QgsPointCloud3DSymbolHandler::triangulate( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, const QgsBox3D &box3D )
void QgsPointCloud3DSymbolHandler::triangulate( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, const QgsBox3D &box3D )
{
if ( outNormal.positions.isEmpty() )
return;
Expand All @@ -543,22 +543,22 @@ void QgsPointCloud3DSymbolHandler::triangulate( QgsPointCloudIndex *pc, const Qg
filterTriangles( triangleIndexes, context, box3D );
}

std::unique_ptr<QgsPointCloudBlock> QgsPointCloud3DSymbolHandler::pointCloudBlock( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QgsPointCloud3DRenderContext &context )
std::unique_ptr<QgsPointCloudBlock> QgsPointCloud3DSymbolHandler::pointCloudBlock( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloudRequest &request, const QgsPointCloud3DRenderContext &context )
{
std::unique_ptr<QgsPointCloudBlock> block;
if ( pc->accessType() == QgsPointCloudIndex::AccessType::Local )
if ( pc.accessType() == QgsPointCloudIndex::AccessType::Local )
{
block = pc->nodeData( n, request );
block = pc.nodeData( n, request );
}
else if ( pc->accessType() == QgsPointCloudIndex::AccessType::Remote )
else if ( pc.accessType() == QgsPointCloudIndex::AccessType::Remote )
{
QgsPointCloudNode node = pc->getNode( n );
QgsPointCloudNode node = pc.getNode( n );
if ( node.pointCount() < 1 )
return block;

bool loopAborted = false;
QEventLoop loop;
QgsPointCloudBlockRequest *req = pc->asyncNodeData( n, request );
QgsPointCloudBlockRequest *req = pc.asyncNodeData( n, request );
QObject::connect( req, &QgsPointCloudBlockRequest::finished, &loop, &QEventLoop::quit );
QObject::connect( context.feedback(), &QgsFeedback::canceled, &loop, [&]() {
loopAborted = true;
Expand All @@ -585,7 +585,7 @@ bool QgsSingleColorPointCloud3DSymbolHandler::prepare( const QgsPointCloud3DRend
return true;
}

void QgsSingleColorPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
void QgsSingleColorPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
{
QgsPointCloudAttributeCollection attributes;
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
Expand Down Expand Up @@ -664,7 +664,7 @@ bool QgsColorRampPointCloud3DSymbolHandler::prepare( const QgsPointCloud3DRender
return true;
}

void QgsColorRampPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
void QgsColorRampPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
{
QgsPointCloudAttributeCollection attributes;
const int xOffset = 0;
Expand Down Expand Up @@ -801,7 +801,7 @@ bool QgsRGBPointCloud3DSymbolHandler::prepare( const QgsPointCloud3DRenderContex
return true;
}

void QgsRGBPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
void QgsRGBPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
{
QgsPointCloudAttributeCollection attributes;
attributes.push_back( QgsPointCloudAttribute( QStringLiteral( "X" ), QgsPointCloudAttribute::Int32 ) );
Expand Down Expand Up @@ -945,7 +945,7 @@ bool QgsClassificationPointCloud3DSymbolHandler::prepare( const QgsPointCloud3DR
return true;
}

void QgsClassificationPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex *pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
void QgsClassificationPointCloud3DSymbolHandler::processNode( QgsPointCloudIndex pc, const QgsPointCloudNodeId &n, const QgsPointCloud3DRenderContext &context, PointData *output )
{
QgsPointCloudAttributeCollection attributes;
const int xOffset = 0;
Expand Down
Loading

0 comments on commit 9a58078

Please sign in to comment.