Commit 4ecbcf87 authored by Mathias Goldau's avatar Mathias Goldau
Browse files

[MERGE]

parents cc213131 191ecbd2
......@@ -25,7 +25,7 @@
#include <iostream>
#include "WConditionOneShot.h"
#include "../common/WLogger.h"
#include "WLogger.h"
#include "WThreadedRunner.h"
......@@ -34,7 +34,6 @@ WThreadedRunner::WThreadedRunner():
{
// initialize members
m_FinishRequested = false;
m_Thread = NULL;
}
WThreadedRunner::~WThreadedRunner()
......@@ -42,20 +41,16 @@ WThreadedRunner::~WThreadedRunner()
// cleanup
// XXX is this working if thread already has finished?
// wait( true ); <-- no
if( m_Thread )
{
delete m_Thread;
}
}
void WThreadedRunner::run()
{
m_Thread = new boost::thread( boost::bind( &WThreadedRunner::threadMain, this ) );
run( boost::bind( &WThreadedRunner::threadMain, this ) );
}
void WThreadedRunner::run( THREADFUNCTION f )
{
m_Thread = new boost::thread( f );
m_thread = boost::thread( f );
}
void WThreadedRunner::wait( bool requestFinish )
......@@ -69,7 +64,7 @@ void WThreadedRunner::wait( bool requestFinish )
m_FinishRequested = true;
m_shutdownFlag( true );
}
m_Thread->join();
m_thread.join();
}
void WThreadedRunner::waitForStop()
......@@ -88,7 +83,7 @@ void WThreadedRunner::notifyStop()
void WThreadedRunner::yield() const
{
m_Thread->yield();
m_thread.yield();
}
void WThreadedRunner::sleep( const int32_t t ) const
......
......@@ -91,7 +91,7 @@ protected:
/**
* Thread instance.
*/
boost::thread* m_Thread;
boost::thread m_thread;
/**
* True if thread should end execution. NOTE: do not use this. Use m_shutdownFlag instead.
......@@ -128,6 +128,21 @@ protected:
WBoolFlag m_shutdownFlag;
private:
/**
* Disallow copy construction.
*
* \param rhs the other threaded runner.
*/
WThreadedRunner( const WThreadedRunner & rhs );
/**
* Disallow copy assignment.
*
* \param rhs the other threaded runner.
* \return this.
*/
WThreadedRunner& operator=( const WThreadedRunner & rhs );
};
#endif // WTHREADEDRUNNER_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 <sstream>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../common/exceptions/WOutOfBounds.h"
#include "io/WPagerEEG.h"
#include "WEEG2.h"
WEEG2::WEEG2( boost::shared_ptr< WPagerEEG > pager )
{
m_segments.reserve( pager->getNumberOfSegments() );
for( std::size_t segmentID = 0; segmentID < pager->getNumberOfSegments(); ++segmentID )
{
m_segments.push_back( boost::shared_ptr< WEEG2Segment >( new WEEG2Segment( pager, segmentID ) ) );
}
}
std::size_t WEEG2::getNumberOfSegments() const
{
return m_segments.size();
}
boost::shared_ptr< WEEG2Segment > WEEG2::getSegment( std::size_t segmentID ) const
{
if( segmentID >= m_segments.size() )
{
std::ostringstream stream;
stream << "The EEG has no segment number " << segmentID;
throw WOutOfBounds( stream.str() );
}
return m_segments[segmentID];
}
//---------------------------------------------------------------------------
//
// 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 WEEG2_H
#define WEEG2_H
#include <cstddef>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "io/WPagerEEG.h"
#include "WEEG2Segment.h"
#include "WRecording.h"
/**
* Class which contains EEG recording data, read from a WPagerEEG.
* \ingroup dataHandler
*/
class WEEG2 : public WRecording
{
public:
/**
* Constructor
*
* \param pager pager class which contains the data, read from a file on
* demand
*/
explicit WEEG2( boost::shared_ptr< WPagerEEG > pager );
/**
* Get the number of segments this EEG consists of.
*
* \return number of segments
*/
std::size_t getNumberOfSegments() const;
/**
* Get one segment.
*
* \param segmentID number of segment
* \return segment
*/
boost::shared_ptr< WEEG2Segment > getSegment( std::size_t segmentID ) const;
protected:
private:
std::vector< boost::shared_ptr< WEEG2Segment > > m_segments; //!< list of all segments this EEG consists of
};
#endif // WEEG2_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 <sstream>
#include <boost/shared_ptr.hpp>
#include "../common/exceptions/WOutOfBounds.h"
#include "exceptions/WDHException.h"
#include "io/WPagerEEG.h"
#include "WEEGValueMatrix.h"
#include "WEEG2Segment.h"
WEEG2Segment::WEEG2Segment( boost::shared_ptr< WPagerEEG > pager, std::size_t segmentID )
: m_pager( pager ),
m_segmentID( segmentID )
{
if( !m_pager )
{
throw WDHException( "Couldn't construct new EEG segment: pager invalid" );
}
if( m_segmentID >= m_pager->getNumberOfSegments() )
{
std::ostringstream stream;
stream << "The EEG has no segment number " << m_segmentID;
throw WOutOfBounds( stream.str() );
}
}
boost::shared_ptr< WEEGValueMatrix > WEEG2Segment::getValues( std::size_t start, std::size_t length ) const
{
// No test whether start and length are valid - this should be done only
// one time by the pager.
return m_pager->getValues( m_segmentID, start, length );
}
//---------------------------------------------------------------------------
//
// 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 WEEG2SEGMENT_H
#define WEEG2SEGMENT_H
#include <cstddef>
#include <boost/shared_ptr.hpp>
#include "io/WPagerEEG.h"
#include "WEEGValueMatrix.h"
/**
* Class which contains one segment of an EEG recording, read from a WPagerEEG.
* \ingroup dataHandler
*/
class WEEG2Segment
{
public:
/**
* Constructor
*
* \param pager pager class which contains the data, read from a file on
* demand
* \param segmentID number of this segment
*/
WEEG2Segment( boost::shared_ptr< WPagerEEG > pager, std::size_t segmentID );
/**
* Get the values of all channels for a given sample range.
*
* \param start start sample of the sample range
* \param length length of the sample range
* \return matrix of values
*/
boost::shared_ptr< WEEGValueMatrix > getValues( std::size_t start, std::size_t length ) const;
protected:
private:
boost::shared_ptr< WPagerEEG > m_pager; //!< pager class which contains the data, read from a file on demand
std::size_t m_segmentID; //!< number of this segment
};
#endif // WEEG2SEGMENT_H
......@@ -83,6 +83,7 @@ public:
*/
virtual size_t elementsPerValue() const
{
// Windows Hack: the MSVC obviously does not support ( oh wonder, which wonder ) pow with integers.
return static_cast< size_t >( std::pow( static_cast< double >( m_dimension ), static_cast< int >( m_order ) ) );
}
......
......@@ -46,15 +46,21 @@ public:
*/
virtual ~WPagerEEG();
/**
* Get the number of segments this EEG consists of.
* \return number of segments
*/
virtual std::size_t getNumberOfSegments() const = 0;
/**
* Get the values of all channels for a given sample range.
*
* \param segment segment number to read the values from
* \param segmentID segment number to read the values from
* \param start start sample of the sample range
* \param length length of the sample range
* \return matrix of values
*/
virtual boost::shared_ptr< WEEGValueMatrix > getValues( std::size_t segment, std::size_t start, std::size_t length ) = 0;
virtual boost::shared_ptr< WEEGValueMatrix > getValues( std::size_t segmentID, std::size_t start, std::size_t length ) const = 0;
protected:
/**
......
......@@ -88,12 +88,17 @@ WPagerEEGLibeep::~WPagerEEGLibeep()
}
}
boost::shared_ptr< WEEGValueMatrix > WPagerEEGLibeep::getValues( std::size_t segment, std::size_t start, std::size_t length )
std::size_t WPagerEEGLibeep::getNumberOfSegments() const
{
if( segment != 0 )
return 1;
}
boost::shared_ptr< WEEGValueMatrix > WPagerEEGLibeep::getValues( std::size_t segmentID, std::size_t start, std::size_t length ) const
{
if( segmentID != 0 )
{
std::ostringstream stream;
stream << m_fileName << " has no segment number " << segment;
stream << m_fileName << " has no segment number " << segmentID;
throw WOutOfBounds( stream.str() );
}
......
......@@ -58,7 +58,9 @@ public:
*/
virtual ~WPagerEEGLibeep();
virtual boost::shared_ptr< WEEGValueMatrix > getValues( std::size_t segment, std::size_t start, std::size_t length );
virtual std::size_t getNumberOfSegments() const;
virtual boost::shared_ptr< WEEGValueMatrix > getValues( std::size_t segmentID, std::size_t start, std::size_t length ) const;
protected:
private:
......
......@@ -177,6 +177,12 @@ boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewerByName( std::string nam
return out;
}
boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewer()
{
boost::mutex::scoped_lock lock( m_viewersLock );
return m_viewers[ "main" ];
}
void WGraphicsEngine::threadMain()
{
WLogger::getLogger()->addLogMessage( "Starting Graphics Engine", "GE", LL_INFO );
......
......@@ -139,6 +139,13 @@ public:
*/
boost::shared_ptr< WGEViewer > getViewerByName( std::string name );
/**
* Returns the unnamed view, which is the view for the default scene which can be acquired using getScene().
*
* \return the viewer for the default scene.
*/
boost::shared_ptr< WGEViewer > getViewer();
/**
* Returns the currently selected default font usable in osgText nodes.
*
......
//---------------------------------------------------------------------------
//
// 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 <osg/Texture>
#include <osg/Texture2D>
#include "WOffscreen.h"
WOffscreen::WOffscreen( osg::ref_ptr< osg::Camera > reference, int num ):
osg::Camera(),
m_referenceCamera( reference ),
m_fbo( new osg::FrameBufferObject() )
{
// initialize members
setClearColor( reference->getClearColor() );
setClearMask( reference->getClearMask() );
setReferenceFrame( osg::Transform::RELATIVE_RF );
setRenderTargetImplementation( osg::Camera::FRAME_BUFFER_OBJECT );
setRenderOrder( osg::Camera::PRE_RENDER, num );
}
WOffscreen::~WOffscreen()
{
// cleanup
}
void WOffscreen::attach( BufferComponent buffer, osg::ref_ptr< osg::Texture2D > texture )
{
m_fbo->setAttachment( buffer, osg::FrameBufferAttachment( texture ) );
osg::Camera::attach( buffer, texture );
}
osg::ref_ptr< osg::Texture2D > WOffscreen::attach( BufferComponent buffer )
{
osg::ref_ptr< osg::Texture2D > tex = createTexture();
attach( buffer, tex );
return tex;
}
void WOffscreen::detach( BufferComponent buffer )
{
m_fbo->setAttachment( buffer, osg::FrameBufferAttachment() );
osg::Camera::detach( buffer );
}
osg::ref_ptr< osg::Texture2D > WOffscreen::createTexture( GLint internalFormat )
{
osg::ref_ptr< osg::Texture2D > tex = new osg::Texture2D;
tex->setTextureSize( m_referenceCamera->getViewport()->width(), m_referenceCamera->getViewport()->height() );
tex->setInternalFormat( internalFormat );
// setup interpolation
tex->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR );
tex->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
// do repeat the texture
tex->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
tex->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
return tex;
}
//---------------------------------------------------------------------------
//
// 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 WOFFSCREEN_H
#define WOFFSCREEN_H
#include <osg/Camera>
#include <osg/FrameBufferObject>
/**
* This class encapsulates an OSG Camera and a corresponding framebuffer object. It is especially useful for offscreen renderings. It is a camera
* which, by default, is the same as the camera in the this instance nesting graph. It allows simple attachment of textures to a offscreen
* rendering as well as easy texture creation.
*/
class WOffscreen: public osg::Camera
{
public:
/**
* Creates a new offscreen rendering instance. It uses the specified camera for setup.
*
* \param reference the reference camera.
* \param num the order number. This camera gets rendered at the num'th place in the pre render queue of the subgraph it is attached to.
*/
WOffscreen( osg::ref_ptr< osg::Camera > reference, int num = 0 );
/**
* Destructor.
*/
virtual ~WOffscreen();
/**
* Attach a given texture to a buffer.
*
* \param buffer the buffer to attach the texture to
* \param texture the texture to attach
*
* \note if the node is added to the graph, these functions should only be called from within an update callback.
*/
void attach( BufferComponent buffer, osg::ref_ptr< osg::Texture2D > texture );
/**
* This method attaches a texture to the given buffer. The texture gets created with the resolution of the FBO.
*
* \param buffer the buffer to attach the new texture to
*
* \note if the node is added to the graph, these functions should only be called from within an update callback.
*
* \return the newly created texture.
*/
osg::ref_ptr< osg::Texture2D > attach( BufferComponent buffer );
/**
* Detaches the texture currently bound to the specified buffer.
*
* \param buffer the buffer to detach.
*
* \note if the node is added to the graph, these functions should only be called from within an update callback.
*/
void detach( BufferComponent buffer );
/**
* Creates a new texture suitable for this offscreen rendering instance. The texture will have the same size as the viewport of this camera.
*