mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#80) Added navigation modes
New navigation modes: GeoQuest and RMS. In addition, right mouse button can now be used for panning in CAD navigation mode.
This commit is contained in:
parent
1a3a2f1ff5
commit
c863d087f0
@ -45,7 +45,9 @@
|
||||
#include "RimEclipseFaultColors.h"
|
||||
|
||||
#include "cafCeetronNavigation.h"
|
||||
#include "cafCadNavigation.h"
|
||||
#include "RiuCadNavigation.h"
|
||||
#include "RiuRmsNavigation.h"
|
||||
#include "RiuGeoQuestNavigation.h"
|
||||
#include "RiaSocketServer.h"
|
||||
#include "cafUiProcess.h"
|
||||
//
|
||||
@ -96,11 +98,12 @@ void AppEnum< RiaApplication::RINavigationPolicy >::setUp()
|
||||
{
|
||||
addItem(RiaApplication::NAVIGATION_POLICY_CEETRON, "NAVIGATION_POLICY_CEETRON", "Ceetron");
|
||||
addItem(RiaApplication::NAVIGATION_POLICY_CAD, "NAVIGATION_POLICY_CAD", "CAD");
|
||||
addItem(RiaApplication::NAVIGATION_POLICY_GEOQUEST, "NAVIGATION_POLICY_GEOQUEST", "GEOQUEST");
|
||||
addItem(RiaApplication::NAVIGATION_POLICY_RMS, "NAVIGATION_POLICY_RMS", "RMS");
|
||||
setDefault(RiaApplication::NAVIGATION_POLICY_CAD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace RegTestNames
|
||||
{
|
||||
const QString generatedFolderName = "RegTestGeneratedImages";
|
||||
@ -1380,11 +1383,23 @@ void RiaApplication::applyPreferences()
|
||||
{
|
||||
if (m_preferences->navigationPolicy() == NAVIGATION_POLICY_CAD)
|
||||
{
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new caf::CadNavigation);
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new RiuCadNavigation);
|
||||
}
|
||||
else if (m_preferences->navigationPolicy() == NAVIGATION_POLICY_CEETRON)
|
||||
{
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new caf::CeetronPlusNavigation);
|
||||
}
|
||||
else if (m_preferences->navigationPolicy() == NAVIGATION_POLICY_GEOQUEST)
|
||||
{
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new RiuGeoQuestNavigation);
|
||||
}
|
||||
else if (m_preferences->navigationPolicy() == NAVIGATION_POLICY_RMS)
|
||||
{
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new RiuRmsNavigation);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_activeReservoirView->viewer()->setNavigationPolicy(new caf::CeetronPlusNavigation);
|
||||
CVF_ASSERT(0);
|
||||
}
|
||||
|
||||
m_activeReservoirView->viewer()->enablePerfInfoHud(m_preferences->showHud());
|
||||
|
@ -61,7 +61,9 @@ public:
|
||||
enum RINavigationPolicy
|
||||
{
|
||||
NAVIGATION_POLICY_CEETRON,
|
||||
NAVIGATION_POLICY_CAD
|
||||
NAVIGATION_POLICY_CAD,
|
||||
NAVIGATION_POLICY_GEOQUEST,
|
||||
NAVIGATION_POLICY_RMS
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -59,7 +59,9 @@ set( USER_INTERFACE_FILES
|
||||
UserInterface/RiuMultiCaseImportDialog.cpp
|
||||
UserInterface/RiuProcessMonitor.cpp
|
||||
UserInterface/RiuViewerCommands.cpp
|
||||
|
||||
UserInterface/RiuCadNavigation.cpp
|
||||
UserInterface/RiuRmsNavigation.cpp
|
||||
UserInterface/RiuGeoQuestNavigation.cpp
|
||||
)
|
||||
|
||||
set( SOCKET_INTERFACE_FILES
|
||||
|
@ -7,7 +7,9 @@
|
||||
#include "RiuViewer.h"
|
||||
#include "RiuMainWindow.h"
|
||||
#include "cafCeetronPlusNavigation.h"
|
||||
#include "cafCadNavigation.h"
|
||||
#include "RiuCadNavigation.h"
|
||||
#include "RiuRmsNavigation.h"
|
||||
#include "RiuGeoQuestNavigation.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfModel.h"
|
||||
#include "cvfModelBasicList.h"
|
||||
@ -139,15 +141,26 @@ void RimView::updateViewerWidget()
|
||||
|
||||
this->resetLegendsInViewer();
|
||||
|
||||
if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_CEETRON)
|
||||
if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_CAD)
|
||||
{
|
||||
m_viewer->setNavigationPolicy(new RiuCadNavigation);
|
||||
}
|
||||
else if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_CEETRON)
|
||||
{
|
||||
m_viewer->setNavigationPolicy(new caf::CeetronPlusNavigation);
|
||||
}
|
||||
else if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_GEOQUEST)
|
||||
{
|
||||
m_viewer->setNavigationPolicy(new RiuGeoQuestNavigation);
|
||||
}
|
||||
else if (RiaApplication::instance()->navigationPolicy() == RiaApplication::NAVIGATION_POLICY_RMS)
|
||||
{
|
||||
m_viewer->setNavigationPolicy(new RiuRmsNavigation);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_viewer->setNavigationPolicy(new caf::CadNavigation);
|
||||
CVF_ASSERT(0);
|
||||
}
|
||||
|
||||
m_viewer->enablePerfInfoHud(RiaApplication::instance()->showPerformanceInfo());
|
||||
|
||||
isViewerCreated = true;
|
||||
|
229
ApplicationCode/UserInterface/RiuCadNavigation.cpp
Normal file
229
ApplicationCode/UserInterface/RiuCadNavigation.cpp
Normal file
@ -0,0 +1,229 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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 <QInputEvent>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::init()
|
||||
{
|
||||
m_trackball = new cvf::ManipulatorTrackball;
|
||||
m_trackball->setCamera(m_viewer->mainCamera());
|
||||
m_isRotCenterInitialized = false;
|
||||
m_isRotating = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
{
|
||||
if (! inputEvent) return false;
|
||||
bool isEventHandled = false;
|
||||
|
||||
switch (inputEvent->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (me->button() == Qt::MidButton)
|
||||
{
|
||||
if (me->modifiers() & Qt::ShiftModifier)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isRotating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
cvf::HitItemCollection hic;
|
||||
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
|
||||
|
||||
if (hitSomething)
|
||||
{
|
||||
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
|
||||
m_trackball->setRotationPoint(pointOfInterest);
|
||||
m_pointOfInterest = pointOfInterest;
|
||||
}
|
||||
else
|
||||
{
|
||||
initializeRotationCenter();
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
//m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE));
|
||||
m_isRotating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
else if (me->button() == Qt::RightButton)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isRotating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
if (m_isRotating)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
if (me->button() == Qt::MidButton || me->button() == Qt::RightButton)
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
//m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK));
|
||||
m_isRotating = false;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (m_isRotating)
|
||||
{
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if (needRedraw)
|
||||
{
|
||||
m_viewer->update();
|
||||
}
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
{
|
||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||
int translatedMousePosX = we->x();
|
||||
int translatedMousePosY = m_viewer->height() - we->y();
|
||||
|
||||
cvf::ref<cvf::Ray> ray;
|
||||
if (we->delta() > 0)
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
else
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY));
|
||||
|
||||
if (ray.notNull() && abs(we->delta()) > 0)
|
||||
{
|
||||
cvf::Vec3d pos, vrp, up;
|
||||
m_viewer->mainCamera()->toLookAt(&pos, &vrp, &up);
|
||||
|
||||
double scale = -we->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->update();
|
||||
}
|
||||
}
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return isEventHandled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::initializeRotationCenter()
|
||||
{
|
||||
if(m_isRotCenterInitialized || m_trackball.isNull() || !m_viewer->mainScene() || !m_viewer->currentScene()->boundingBox().isValid()) return;
|
||||
m_pointOfInterest = m_viewer->currentScene()->boundingBox().center();
|
||||
|
||||
m_trackball->setRotationPoint(m_pointOfInterest);
|
||||
m_isRotCenterInitialized = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// 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;
|
||||
}
|
46
ApplicationCode/UserInterface/RiuCadNavigation.h
Normal file
46
ApplicationCode/UserInterface/RiuCadNavigation.h
Normal file
@ -0,0 +1,46 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cafNavigationPolicy.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfRay.h"
|
||||
|
||||
|
||||
class RiuCadNavigation : public caf::NavigationPolicy
|
||||
{
|
||||
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);
|
||||
|
||||
|
||||
// Cad navigation specific
|
||||
void initializeRotationCenter();
|
||||
|
||||
cvf::ref<cvf::ManipulatorTrackball> m_trackball;
|
||||
bool m_isRotCenterInitialized;
|
||||
bool m_isRotating;
|
||||
cvf::Vec3d m_pointOfInterest;
|
||||
};
|
250
ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp
Normal file
250
ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp
Normal file
@ -0,0 +1,250 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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 <QInputEvent>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGeoQuestNavigation::init()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
{
|
||||
if (! inputEvent) return false;
|
||||
bool isEventHandled = false;
|
||||
switch (inputEvent->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (me->button() == Qt::RightButton)
|
||||
{
|
||||
cvf::HitItemCollection hic;
|
||||
bool hitSomething = m_viewer->rayPick(me->x(), me->y(), &hic);
|
||||
|
||||
if (hitSomething)
|
||||
{
|
||||
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
|
||||
m_trackball->setRotationPoint(pointOfInterest);
|
||||
m_pointOfInterest = pointOfInterest;
|
||||
}
|
||||
else
|
||||
{
|
||||
initializeRotationCenter();
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
//m_viewer->setCursor(RICursors::get(RICursors::ROTATE));
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->button() == Qt::MidButton)
|
||||
{
|
||||
if (me->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
if (m_isNavigating)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
if (me->button() == Qt::RightButton || me->button() == Qt::MidButton )
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
|
||||
m_isNavigating = false;
|
||||
if (m_hasMovedMouseDuringNavigation) isEventHandled = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (m_isNavigating)
|
||||
{
|
||||
if (m_isZooming)
|
||||
{
|
||||
int delta = 3*(m_lastPosY - me->y());
|
||||
this->zoomAlongRay(m_zoomRay.p(), delta);
|
||||
m_lastPosX = me->x();
|
||||
m_lastPosY = me->y();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if (needRedraw)
|
||||
{
|
||||
m_viewer->update();
|
||||
}
|
||||
}
|
||||
isEventHandled = true;
|
||||
m_hasMovedMouseDuringNavigation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
{
|
||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
||||
int translatedMousePosX = we->x();
|
||||
int translatedMousePosY = m_viewer->height() - we->y();
|
||||
int delta = we->delta();
|
||||
|
||||
cvf::ref<cvf::Ray> ray;
|
||||
if (delta < 0)
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
else
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY));
|
||||
|
||||
zoomAlongRay(ray.p(), delta);
|
||||
|
||||
}
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;//isEventHandled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGeoQuestNavigation::initializeRotationCenter()
|
||||
{
|
||||
if(m_isRotCenterInitialized || m_trackball.isNull() || !m_viewer->mainScene() || !m_viewer->currentScene()->boundingBox().isValid()) return;
|
||||
m_pointOfInterest = m_viewer->currentScene()->boundingBox().center();
|
||||
|
||||
m_trackball->setRotationPoint(m_pointOfInterest);
|
||||
m_isRotCenterInitialized = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// 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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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->update();
|
||||
}
|
||||
}
|
55
ApplicationCode/UserInterface/RiuGeoQuestNavigation.h
Normal file
55
ApplicationCode/UserInterface/RiuGeoQuestNavigation.h
Normal file
@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cafNavigationPolicy.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfRay.h"
|
||||
|
||||
|
||||
class RiuGeoQuestNavigation : public caf::NavigationPolicy
|
||||
{
|
||||
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<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;
|
||||
|
||||
};
|
274
ApplicationCode/UserInterface/RiuRmsNavigation.cpp
Normal file
274
ApplicationCode/UserInterface/RiuRmsNavigation.cpp
Normal file
@ -0,0 +1,274 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#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 <QInputEvent>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuRmsNavigation::init()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
{
|
||||
if (! inputEvent) return false;
|
||||
bool isEventHandled = false;
|
||||
switch (inputEvent->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (me->button() == Qt::MidButton)
|
||||
{
|
||||
cvf::HitItemCollection hic;
|
||||
bool hitSomething = m_viewer->rayPick(me->x(), me->y(), &hic);
|
||||
|
||||
if (hitSomething)
|
||||
{
|
||||
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
|
||||
m_trackball->setRotationPoint(pointOfInterest);
|
||||
m_pointOfInterest = pointOfInterest;
|
||||
}
|
||||
else
|
||||
{
|
||||
initializeRotationCenter();
|
||||
}
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
//m_viewer->setCursor(RICursors::get(RICursors::ROTATE));
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->button() == Qt::LeftButton)
|
||||
{
|
||||
if (me->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
QMouseEvent* we = static_cast<QMouseEvent*> ( inputEvent);
|
||||
m_lastPosX = we->x();
|
||||
m_lastPosY = we->y();
|
||||
|
||||
m_zoomRay = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
m_isZooming = true;
|
||||
}
|
||||
}
|
||||
else if (me->button() == Qt::RightButton)
|
||||
{
|
||||
if (me->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isNavigating = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
if (m_isNavigating)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
if (me->button() == Qt::RightButton || me->button() == Qt::MidButton )
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
|
||||
m_isNavigating = false;
|
||||
if (m_hasMovedMouseDuringNavigation) isEventHandled = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
}
|
||||
else if ( me->button() == Qt::LeftButton )
|
||||
{
|
||||
m_isZooming = false;
|
||||
|
||||
m_isNavigating = false;
|
||||
if (m_hasMovedMouseDuringNavigation) isEventHandled = true;
|
||||
m_hasMovedMouseDuringNavigation = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (m_isNavigating)
|
||||
{
|
||||
if (m_isZooming)
|
||||
{
|
||||
int delta = -3*(m_lastPosY - me->y());
|
||||
this->zoomAlongRay(m_zoomRay.p(), delta);
|
||||
m_lastPosX = me->x();
|
||||
m_lastPosY = me->y();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if (needRedraw)
|
||||
{
|
||||
m_viewer->update();
|
||||
}
|
||||
}
|
||||
isEventHandled = true;
|
||||
m_hasMovedMouseDuringNavigation = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
{
|
||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||
{
|
||||
initializeRotationCenter();
|
||||
if (m_isRotCenterInitialized)
|
||||
{
|
||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
||||
int translatedMousePosX = we->x();
|
||||
int translatedMousePosY = m_viewer->height() - we->y();
|
||||
int delta = we->delta();
|
||||
|
||||
cvf::ref<cvf::Ray> ray;
|
||||
if (delta < 0)
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
||||
else
|
||||
ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY));
|
||||
|
||||
zoomAlongRay(ray.p(), -delta);
|
||||
|
||||
}
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;//isEventHandled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuRmsNavigation::initializeRotationCenter()
|
||||
{
|
||||
if(m_isRotCenterInitialized || m_trackball.isNull() || !m_viewer->mainScene() || !m_viewer->currentScene()->boundingBox().isValid()) return;
|
||||
m_pointOfInterest = m_viewer->currentScene()->boundingBox().center();
|
||||
|
||||
m_trackball->setRotationPoint(m_pointOfInterest);
|
||||
m_isRotCenterInitialized = true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// 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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
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->update();
|
||||
}
|
||||
}
|
55
ApplicationCode/UserInterface/RiuRmsNavigation.h
Normal file
55
ApplicationCode/UserInterface/RiuRmsNavigation.h
Normal file
@ -0,0 +1,55 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2015- Statoil ASA
|
||||
// Copyright (C) 2015- Ceetron Solutions AS
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cvfBase.h"
|
||||
#include "cafNavigationPolicy.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
#include "cvfRay.h"
|
||||
|
||||
|
||||
class RiuRmsNavigation : public caf::NavigationPolicy
|
||||
{
|
||||
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<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;
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user