Skip to content

Commit

Permalink
Remove index reference from QgsPointCloudNode
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon committed Nov 25, 2024
1 parent c8af873 commit 2d3f664
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/core/pointcloud/qgscopcpointcloudindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ QgsPointCloudNode QgsCopcPointCloudIndex::getNode( const QgsPointCloudNodeId &id
}
}

return QgsPointCloudNode( *this, id, pointCount, children );
QgsBox3D bounds = QgsPointCloudNode::bounds( mRootBounds, id );
return QgsPointCloudNode( id, pointCount, children, bounds.width() / mSpan, bounds );
}

void QgsCopcPointCloudIndex::copyCommonProperties( QgsCopcPointCloudIndex *destination ) const
Expand Down
2 changes: 1 addition & 1 deletion src/core/pointcloud/qgseptpointcloudindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ QgsPointCloudNode QgsEptPointCloudIndex::getNode( const QgsPointCloudNodeId &id
QMutexLocker locker( &mHierarchyMutex );
qint64 pointCount = mHierarchy.value( id, -1 );
if ( pointCount != -1 )
return QgsPointCloudNode( *this, id, pointCount, node.children() );
return QgsPointCloudNode( id, pointCount, node.children(), node.error(), node.bounds() );
}

// If we fail, return with pointCount = -1 anyway
Expand Down
25 changes: 15 additions & 10 deletions src/core/pointcloud/qgspointcloudindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,27 @@ uint qHash( const QgsPointCloudCacheKey &key )

QgsBox3D QgsPointCloudNode::bounds() const
{
const QgsBox3D rootBounds = mIndex.rootNodeBounds();
return mBounds;
}

QgsBox3D QgsPointCloudNode::bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id )
{
const double d = rootBounds.xMaximum() - rootBounds.xMinimum();
const double dLevel = d / pow( 2, mId.d() );
const double dLevel = d / pow( 2, id.d() );

const double xMin = rootBounds.xMinimum() + dLevel * mId.x();
const double xMax = rootBounds.xMinimum() + dLevel * ( mId.x() + 1 );
const double yMin = rootBounds.yMinimum() + dLevel * mId.y();
const double yMax = rootBounds.yMinimum() + dLevel * ( mId.y() + 1 );
const double zMin = rootBounds.zMinimum() + dLevel * mId.z();
const double zMax = rootBounds.zMinimum() + dLevel * ( mId.z() + 1 );
const double xMin = rootBounds.xMinimum() + dLevel * id.x();
const double xMax = rootBounds.xMinimum() + dLevel * ( id.x() + 1 );
const double yMin = rootBounds.yMinimum() + dLevel * id.y();
const double yMax = rootBounds.yMinimum() + dLevel * ( id.y() + 1 );
const double zMin = rootBounds.zMinimum() + dLevel * id.z();
const double zMax = rootBounds.zMinimum() + dLevel * ( id.z() + 1 );

return QgsBox3D( xMin, yMin, zMin, xMax, yMax, zMax );
}

float QgsPointCloudNode::error() const
{
return bounds().width() / mIndex.span();
return mError;
}

///@endcond
Expand Down Expand Up @@ -186,7 +190,8 @@ QgsPointCloudNode QgsPointCloudIndex::getNode( const QgsPointCloudNodeId &id ) c
}
}

return QgsPointCloudNode( *this, id, pointCount, children );
QgsBox3D bounds = QgsPointCloudNode::bounds( mRootBounds, id );
return QgsPointCloudNode( id, pointCount, children, bounds.width() / mSpan, bounds );
}

QgsPointCloudAttributeCollection QgsPointCloudIndex::attributes() const
Expand Down
18 changes: 13 additions & 5 deletions src/core/pointcloud/qgspointcloudindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ uint qHash( const QgsPointCloudCacheKey &key );
class CORE_EXPORT QgsPointCloudNode
{
public:
//! Constructs new node object. Should only be called by QgsPointCloudIndex::getNode()
QgsPointCloudNode( const QgsPointCloudIndex &index, QgsPointCloudNodeId id, qint64 pointCount,
QList<QgsPointCloudNodeId> childIds )
: mIndex( index ), mId( id ), mPointCount( pointCount ), mChildIds( childIds )

/**
* Constructs new node object. Should only be called by QgsPointCloudIndex::getNode().
* Bounds should always be computed by QgsPointCloudNode::bounds().
*/
QgsPointCloudNode( QgsPointCloudNodeId id, qint64 pointCount,
QList<QgsPointCloudNodeId> childIds, float error, QgsBox3D bounds )
: mId( id ), mPointCount( pointCount ), mChildIds( childIds ), mError( error ), mBounds( bounds )
{
}
//! Returns node's ID (unique in index)
Expand All @@ -175,12 +179,16 @@ class CORE_EXPORT QgsPointCloudNode
//! Returns node's bounding cube in CRS coords
QgsBox3D bounds() const;

//! Returns bounding box of specific node
static QgsBox3D bounds( QgsBox3D rootBounds, QgsPointCloudNodeId id );

private:
const QgsPointCloudIndex &mIndex;
// Specific node metadata:
QgsPointCloudNodeId mId;
qint64 mPointCount;
QList<QgsPointCloudNodeId> mChildIds;
float mError;
QgsBox3D mBounds;
};

/**
Expand Down

0 comments on commit 2d3f664

Please sign in to comment.