(#168) (#695) Wip: Refactoring the ResInsight nav policies to make bugfixing simpler

This commit is contained in:
Jacob Støren 2015-12-09 15:51:38 +01:00
parent f3eb304d66
commit 5874df7cc9
6 changed files with 65 additions and 352 deletions

View File

@ -20,26 +20,35 @@
#include "RiuCadNavigation.h" #include "RiuCadNavigation.h"
#include "cafViewer.h" #include "cafViewer.h"
#include "cvfCamera.h" #include "cvfCamera.h"
#include "cvfScene.h"
#include "cvfModel.h"
#include "cvfViewport.h" #include "cvfViewport.h"
#include "cvfHitItemCollection.h" #include "cvfHitItemCollection.h"
#include "cvfRay.h" #include "cvfRay.h"
#include "cvfManipulatorTrackball.h"
#include <QInputEvent> #include <QInputEvent>
#include <QHBoxLayout>
using cvf::ManipulatorTrackball; //--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuCadNavigation::RiuCadNavigation()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuCadNavigation::~RiuCadNavigation()
{
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuCadNavigation::init() void RiuCadNavigation::init()
{ {
m_trackball = new cvf::ManipulatorTrackball; caf::TrackBallBasedNavigation::init();
m_trackball->setCamera(m_viewer->mainCamera());
m_isRotCenterInitialized = false;
m_isRotating = false;
m_navigationUpdated = false; m_navigationUpdated = false;
} }
@ -62,7 +71,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
if (me->button() == Qt::LeftButton) if (me->button() == Qt::LeftButton)
{ {
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
m_isRotating = true; m_isNavigating = true;
isEventHandled = true; isEventHandled = true;
} }
else if (me->button() == Qt::MidButton) else if (me->button() == Qt::MidButton)
@ -70,7 +79,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
if (me->modifiers() & Qt::ShiftModifier) if (me->modifiers() & Qt::ShiftModifier)
{ {
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
m_isRotating = true; m_isNavigating = true;
isEventHandled = true; isEventHandled = true;
} }
else if (me->modifiers() == Qt::NoModifier) else if (me->modifiers() == Qt::NoModifier)
@ -90,7 +99,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
//m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE)); //m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE));
m_isRotating = true; m_isNavigating = true;
isEventHandled = true; isEventHandled = true;
} }
} }
@ -103,14 +112,14 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
break; break;
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
{ {
if (m_isRotating) if (m_isNavigating)
{ {
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent); QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
if (me->button() == Qt::MidButton || me->button() == Qt::LeftButton) if (me->button() == Qt::MidButton || me->button() == Qt::LeftButton)
{ {
m_trackball->endNavigation(); m_trackball->endNavigation();
//m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK)); //m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK));
m_isRotating = false; m_isNavigating = false;
isEventHandled = m_navigationUpdated; isEventHandled = m_navigationUpdated;
m_navigationUpdated = false; m_navigationUpdated = false;
@ -127,7 +136,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
int translatedMousePosX = me->x(); int translatedMousePosX = me->x();
int translatedMousePosY = m_viewer->height() - me->y(); int translatedMousePosY = m_viewer->height() - me->y();
if (m_isRotating) if (m_isNavigating)
{ {
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY); bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
if (needRedraw) if (needRedraw)
@ -182,65 +191,3 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
return isEventHandled; 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);
}

View File

@ -19,29 +19,16 @@
#pragma once #pragma once
#include "cvfBase.h" #include "cafTrackBallBasedNavigation.h"
#include "cafNavigationPolicy.h"
#include "cvfManipulatorTrackball.h"
#include "cvfRay.h"
class RiuCadNavigation : public caf::TrackBallBasedNavigation
class RiuCadNavigation : public caf::NavigationPolicy
{ {
public:
RiuCadNavigation();
virtual ~RiuCadNavigation();
protected: protected:
// General navigation policy reimplememtation virtual void init();
virtual void init(); virtual bool handleInputEvent(QInputEvent* inputEvent);
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);
bool m_navigationUpdated;
// Cad navigation specific
void initializeRotationCenter();
cvf::ref<cvf::ManipulatorTrackball> m_trackball;
bool m_isRotCenterInitialized;
bool m_isRotating;
cvf::Vec3d m_pointOfInterest;
bool m_navigationUpdated;
}; };

View File

@ -20,30 +20,27 @@
#include "RiuGeoQuestNavigation.h" #include "RiuGeoQuestNavigation.h"
#include "cafViewer.h" #include "cafViewer.h"
#include "cvfCamera.h" #include "cvfCamera.h"
#include "cvfScene.h"
#include "cvfModel.h"
#include "cvfViewport.h" #include "cvfViewport.h"
#include "cvfHitItemCollection.h" #include "cvfHitItemCollection.h"
#include "cvfRay.h" #include "cvfRay.h"
#include "cvfManipulatorTrackball.h"
#include <QInputEvent> #include <QInputEvent>
#include <QHBoxLayout>
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; RiuGeoQuestNavigation::~RiuGeoQuestNavigation()
m_lastPosY = 0; {
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -171,88 +168,3 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent)
return false;//isEventHandled; 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();
}
}

View File

@ -19,37 +19,14 @@
#pragma once #pragma once
#include "cvfBase.h" #include "cafTrackBallBasedNavigation.h"
#include "cafNavigationPolicy.h"
#include "cvfManipulatorTrackball.h"
#include "cvfRay.h"
class RiuGeoQuestNavigation : public caf::NavigationPolicy class RiuGeoQuestNavigation : public caf::TrackBallBasedNavigation
{ {
public:
RiuGeoQuestNavigation();
virtual ~RiuGeoQuestNavigation();
protected: protected:
// General navigation policy overrides virtual bool handleInputEvent(QInputEvent* inputEvent);
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<cvf::ManipulatorTrackball> 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<cvf::Ray> m_zoomRay;
int m_lastPosX; /// Previous mouse position
int m_lastPosY;
}; };

View File

@ -20,30 +20,27 @@
#include "RiuRmsNavigation.h" #include "RiuRmsNavigation.h"
#include "cafViewer.h" #include "cafViewer.h"
#include "cvfCamera.h" #include "cvfCamera.h"
#include "cvfScene.h"
#include "cvfModel.h"
#include "cvfViewport.h" #include "cvfViewport.h"
#include "cvfHitItemCollection.h" #include "cvfHitItemCollection.h"
#include "cvfRay.h" #include "cvfRay.h"
#include "cvfManipulatorTrackball.h"
#include <QInputEvent> #include <QInputEvent>
#include <QHBoxLayout>
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; RiuRmsNavigation::~RiuRmsNavigation()
m_lastPosY = 0; {
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -196,87 +193,3 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
return false;//isEventHandled; 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();
}
}

View File

@ -19,37 +19,14 @@
#pragma once #pragma once
#include "cvfBase.h" #include "cafTrackBallBasedNavigation.h"
#include "cafNavigationPolicy.h"
#include "cvfManipulatorTrackball.h"
#include "cvfRay.h"
class RiuRmsNavigation : public caf::NavigationPolicy class RiuRmsNavigation : public caf::TrackBallBasedNavigation
{ {
public:
RiuRmsNavigation();
virtual ~RiuRmsNavigation();
protected: protected:
// General navigation policy overrides virtual bool handleInputEvent(QInputEvent* inputEvent);
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<cvf::ManipulatorTrackball> 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<cvf::Ray> m_zoomRay;
int m_lastPosX; /// Previous mouse position
int m_lastPosY;
}; };