Commit 634076cd authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 6b0205d7 ed3d9dea
......@@ -49,8 +49,8 @@
#include "exceptions/WNotFound.h"
/**
* This namespace contains the WStructuredTextParser data types and the parser. It builds up the AST for the given input
* which later can be traversed.
* This namespace contains the WStructuredTextParser data types and the parser. It builds up the abstract syntax tree (AST)
* for the given input which later can be traversed.
*/
namespace WStructuredTextParser
{
......
......@@ -53,7 +53,7 @@ class WDataSet: public WTransferable, public boost::enable_shared_from_this< WDa
public:
/**
* This constructor should be used if a dataSet does not stem from a file.
* It presets the its correpsonding filename as empty string.
* It presets the correpsonding filename as empty string.
*/
WDataSet();
......
//---------------------------------------------------------------------------
//
// 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 "WDataSetDipole.h"
// prototype instance as singleton
boost::shared_ptr< WPrototyped > WDataSetDipole::m_prototype = boost::shared_ptr< WPrototyped >();
WDataSetDipole::WDataSetDipole()
{
}
WDataSetDipole::WDataSetDipole( WPosition dipPos )
: m_dipolePosition( dipPos )
{
}
WDataSetDipole::~WDataSetDipole()
{
}
boost::shared_ptr< WPrototyped > WDataSetDipole::getPrototype()
{
if( !m_prototype )
{
m_prototype = boost::shared_ptr< WPrototyped >( new WDataSetDipole() );
}
return m_prototype;
}
WPosition WDataSetDipole::getPosition()
{
return m_dipolePosition;
}
//---------------------------------------------------------------------------
//
// 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 WDATASETDIPOLE_H
#define WDATASETDIPOLE_H
#include <boost/shared_ptr.hpp>
#include "WDataSet.h"
/**
* Represents a dipole dataset.
*/
class WDataSetDipole : public WDataSet
{
public:
/**
* Creates a new dipole dataset.
*/
WDataSetDipole();
/**
* Creates a new dipole with given location.
*
* \param dipPos Spatial location of the dipole
*/
explicit WDataSetDipole( WPosition dipPos );
/**
* Destructs this dataset.
*/
~WDataSetDipole();
/**
* Returns a prototype instantiated with the true type of the deriving class.
*
* \return the prototype.
*/
static boost::shared_ptr< WPrototyped > getPrototype();
/**
* Return position of dipole.
*
* \return Position of the dipole.
*/
WPosition getPosition();
protected:
/**
* The prototype as singleton.
*/
static boost::shared_ptr< WPrototyped > m_prototype;
private:
WPosition m_dipolePosition; //!< The location of the dipole
};
#endif // WDATASETDIPOLE_H
......@@ -56,7 +56,7 @@ boost::shared_ptr< WDataSetFibers > WReaderFiberVTK::read()
m_ifs->open( m_fname.c_str(), std::ifstream::in | std::ifstream::binary );
if( !m_ifs || m_ifs->bad() )
{
throw WDHIOFailure( std::string( "internal error while opening" ) );
throw WDHIOFailure( std::string( "internal error while opening file" ) );
}
readHeader();
readPoints();
......
/* XPM */
static const char * datacreator_xpm[] = {
"32 32 2 1",
"32 32 3 1",
" c None",
". c #0000ff",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ... ",
" .. .. ",
" . .. ",
" .. . ",
" . . ",
" . . ",
" . .. ",
" . . ",
" . . ",
" .. .. ",
" . . ",
" .. .. ",
" .. .. ",
" .. .. ",
" .... .... ",
" .... ... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
". c #000000",
"+ c #4444FF",
" ",
" ",
" . .... +....+++.+ .... ",
" . .. +++..++++++.++.. ",
" . . ++.++.+ . +.++.++ . ",
" . .++++.++. . . +.++ . ",
" . .++++. . . . .++ . ",
" . ++.++.. . .. . .+ .. ",
" . ++.... .... . .... ",
" ++++++ + ",
" ++++++ ",
" ....+ .... .... . ..",
" ..++++ .. .. . .. ",
" .++++. . . . . . . ",
" .++++. . . . . . . ",
" .++++. . . . . . . ",
" +.++.. . .. . .. . . ",
" +....+ .... .... . ..",
" +++++++ ",
" ++++++ ",
" .++.+++.... . .... ....",
" .++.++.. . .. .. ",
" . +.++.+ . . . . . ",
" . .++.++ . . . . . ",
" . .++.++++. . . . . ",
" . .+++.++.. . . ..++ . .",
" . . +....+++.+++....++ ....",
" +++++++++++++++ ",
" +++++++++ ",
" . .... .... . . ....",
" . .. .. . . .. ",
" . . . . . . . . "};
......@@ -35,7 +35,7 @@
#include "WDataCreatorSphere.h"
#include "WDataCreatorRandom.h"
#include "WMDataCreator.xpm"
#include "WMDataCreatorVector.xpm"
#include "WMDataCreatorVector.h"
WMDataCreatorVector::WMDataCreatorVector():
......@@ -62,7 +62,7 @@ boost::shared_ptr< WModule > WMDataCreatorVector::factory() const
const char** WMDataCreatorVector::getXPMIcon() const
{
return datacreator_xpm;
return WMDataCreatorVector_xpm;
}
const std::string WMDataCreatorVector::getName() const
......
/* XPM */
static const char * WMDataCreatorVector_xpm[] = {
"32 32 12 1",
" c None",
". c #000000",
"+ c #4444FF",
"@ c #006600",
"# c #165A53",
"$ c #4244F9",
"% c #056316",
"& c #115D41",
"* c #1B5868",
"= c #006502",
"- c #03640C",
"; c #0C5F2D",
" ",
" ",
" . .... +....+++.+ .... ",
" . .. +++..++++++.++.. ",
" . . ++.++.+ . +.++.++ . ",
" . .++++.++. . . +.++ . ",
" . .++++. . . . .++ . ",
" . ++.++.. . .. . .+ .. ",
" . ++....@@@@.... @.@@#.... ",
" +++++$%@@@@@@@ @@@&+* ",
" ++++++@@@@@@ @=- ",
" ....+ @.... ....@@ . ..",
" ..++++ ..@@@@ .. @@@ . .. ",
" .++++. .@@@@. . @. . . ",
" .++++. .@@@@. . @@. . . ",
" .++++. . @@@.@ . @@. . . ",
" +.++.. .@@..@ . @.. . . ",
" +....+ ....@@ .... . ..",
" +++++++ @@@@@ @@ ",
" ++++++ @@@@@ @@@ ",
" .++.+++.... @@.@@@.... ....",
" .++.++.. @@.@@.. .. ",
" . +.++.+ .@@.@@. . . ",
" . .++.++ . @.@@. . . ",
" . .++.++++. @.@@. . . ",
" . .+++.++.. ;.@@ . ..++ . .",
" . . +....+++.+++....++ ....",
" +++++++++++++++ ",
" +++++++++ ",
" . .... .... . . ....",
" . .. .. . . .. ",
" . . . . . . . . "};
......@@ -29,6 +29,7 @@
#include <osg/ShapeDrawable>
#include <osgSim/ColorRange>
#include "core/dataHandler/WDataSetDipole.h"
#include "core/dataHandler/WEEG2.h"
#include "core/dataHandler/WEEG2Segment.h"
#include "core/dataHandler/WEEGChannelInfo.h"
......@@ -92,13 +93,14 @@ const char** WMEEGView::getXPMIcon() const
void WMEEGView::connectors()
{
// initialize connectors
m_input = boost::shared_ptr< WModuleInputData< WEEG2 > >( new WModuleInputData< WEEG2 >(
shared_from_this(), "in", "Loaded EEG-dataset." ) );
// add it to the list of connectors. Please note, that a connector NOT added via addConnector will not work as expected.
shared_from_this(), "EEG recording", "Loaded EEG-dataset." ) );
addConnector( m_input );
m_dipoles = boost::shared_ptr< WModuleInputData< WDataSetDipole > >( new WModuleInputData< WDataSetDipole >(
shared_from_this(), "Dipoles", "The reconstructed dipoles for the EEG." ) );
addConnector( m_dipoles );
// call WModules initialization
WModule::connectors();
}
......@@ -118,6 +120,10 @@ void WMEEGView::properties()
"Draw the labels of the electrodes at their 3D positions.",
true,
m_propCondition );
m_proofOfConcept = m_properties->addProperty( "Enable POC",
"Use proof of concept (POC) ROI positioning instead of real dipoles position.",
true,
m_propCondition );
m_labelsWidth = m_properties->addProperty( "Labels width",
"The width of the label display in pixel.",
24 );
......@@ -196,32 +202,8 @@ void WMEEGView::moduleMain()
m_event = boost::shared_ptr< WFlag< boost::shared_ptr< WEEGEvent > > >( new WFlag< boost::shared_ptr< WEEGEvent > >(
m_propCondition, boost::shared_ptr< WEEGEvent >() ) );
{
// create color map
std::vector< osg::Vec4 > colors;
colors.reserve( 3 );
colors.push_back( osg::Vec4( 0.0, 0.0, 1.0, 1.0 ) ); // blue
colors.push_back( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) ); // white
colors.push_back( osg::Vec4( 1.0, 0.0, 0.0, 1.0 ) ); // red
m_colorMap = new osgSim::ColorRange( -1.0, 1.0, colors );
// create texture containing color map
const int size = 256;
osg::Image* image = new osg::Image;
// allocate the image data, size x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( size, 1, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
osg::Vec4* data = reinterpret_cast< osg::Vec4* >( image->data() );
for( int i = 0; i < size; ++i)
{
data[i] = m_colorMap->getColor( ( 2 * i + 1 - size ) / static_cast< float >( size - 1 ) );
}
m_colorMapTexture = new osg::Texture1D( image );
m_colorMapTexture->setWrap( osg::Texture1D::WRAP_S, osg::Texture1D::CLAMP_TO_EDGE );
m_colorMapTexture->setFilter( osg::Texture1D::MIN_FILTER, osg::Texture1D::LINEAR );
}
createColorMap();
// signal ready
ready();
......@@ -310,10 +292,24 @@ void WMEEGView::moduleMain()
if( m_sourceCalculator )
{
WPosition position = m_sourceCalculator->calculate( event );
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_proofOfConcept->get() )
{
WPosition position = m_sourceCalculator->calculate( event );
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 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 );
}
else
{
debugLog() << "No dipoles found and not in POC mode: placing NO ROI.";
}
}
else
{
......@@ -365,6 +361,34 @@ void WMEEGView::moduleMain()
}
}
void WMEEGView::createColorMap()
{
// create color map
std::vector< osg::Vec4 > colors;
colors.reserve( 3 );
colors.push_back( osg::Vec4( 0.0, 0.0, 1.0, 1.0 ) ); // blue
colors.push_back( osg::Vec4( 1.0, 1.0, 1.0, 1.0 ) ); // white
colors.push_back( osg::Vec4( 1.0, 0.0, 0.0, 1.0 ) ); // red
m_colorMap = new osgSim::ColorRange( -1.0, 1.0, colors );
// create texture containing color map
const int size = 256;
osg::Image* image = new osg::Image;
// allocate the image data, size x 1 x 1 with 4 rgba floats - equivalent to a Vec4!
image->allocateImage( size, 1, 1, GL_RGBA, GL_FLOAT );
image->setInternalTextureFormat( GL_RGBA );
osg::Vec4* data = reinterpret_cast< osg::Vec4* >( image->data() );
for( int i = 0; i < size; ++i)
{
data[i] = m_colorMap->getColor( ( 2 * i + 1 - size ) / static_cast< float >( size - 1 ) );
}
m_colorMapTexture = new osg::Texture1D( image );
m_colorMapTexture->setWrap( osg::Texture1D::WRAP_S, osg::Texture1D::CLAMP_TO_EDGE );
m_colorMapTexture->setFilter( osg::Texture1D::MIN_FILTER, osg::Texture1D::LINEAR );
}
bool WMEEGView::openCustomWidget()
{
debugLog() << "Try to open EEG View widget...";
......
......@@ -34,11 +34,12 @@
// forward declarations
class WCustomWidget;
class WDataSetDipole;
class WEEG2;
class WEEGSourceCalculator;
class WEEGViewHandler;
class WGEGroupNode;
class WROIBox;
class WEEGViewHandler;
class WEEGSourceCalculator;
template< class T > class WModuleInputData;
/**
......@@ -125,6 +126,11 @@ private:
*/
boost::shared_ptr< WModuleInputData< WEEG2 > > m_input;
/**
* Input connector for dipoles of EEG data
*/
boost::shared_ptr< WModuleInputData< WDataSetDipole > > m_dipoles;
/**
* A condition used to notify about changes in several properties.
*/
......@@ -150,6 +156,11 @@ private:
*/
WPropBool m_drawLabels;
/**
* Property determining whetherwe only show the proof of concept or the real dipoles
*/
WPropBool m_proofOfConcept;
/**
* the width of the label display in pixel as property
*/
......@@ -279,6 +290,11 @@ private:
*/
boost::shared_ptr< WEEGSourceCalculator > m_sourceCalculator;
/**
* Prepare textures for colormapping EEG signal
*/
void createColorMap();
/**
* Opens a custom widget and connects the m_node with it.
*
......
ADD_MODULE( eegView )
ADD_MODULE( readDipoles )
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-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 <fstream>
#include <string>
#include "core/common/WPathHelper.h"
#include "core/dataHandler/WDataSetDipole.h"
#include "core/dataHandler/exceptions/WDHIOFailure.h"
#include "core/kernel/WKernel.h"
#include "modules/readDipoles/WMReadDipoles.xpm"
#include "WMReadDipoles.h"
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
W_LOADABLE_MODULE( WMReadDipoles )
WMReadDipoles::WMReadDipoles():
WModule()
{
}
WMReadDipoles::~WMReadDipoles()
{
// Cleanup!
}
boost::shared_ptr< WModule > WMReadDipoles::factory() const
{
return boost::shared_ptr< WModule >( new WMReadDipoles() );
}
const char** WMReadDipoles::getXPMIcon() const
{
return WMReadDipoles_xpm; // Please put a real icon here.
}
const std::string WMReadDipoles::getName() const
{
return "Read Dipoles";
}
const std::string WMReadDipoles::getDescription() const
{
return "Reading \".dip\" files containing position and additional information on dipoles reconstructed from EEG..";
}
void WMReadDipoles::connectors()
{
m_dipoles = boost::shared_ptr< WModuleOutputData< WDataSetDipole > >( new WModuleOutputData< WDataSetDipole >(
shared_from_this(), "Dipoles", "The loaded dipoles reconstructed from EEG." ) );
addConnector( m_dipoles );
WModule::connectors();
}
void WMReadDipoles::properties()
{
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
m_dataFile = m_properties->addProperty( "File", "", WPathHelper::getAppPath(), m_propCondition );
WPropertyHelper::PC_PATHEXISTS::addTo( m_dataFile );
WModule::properties();
}
void WMReadDipoles::requirements()
{
// Put the code for your requirements here. See "src/modules/template/" for an extensively documented example.
}
void WMReadDipoles::moduleMain()
{
m_moduleState.add( m_propCondition );
ready();
while( !m_shutdownFlag() )
{
m_moduleState.wait();
if( m_shutdownFlag() )
{
break;
}
boost::shared_ptr< WProgress > progress = boost::shared_ptr< WProgress >( new WProgress( "Read Dipoles", 2 ) );
++*progress;
m_dataSet = readData( m_dataFile->get().string() );
++*progress;
m_dipoles->updateData( m_dataSet );
progress->finish();
}
}
boost::shared_ptr< WDataSetDipole > WMReadDipoles::readData( std::string filename )
{
std::ifstream ifs;
ifs.open( filename.c_str(), std::ifstream::in );
if( !ifs || ifs.bad() )
{