#14602 Contour map: Keep interactive panning when reloading a project

Viewer::setView() moves the camera to look straight at the point of interest. Panning does not move the point of interest, so this discarded the camera position restored from the project file.

Only reset the view direction if the camera is not already oriented top-down, which is the case when a contour map has been rotated by a linked 3D view.
This commit is contained in:
Magne Sjaastad
2026-08-27 10:16:06 +02:00
parent cf3dadacf7
commit 61117162da
4 changed files with 36 additions and 4 deletions
@@ -506,9 +506,18 @@ void RimEclipseContourMapView::updateViewFollowingCellFilterUpdates()
void RimEclipseContourMapView::onLoadDataAndUpdate()
{
RimEclipseView::onLoadDataAndUpdate();
if ( nativeOrOverrideViewer() )
if ( auto viewer = nativeOrOverrideViewer() )
{
nativeOrOverrideViewer()->setView( cvf::Vec3d( 0, 0, -1 ), cvf::Vec3d( 0, 1, 0 ) );
const cvf::Vec3d viewDirection( 0, 0, -1 );
const cvf::Vec3d upDirection( 0, 1, 0 );
// setView() moves the camera to look straight at the point of interest. Panning does not move the point of
// interest, so calling setView() will discard the panning restored from the project file. The camera is
// already oriented correctly for a contour map, unless the view has been rotated by a linked 3D view.
if ( !isCameraOriented( viewDirection, upDirection ) )
{
viewer->setView( viewDirection, upDirection );
}
}
}
@@ -460,9 +460,18 @@ void RimGeoMechContourMapView::updateViewFollowingCellFilterUpdates()
void RimGeoMechContourMapView::onLoadDataAndUpdate()
{
RimGeoMechView::onLoadDataAndUpdate();
if ( nativeOrOverrideViewer() )
if ( auto viewer = nativeOrOverrideViewer() )
{
nativeOrOverrideViewer()->setView( cvf::Vec3d( 0, 0, -1 ), cvf::Vec3d( 0, 1, 0 ) );
const cvf::Vec3d viewDirection( 0, 0, -1 );
const cvf::Vec3d upDirection( 0, 1, 0 );
// setView() moves the camera to look straight at the point of interest. Panning does not move the point of
// interest, so calling setView() will discard the panning restored from the project file. The camera is
// already oriented correctly for a contour map, unless the view has been rotated by a linked 3D view.
if ( !isCameraOriented( viewDirection, upDirection ) )
{
viewer->setView( viewDirection, upDirection );
}
}
}
@@ -1653,6 +1653,19 @@ cvf::Vec3d Rim3dView::cameraPointOfInterest() const
return m_cameraPointOfInterest();
}
//--------------------------------------------------------------------------------------------------
/// Returns true if the camera is already oriented along the given view direction and up direction
//--------------------------------------------------------------------------------------------------
bool Rim3dView::isCameraOriented( const cvf::Vec3d& viewDirection, const cvf::Vec3d& upDirection ) const
{
auto viewer = nativeOrOverrideViewer();
if ( !viewer || !viewer->mainCamera() ) return false;
const double tolerance = 1.0e-6;
return ( viewer->mainCamera()->direction() - viewDirection ).length() < tolerance &&
( viewer->mainCamera()->up() - upDirection ).length() < tolerance;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -214,6 +214,7 @@ protected:
virtual void setDefaultView();
cvf::Mat4d cameraPosition() const;
cvf::Vec3d cameraPointOfInterest() const;
bool isCameraOriented( const cvf::Vec3d& viewDirection, const cvf::Vec3d& upDirection ) const;
void disableGridBoxField();
void disablePerspectiveProjectionField();