Commit 76e0d494 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[ADD] module for testing EEG stuff

parent 97befc4c
//---------------------------------------------------------------------------
//
// 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 <iostream>
#include <string>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include "WEEGTestModule.h"
#include "../../kernel/WKernel.h"
#include "../../dataHandler/WLoaderManager.h"
#include "../../dataHandler/WEEG.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
WEEGTestModule::WEEGTestModule():
WModule()
{
// initialize members
}
WEEGTestModule::~WEEGTestModule()
{
// cleanup
}
WEEGTestModule::WEEGTestModule( const WEEGTestModule& other )
: WModule()
{
*this = other;
}
const std::string WEEGTestModule::getName() const
{
return "Eeg Module";
}
const std::string WEEGTestModule::getDescription() const
{
return "This module is for testing and development";
}
void drawChannel( boost::shared_ptr< const WEEG > eegData, size_t channelId, osg::Geode* sceneDataGeode )
{
// create Geometry object to store all the vetices and lines primtive.
osg::Geometry* linesGeom = new osg::Geometry();
const size_t segmentId = 0;
const size_t nbSamples = eegData->getNumberOfSamples( segmentId );
const double scaleX = 1;
const double scaleY = 1;
const double scaleZ = .1;
osg::Vec3Array* vertices = new osg::Vec3Array( nbSamples );
osg::Vec3Array::iterator vitr = vertices->begin();
for( unsigned int i = 0; i < nbSamples; ++i )
{
(vitr++)->set( i * scaleX, 0 * scaleY, (*eegData)( 0, channelId, i ) * scaleZ );
}
linesGeom->setVertexArray( vertices );
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back( osg::Vec4( 1.0f, 1.0f, 0.0f, 1.0f ) );
linesGeom->setColorArray( colors );
linesGeom->setColorBinding( osg::Geometry::BIND_OVERALL );
linesGeom->addPrimitiveSet( new osg::DrawArrays( osg::PrimitiveSet::LINE_STRIP, 0, nbSamples ) );
sceneDataGeode ->addDrawable( linesGeom );
}
void WEEGTestModule::threadMain()
{
// load the sample scene.
osg::Geode* sceneDataGeode = new osg::Geode();
std::string fileName = "dataHandler/fixtures/eeg_testData.asc";
std::cout << "Test loading of " << fileName << "." << std::endl;
boost::shared_ptr< WDataHandler > dataHandler =
boost::shared_ptr< WDataHandler >( new WDataHandler() );
WLoaderManager testLoaderManager;
testLoaderManager.load( fileName, dataHandler );
std::cout << "Number of DS: " << dataHandler->getNumberOfSubjects() << std::endl;
sleep( 4 ); // we need this to allow the thread to terminate
std::cout << "Number of DS: " << dataHandler->getNumberOfSubjects() << std::endl;
boost::shared_ptr< const WEEG > eegData;
eegData = boost::shared_dynamic_cast< const WEEG >( dataHandler->getSubject( 0 )->getDataSet( 0 ) );
for( unsigned int channelId = 0; channelId < eegData->getNumberOfChannels() ; ++channelId )
{
std::cout << "Draw channel " << channelId << std::endl;
drawChannel( eegData, channelId, sceneDataGeode );
}
WKernel::getRunningKernel()->getGraphicsEngine()->getScene()->addChild( sceneDataGeode );
std::cout << "Number of DS: " << dataHandler->getNumberOfSubjects() << std::endl;
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
// do fancy stuff
sleep( 1 );
}
std::cout << "Number of DS: " << dataHandler->getNumberOfSubjects() << std::endl;
// clean up stuff
}
//---------------------------------------------------------------------------
//
// 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 WEEGTESTMODULE_H
#define WEEGTESTMODULE_H
#include <string>
#include "../../kernel/WModule.h"
/**
* Simple module for testing Eeg loading stuff.
* \ingroup kernel
*/
class WEEGTestModule: public WModule
{
public:
/**
* Default constructor.
*/
WEEGTestModule();
/**
* Destructor.
*/
virtual ~WEEGTestModule();
/**
* Copy constructor
* \param other Reference on object to copy.
*/
WEEGTestModule( const WEEGTestModule& other );
/**
* Gives back the name of this module.
* \return the module's name.
*/
virtual const std::string getName() const;
/**
* Gives back a description of this module.
* \return description to module.
*/
virtual const std::string getDescription() const;
protected:
/**
* Entry point after loading the module. Runs in separate thread.
*/
virtual void threadMain();
private:
};
#endif // WEEGTESTMODULE_H
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