Commit 218c1738 authored by cornimueller's avatar cornimueller
Browse files

[ADD] The EEG View module calculates a dummy source location and creates the ROI at this position.

parent 1c046ac2
//---------------------------------------------------------------------------
//
// 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 <cstddef>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../../common/math/WPosition.h"
#include "../../dataHandler/WEEG2.h"
#include "../../dataHandler/WEEGChannelInfo.h"
#include "../../dataHandler/exceptions/WDHException.h"
#include "WEEGEvent.h"
#include "WEEGSourceCalculator.h"
WEEGSourceCalculator::WEEGSourceCalculator( const boost::shared_ptr< const WEEG2 > eeg )
: m_eeg( eeg )
{
// it is possible to calculate some time position independend data
// structures here (like the lead matrix)
m_hasPosition.reserve( m_eeg->getNumberOfChannels() );
for( std::size_t channelID = 0; channelID < m_eeg->getNumberOfChannels(); ++channelID )
{
try
{
m_eeg->getChannelInfo( channelID )->getPosition();
m_hasPosition.push_back( true );
}
catch( const WDHException& )
{
m_hasPosition.push_back( false );
}
}
}
wmath::WPosition WEEGSourceCalculator::calculate( const boost::shared_ptr< const WEEGEvent > event ) const
{
const std::vector< double >& values = event->getValues();
double min = 1.0 / 0.0;
double sum = 0.0;
for( std::size_t channelID = 0; channelID < values.size(); ++channelID )
{
if( m_hasPosition[channelID] )
{
if( values[channelID] < min )
{
min = values[channelID];
}
sum += values[channelID];
}
}
sum -= values.size() * min;
wmath::WPosition source;
for( std::size_t channelID = 0; channelID < values.size(); ++channelID )
{
if( m_hasPosition[channelID] )
{
source += ( values[channelID] - min ) / sum * m_eeg->getChannelInfo( channelID )->getPosition();
}
}
return source;
}
//---------------------------------------------------------------------------
//
// 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 WEEGSOURCECALCULATOR_H
#define WEEGSOURCECALCULATOR_H
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../../common/math/WPosition.h"
#include "../../dataHandler/WEEG2.h"
#include "WEEGEvent.h"
/**
* Class which calculates a source position from an EEG recording at a given
* time position
*/
class WEEGSourceCalculator
{
public:
/**
* Constructor
*
* \param eeg pointer to the EEG dataset
*/
explicit WEEGSourceCalculator( const boost::shared_ptr< const WEEG2 > eeg );
/**
* Does the calculation
*
* \param event an event marking a time position
* \return the calculated position
*/
wmath::WPosition calculate( const boost::shared_ptr< const WEEGEvent > event ) const;
protected:
private:
/**
* pointer to the EEG dataset
*/
const boost::shared_ptr< const WEEG2 > m_eeg;
/**
* vector which says for each channel whether there is a position in the EEG
* dataset
*/
std::vector< bool > m_hasPosition;
};
#endif // WEEGSOURCECALCULATOR_H
......@@ -37,6 +37,7 @@
#include "../../graphicsEngine/WGEUtils.h"
#include "../../graphicsEngine/WROIBox.h"
#include "../../kernel/WKernel.h"
#include "WEEGSourceCalculator.h"
#include "WEEGViewHandler.h"
#include "WElectrodePositionCallback.h"
#include "WHeadSurfaceCallback.h"
......@@ -288,12 +289,18 @@ void WMEEGView::moduleMain()
WKernel::getRunningKernel()->getRoiManager()->removeRoi( roi );
}
// TODO(cornimueller): calculate new position
wmath::WPosition position( 0.0, 0.0, 0.0 );
if( m_sourceCalculator )
{
wmath::WPosition position = m_sourceCalculator->calculate( event );
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_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 ) ) );
}
else
{
m_roi.reset();
}
m_currentEventTime = event->getTime();
}
......@@ -560,6 +567,9 @@ void WMEEGView::redraw()
m_widget->getViewer()->getView()->addEventHandler( m_handler );
}
// create new source calculator
m_sourceCalculator = boost::shared_ptr< WEEGSourceCalculator >( new WEEGSourceCalculator( m_eeg ) );
}
else
{
......@@ -570,6 +580,8 @@ void WMEEGView::redraw()
m_electrodesNode = NULL;
m_headSurfaceNode = NULL;
m_labelsNode = NULL;
m_sourceCalculator.reset();
}
}
......
......@@ -37,6 +37,7 @@
#include "../../kernel/WModuleInputData.h"
#include "../fiberDisplay/WRMROIRepresentation.h"
#include "WEEGEvent.h"
#include "WEEGSourceCalculator.h"
#include "WEEGViewHandler.h"
......@@ -263,6 +264,11 @@ private:
*/
osg::ref_ptr< osg::Texture1D > m_colorMapTexture;
/**
* calculates a source position at a given time position
*/
boost::shared_ptr< WEEGSourceCalculator > m_sourceCalculator;
/**
* Opens a custom widget and connects the m_node with it.
*
......
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