diff --git a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp index d5baa3feb6..8765deea33 100644 --- a/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/ContourMap/RimEclipseContourMapView.cpp @@ -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 ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp index 499bbfddbc..f5468850d3 100644 --- a/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp +++ b/ApplicationLibCode/ProjectDataModel/GeoMech/RimGeoMechContourMapView.cpp @@ -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 ); + } } } diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp index f4a8574bb1..370778302b 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.cpp @@ -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; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dView.h b/ApplicationLibCode/ProjectDataModel/Rim3dView.h index 4ddee74370..01e2d8e851 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dView.h +++ b/ApplicationLibCode/ProjectDataModel/Rim3dView.h @@ -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();