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

[MERGE]

parents 9128b74d 62971b94
......@@ -24,6 +24,15 @@
#include <string>
#include <boost/regex.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <osg/Camera>
#include "../common/WLogger.h"
#include "WGraphicsEngine.h"
#include "WGEProjectFileIO.h"
WGEProjectFileIO::WGEProjectFileIO():
......@@ -39,6 +48,59 @@ WGEProjectFileIO::~WGEProjectFileIO()
bool WGEProjectFileIO::parse( std::string line, unsigned int lineNumber )
{
// regular expressions to parse the line
static const boost::regex camRe( "^ *CAMERA:([0-9]*):(.*)$" );
static const boost::regex pmatrixRe( "^ *PROJECTIONMATRIX:\\(([0-9]*),(.*)\\)=(.*)$" );
static const boost::regex mmatrixRe( "^ *MODELVIEWMATRIX:\\(([0-9]*),(.*)\\)=(.*)$" );
// use regex to parse it
boost::smatch matches; // the list of matches
if ( boost::regex_match( line, matches, camRe ) )
{
// it is a camera line
// matches[1] is the ID
// matches[2] is the name of the view/camera
wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Camera \"" << matches[2] << "\" with ID " << matches[1];
// store it
m_cameras[ boost::lexical_cast< unsigned int >( matches[1] ) ] = matches[2];
return true;
}
else if ( boost::regex_match( line, matches, mmatrixRe ) )
{
// it is a camera modelview matrix line
// matches[1] is the ID of the camera
// matches[2] is the type of matrix definition (currently only "Matrix", later there might be "Eye", "Center", "Up".
// matches[3] is the matrix line
wlog::debug( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Camera Modelview Matrix \"" << matches[2]
<< "\" with ID " << matches[1];
// valid?
if ( ( matches[2] != "Matrix" ) )
{
wlog::error( "Project Loader [Parser]" ) << "Line " << lineNumber << ": Camera Matrix definition type unknown: \"" << matches[2]
<< "\" for camera with ID " << matches[1];
return true;
}
// is there already a matrix for this camera? -> we do not care :-). Overwrite it.
m_viewMatrices[ boost::lexical_cast< unsigned int >( matches[1] ) ] = osg::Matrixd::identity();
// parse the matrix -> tokenize it and fill pointer appropriately
typedef boost::tokenizer<boost::char_separator< char > > tokenizer;
boost::char_separator< char > sep( ";" ); // separate by ;
tokenizer tok( boost::lexical_cast< std::string >( matches[3] ), sep );
// each value must be stored at the proper position
//double* values = new
for ( tokenizer::iterator it = tok.begin(); it != tok.end(); ++it )
{
}
return true;
}
return false;
}
......@@ -49,6 +111,31 @@ void WGEProjectFileIO::done()
void WGEProjectFileIO::save( std::ostream& output ) // NOLINT
{
// save camera state here
output << "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
"// Camera definitions" << std::endl <<
"//////////////////////////////////////////////////////////////////////////////////////////////////////////////////" << std::endl <<
std::endl;
// grab the main camera
osg::ref_ptr<osg::Camera> cam = WGraphicsEngine::getGraphicsEngine()->getViewer()->getCamera();
std::string name = WGraphicsEngine::getGraphicsEngine()->getViewer()->getName();
output << "CAMERA:0:" << name << std::endl;
// get the matrices
osg::Matrixd view = cam->getViewMatrix();
osg::Matrixd proj = cam->getProjectionMatrix();
output << "//Camera Matrices: \"" << name << "\"" << std::endl;
output << " MODELVIEWMATRIX:(0,Matrix)=";
output << view( 0, 0 ) << ";" << view( 0, 1 ) << ";" << view( 0, 2 ) << ";" << view( 0, 3 ) << ";"
<< view( 1, 0 ) << ";" << view( 1, 1 ) << ";" << view( 1, 2 ) << ";" << view( 1, 3 ) << ";"
<< view( 2, 0 ) << ";" << view( 2, 1 ) << ";" << view( 2, 2 ) << ";" << view( 2, 3 ) << ";"
<< view( 3, 0 ) << ";" << view( 3, 1 ) << ";" << view( 3, 2 ) << ";" << view( 3, 3 ) << std::endl;
output << " PROJECTIONMATRIX:(0,Matrix)=";
output << proj( 0, 0 ) << ";" << proj( 0, 1 ) << ";" << proj( 0, 2 ) << ";" << proj( 0, 3 ) << ";"
<< proj( 1, 0 ) << ";" << proj( 1, 1 ) << ";" << proj( 1, 2 ) << ";" << proj( 1, 3 ) << ";"
<< proj( 2, 0 ) << ";" << proj( 2, 1 ) << ";" << proj( 2, 2 ) << ";" << proj( 2, 3 ) << ";"
<< proj( 3, 0 ) << ";" << proj( 3, 1 ) << ";" << proj( 3, 2 ) << ";" << proj( 3, 3 ) << std::endl;
output << "//Camera Matrices END: \"" << name << "\"" << std::endl;
}
......@@ -26,8 +26,11 @@
#define WGEPROJECTFILEIO_H
#include <string>
#include <map>
#include "../kernel/WProjectFileIO.h"
#include <osg/Matrixd>
#include "../common/WProjectFileIO.h"
/**
* IO class for writing the graphics engine state to a project file. Currently it only writes the camera settings.
......@@ -71,6 +74,21 @@ public:
protected:
/**
* All Cameras parsed.
*/
std::map< unsigned int, std::string > m_cameras;
/**
* All camera view matrices.
*/
std::map< unsigned int, osg::Matrixd > m_viewMatrices;
/**
* All camera projection matrices.
*/
std::map< unsigned int, osg::Matrixd > m_projMatrices;
private:
};
......
......@@ -87,6 +87,7 @@ void WProjectFile::save()
for ( std::vector< WProjectFileIO* >::const_iterator iter = m_parsers.begin(); iter != m_parsers.end(); ++iter )
{
( *iter )->save( output );
output << std::endl;
}
output.close();
......
......@@ -31,7 +31,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>
#include "WProjectFileIO.h"
#include "../common/WProjectFileIO.h"
/**
* Class loading project files. This class opens an file and reads it line by line. It delegates the actual parsing to each of the known
......
......@@ -33,7 +33,7 @@
#include <boost/shared_ptr.hpp>
#include "../WProjectFileIO.h"
#include "../../common/WProjectFileIO.h"
#include "../WModuleCombiner.h"
......
//---------------------------------------------------------------------------
//
// 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