Skip to content

Commit

Permalink
Fix reset view in 3D view for VPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
Withalion committed Mar 4, 2025
1 parent fa9f867 commit 001a324
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/3d/qgs3dmapscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ void Qgs3DMapScene::viewZoomFull()
double d = side / 2 / std::tan( cameraController()->camera()->fieldOfView() / 2 * M_PI / 180 );
d += zRange.isInfinite() ? 0. : zRange.upper();
mCameraController->resetView( static_cast<float>( d ) );
return;
}

void Qgs3DMapScene::setViewFrom2DExtent( const QgsRectangle &extent )
Expand Down
6 changes: 3 additions & 3 deletions src/3d/qgscameracontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ void QgsCameraController::setViewFromTop( float worldX, float worldY, float dist
camPose.setDistanceFromCenterPoint( distance );
camPose.setHeadingAngle( yaw );

// a basic setup to make frustum depth range long enough that it does not cull everything
mCamera->setNearPlane( distance / 2 );
mCamera->setFarPlane( distance * 2 );
// we force the updateCameraNearFarPlanes() in Qgs3DMapScene to properly set the planes
// by making sure the cameraPose is never the same, which will emit cameraChanged()
mCameraPose.setDistanceFromCenterPoint( camPose.distanceFromCenterPoint() + 1 );

setCameraPose( camPose );
}
Expand Down
24 changes: 21 additions & 3 deletions src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qgsapplication.h"
#include "qgscolorschemeregistry.h"
#include "qgscolorutils.h"
#include "qgsvirtualpointcloudprovider.h"

QgsPointCloudLayerElevationProperties::QgsPointCloudLayerElevationProperties( QObject *parent )
: QgsMapLayerElevationProperties( parent )
Expand Down Expand Up @@ -127,11 +128,28 @@ QgsDoubleRange QgsPointCloudLayerElevationProperties::calculateZRange( QgsMapLay
{
if ( pcLayer->dataProvider() )
{
double zMin = std::numeric_limits<double>::quiet_NaN();
double zMax = std::numeric_limits<double>::quiet_NaN();
const QgsPointCloudStatistics stats = pcLayer->statistics();
if ( !stats.statisticsMap().isEmpty() )
{
// try to fetch z range from provider metadata
zMin = stats.minimum( QStringLiteral( "Z" ) );
zMax = stats.maximum( QStringLiteral( "Z" ) );
}
// try to fetch the elevation properties from virtual point cloud metadata
else if ( QgsVirtualPointCloudProvider *virtualProvider = dynamic_cast< QgsVirtualPointCloudProvider * >( pcLayer->dataProvider() ) )
{
zMin = virtualProvider->subIndexes()[0].zRange().lower();
zMax = virtualProvider->subIndexes()[0].zRange().upper();
for ( QgsPointCloudSubIndex subIndex : virtualProvider->subIndexes() )
{
const QgsDoubleRange newRange = subIndex.zRange();
zMin = std::min( zMin, newRange.lower() );
zMax = std::max( zMax, newRange.upper() );
}
}

// try to fetch z range from provider metadata
const double zMin = stats.minimum( QStringLiteral( "Z" ) );
const double zMax = stats.maximum( QStringLiteral( "Z" ) );
if ( !std::isnan( zMin ) && !std::isnan( zMax ) )
{
return QgsDoubleRange( zMin * mZScale + mZOffset, zMax * mZScale + mZOffset );
Expand Down

0 comments on commit 001a324

Please sign in to comment.