From 5874df7cc98383edd5fa0dba09f7b1bd65c83758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Wed, 9 Dec 2015 15:51:38 +0100 Subject: [PATCH] (#168) (#695) Wip: Refactoring the ResInsight nav policies to make bugfixing simpler --- .../UserInterface/RiuCadNavigation.cpp | 99 ++++------------ .../UserInterface/RiuCadNavigation.h | 29 ++--- .../UserInterface/RiuGeoQuestNavigation.cpp | 110 ++---------------- .../UserInterface/RiuGeoQuestNavigation.h | 35 +----- .../UserInterface/RiuRmsNavigation.cpp | 109 ++--------------- .../UserInterface/RiuRmsNavigation.h | 35 +----- 6 files changed, 65 insertions(+), 352 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuCadNavigation.cpp b/ApplicationCode/UserInterface/RiuCadNavigation.cpp index d86f641970..a02fe70131 100644 --- a/ApplicationCode/UserInterface/RiuCadNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuCadNavigation.cpp @@ -20,26 +20,35 @@ #include "RiuCadNavigation.h" #include "cafViewer.h" #include "cvfCamera.h" -#include "cvfScene.h" -#include "cvfModel.h" #include "cvfViewport.h" #include "cvfHitItemCollection.h" #include "cvfRay.h" +#include "cvfManipulatorTrackball.h" #include -#include -using cvf::ManipulatorTrackball; +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuCadNavigation::RiuCadNavigation() +{ + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuCadNavigation::~RiuCadNavigation() +{ + +} //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuCadNavigation::init() { - m_trackball = new cvf::ManipulatorTrackball; - m_trackball->setCamera(m_viewer->mainCamera()); - m_isRotCenterInitialized = false; - m_isRotating = false; + caf::TrackBallBasedNavigation::init(); m_navigationUpdated = false; } @@ -62,7 +71,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) if (me->button() == Qt::LeftButton) { m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); - m_isRotating = true; + m_isNavigating = true; isEventHandled = true; } else if (me->button() == Qt::MidButton) @@ -70,7 +79,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) if (me->modifiers() & Qt::ShiftModifier) { m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); - m_isRotating = true; + m_isNavigating = true; isEventHandled = true; } else if (me->modifiers() == Qt::NoModifier) @@ -90,7 +99,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); //m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE)); - m_isRotating = true; + m_isNavigating = true; isEventHandled = true; } } @@ -103,14 +112,14 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) break; case QEvent::MouseButtonRelease: { - if (m_isRotating) + if (m_isNavigating) { QMouseEvent * me = static_cast( inputEvent); if (me->button() == Qt::MidButton || me->button() == Qt::LeftButton) { m_trackball->endNavigation(); //m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK)); - m_isRotating = false; + m_isNavigating = false; isEventHandled = m_navigationUpdated; m_navigationUpdated = false; @@ -127,7 +136,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) int translatedMousePosX = me->x(); int translatedMousePosY = m_viewer->height() - me->y(); - if (m_isRotating) + if (m_isNavigating) { bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY); if (needRedraw) @@ -182,65 +191,3 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) return isEventHandled; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuCadNavigation::initializeRotationCenter() -{ - if (m_isRotCenterInitialized - || m_trackball.isNull() - || !m_viewer->currentScene()->boundingBox().isValid()) - { - return; - } - - cvf::Vec3d pointOfInterest = m_viewer->currentScene()->boundingBox().center(); - - this->setPointOfInterest(pointOfInterest); -} - -//-------------------------------------------------------------------------------------------------- -/// Repositions and orients the camera to view the rotation point along the -/// direction "alongDirection". The distance to the rotation point is maintained. -/// -//-------------------------------------------------------------------------------------------------- -void RiuCadNavigation::setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) -{ - m_trackball->setView(alongDirection, upDirection); - /* - if (m_camera.isNull()) return; - - Vec3d dir = alongDirection; - if (!dir.normalize()) return; - Vec3d up = upDirection; - if(!up.normalize()) up = Vec3d::Z_AXIS; - - if((up * dir) < 1e-2) up = dir.perpendicularVector(); - - Vec3d cToE = m_camera->position() - m_rotationPoint; - Vec3d newEye = m_rotationPoint - cToE.length() * dir; - - m_camera->setFromLookAt(newEye, m_rotationPoint, upDirection); - */ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec3d RiuCadNavigation::pointOfInterest() -{ - initializeRotationCenter(); - return m_pointOfInterest; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuCadNavigation::setPointOfInterest(cvf::Vec3d poi) -{ - m_pointOfInterest = poi; - m_trackball->setRotationPoint(poi); - m_isRotCenterInitialized = true; - m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); - -} diff --git a/ApplicationCode/UserInterface/RiuCadNavigation.h b/ApplicationCode/UserInterface/RiuCadNavigation.h index 08f14c818f..955eb3c3b7 100644 --- a/ApplicationCode/UserInterface/RiuCadNavigation.h +++ b/ApplicationCode/UserInterface/RiuCadNavigation.h @@ -19,29 +19,16 @@ #pragma once -#include "cvfBase.h" -#include "cafNavigationPolicy.h" -#include "cvfManipulatorTrackball.h" -#include "cvfRay.h" +#include "cafTrackBallBasedNavigation.h" - -class RiuCadNavigation : public caf::NavigationPolicy +class RiuCadNavigation : public caf::TrackBallBasedNavigation { +public: + RiuCadNavigation(); + virtual ~RiuCadNavigation(); protected: - // General navigation policy reimplememtation - virtual void init(); - virtual bool handleInputEvent(QInputEvent* inputEvent); - virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ); - virtual cvf::Vec3d pointOfInterest(); - virtual void setPointOfInterest(cvf::Vec3d poi); + virtual void init(); + virtual bool handleInputEvent(QInputEvent* inputEvent); - - // Cad navigation specific - void initializeRotationCenter(); - - cvf::ref m_trackball; - bool m_isRotCenterInitialized; - bool m_isRotating; - cvf::Vec3d m_pointOfInterest; - bool m_navigationUpdated; + bool m_navigationUpdated; }; diff --git a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp index 3d5977a987..3bb0ed1797 100644 --- a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp @@ -20,30 +20,27 @@ #include "RiuGeoQuestNavigation.h" #include "cafViewer.h" #include "cvfCamera.h" -#include "cvfScene.h" -#include "cvfModel.h" #include "cvfViewport.h" #include "cvfHitItemCollection.h" #include "cvfRay.h" +#include "cvfManipulatorTrackball.h" #include -#include - -using cvf::ManipulatorTrackball; //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuGeoQuestNavigation::init() +RiuGeoQuestNavigation::RiuGeoQuestNavigation() { - m_trackball = new cvf::ManipulatorTrackball; - m_trackball->setCamera(m_viewer->mainCamera()); - m_isRotCenterInitialized = false; - m_hasMovedMouseDuringNavigation = false; - m_isNavigating = false; - m_isZooming = false; - m_lastPosX = 0; - m_lastPosY = 0; + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuGeoQuestNavigation::~RiuGeoQuestNavigation() +{ + } //-------------------------------------------------------------------------------------------------- @@ -171,88 +168,3 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent) return false;//isEventHandled; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuGeoQuestNavigation::initializeRotationCenter() -{ - if (m_isRotCenterInitialized - || m_trackball.isNull() - || !m_viewer->currentScene()->boundingBox().isValid()) - { - return; - } - - cvf::Vec3d pointOfInterest = m_viewer->currentScene()->boundingBox().center(); - - this->setPointOfInterest(pointOfInterest); -} - -//-------------------------------------------------------------------------------------------------- -/// Repositions and orients the camera to view the rotation point along the -/// direction "alongDirection". The distance to the rotation point is maintained. -/// -//-------------------------------------------------------------------------------------------------- -void RiuGeoQuestNavigation::setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) -{ - m_trackball->setView(alongDirection, upDirection); - /* - if (m_camera.isNull()) return; - - Vec3d dir = alongDirection; - if (!dir.normalize()) return; - Vec3d up = upDirection; - if(!up.normalize()) up = Vec3d::Z_AXIS; - - if((up * dir) < 1e-2) up = dir.perpendicularVector(); - - Vec3d cToE = m_camera->position() - m_rotationPoint; - Vec3d newEye = m_rotationPoint - cToE.length() * dir; - - m_camera->setFromLookAt(newEye, m_rotationPoint, upDirection); - */ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec3d RiuGeoQuestNavigation::pointOfInterest() -{ - initializeRotationCenter(); - return m_pointOfInterest; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuGeoQuestNavigation::setPointOfInterest(cvf::Vec3d poi) -{ - m_pointOfInterest = poi; - m_trackball->setRotationPoint(poi); - m_isRotCenterInitialized = true; - m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuGeoQuestNavigation::zoomAlongRay(cvf::Ray* ray, int delta) -{ - if (ray && abs(delta) > 0) - { - cvf::Vec3d pos, vrp, up; - m_viewer->mainCamera()->toLookAt(&pos, &vrp, &up); - - double scale = delta/8.0 * 1.0/150 * (pos - m_pointOfInterest).length(); - cvf::Vec3d trans = scale * ray->direction(); - cvf::Vec3d newPos = pos + trans; - cvf::Vec3d newVrp = vrp + trans; - - m_viewer->mainCamera()->setFromLookAt(newPos, newVrp, up ); - m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest); - - m_viewer->navigationPolicyUpdate(); - } -} diff --git a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.h b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.h index 6dce37449b..2a2814bea3 100644 --- a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.h +++ b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.h @@ -19,37 +19,14 @@ #pragma once -#include "cvfBase.h" -#include "cafNavigationPolicy.h" -#include "cvfManipulatorTrackball.h" -#include "cvfRay.h" +#include "cafTrackBallBasedNavigation.h" -class RiuGeoQuestNavigation : public caf::NavigationPolicy +class RiuGeoQuestNavigation : public caf::TrackBallBasedNavigation { +public: + RiuGeoQuestNavigation(); + virtual ~RiuGeoQuestNavigation(); protected: - // General navigation policy overrides - virtual void init(); - virtual bool handleInputEvent(QInputEvent* inputEvent); - - virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ); - virtual cvf::Vec3d pointOfInterest(); - virtual void setPointOfInterest(cvf::Vec3d poi); - - // PdvNavigation specific - void initializeRotationCenter(); - cvf::ref m_trackball; - bool m_isRotCenterInitialized; - cvf::Vec3d m_pointOfInterest; - - bool m_isNavigating; - bool m_hasMovedMouseDuringNavigation; - - // Handle mid mouse button zoom - void zoomAlongRay( cvf::Ray* ray, int delta ); - bool m_isZooming; - cvf::ref m_zoomRay; - int m_lastPosX; /// Previous mouse position - int m_lastPosY; - + virtual bool handleInputEvent(QInputEvent* inputEvent); }; diff --git a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp index e8b5be8694..e689ed92a2 100644 --- a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp @@ -20,30 +20,27 @@ #include "RiuRmsNavigation.h" #include "cafViewer.h" #include "cvfCamera.h" -#include "cvfScene.h" -#include "cvfModel.h" #include "cvfViewport.h" #include "cvfHitItemCollection.h" #include "cvfRay.h" +#include "cvfManipulatorTrackball.h" #include -#include - -using cvf::ManipulatorTrackball; //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuRmsNavigation::init() +RiuRmsNavigation::RiuRmsNavigation() { - m_trackball = new cvf::ManipulatorTrackball; - m_trackball->setCamera(m_viewer->mainCamera()); - m_isRotCenterInitialized = false; - m_hasMovedMouseDuringNavigation = false; - m_isNavigating = false; - m_isZooming = false; - m_lastPosX = 0; - m_lastPosY = 0; + +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuRmsNavigation::~RiuRmsNavigation() +{ + } //-------------------------------------------------------------------------------------------------- @@ -196,87 +193,3 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) return false;//isEventHandled; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuRmsNavigation::initializeRotationCenter() -{ - if (m_isRotCenterInitialized - || m_trackball.isNull() - || !m_viewer->currentScene()->boundingBox().isValid()) - { - return; - } - - cvf::Vec3d pointOfInterest = m_viewer->currentScene()->boundingBox().center(); - - this->setPointOfInterest(pointOfInterest); -} - -//-------------------------------------------------------------------------------------------------- -/// Repositions and orients the camera to view the rotation point along the -/// direction "alongDirection". The distance to the rotation point is maintained. -/// -//-------------------------------------------------------------------------------------------------- -void RiuRmsNavigation::setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) -{ - m_trackball->setView(alongDirection, upDirection); - /* - if (m_camera.isNull()) return; - - Vec3d dir = alongDirection; - if (!dir.normalize()) return; - Vec3d up = upDirection; - if(!up.normalize()) up = Vec3d::Z_AXIS; - - if((up * dir) < 1e-2) up = dir.perpendicularVector(); - - Vec3d cToE = m_camera->position() - m_rotationPoint; - Vec3d newEye = m_rotationPoint - cToE.length() * dir; - - m_camera->setFromLookAt(newEye, m_rotationPoint, upDirection); - */ -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -cvf::Vec3d RiuRmsNavigation::pointOfInterest() -{ - initializeRotationCenter(); - return m_pointOfInterest; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuRmsNavigation::setPointOfInterest(cvf::Vec3d poi) -{ - m_pointOfInterest = poi; - m_trackball->setRotationPoint(poi); - m_isRotCenterInitialized = true; - m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); - -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiuRmsNavigation::zoomAlongRay(cvf::Ray* ray, int delta) -{ - if (ray && abs(delta) > 0) - { - cvf::Vec3d pos, vrp, up; - m_viewer->mainCamera()->toLookAt(&pos, &vrp, &up); - - double scale = delta/8.0 * 1.0/150 * (pos - m_pointOfInterest).length(); - cvf::Vec3d trans = scale * ray->direction(); - cvf::Vec3d newPos = pos + trans; - cvf::Vec3d newVrp = vrp + trans; - - m_viewer->mainCamera()->setFromLookAt(newPos, newVrp, up ); - m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest); - - m_viewer->navigationPolicyUpdate(); - } -} diff --git a/ApplicationCode/UserInterface/RiuRmsNavigation.h b/ApplicationCode/UserInterface/RiuRmsNavigation.h index 93fb068ec2..7274105dc7 100644 --- a/ApplicationCode/UserInterface/RiuRmsNavigation.h +++ b/ApplicationCode/UserInterface/RiuRmsNavigation.h @@ -19,37 +19,14 @@ #pragma once -#include "cvfBase.h" -#include "cafNavigationPolicy.h" -#include "cvfManipulatorTrackball.h" -#include "cvfRay.h" +#include "cafTrackBallBasedNavigation.h" -class RiuRmsNavigation : public caf::NavigationPolicy +class RiuRmsNavigation : public caf::TrackBallBasedNavigation { +public: + RiuRmsNavigation(); + virtual ~RiuRmsNavigation(); protected: - // General navigation policy overrides - virtual void init(); - virtual bool handleInputEvent(QInputEvent* inputEvent); - - virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ); - virtual cvf::Vec3d pointOfInterest(); - virtual void setPointOfInterest(cvf::Vec3d poi); - - // PdvNavigation specific - void initializeRotationCenter(); - cvf::ref m_trackball; - bool m_isRotCenterInitialized; - cvf::Vec3d m_pointOfInterest; - - bool m_isNavigating; - bool m_hasMovedMouseDuringNavigation; - - // Handle mid mouse button zoom - void zoomAlongRay( cvf::Ray* ray, int delta ); - bool m_isZooming; - cvf::ref m_zoomRay; - int m_lastPosX; /// Previous mouse position - int m_lastPosY; - + virtual bool handleInputEvent(QInputEvent* inputEvent); };