Commit 0f78a82d authored by cornimueller's avatar cornimueller
Browse files

[ADD] Added ability to remove a ROI for other classes then the Datasetbrowser,...

[ADD] Added ability to remove a ROI for other classes then the Datasetbrowser, especially for a module. This is uses by the EEG View module to set and update a ROI when a new event position is marked.
parent 07b177ba
......@@ -46,6 +46,7 @@
#include "WQt4Gui.h"
#include "events/WModuleAssocEvent.h"
#include "events/WRoiAssocEvent.h"
#include "events/WRoiRemoveEvent.h"
#include "events/WModuleReadyEvent.h"
#include "events/WModuleCrashEvent.h"
#include "events/WUpdateTextureSorterEvent.h"
......@@ -151,8 +152,12 @@ int WQt4Gui::run()
m_kernel->getRootContainer()->addDefaultNotifier( WM_ASSOCIATED, assocSignal );
t_ModuleGenericSignalHandlerType readySignal = boost::bind( &WQt4Gui::slotActivateDatasetOrModuleInBrowser, this, _1 );
m_kernel->getRootContainer()->addDefaultNotifier( WM_READY, readySignal );
boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > assocRoiSignal = boost::bind( &WQt4Gui::slotAddRoiToBrowser, this, _1 );
m_kernel->getRoiManager()->addDefaultNotifier( assocRoiSignal );
boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > assocRoiSignal =
boost::bind( &WQt4Gui::slotAddRoiToBrowser, this, _1 );
m_kernel->getRoiManager()->addAddNotifier( assocRoiSignal );
boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > removeRoiSignal =
boost::bind( &WQt4Gui::slotRemoveRoiFromBrowser, this, _1 );
m_kernel->getRoiManager()->addRemoveNotifier( removeRoiSignal );
// now we are initialized
m_isInitialized( true );
......@@ -243,6 +248,11 @@ void WQt4Gui::slotAddRoiToBrowser( boost::shared_ptr< WRMROIRepresentation > roi
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WRoiAssocEvent( roi ) );
}
void WQt4Gui::slotRemoveRoiFromBrowser( boost::shared_ptr< WRMROIRepresentation > roi )
{
QCoreApplication::postEvent( m_mainWindow->getDatasetBrowser(), new WRoiRemoveEvent( roi ) );
}
void WQt4Gui::slotActivateDatasetOrModuleInBrowser( boost::shared_ptr< WModule > module )
{
// create a new event for this and insert it into event queue
......
......@@ -94,6 +94,12 @@ public:
*/
virtual void slotAddRoiToBrowser( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* Slot gets called whenever a roi is removed.
*
* \param roi the roi to be removed
*/
virtual void slotRemoveRoiFromBrowser( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* Slot gets called whenever a module switches its state to "ready".
......
......@@ -40,6 +40,7 @@
#include "WQtDatasetBrowser.h"
#include "../events/WModuleAssocEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h"
#include "../events/WModuleReadyEvent.h"
#include "../events/WEventTypes.h"
#include "../guiElements/WQtApplyModulePushButton.h"
......@@ -186,6 +187,17 @@ bool WQtDatasetBrowser::event( QEvent* event )
return true;
}
if( event->type() == WQT_ROI_REMOVE_EVENT )
{
WRoiRemoveEvent* e3 = dynamic_cast< WRoiRemoveEvent* >( event );
if( e3 )
{
removeRoi( e3->getRoi() );
WLogger::getLogger()->addLogMessage( "Removing roi from dataset browser.", "DatasetBrowser", LL_DEBUG );
}
return true;
}
// a module changed its state to "ready" -> activate it in dataset browser
if ( event->type() == WQT_READY_EVENT )
......@@ -301,6 +313,29 @@ void WQtDatasetBrowser::addRoi( boost::shared_ptr< WRMROIRepresentation > roi )
newItem->setSelected( true );
}
void WQtDatasetBrowser::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi )
{
for( int branchID = 0; branchID < m_tiRois->childCount(); ++branchID )
{
QTreeWidgetItem* branchTreeItem = m_tiRois->child( branchID );
for( int roiID = 0; roiID < branchTreeItem->childCount(); ++roiID )
{
WQtRoiTreeItem* roiTreeItem = dynamic_cast< WQtRoiTreeItem* >( branchTreeItem->child( roiID ) );
if( roiTreeItem && roiTreeItem->getRoi() == roi )
{
delete roiTreeItem;
if( branchTreeItem->childCount() == 0 )
{
delete branchTreeItem;
}
break;
}
}
}
}
boost::shared_ptr< WModule > WQtDatasetBrowser::getSelectedModule()
{
if ( m_treeWidget->selectedItems().at( 0 )->type() == 1 )
......@@ -591,15 +626,10 @@ void WQtDatasetBrowser::deleteTreeItem()
else if ( m_roiTreeWidget->selectedItems().at( 0 )->type() == ROI )
{
roi =( static_cast< WQtRoiTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 ) ) )->getRoi();
WQtBranchTreeItem* branch = ( static_cast< WQtBranchTreeItem* >( m_roiTreeWidget->selectedItems().at( 0 )->parent() ) );
if ( roi )
{
delete m_roiTreeWidget->selectedItems().at( 0 );
WKernel::getRunningKernel()->getRoiManager()->removeRoi( roi );
}
if ( branch->childCount() == 0 )
{
delete branch;
// Removing the roi from the tree widget is also done by WROIManagerFibers::removeRoi().
}
}
}
......
......@@ -110,6 +110,13 @@ public:
*/
void addRoi( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* Removes a roi entry from the dataset browser
*
* \param roi pointer to the roi representation object
*/
void removeRoi( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* helper funtion to connect all qt widgets with their functions
*/
......
......@@ -51,5 +51,7 @@
// when a property changes
#define WQT_PROPERTY_CHANGED_EVENT QEvent::User + 6
#endif // WEVENTTYPES_H
// when a roi got removed
#define WQT_ROI_REMOVE_EVENT QEvent::User + 7
#endif // WEVENTTYPES_H
//---------------------------------------------------------------------------
//
// 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 "WEventTypes.h"
#include "WRoiRemoveEvent.h"
WRoiRemoveEvent::WRoiRemoveEvent( boost::shared_ptr< WRMROIRepresentation > roi )
: QEvent( static_cast< QEvent::Type >( WQT_ROI_REMOVE_EVENT ) ),
m_roi( roi )
{
// initialize members
}
WRoiRemoveEvent::~WRoiRemoveEvent()
{
// cleanup
}
boost::shared_ptr< WRMROIRepresentation > WRoiRemoveEvent::getRoi()
{
return m_roi;
}
//---------------------------------------------------------------------------
//
// 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 WROIREMOVEEVENT_H
#define WROIREMOVEEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#include "../../../graphicsEngine/WROI.h"
#include "../../../modules/fiberDisplay/WRMROIRepresentation.h"
/**
* Event signalling a roi has been removed from the roi manager in the kernel.
*/
class WRoiRemoveEvent : public QEvent
{
public:
/**
* constructor
* \param roi
*/
explicit WRoiRemoveEvent( boost::shared_ptr< WRMROIRepresentation > roi );
/**
* destructor
*/
~WRoiRemoveEvent();
/**
* Getter for the roi that got removed.
*
* \return the roi.
*/
boost::shared_ptr< WRMROIRepresentation > getRoi();
protected:
/**
* The roi that got removed.
*/
boost::shared_ptr< WRMROIRepresentation > m_roi;
private:
};
#endif // WROIREMOVEEVENT_H
......@@ -35,6 +35,7 @@
#include "../../graphicsEngine/WGEGeodeUtils.h"
#include "../../graphicsEngine/WGEGeometryUtils.h"
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../../kernel/WKernel.h"
#include "WEEGViewHandler.h"
#include "WElectrodePositionCallback.h"
......@@ -50,7 +51,8 @@
WMEEGView::WMEEGView()
: WModule(),
m_dataChanged( new WCondition, true ),
m_wasActive( false )
m_wasActive( false ),
m_currentEventTime( -1.0 )
{
}
......@@ -172,7 +174,7 @@ void WMEEGView::moduleMain()
// create WFlag for the event
m_event = boost::shared_ptr< WFlag< boost::shared_ptr< WEEGEvent > > >( new WFlag< boost::shared_ptr< WEEGEvent > >(
new WCondition, boost::shared_ptr< WEEGEvent >() ) );
m_propCondition, boost::shared_ptr< WEEGEvent >() ) );
{
// create color map
......@@ -275,6 +277,27 @@ void WMEEGView::moduleMain()
}
}
// event position changed?
boost::shared_ptr< WEEGEvent > event = m_event->get();
if( event && event->getTime() != m_currentEventTime )
{
debugLog() << "New event position: " << event->getTime();
if( boost::shared_ptr< WRMROIRepresentation > roi = m_roi.lock() )
{
WKernel::getRunningKernel()->getRoiManager()->removeRoi( roi );
}
// TODO(cornimueller): calculate new position
wmath::WPosition position( 0.0, 0.0, 0.0 );
m_roi = WKernel::getRunningKernel()->getRoiManager()->addRoi( new WROIBox(
position - wmath::WVector3D( 10.0, 10.0, 10.0 ),
position + wmath::WVector3D( 10.0, 10.0, 10.0 ) ) );
m_currentEventTime = event->getTime();
}
// "active" property changed?
bool isActive = m_active->get();
if( isActive != m_wasActive )
......
......@@ -35,6 +35,7 @@
#include "../../graphicsEngine/WGEGroupNode.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleInputData.h"
#include "../fiberDisplay/WRMROIRepresentation.h"
#include "WEEGEvent.h"
#include "WEEGViewHandler.h"
......@@ -227,6 +228,13 @@ private:
*/
osg::ref_ptr< osg::Node > m_labelsNode;
/**
* The ROI around the source dipole position at the time determined by
* m_event.
* Used to select the fibers around this dipole.
*/
boost::weak_ptr< WRMROIRepresentation > m_roi;
/**
* Bool flag which gets set when the data was changed.
* The module threads waits for this flag and performs a redraw.
......@@ -238,6 +246,11 @@ private:
*/
bool m_wasActive;
/**
* The time of the current event. Used to check whether the event changed.
*/
double m_currentEventTime;
/**
* A ScalarsToColors object mapping the potentials at the electrodes to
* colors. Used for the display of electrode positions and the head surface.
......
......@@ -39,7 +39,7 @@ WROIManagerFibers::~WROIManagerFibers()
{
}
void WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi )
boost::shared_ptr< WRMROIRepresentation > WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi )
{
// create new branch
boost::shared_ptr< WRMBranch > newBranch = boost::shared_ptr< WRMBranch >( new WRMBranch( shared_from_this() ) );
......@@ -52,14 +52,16 @@ void WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi )
// add bit fields
newBranch->addBitField( m_fibers.get()->size() );
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_notifiers.begin(); iter
!= m_notifiers.end(); ++iter )
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_addNotifiers.begin();
iter != m_addNotifiers.end(); ++iter )
{
( *iter )( rroi );
}
return rroi;
}
void WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi )
boost::shared_ptr< WRMROIRepresentation > WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi )
{
// find branch
boost::shared_ptr< WRMBranch > branch;
......@@ -77,11 +79,13 @@ void WROIManagerFibers::addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI
// add roi to branch
branch->addRoi( rroi );
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_notifiers.begin(); iter
!= m_notifiers.end(); ++iter )
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_addNotifiers.begin();
iter != m_addNotifiers.end(); ++iter )
{
( *iter )( rroi );
}
return rroi;
}
void WROIManagerFibers::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi )
......@@ -103,6 +107,12 @@ void WROIManagerFibers::removeRoi( boost::shared_ptr< WRMROIRepresentation > roi
m_recalcLock = false;
setDirty();
for ( std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > >::iterator iter = m_removeNotifiers.begin();
iter != m_removeNotifiers.end(); ++iter )
{
( *iter )( roi );
}
}
void WROIManagerFibers::removeBranch( boost::shared_ptr< WRMROIRepresentation > roi )
......@@ -286,11 +296,19 @@ bool WROIManagerFibers::isDirty()
return m_dirty;
}
void WROIManagerFibers::addDefaultNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier )
void WROIManagerFibers::addAddNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
m_addNotifiers.push_back( notifier );
lock.unlock();
}
void WROIManagerFibers::addRemoveNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier )
{
boost::unique_lock< boost::shared_mutex > lock;
lock = boost::unique_lock< boost::shared_mutex >( m_associatedNotifiersLock );
m_notifiers.push_back( notifier );
m_removeNotifiers.push_back( notifier );
lock.unlock();
}
......
......@@ -56,16 +56,18 @@ public:
* adds a new master ROI
*
* \param newRoi
* \return ROI representation which can be used to remove the ROI
*/
void addRoi( osg::ref_ptr< WROI > newRoi );
boost::shared_ptr< WRMROIRepresentation > addRoi( osg::ref_ptr< WROI > newRoi );
/**
* adds a new ROI below a master ROI
*
* \param newRoi
* \param parentRoi
* \return ROI representation which can be used to remove the ROI
*/
void addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
boost::shared_ptr< WRMROIRepresentation > addRoi( osg::ref_ptr< WROI > newRoi, osg::ref_ptr< WROI > parentRoi );
/**
* removes a roi
......@@ -135,11 +137,18 @@ public:
bool isDirty();
/**
* Add a specified notifier to the list of default notifiers which get connected to each added module.
* Add a specified notifier to the list of default notifiers which get connected to each added roi.
*
* \param notifier the notifier function
*/
virtual void addDefaultNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier );
virtual void addAddNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier );
/**
* Add a specified notifier to the list of default notifiers which get connected to each removed roi.
*
* \param notifier the notifier function
*/
virtual void addRemoveNotifier( boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > notifier );
/**
* updates the bit fields
......@@ -172,9 +181,9 @@ private:
boost::shared_ptr< const WDataSetFibers >m_fibers; //!< registered fiber dataset
boost::shared_ptr< std::vector< bool > >m_bitField; //!< bit field of acteivated fibers
boost::shared_ptr< std::vector< bool > >m_bitField; //!< bit field of activated fibers
boost::shared_ptr< std::vector< bool > >m_bitField2; //!< bit field of acteivated fibers
boost::shared_ptr< std::vector< bool > >m_bitField2; //!< bit field of activated fibers
std::list< boost::shared_ptr< WRMBranch > > m_branches; //!< list of branches in the logical tree structure
......@@ -195,7 +204,12 @@ private:
/**
* The notifiers connected to added rois by default.
*/
std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > > m_notifiers;
std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > > m_addNotifiers;
/**
* The notifiers connected to removed rois by default.
*/
std::list< boost::function< void( boost::shared_ptr< WRMROIRepresentation > ) > > m_removeNotifiers;
/**
* lock to prevent concurrent threads trying to update the branch
......
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