Commit afa6529b authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents 4e1eab9d f7438892
//---------------------------------------------------------------------------
//
// 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 "WEvent.h"
WEvent::WEvent( double time )
: m_time( time )
{
}
void WEvent::setTime( double time )
{
m_time = time;
}
double WEvent::getTime() const
{
return m_time;
}
void WEvent::setNode( osg::ref_ptr< osg::Node > node )
{
m_node = node;
}
osg::ref_ptr< osg::Node > WEvent::getNode() const
{
return m_node;
}
//---------------------------------------------------------------------------
//
// 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 WEVENT_H
#define WEVENT_H
#include <osg/Node>
/**
* This class marks a special time position in an EEG or MEG recording.
*/
class WEvent
{
public:
/**
* Constructor
*
* \param time sets the time position
*/
explicit WEvent( double time );
/**
* Set the time position
*
* \param time time position
*/
void setTime( double time );
/**
* Get the time position
*
* \return time position
*/
double getTime() const;
/**
* Set the OSG-Node representing the event
*
* \param node OSG-Node as ref_ptr
*/
void setNode( osg::ref_ptr< osg::Node > node );
/**
* Get the OSG-Node representing the event
*
* \return OSG-Node as ref_ptr
*/
osg::ref_ptr< osg::Node > getNode() const;
protected:
private:
/**
* time position
*/
double m_time;
/**
* OSG-Node representing the event
*/
osg::ref_ptr< osg::Node > m_node;
};
#endif // WEVENT_H
......@@ -26,7 +26,7 @@
WGE2DManipulator::WGE2DManipulator()
: m_positionX( 0.0 ),
: m_positionX( -64.0 ),
m_positionY( 0.0 ),
m_zoom( 1.0 )
{
......@@ -63,7 +63,7 @@ osg::Matrixd WGE2DManipulator::getInverseMatrix() const
void WGE2DManipulator::home( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& us ) // NOLINT We can not change the interface of OSG
{
m_positionX = 0.0;
m_positionX = -64.0;
m_positionY = 0.0;
m_zoom = 1.0;
......
......@@ -93,7 +93,7 @@ public:
/**
* Handle events
*
* \param ea event class for storing Keyboard, mouse and window 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
*/
......@@ -149,7 +149,7 @@ private:
/**
* Handles events related to zooming.
*
* \param ea event class for storing Keyboard, mouse and window events
* \param ea event class for storing keyboard, mouse and window events
*/
bool zoom( const osgGA::GUIEventAdapter& ea );
......
......@@ -60,15 +60,18 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
m_View->setCamera( new WGECamera( width, height, projectionMode ) );
m_View->getCamera()->setGraphicsContext( m_GraphicsContext );
// camera manipulator
switch( projectionMode )
{
case( WGECamera::ORTHOGRAPHIC ):
case( WGECamera::PERSPECTIVE ):
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
break;
case( WGECamera::TWO_D ):
m_View->setCameraManipulator( new WGE2DManipulator() );
m_markHandler = new WMarkHandler();
m_View->addEventHandler( m_markHandler );
break;
default:
throw WGEInitFailed( "Unknown projection mode" );
......@@ -165,6 +168,11 @@ osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
return m_pickHandler;
}
osg::ref_ptr< WMarkHandler > WGEViewer::getMarkHandler() const
{
return m_markHandler;
}
void WGEViewer::reset()
{
m_View->home();
......
......@@ -44,6 +44,7 @@
#include "WGEGraphicsWindow.h"
#include "WGECamera.h"
#include "WMarkHandler.h"
#include "WPickHandler.h"
......@@ -164,6 +165,13 @@ public:
*/
osg::ref_ptr< WPickHandler > getPickHandler();
/**
* Getter for the mark handler
*
* \return the mark handler
*/
osg::ref_ptr< WMarkHandler > getMarkHandler() const;
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
......@@ -180,6 +188,11 @@ protected:
*/
osg::ref_ptr<WPickHandler> m_pickHandler;
/**
* Pointer to the mark handler of the viewer.
*/
osg::ref_ptr<WMarkHandler> m_markHandler;
private:
};
......
//---------------------------------------------------------------------------
//
// 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 "WMarkHandler.h"
WMarkHandler::WMarkHandler()
: m_positionFlag( new WCondition, -1.0 )
{
}
WFlag< double >* WMarkHandler::getPositionFlag()
{
return &m_positionFlag;
}
WMarkHandler::~WMarkHandler()
{
}
bool WMarkHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
bool handled = false;
switch( ea.getEventType() )
{
case osgGA::GUIEventAdapter::PUSH:
case osgGA::GUIEventAdapter::DRAG:
if( ea.getButtonMask() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON )
{
handled = calculateNewPosition( ea, aa );
}
break;
default:
// do nothing
break;
}
return handled;
}
bool WMarkHandler::calculateNewPosition( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
bool handled = false;
osg::View* view = aa.asView();
if( view )
{
osg::Camera* camera = view->getCamera();
if( camera )
{
osg::Matrixd matrix = camera->getViewMatrix();
matrix.postMult( camera->getProjectionMatrix() );
if( camera->getViewport() )
{
matrix.postMult( camera->getViewport()->computeWindowMatrix() );
}
osg::Vec3d selectedPoint = osg::Vec3d( ea.getX(), ea.getY(), 0.0 ) * osg::Matrixd::inverse( matrix );
m_positionFlag.set( selectedPoint.x() );
handled = true;
}
}
return handled;
}
//---------------------------------------------------------------------------
//
// 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 WMARKHANDLER_H
#define WMARKHANDLER_H
#include <osgGA/GUIEventHandler>
#include "../common/WFlag.h"
/**
* Class to handle events which mark a time position in an EEG or MEG recording.
*/
class WMarkHandler : public osgGA::GUIEventHandler
{
public:
/**
* Constructor
*/
WMarkHandler();
/**
* Handle events.
*
* \param ea event class for storing keyboard, mouse and window events
* \param aa the action adapter
* \return true if handled, false otherwise
*/
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
/**
* Get the flag which contains the marked position
*
* \return the flag as pointer
*/
WFlag< double >* getPositionFlag();
protected:
/**
* Protected destructor because this class is derived from an OSG class
*/
virtual ~WMarkHandler();
private:
/**
* Flag which contains the marked position
*/
WFlag< double > m_positionFlag;
/**
* Calculate the new marked position
*
* \param ea event class for storing keyboard, mouse and window events
* \param aa the action adapter
* \return true if handled, false otherwise
*/
bool calculateNewPosition( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
};
#endif // WMARKHANDLER_H
......@@ -54,10 +54,9 @@ private:
bool m_useColor; //!< Indicated whether m_color should be used for display.
/**
* updates the graphics
* \param text text info from pick
* updates the graphics. Remember that this shoudl only be called from a node callback
*/
virtual void updateGFX( std::string text ) = 0;
virtual void updateGFX() = 0;
};
#endif // WROI_H
......@@ -111,7 +111,8 @@ void setVertices( osg::Vec3Array* vertices, wmath::WPosition minPos, wmath::WPos
WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
WROI(),
boxId( maxBoxId++ )
boxId( maxBoxId++ ),
needUpdate( false )
{
m_minPos = minPos;
m_maxPos = maxPos;
......@@ -122,11 +123,14 @@ WROIBox::WROIBox( wmath::WPosition minPos, wmath::WPosition maxPos ) :
boost::shared_ptr< WGEViewer > viewer = ge->getViewerByName( "main" );
assert( viewer );
m_pickHandler = viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::updateGFX, this, _1 ) );
m_pickHandler->getPickSignal()->connect( boost::bind( &WROIBox::registerPick, this, _1 ) );
osg::Geometry* surfaceGeometry = new osg::Geometry();
m_geode = new osg::Geode;
m_geode->setUserData( this );
m_geode->setUpdateCallback( new ROIBoxNodeCallback );
std::stringstream ss;
ss << "ROIBox" << boxId;
......@@ -180,16 +184,32 @@ wmath::WPosition WROIBox::getMaxPos() const
return m_maxPos;
}
void WROIBox::registerPick( std::string text )
{
boost::unique_lock<boost::shared_mutex> slock;
slock = boost::unique_lock<boost::shared_mutex>( m_updateLock );
infoText = text;
needUpdate = true;
void WROIBox::updateGFX( std::string text )
slock.unlock();
}
void WROIBox::updateGFX()
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
boost::unique_lock<boost::shared_mutex> slock;
slock = boost::unique_lock<boost::shared_mutex>( m_updateLock );
if( !needUpdate ) // exit early if we do not need an update
{
slock.unlock();
return;
}
std::stringstream ss;
ss << "\"ROIBox" << boxId << "\"";
if( text.find( "Object ") != std::string::npos
&& text.find( ss.str() ) != std::string::npos )
if( infoText.find( "Object ") != std::string::npos
&& infoText.find( ss.str() ) != std::string::npos )
{
wmath::WPosition newPos( m_pickHandler->getHitPosition() );
if( m_isPicked )
......@@ -210,7 +230,7 @@ void WROIBox::updateGFX( std::string text )
m_pickedPosition = newPos;
m_isPicked = true;
}
if( m_isPicked && text.find( "unpick" ) != std::string::npos )
if( m_isPicked && infoText.find( "unpick" ) != std::string::npos )
{
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 0.f, 0.f, 1.f, 0.5f ) );
......
......@@ -37,7 +37,7 @@
/**
* A box representing a region of interest.
*/
class WROIBox : public WROI
class WROIBox : public WROI, public osg::Referenced
{
public:
/**
......@@ -68,11 +68,44 @@ private:
wmath::WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison
boost::shared_mutex m_updateLock; //!< Lock to prevent concurrent threads trying to update the osg node
std::string infoText; //!< The info text coming from the last pick.
bool needUpdate; //!< Indicates whether the grafics need update due to changed text.
/**
* updates the graphics
* \param text text info from pick
* note that there was a pick
* \param text info from pick
*/
virtual void updateGFX( std::string text );
void registerPick( std::string text );
/**
* updates the graphics
*/
void updateGFX();
/**
* Node callback to handle updates properly
*/
class ROIBoxNodeCallback : public osg::NodeCallback
{
public: // NOLINT
/**
* operator ()
*
* \param node the osg node
* \param nv the node visitor
*/
virtual void operator()( osg::Node* node, osg::NodeVisitor* nv )
{
osg::ref_ptr< WROIBox > module = static_cast< WROIBox* > ( node->getUserData() );
if ( module )
{
module->updateGFX();
}
traverse( node, nv );
}
};
};
#endif // WROIBOX_H
......@@ -25,7 +25,13 @@
#ifndef WCUSTOMWIDGET_H
#define WCUSTOMWIDGET_H
#include "../graphicsEngine/WGEGroupNode.h"
#include <boost/shared_ptr.hpp>
#include <osg/ref_ptr>
class WGEGroupNode;
class WGEViewer;
/**
* Custom widget which is created by a module to display custom information.
......@@ -45,6 +51,13 @@ public:
*/
virtual osg::ref_ptr< WGEGroupNode > getScene() const = 0;
/**
* Get the viewer which is used
*
* \return the viewer as boost::shard_ptr
*/
virtual boost::shared_ptr< WGEViewer > getViewer() const = 0;
protected:
private:
};
......
......@@ -50,6 +50,11 @@ osg::ref_ptr< WGEGroupNode > WQtCustomDockWidget::getScene() const
return m_scene;
}
boost::shared_ptr< WGEViewer > WQtCustomDockWidget::getViewer() const
{
return m_glWidget->getViewer();
}
void WQtCustomDockWidget::increaseUseCount()
{
++m_useCount;
......
......@@ -56,6 +56,13 @@ public:
*/
virtual osg::ref_ptr< WGEGroupNode > getScene() const;
/**
* Get the viewer which is used by the GL widget
*
* \return the viewer as boost::shard_ptr
*/
virtual boost::shared_ptr< WGEViewer > getViewer() const;
/**
* Notify the widget that another module needs it.
*/
......
......@@ -253,7 +253,7 @@ void WQtDatasetBrowser::selectTreeItem()
module = ( ( WQtModuleTreeItem* ) m_treeWidget->selectedItems().at( 0 ) )->getModule();
}
// every module may have compatibles: create ribbon menu entry
// every module may have compatibles: create toolBar entry
std::set< boost::shared_ptr< WModule > > comps = WModuleFactory::getModuleFactory()->getCompatiblePrototypes( module );
for ( std::set< boost::shared_ptr< WModule > >::iterator iter = comps.begin(); iter != comps.end(); ++iter )
{
......
......@@ -32,7 +32,9 @@ WMEEGView::WMEEGView()
: WModule(),
m_dataChanged( new WCondition, true ),
m_isActive( new WCondition, true ),