Commit ad55670d authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD #163] times and magnitudes of dipoles

* Can load times and magnitudes of dipoles
* EEGView can display ROI for dipole at times where the magnitude is non-zero and hide them at all other times.
parent 73230200
......@@ -32,9 +32,14 @@ WDataSetDipole::WDataSetDipole()
{
}
WDataSetDipole::WDataSetDipole( WPosition dipPos )
: m_dipolePosition( dipPos )
WDataSetDipole::WDataSetDipole( WPosition dipPos, std::vector<float> mags, std::vector<float> times )
: m_dipolePosition( dipPos ), m_magnitudes( mags ), m_times( times )
{
WAssert( mags.size() == times.size(), "There has to be a magnitude for every time and vice versa." );
for( size_t id = 0; id < times.size() - 1; ++id )
{
WAssert( times[id] < times[id+1], "Times need to be ascending." );
}
}
WDataSetDipole::~WDataSetDipole()
......@@ -55,3 +60,26 @@ WPosition WDataSetDipole::getPosition()
{
return m_dipolePosition;
}
float WDataSetDipole::getMagnitude( float time )
{
if( time < m_times[0] || time > m_times.back() )
{
return 0;
}
else
{
size_t upperBoundId;
for( size_t id = 0; id < m_times.size(); ++id )
{
if( time < m_times[id] )
{
upperBoundId = id - 1;
break;
}
}
float scale = ( time - m_times[upperBoundId-1] ) / ( m_times[upperBoundId] - m_times[upperBoundId-1] );
float magnitude = m_magnitudes[upperBoundId-1] + scale * ( m_magnitudes[upperBoundId] - m_magnitudes[upperBoundId-1] );
return magnitude;
}
}
......@@ -42,11 +42,13 @@ public:
WDataSetDipole();
/**
* Creates a new dipole with given location.
* Creates a new dipole with given information and checks consistency of the information.
*
* \param dipPos Spatial location of the dipole
* \param mags Magnitudes of dipole over time
* \param times Times for the dipole activity
*/
explicit WDataSetDipole( WPosition dipPos );
explicit WDataSetDipole( WPosition dipPos, std::vector<float> mags, std::vector<float> times );
/**
* Destructs this dataset.
......@@ -67,6 +69,14 @@ public:
*/
WPosition getPosition();
/**
* Return magnitude of dipole for a given time.
*
* \param time The selected time.
* \return Magnitude of the dipole.
*/
float getMagnitude( float time );
protected:
/**
* The prototype as singleton.
......@@ -75,6 +85,8 @@ protected:
private:
WPosition m_dipolePosition; //!< The location of the dipole
std::vector<float> m_magnitudes; //!< The magnitude of the dipole
std::vector<float> m_times; //!< Times for the different magnitudes
};
#endif // WDATASETDIPOLE_H
......@@ -301,10 +301,13 @@ void WMEEGView::moduleMain()
}
else if( m_dipoles->getData() )
{
WPosition position = m_dipoles->getData()->getPosition();
m_roi = new WROIBox( position - WVector3d( 5.0, 5.0, 5.0 ),
position + WVector3d( 5.0, 5.0, 5.0 ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( m_roi );
if( m_dipoles->getData()->getMagnitude( event->getTime() ) != 0 )
{
WPosition position = m_dipoles->getData()->getPosition();
m_roi = new WROIBox( position - WVector3d( 5.0, 5.0, 5.0 ),
position + WVector3d( 5.0, 5.0, 5.0 ) );
WKernel::getRunningKernel()->getRoiManager()->addRoi( m_roi );
}
}
else
{
......
......@@ -121,7 +121,36 @@ boost::shared_ptr< WDataSetDipole > WMReadDipoles::readData( std::string filenam
}
std::string line;
std::vector< std::string > tokens;
std::getline( ifs, line, '\n' );
while( line.find( "NumberTimeSteps" ) )
{
std::getline( ifs, line, '\n' );
}
tokens = string_utils::tokenize( line );
size_t nbTimeSteps = string_utils::fromString< size_t >( tokens[1].c_str() );
std::getline( ifs, line, '\n' );
while( line.find( "TimeSteps" ) )
{
std::getline( ifs, line, '\n' );
}
tokens = string_utils::tokenize( line );
tokens = string_utils::tokenize( tokens[1], "()" );
float timeFirst = string_utils::fromString< float >( tokens[0].c_str() );
float timeDistance = string_utils::fromString< float >( tokens[1].c_str() );
float timeLast = string_utils::fromString< float >( tokens[2].c_str() );
std::vector< float > times( nbTimeSteps );
for( size_t timeStep = 0; timeStep < nbTimeSteps; ++timeStep )
{
times[timeStep] = timeFirst + timeStep * timeDistance;
}
std::cout<<times[nbTimeSteps-1]<< " " << timeLast << std::endl;
WAssert( std::abs( times[nbTimeSteps-1] - timeLast ) < 1e-4, "Error during filling times vector." );
while( line.find( "PositionsFixed" ) )
{
std::getline( ifs, line, '\n' );
......@@ -130,9 +159,26 @@ boost::shared_ptr< WDataSetDipole > WMReadDipoles::readData( std::string filenam
WPosition pos;
ifs >> pos[0] >> pos[1] >> pos[2];
std::vector< float > magnitudes;
while( line.find( "Magnitudes" ) )
{
std::getline( ifs, line, '\n' );
}
std::getline( ifs, line, '\n' );
tokens = string_utils::tokenize( line );
for( unsigned int tokenId = 0; tokenId < tokens.size(); ++tokenId )
{
magnitudes.push_back( string_utils::fromString< float >( tokens[tokenId].c_str() ) );
}
WAssert( magnitudes.size() == nbTimeSteps, "Number of time steps and magnitudes must be equal" );
WAssert( times.size() == nbTimeSteps, "Number of time steps and times must be equal" );
ifs.close();
boost::shared_ptr< WDataSetDipole > loadedData( new WDataSetDipole( pos ) );
std::cout << "BLAAAAAAA " << pos << std::endl;
boost::shared_ptr< WDataSetDipole > loadedData( new WDataSetDipole( pos, magnitudes, times ) );
return loadedData;
}
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