From e3dc32bd71e47d9bf3b72de40c1392315a1d0491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 16 Oct 2019 14:08:16 +0200 Subject: [PATCH] #4857 AppFwk: Add handling of comparison view to the 3d navigation policies --- Fwk/AppFwk/cafViewer/cafCadNavigation.cpp | 13 +---- .../cafViewer/cafCeetronPlusNavigation.cpp | 13 +---- .../cafViewer/cafTrackBallBasedNavigation.cpp | 47 +++++++++++++------ .../cafViewer/cafTrackBallBasedNavigation.h | 7 +-- 4 files changed, 38 insertions(+), 42 deletions(-) diff --git a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp index 1a5a44f5ac..abc6fd2d63 100644 --- a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp @@ -79,18 +79,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled()) { - cvf::HitItemCollection hic; - bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic); - - if (hitSomething) - { - cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); - this->setPointOfInterest(pointOfInterest); - } - else - { - initializeRotationCenter(); - } + this->pickAndSetPointOfInterest(me->x(), me->y()); m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); m_roationSensitivityCalculator.init(me); diff --git a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp index 5fa26f6f24..2ba9586675 100644 --- a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp @@ -81,18 +81,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) if (me->button() == Qt::RightButton && isRotationEnabled()) { - cvf::HitItemCollection hic; - bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic); - - if (hitSomething) - { - cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); - this->setPointOfInterest(pointOfInterest); - } - else - { - initializeRotationCenter(); - } + this->pickAndSetPointOfInterest(me->x(), me->y()); m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); m_roationSensitivityCalculator.init(me); diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index 03d7836288..9f8b41fa10 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -157,21 +157,22 @@ void caf::TrackBallBasedNavigation::setPointOfInterest(cvf::Vec3d poi) } //-------------------------------------------------------------------------------------------------- -/// +/// //-------------------------------------------------------------------------------------------------- -void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY) +void caf::TrackBallBasedNavigation::pickAndSetPointOfInterest(int winPosX, int winPosY) { - bool hitSomething = false; cvf::HitItemCollection hic; - if (shouldRaytraceForNewPoiDuringWheelZoom(zoomX, zoomY)) - { - hitSomething = m_viewer->rayPick(zoomX, zoomY, &hic); - updateWheelZoomPosition(zoomX, zoomY); - } + bool hitSomething = m_viewer->rayPick( winPosX, winPosY, &hic); if (hitSomething) - { + { cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); + + if (m_viewer->isMousePosWithinComparisonView( winPosX, winPosY )) + { + pointOfInterest -= m_viewer->comparisonViewEyePointOffset(); + } + this->setPointOfInterest(pointOfInterest); } else @@ -180,6 +181,22 @@ void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(i } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int winPosX, int winPosY) +{ + if (shouldRaytraceForNewPoiDuringWheelZoom(winPosX, winPosY)) + { + this->pickAndSetPointOfInterest(winPosX, winPosY); + updateWheelZoomPosition(winPosX, winPosY); + } + else + { + initializeRotationCenter(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -271,24 +288,24 @@ cvf::ref caf::TrackBallBasedNavigation::createZoomRay(int cvfXPos, int //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int zoomX, int zoomY) +void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int winPosX, int winPosY) { - m_lastWheelZoomPosX = zoomX; - m_lastWheelZoomPosY = zoomY; + m_lastWheelZoomPosX = winPosX; + m_lastWheelZoomPosY = winPosY; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const +bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int winPosX, int winPosY) const { // Raytrace if the last zoom position isn't set if (m_lastWheelZoomPosX == -1 || m_lastWheelZoomPosY == -1) { return true; } - int diffX = zoomX - m_lastWheelZoomPosX; - int diffY = zoomY - m_lastWheelZoomPosY; + int diffX = winPosX - m_lastWheelZoomPosX; + int diffY = winPosY - m_lastWheelZoomPosY; const int pixelThreshold = 5; if (diffX * diffX + diffY * diffY > pixelThreshold * pixelThreshold) diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h index 5328b1efe1..76134408dd 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h @@ -107,7 +107,8 @@ protected: void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) override; cvf::Vec3d pointOfInterest() override; void setPointOfInterest(cvf::Vec3d poi) override; - void updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY); + void pickAndSetPointOfInterest(int winPosX, int winPosY); + void updatePointOfInterestDuringZoomIfNecessary(int winPosX, int winPosY); void forcePointOfInterestUpdateDuringNextWheelZoom(); // Track ball navigation specific @@ -134,8 +135,8 @@ protected: bool isRotationEnabled() { return m_isRotationEnabled; } private: - void updateWheelZoomPosition(int zoomX, int zoomY); - bool shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const; + void updateWheelZoomPosition(int winPosX, int winPosY); + bool shouldRaytraceForNewPoiDuringWheelZoom(int winPosX, int winPosY) const; private: bool m_consumeEvents;