Commit 72f16d76 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE] - merged with default

parents 45df041c 07ecb6d5
......@@ -63,6 +63,9 @@ deleteROIKey = Del
# hideMenuBar = yes # hide the menu bar
# This filename is used as default filename in the Screen Capture/Movie/Animation dock.
# defaultScreenCaptureFilename = /tmp/OpenWalnut_%f.png
[ge] ## Settings for the graphics engine
# bgColor.r = .9 # background color (red part)
# bgColor.g = .9 # background color (green part)
......
......@@ -66,6 +66,9 @@ deleteROIKey = Del
# hideMenuBar = yes # hide the menu bar
# This filename is used as default filename in the Screen Capture/Movie/Animation dock.
# defaultScreenCaptureFilename = /tmp/OpenWalnut_%f.png
[ge] ## Settings for the graphics engine
# bgColor.r = .9 # background color (red part)
# bgColor.g = .9 # background color (green part)
......
......@@ -6,6 +6,7 @@ IF( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
MESSAGE( FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. (you may need to remove CMakeCache.txt" )
ENDIF()
ADD_DEFINITIONS( -DBOOST_FILESYSTEM_VERSION=2 )
IF( CMAKE_GENERATOR MATCHES "Visual Studio" )
ADD_DEFINITIONS( -DEIGEN_DONT_VECTORIZE -DEIGEN_DONT_ALIGN -DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT )
......
......@@ -68,6 +68,8 @@ namespace defaultColor
static const WColor GREEN( 0.0, 1.0, 0.0, 1.0 ); //!< Default for green
static const WColor RED( 1.0, 0.0, 0.0, 1.0 ); //!< Default for red
static const WColor BLUE( 0.0, 0.0, 1.0, 1.0 ); //!< Default for blue
static const WColor BLACK( 0.0, 0.0, 0.0, 1.0 ); //!< Default for black
static const WColor WHITE( 1.0, 1.0, 1.0, 1.0 ); //!< Default for black
// \endcond
}
......
......@@ -45,7 +45,7 @@ void WCondition::notify()
m_condition.notify_all();
}
boost::signals2::connection WCondition::subscribeSignal( t_ConditionNotifierType notifier )
boost::signals2::connection WCondition::subscribeSignal( t_ConditionNotifierType notifier ) const
{
return signal_ConditionFired.connect( notifier );
}
......
......@@ -82,7 +82,7 @@ public:
*
* \return the connection.
*/
boost::signals2::connection subscribeSignal( t_ConditionNotifierType notifier );
boost::signals2::connection subscribeSignal( t_ConditionNotifierType notifier ) const;
protected:
......@@ -94,7 +94,7 @@ protected:
/**
* Signal getting fired whenever the condition fires.
*/
t_ConditionSignalType signal_ConditionFired;
mutable t_ConditionSignalType signal_ConditionFired;
/**
* The condition.
......
//---------------------------------------------------------------------------
//
// 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 "WRealtimeTimer.h"
WRealtimeTimer::WRealtimeTimer():
WTimer(),
m_timer( osg::Timer() )
{
// initialize
}
WRealtimeTimer::~WRealtimeTimer()
{
// cleanup
}
void WRealtimeTimer::reset()
{
m_timer.setStartTick();
}
double WRealtimeTimer::elapsed() const
{
return m_timer.time_m() / 1000.0;
}
//---------------------------------------------------------------------------
//
// 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 WREALTIMETIMER_H
#define WREALTIMETIMER_H
#include <boost/shared_ptr.hpp>
#include <osg/Timer>
#include "WTimer.h"
#include "WExportCommon.h"
/**
* Realtime timing. Internally, this uses an osg::Timer.
*/
class OWCOMMON_EXPORT WRealtimeTimer: public WTimer
{
public:
/**
* Convenience typedef for a shared_ptr
*/
typedef boost::shared_ptr< WRealtimeTimer > SPtr;
/**
* Convenience typedef for a const shared_ptr.
*/
typedef boost::shared_ptr< const WRealtimeTimer > ConstSPtr;
/**
* Constructs a realtime animation timer.
*/
WRealtimeTimer();
/**
* Destructor.
*/
virtual ~WRealtimeTimer();
/**
* Resets the start-tick.
*/
virtual void reset();
/**
* Returns the elapsed time since the last reset in seconds with milliseconds precision.
*
* \return elapsed time in seconds with millisecond precision.
*/
virtual double elapsed() const;
private:
/**
* The osg timer is used here.
*/
osg::Timer m_timer;
};
#endif // WREALTIMETIMER_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 "WTimer.h"
WTimer::WTimer()
{
// initialize
}
WTimer::~WTimer()
{
// cleanup
}
//---------------------------------------------------------------------------
//
// 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 WTIMER_H
#define WTIMER_H
#include <boost/shared_ptr.hpp>
#include "WExportCommon.h"
/**
* Base class for timing. Derive from it to write several timers like a frame-timer or realtime-timer.
*/
class OWCOMMON_EXPORT WTimer // NOLINT - no OWCOMMON_EXPORT does not need an virtual destructor.
{
public:
/**
* Convenience typedef for a shared_ptr
*/
typedef boost::shared_ptr< WTimer > SPtr;
/**
* Convenience typedef for a const shared_ptr.
*/
typedef boost::shared_ptr< const WTimer > ConstSPtr;
/**
* Constructs a animation timer.
*/
WTimer();
/**
* Destructor.
*/
virtual ~WTimer();
/**
* Resets the start-tick.
*/
virtual void reset() = 0;
/**
* Returns the elapsed time since the last reset in seconds with milliseconds precision.
*
* \return elapsed time in seconds with millisecond precision.
*/
virtual double elapsed() const = 0;
private:
};
#endif // WTIMER_H
......@@ -49,6 +49,15 @@ class OWDATAHANDLER_EXPORT WDataSetFibers : public WDataSet // NOLINT
public:
// some type alias for the used arrays.
/**
* Pointer to dataset.
*/
typedef boost::shared_ptr< WDataSetFibers > SPtr;
/**
* Pointer to const dataset.
*/
typedef boost::shared_ptr< const WDataSetFibers > ConstSPtr;
/**
* List of vertex coordinates in term of components of vertices.
......
......@@ -7,6 +7,7 @@ ADD_SUBDIRECTORY( offscreen )
ADD_SUBDIRECTORY( shaders )
ADD_SUBDIRECTORY( geodes )
ADD_SUBDIRECTORY( postprocessing )
ADD_SUBDIRECTORY( animation )
ADD_SUBDIRECTORY( algorithms )
FILE( GLOB GE_EXCEPTIONS_SRC "exceptions/*.cpp" "exceptions/*.h" )
......@@ -17,6 +18,7 @@ FILE( GLOB GE_OFFSCREEN_SRC "offscreen/*.cpp" "offscreen/*.h" )
FILE( GLOB GE_GEODES_SRC "geodes/*.cpp" "geodes/*.h" )
FILE( GLOB_RECURSE GE_WIDGETS_SRC "widgets/*.cpp" "widgets/*.h" )
FILE( GLOB GE_POSTPROCESSING_SRC "postprocessing/*.cpp" "postprocessing/*.h" )
FILE( GLOB GE_ANIMATION_SRC "animation/*.cpp" "animation/*.h" )
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
FILE( GLOB GE_PLATFORMDEPENDENT_SRC
......@@ -45,9 +47,9 @@ ENDIF ( OPENCL_FOUND )
SET( LIB_NAME "${OWgeName}" )
SET( ${LIB_NAME}_COMBINER_SRC ${GE_EXCEPTIONS_SRC} ${GE_CALLBACKS_SRC} ${GE_ALGORITHMS_SRC} ${GE_OFFSCREEN_SRC} ${GE_SHADERS_SRC}
${GE_PLATFORMDEPENDENT_SRC} ${GE_SRC} ${GE_GEODES_SRC} ${GE_WIDGETS_SRC} ${GE_POSTPROCESSING_SRC} ${GE_OPENCL_SRC} )
${GE_PLATFORMDEPENDENT_SRC} ${GE_SRC} ${GE_GEODES_SRC} ${GE_WIDGETS_SRC} ${GE_POSTPROCESSING_SRC} ${GE_OPENCL_SRC} ${GE_ANIMATION_SRC} )
SET( ${LIB_NAME}_ALL_CPP ${GE_EXCEPTIONS_SRC} ${GE_CALLBACKS_SRC} ${GE_ALGORITHMS_SRC} ${GE_OFFSCREEN_SRC} ${GE_SHADERS_SRC}
${GE_PLATFORMDEPENDENT_SRC} ${GE_SRC} ${GE_GEODES_SRC} ${GE_WIDGETS_SRC} ${GE_POSTPROCESSING_SRC} ${OPENCL_LIBRARY} )
${GE_PLATFORMDEPENDENT_SRC} ${GE_SRC} ${GE_GEODES_SRC} ${GE_WIDGETS_SRC} ${GE_POSTPROCESSING_SRC} ${OPENCL_LIBRARY} ${GE_ANIMATION_SRC} )
FILE( GLOB_RECURSE ${LIB_NAME}_REMOVE_H "*.h" )
LIST( REMOVE_ITEM ${LIB_NAME}_ALL_CPP ${${LIB_NAME}_REMOVE_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 <osg/BufferObject>
#include "animation/WGEAnimationFrameTimer.h"
#include "WGEScreenCapture.h"
WGEScreenCapture::WGEScreenCapture():
m_timer( new WGEAnimationFrameTimer() )
{
// initialize
SharedRecordingInformation::WriteTicket w = m_recordingInformation.getWriteTicket();
w->get().m_frames = 0;
w->get().m_framesLeft = 0;
}
WGEScreenCapture::~WGEScreenCapture()
{
// cleanup
}
WGEAnimationFrameTimer::ConstSPtr WGEScreenCapture::getFrameTimer() const
{
return m_timer;
}
void WGEScreenCapture::recordStart()
{
record();
}
void WGEScreenCapture::recordStop()
{
record( 0 );
}
void WGEScreenCapture::screenshot()
{
record( 1 );
}
void WGEScreenCapture::record( size_t frames )
{
SharedRecordingInformation::WriteTicket w = m_recordingInformation.getWriteTicket();
w->get().m_framesLeft = frames;
}
bool WGEScreenCapture::isRecording()
{
SharedRecordingInformation::ReadTicket r = m_recordingInformation.getReadTicket();
return r->get().m_framesLeft;
}
void WGEScreenCapture::operator()( osg::RenderInfo& renderInfo ) const // NOLINT - osg wants this to be a non-const reference
{
SharedRecordingInformation::WriteTicket w = m_recordingInformation.getWriteTicket();
RecordingInformation& frameCounter = w->get();
// is there something to record?
if ( !frameCounter.m_framesLeft )
{
return;
}
// we need the graphics context here.
osg::GraphicsContext* gc = renderInfo.getState()->getGraphicsContext();
// get size and color mode
size_t width = 0;
size_t height = 0;
GLenum pixelFormat = GL_RGB;
if (gc->getTraits())
{
width = gc->getTraits()->width;
height = gc->getTraits()->height;
pixelFormat = gc->getTraits()->alpha ? GL_RGBA : GL_RGB;
}
// count frames
frameCounter.m_frames++;
frameCounter.m_framesLeft--;
// read back buffer
glReadBuffer( GL_BACK );
// The following code uses PBO to grab the framebuffer. This sometimes causes errors. I am not sure why. glReadPixels
// osg::ref_ptr< osg::Image > imagePBO = new osg::Image();
// osg::BufferObject::Extensions* ext = osg::BufferObject::getExtensions( gc->getState()->getContextID(), true );
// imagePBO->allocateImage( width, height, 1, pixelFormat, GL_UNSIGNED_BYTE );
// if (m_pbo==0)
// {
// std::cout << "CREATE" << std::endl;
// ext->glGenBuffers( 1, &m_pbo );
// ext->glBindBuffer( GL_PIXEL_PACK_BUFFER_ARB, m_pbo );
// ext->glBufferData( GL_PIXEL_PACK_BUFFER_ARB, imagePBO->getTotalSizeInBytes(), 0, GL_STREAM_READ );
// }
// else
// {
// std::cout << "BIND" << std::endl;
// ext->glBindBuffer( GL_PIXEL_PACK_BUFFER_ARB, m_pbo );
// }
// std::cout << "READ" << std::endl;
// glReadPixels( 0, 0, width, height, pixelFormat, GL_UNSIGNED_BYTE, 0 );
// std::cout << "MAP" << std::endl;
// GLubyte* src = static_cast< GLubyte* >( ext->glMapBuffer( GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB ) );
// if(src)
// {
// std::cout << "COPY" << std::endl;
// memcpy( imagePBO->data(), src, imagePBO->getTotalSizeInBytes() );
// ext->glUnmapBuffer( GL_PIXEL_PACK_BUFFER_ARB );
//}
//
// std::cout << "RESTORE" << std::endl;
// ext->glBindBuffer( GL_PIXEL_PACK_BUFFER_ARB, 0 );
// create image and read pixels into it
osg::ref_ptr< osg::Image > image = new osg::Image();
image->readPixels( 0, 0, width, height, pixelFormat, GL_UNSIGNED_BYTE );
// another frame.
m_timer->tick();
// someone wants this image
handleImage( frameCounter.m_framesLeft, frameCounter.m_frames, image );
}
WCondition::ConstSPtr WGEScreenCapture::getRecordCondition() const
{
return m_recordingInformation.getChangeCondition();
}
WGEScreenCapture::SharedRecordingInformation::ReadTicket WGEScreenCapture::getRecordingInformation() const
{
return m_recordingInformation.getReadTicket();
}
void WGEScreenCapture::resetFrameCounter()
{
SharedRecordingInformation::WriteTicket w = m_recordingInformation.getWriteTicket();
w->get().m_frames = 0;
m_timer->reset();
}
void WGEScreenCapture::handleImage( size_t framesLeft, size_t totalFrames, osg::ref_ptr< osg::Image > image ) const
{
m_signalHandleImage( framesLeft, totalFrames, image );
}
boost::signals2::connection WGEScreenCapture::subscribeSignal( HandleImageCallbackType callback )
{
return m_signalHandleImage.connect( callback );
}
//---------------------------------------------------------------------------
//
// 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 WGESCREENCAPTURE_H
#define WGESCREENCAPTURE_H
#include <limits>
#include <boost/signals2.hpp>
#include <boost/function.hpp>
#include <osg/Camera>
#include <osg/Image>
#include <osg/RenderInfo>
#include "../common/WSharedObject.h"
#include "../common/WCondition.h"
#include "animation/WGEAnimationFrameTimer.h"
#include "WExportWGE.h"
/**
* This class is a screen recorder. It records the frame buffer to files on a per-frame-basis. This class is NOT thread-safe due to performance
* reasons. You should not distribute the instance among multiple threads. It can be applied to <b>ONE</b> camera only by setting it as
* finalDrawCallback (osg::Camera::setFinalDrawCallback). Each camera can only use ONE final draw callback.
*
* This class is abstract. Derive your own class and handle image writing.
*
* \note This class does NOT write the images to disk. Set a callback for this.
*
* \ingroup GE
*/
class WGE_EXPORT WGEScreenCapture: public osg::Camera::DrawCallback
{
public:
/**
* Keeps track of several frame-counts.
*/
typedef struct
{
size_t m_frames; //!< current number of frames.
size_t m_framesLeft; //!< the frames to take until stop.
}
RecordingInformation;
/**
* The shared access type to the FrameCounting struct.
*/
typedef WSharedObject< RecordingInformation > SharedRecordingInformation;
/**
* Convenience typedef
*/
typedef osg::ref_ptr< WGEScreenCapture > RefPtr;
/**
* Convenience typedef
*/
typedef osg::ref_ptr< const WGEScreenCapture > ConstRefPtr;
/**
* This callback signature is needed to subscribe to the handleImage signal.
*/
typedef boost::function< void( size_t, size_t, osg::ref_ptr< osg::Image > ) > HandleImageCallbackType;
/**