Commit 65df0569 authored by cornimueller's avatar cornimueller
Browse files

[FIX] Fixed crash when marking a new event position in the EEG View module...

[FIX] Fixed crash when marking a new event position in the EEG View module without having a fiber dataset loaded
[CHANGE] Some code changes in WEEGSourceCalculator
parent 36b92ba0
......@@ -24,10 +24,12 @@
#include <cstddef>
#include <limits>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../../common/WAssert.h"
#include "../../common/math/WPosition.h"
#include "../../dataHandler/WEEG2.h"
#include "../../dataHandler/WEEGChannelInfo.h"
......@@ -37,7 +39,8 @@
WEEGSourceCalculator::WEEGSourceCalculator( const boost::shared_ptr< const WEEG2 > eeg )
: m_eeg( eeg )
: m_eeg( eeg ),
m_numPositions( 0 )
{
// it is possible to calculate some time position independend data
// structures here (like the lead matrix)
......@@ -49,6 +52,7 @@ WEEGSourceCalculator::WEEGSourceCalculator( const boost::shared_ptr< const WEEG2
{
m_eeg->getChannelInfo( channelID )->getPosition();
m_hasPosition.push_back( true );
++m_numPositions;
}
catch( const WDHException& )
{
......@@ -60,21 +64,24 @@ WEEGSourceCalculator::WEEGSourceCalculator( const boost::shared_ptr< const WEEG2
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;
WAssert( values.size() == m_hasPosition.size(), "Event and loaded EEG dataset have to have the same number of channels" );
double sum = 0.0;
double min = std::numeric_limits< double >::infinity();
for( std::size_t channelID = 0; channelID < values.size(); ++channelID )
{
if( m_hasPosition[channelID] )
{
sum += values[channelID];
if( values[channelID] < min )
{
min = values[channelID];
}
sum += values[channelID];
}
}
sum -= values.size() * min;
sum -= m_numPositions * min;
wmath::WPosition source;
for( std::size_t channelID = 0; channelID < values.size(); ++channelID )
......
......@@ -25,6 +25,8 @@
#ifndef WEEGSOURCECALCULATOR_H
#define WEEGSOURCECALCULATOR_H
#include <cstddef>
#include <vector>
#include <boost/shared_ptr.hpp>
......@@ -64,10 +66,15 @@ private:
const boost::shared_ptr< const WEEG2 > m_eeg;
/**
* vector which says for each channel whether there is a position in the EEG
* dataset
* vector which saves for each channel whether there exists a position in
* the EEG dataset or not
*/
std::vector< bool > m_hasPosition;
/**
* how many channels with positions exist in the EEG dataset
*/
std::size_t m_numPositions;
};
#endif // WEEGSOURCECALCULATOR_H
......@@ -289,7 +289,7 @@ void WMEEGView::moduleMain()
WKernel::getRunningKernel()->getRoiManager()->removeRoi( roi );
}
if( m_sourceCalculator )
if( WKernel::getRunningKernel()->getRoiManager()->getBitField() && m_sourceCalculator )
{
wmath::WPosition position = m_sourceCalculator->calculate( event );
......
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