Commit 3fe95a1e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[ADD] - re-added nav-slice in the nav widgets. This uses a new projection mode...

[ADD] - re-added nav-slice in the nav widgets. This uses a new projection mode TWO_D_UNIT with a No-Op manipulator. This causes the extra code in WMNavSlices to be minimal compared to the last implemenation we had.
parent b14a051e
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include <string>
#include "exceptions/WGEInitFailed.h"
......@@ -55,21 +56,25 @@ void WGECamera::reset()
{
switch( m_DefProjMode )
{
case( ORTHOGRAPHIC ):
case ORTHOGRAPHIC:
setProjectionMatrixAsOrtho( -120.0 * getViewport()->aspectRatio(), 120.0 * getViewport()->aspectRatio(),
-120.0, 120.0, -1000.0, +1000.0 );
setProjectionResizePolicy( HORIZONTAL );
break;
case( PERSPECTIVE ):
case PERSPECTIVE:
setProjectionMatrixAsPerspective( 30.0, getViewport()->aspectRatio(), 1.0, 1000.0 );
setProjectionResizePolicy( osg::Camera::HORIZONTAL );
break;
case( TWO_D ):
setProjectionMatrixAsOrtho2D( 0.0, getViewport()->width(), 0.0, getViewport()->height() );
case TWO_D:
resize();
setProjectionResizePolicy( osg::Camera::FIXED );
break;
case TWO_D_UNIT:
resize();
setProjectionResizePolicy( osg::Camera::FIXED );
break;
default:
throw WGEInitFailed( std::string( "Unknown projection mode" ) );
throw WGEInitFailed( std::string( "Unknown projection mode." ) );
}
}
......@@ -79,4 +84,16 @@ void WGECamera::resize()
{
setProjectionMatrixAsOrtho2D( 0.0, getViewport()->width(), 0.0, getViewport()->height() );
}
else if( m_DefProjMode == TWO_D_UNIT )
{
double aspectWH = static_cast< double >( getViewport()->width() ) / static_cast< double >( getViewport()->height() );
double aspectHW = 1.0 / aspectWH;
double w = aspectWH > aspectHW ? aspectWH : 1.0;
double h = aspectWH > aspectHW ? 1.0 : aspectHW;
w *= 0.5;
h *= 0.5;
setProjectionMatrixAsOrtho( -w, w, -h, h, 0.0, 1.0 );
}
}
......@@ -38,11 +38,17 @@ class WGE_EXPORT WGECamera: public osg::Camera
{
public:
/**
* List of possible camera modes.
* List of possible camera modes. The TWO_D modes use a standard two dimensional orthogonal projection. TWO_D_UNOT is somewhat special. It
* creates a view-cube with an edge-length of 1, centered at 0 for X and Y. For Z, it is from 0 to 1. This relates to the standard glOrtho
* command.
*/
enum ProjectionMode
{
ORTHOGRAPHIC, PERSPECTIVE, TWO_D
ORTHOGRAPHIC,
PERSPECTIVE,
TWO_D, // two dimensional ortographic projection, dimension is viewport
TWO_D_UNIT // like TWO_D but size is unit-cube with proper scaling and aspect ratio. This is useful for widgets where viewport size is
// unimportant.
};
/**
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WGENoOpManipulator.h"
WGENoOpManipulator::WGENoOpManipulator():
osgGA::MatrixManipulator()
{
// initialize members
}
WGENoOpManipulator::~WGENoOpManipulator()
{
// cleanup
}
const char* WGENoOpManipulator::className() const
{
return "WGENoOpManipulator";
}
void WGENoOpManipulator::setByMatrix( const osg::Matrixd& /* matrix */ )
{
// do nothing here
}
void WGENoOpManipulator::setByInverseMatrix( const osg::Matrixd& /* matrix */ )
{
// do nothing here
}
osg::Matrixd WGENoOpManipulator::getMatrix() const
{
return osg::Matrixd::identity();
}
osg::Matrixd WGENoOpManipulator::getInverseMatrix() const
{
return osg::Matrixd::identity();
}
void WGENoOpManipulator::home( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& /*us*/ )
{
// No Op
}
void WGENoOpManipulator::init( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& /*us*/ )
{
// No Op
}
bool WGENoOpManipulator::handle( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& /*us*/ )
{
// No Op
return true;
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGENOOPMANIPULATOR_H
#define WGENOOPMANIPULATOR_H
#include <osg/Version>
// OSG interface changed in 2.9.7, to make it compile also with those versions we do this:
// OSG_MIN_VERSION_REQUIRED(2, 9, 8) macro is not available in e.g. OSG 2.8.1, hence we use the old way
#if ( ( OPENSCENEGRAPH_MAJOR_VERSION > 2 ) || ( OPENSCENEGRAPH_MAJOR_VERSION == 2 && ( OPENSCENEGRAPH_MINOR_VERSION > 9 || \
( OPENSCENEGRAPH_MINOR_VERSION == 9 && OPENSCENEGRAPH_PATCH_VERSION >= 8 ) ) ) )
#include <osgGA/CameraManipulator>
namespace osgGA
{
typedef CameraManipulator MatrixManipulator;
}
#else
#include <osgGA/MatrixManipulator>
#endif
/**
* This is an OSG Manipulator implementation which does nothing. It is very useful for simple two-d views.
*/
class WGENoOpManipulator: public osgGA::MatrixManipulator
{
public:
/**
* Convenience typedef for a boost::shared_ptr< WGENoOpManipulator >.
*/
typedef osg::ref_ptr< WGENoOpManipulator > SPtr;
/**
* Convenience typedef for a boost::shared_ptr< const WGENoOpManipulator >.
*/
typedef osg::ref_ptr< const WGENoOpManipulator > ConstSPtr;
/**
* Default constructor.
*/
WGENoOpManipulator();
/**
* Destructor.
*/
virtual ~WGENoOpManipulator();
/**
* Return the name of the object's class type.
*
* \return the name of the object's class type
*/
virtual const char* className() const;
/**
* Set the position of the matrix manipulator using a 4x4 matrix.
*
* \param matrix a 4x4 matrix
*/
virtual void setByMatrix( const osg::Matrixd& matrix );
/**
* Set the position of the matrix manipulator using a 4x4 matrix.
*
* \param matrix a 4x4 matrix
*/
virtual void setByInverseMatrix( const osg::Matrixd& matrix );
/**
* Get the position of the manipulator as 4x4 matrix.
*
* \return the position of the manipulator as 4x4 matrix
*/
virtual osg::Matrixd getMatrix() const;
/**
* Get the position of the manipulator as a inverse matrix of the
* manipulator, typically used as a model view matrix.
*
* \return the position of the manipulator as a inverse matrix
*/
virtual osg::Matrixd getInverseMatrix() const;
/**
* Move the camera to the default position.
*
* \param us the action adapter used to request actions of the GUI
*/
virtual void home( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& us ); // NOLINT We can not change the interface of OSG
/**
* Start/restart the manipulator.
*
* \param us the action adapter used to request actions of the GUI
*/
virtual void init( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& us ); // NOLINT We can not change the interface of OSG
/**
* Handle events
*
* \param ea event class for storing keyboard, mouse and window events
* \param us the action adapter used to request actions of the GUI
* \return true if handled, false otherwise
*/
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
protected:
private:
};
#endif // WGENOOPMANIPULATOR_H
......@@ -42,6 +42,7 @@
#include "exceptions/WGEInitFailed.h"
#include "WGE2DManipulator.h"
#include "WGENoOpManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
......@@ -86,6 +87,10 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int
case( WGECamera::TWO_D ):
// no manipulators nor gui handlers
break;
case( WGECamera::TWO_D_UNIT ):
// use no-op handler by default
m_View->setCameraManipulator( new WGENoOpManipulator() );
break;
default:
throw WGEInitFailed( std::string( "Unknown projection mode" ) );
}
......
......@@ -131,6 +131,8 @@ void WMNavigationSlices::initOSG()
WBoundingBox bb = WGEColormapping::instance()->getBoundingBox();
WVector3d minV = bb.getMin();
WVector3d maxV = bb.getMax();
WVector3d sizes = ( maxV - minV );
WVector3d midBB = minV + ( sizes * 0.5 );
// update the properties
m_xPos->setMin( minV[0] );
......@@ -148,11 +150,37 @@ void WMNavigationSlices::initOSG()
if( m_first )
{
m_first = false;
m_xPos->set( ( maxV[0] - minV[0] ) / 2.0 );
m_yPos->set( ( maxV[1] - minV[1] ) / 2.0 );
m_zPos->set( ( maxV[2] - minV[2] ) / 2.0 );
m_xPos->set( midBB[0] );
m_yPos->set( midBB[1] );
m_zPos->set( midBB[2] );
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Navigation View Setup
///////////////////////////////////////////////////////////////////////////////////////////////
double maxSizeInv = 1.0 / std::max( sizes[0], std::max( sizes[1], sizes[2] ) );
m_axialOutput->setMatrix(
osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
osg::Matrixd::translate( 0.0, 0.0, -0.5 )
);
m_coronalOutput->setMatrix(
osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
osg::Matrixd::rotate( -0.5 * piDouble, 1.0, 0.0 , 0.0 ) *
osg::Matrixd::translate( 0.0, 0.0, -0.5 )
);
m_sagittalOutput->setMatrix(
osg::Matrixd::translate( -midBB[0], -midBB[1], -midBB[2] ) *
osg::Matrixd::scale( maxSizeInv, maxSizeInv, maxSizeInv ) *
osg::Matrixd::rotate( -0.5 * piDouble, 1.0, 0.0 , 0.0 ) *
osg::Matrixd::rotate( 0.5 * piDouble, 0.0, 1.0 , 0.0 ) *
osg::Matrixd::translate( 0.0, 0.0, -0.5 )
);
///////////////////////////////////////////////////////////////////////////////////////////////
// Slice Setup
///////////////////////////////////////////////////////////////////////////////////////////////
......@@ -237,6 +265,10 @@ void WMNavigationSlices::initOSG()
m_output->insert( mY );
m_output->insert( mZ );
m_output->dirtyBound();
m_axialOutput->insert( m_output );
m_sagittalOutput->insert( m_output );
m_coronalOutput->insert( m_output );
}
WMNavigationSlices::PickCallback::PickCallback( osg::ref_ptr< osg::Node > node, WPropDouble property, bool negateDirection ):
......@@ -298,7 +330,16 @@ void WMNavigationSlices::moduleMain()
// apply colormapping to transformation
osg::ref_ptr< WGEShader > shader = new WGEShader( "WMNavigationSlices", m_localPath );
WGEColormapping::apply( m_output, shader ); // this automatically applies the shader
// create the roots for the nav-views
m_sagittalOutput = osg::ref_ptr< WGEGroupNode > ( new WGEGroupNode() );
m_coronalOutput = osg::ref_ptr< WGEGroupNode > ( new WGEGroupNode() );
m_axialOutput = osg::ref_ptr< WGEGroupNode > ( new WGEGroupNode() );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->insert( m_output );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Axial View" )->getScene()->insert( m_axialOutput );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Coronal View" )->getScene()->insert( m_coronalOutput );
WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "Sagittal View" )->getScene()->insert( m_sagittalOutput );
// we need to be informed if the bounding box of the volume containing all the data changes.
m_moduleState.add( WGEColormapping::instance()->getChangeCondition() );
......@@ -330,5 +371,8 @@ void WMNavigationSlices::moduleMain()
m_zSlicePicker.reset();
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_output );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_axialOutput );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_coronalOutput );
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->remove( m_sagittalOutput );
}
......@@ -33,6 +33,7 @@
#include <boost/signals2.hpp>
#include "core/graphicsEngine/WGEManagedGroupNode.h"
#include "core/graphicsEngine/WGEGroupNode.h"
#include "core/common/math/linearAlgebra/WLinearAlgebra.h"
#include "core/common/WPropertyTypes.h"
#include "core/graphicsEngine/WPickInfo.h"
......@@ -197,6 +198,21 @@ private:
*/
osg::ref_ptr< WGEManagedGroupNode > m_output;
/**
* The geode with the slice only for the nav widgets
*/
osg::ref_ptr< WGEGroupNode > m_axialOutput;
/**
* The geode with the slice only for the nav widgets
*/
osg::ref_ptr< WGEGroupNode > m_coronalOutput;
/**
* The geode with the slice only for the nav widgets
*/
osg::ref_ptr< WGEGroupNode > m_sagittalOutput;
WPropBool m_noTransparency; //!< if true, the whole slices are shown.
WPropGroup m_sliceGroup; //!< the group contains several slice properties
......
......@@ -372,6 +372,7 @@ void WMainWindow::setupGUI()
m_mainGLWidget.get() ) );
m_navAxial->setFeatures( QDockWidget::AllDockWidgetFeatures );
m_navAxial->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropAxialPos() );
m_navAxial->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navAxial.get() );
......@@ -379,6 +380,7 @@ void WMainWindow::setupGUI()
m_mainGLWidget.get() ) );
m_navCoronal->setFeatures( QDockWidget::AllDockWidgetFeatures );
m_navCoronal->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropCoronalPos() );
m_navCoronal->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navCoronal.get() );
......@@ -387,6 +389,7 @@ void WMainWindow::setupGUI()
m_mainGLWidget.get() ) );
m_navSagittal->setFeatures( QDockWidget::AllDockWidgetFeatures );
m_navSagittal->setSliderProperty( WKernel::getRunningKernel()->getSelectionManager()->getPropSagittalPos() );
m_navSagittal->getGLWidget()->setCameraManipulator( WQtGLWidget::NO_OP );
m_glDock->addDockWidget( Qt::LeftDockWidgetArea, m_navSagittal.get() );
......
......@@ -38,6 +38,7 @@
#include "core/common/WLogger.h"
#include "core/common/WColor.h"
#include "core/graphicsEngine/WGE2DManipulator.h"
#include "core/graphicsEngine/WGENoOpManipulator.h"
#include "core/graphicsEngine/WGEViewer.h"
#include "core/graphicsEngine/WGEZoomTrackballManipulator.h"
#include "core/graphicsEngine/WGraphicsEngine.h"
......@@ -134,6 +135,13 @@ void WQtGLWidget::setCameraManipulator( WQtGLWidget::CameraManipulators manipula
m_Viewer->setCameraManipulator( new( WGE2DManipulator ) );
break;
case NO_OP:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGENoOp\".",
"WQtGLWidget(" + m_Viewer->getName() + ")",
LL_DEBUG );
m_Viewer->setCameraManipulator( new( WGENoOpManipulator ) );
break;
case TRACKBALL:
default:
WLogger::getLogger()->addLogMessage( "Switched to OSG manipulator \"WGETrackball\".",
......
......@@ -86,7 +86,7 @@ public:
*/
enum CameraManipulators
{
TRACKBALL, TWO_D
TRACKBALL, TWO_D, NO_OP
};
/**
......
......@@ -40,7 +40,7 @@
#include "WQtNavGLWidget.moc"
WQtNavGLWidget::WQtNavGLWidget( QString viewTitle, QString dockTitle, QWidget* parent, std::string sliderTitle, const QWidget * shareWidget )
: WQtGLDockWidget( viewTitle, dockTitle, parent, WGECamera::ORTHOGRAPHIC, shareWidget )
: WQtGLDockWidget( viewTitle, dockTitle, parent, WGECamera::TWO_D_UNIT, shareWidget )
{
propertyWidgetMap.clear();
m_sliderTitle = QString( sliderTitle.c_str() );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment