Commit dffedf0e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[MERGE]

parents 92a134fd 5d5e55fa
......@@ -76,7 +76,7 @@ void WCreateColorArraysThread::threadMain()
float r, g, b, rr, gg, bb;
float x1, x2, y1, y2, z1, z2;
float lastx, lasty, lastz;
for ( int i = m_left; i < m_right; ++i )
for ( int i = m_left; i <= m_right; ++i )
{
x1 = (*m_vertices)[pc];
y1 = (*m_vertices)[pc + 1];
......@@ -134,7 +134,6 @@ void WCreateColorArraysThread::threadMain()
(*m_globalColors)[pc] = r;
(*m_globalColors)[pc+1] = g;
(*m_globalColors)[pc+2] = b;
pc += 3;
}
}
......
......@@ -57,16 +57,6 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
m_verticesReverse( verticesReverse )
{
// TODO(schurade): replace this with a permanent solution
for ( size_t i = 0; i < m_vertices->size(); ++i )
{
m_vertices->at( i ) = 160 - m_vertices->at( i );
++i;
m_vertices->at( i ) = 200 - m_vertices->at( i );
++i;
//m_pointArray[i] = m_dh->frames - m_pointArray[i];
}
m_tangents = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_tangents->resize( m_vertices->size() );
m_globalColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
......@@ -74,14 +64,13 @@ WDataSetFibers::WDataSetFibers( boost::shared_ptr< std::vector< float > >vertice
m_localColors = boost::shared_ptr< std::vector< float > >( new std::vector<float>() );
m_localColors->resize( m_vertices->size() );
WCreateColorArraysThread* t1 = new WCreateColorArraysThread( 0, m_lineLengths->size()/4, m_vertices,
m_lineStartIndexes, m_lineLengths, m_globalColors, m_localColors, m_tangents );
WCreateColorArraysThread* t2 = new WCreateColorArraysThread( m_lineLengths->size()/4+1, m_lineLengths->size()/2, m_vertices,
m_lineStartIndexes, m_lineLengths, m_globalColors, m_localColors, m_tangents );
WCreateColorArraysThread* t3 = new WCreateColorArraysThread( m_lineLengths->size()/2+1, m_lineLengths->size()/4*3, m_vertices,
m_lineStartIndexes, m_lineLengths, m_globalColors, m_localColors, m_tangents );
WCreateColorArraysThread* t4 = new WCreateColorArraysThread( m_lineLengths->size()/4*3+1, m_lineLengths->size(), m_vertices,
WCreateColorArraysThread* t4 = new WCreateColorArraysThread( m_lineLengths->size()/4*3+1, m_lineLengths->size()-1, m_vertices,
m_lineStartIndexes, m_lineLengths, m_globalColors, m_localColors, m_tangents );
t1->run();
t2->run();
......
......@@ -22,6 +22,7 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "../common/WAssert.h"
......@@ -72,7 +73,17 @@ const wmath::WVector3D& WDataSetRawHARDI::getGradient( size_t index ) const
#endif
}
std::size_t WDataSetRawHARDI::getMeasures() const
std::size_t WDataSetRawHARDI::getNumberOfMeasurements() const
{
return m_gradients->size();
}
const std::string WDataSetRawHARDI::getName() const
{
return "WDataSetRawHARDI";
}
const std::string WDataSetRawHARDI::getDescription() const
{
return "Contains HARDI measurements.";
}
......@@ -25,6 +25,7 @@
#ifndef WDATASETRAWHARDI_H
#define WDATASETRAWHARDI_H
#include <string>
#include <vector>
#include "WDataSetSingle.h"
......@@ -79,11 +80,25 @@ public:
const wmath::WVector3D& getGradient( size_t index ) const;
/**
* Returns the count of measures per voxel, which is equal to the count of the used gradients.
* Returns the count of measurements per voxel, which is equal to the count of the used gradients.
*
* \return measures per voxel
* \return measurements per voxel
*/
std::size_t getMeasures() const;
std::size_t getNumberOfMeasurements() const;
/**
* Gets the name of this prototype.
*
* \return the name.
*/
virtual const std::string getName() const;
/**
* Gets the description for this prototype.
*
* \return the description
*/
virtual const std::string getDescription() const;
protected:
......
......@@ -154,7 +154,7 @@ double WDataSetScalar::interpolate( const wmath::WPosition& pos, bool* success )
return result;
}
double WDataSetScalar::getValueAt( int x, int y, int z )
double WDataSetScalar::getValueAt( int x, int y, int z ) const
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_grid );
size_t id = x + y * grid->getNbCoordsX() + z * grid->getNbCoordsX() * grid->getNbCoordsY();
......
......@@ -107,7 +107,7 @@ public:
*
* \return the double value at the given cell.
*/
double getValueAt( int x, int y, int z );
double getValueAt( int x, int y, int z ) const;
/**
......
......@@ -106,7 +106,7 @@ boost::shared_ptr< WPrototyped > WDataSetSingle::getPrototype()
return m_prototype;
}
double WDataSetSingle::getValueAt( size_t id )
double WDataSetSingle::getValueAt( size_t id ) const
{
switch( getValueSet()->getDataType() )
{
......
......@@ -90,7 +90,7 @@ public:
*
* \return Scalar value for that given position
*/
double getValueAt( size_t id );
double getValueAt( size_t id ) const;
/**
* Determines whether this dataset can be used as a texture.
......
......@@ -243,10 +243,10 @@ public:
| : | |
| : *<--|--------- grid point (0, 0, 0)
| :........|....|__
dz == 1| ´ | /
| ´ | / dy == 1
| ´ | /
_|´____________|/__
dz == 1| / | /
| / | / dy == 1
| / | /
_|/____________|/__
|<- dx == 1 ->|
-0.5,-0.5,-0.5
\endverbatim
......
......@@ -130,6 +130,11 @@ WSubject::DatasetSharedContainerType::ReadTicket WSubject::getDatasets() const
return m_datasets.getReadTicket();
}
WSubject::DatasetSharedContainerType::WriteTicket WSubject::getDatasetsForWriting() const
{
return m_datasets.getWriteTicket();
}
std::vector< boost::shared_ptr< WDataTexture3D > > WSubject::getDataTextures( bool onlyActive )
{
std::vector< boost::shared_ptr< WDataTexture3D > > tex;
......@@ -150,12 +155,6 @@ std::vector< boost::shared_ptr< WDataTexture3D > > WSubject::getDataTextures( bo
return tex;
}
WSubject::DatasetAccess WSubject::getAccessObject()
{
// TODO(ebaum): clean up if it is not used anymore
return m_datasets.getAccessObject();
}
boost::shared_ptr< WCondition > WSubject::getChangeCondition() const
{
return m_changeCondition;
......
......@@ -142,20 +142,19 @@ public:
DatasetSharedContainerType::ReadTicket getDatasets() const;
/**
* This gives a list of data textures from all supporting datasets in this subject.
* Returns write-access to the dataset list. As long as the returned ticket exists, the list of datasets can't be changed by others.
*
* \param onlyActive true whenever only textures should be returned where isGloballyActive() == true.
* \return the list of textures.
* \return the write ticket.
*/
std::vector< boost::shared_ptr< WDataTexture3D > > getDataTextures( bool onlyActive = false );
DatasetSharedContainerType::WriteTicket getDatasetsForWriting() const;
/**
* Gets an access object which allows thread save iteration over the datasets.
* This gives a list of data textures from all supporting datasets in this subject.
*
* \deprecated do not use this anymore. Use getDatasets instead.
* \return the access object.
* \param onlyActive true whenever only textures should be returned where isGloballyActive() == true.
* \return the list of textures.
*/
DatasetAccess getAccessObject();
std::vector< boost::shared_ptr< WDataTexture3D > > getDataTextures( bool onlyActive = false );
/**
* This condition fires whenever the list of datasets changes, or one dataset got marked as "dirty" (threshold, opacity, ...).
......
......@@ -6,7 +6,7 @@ FILE( GLOB GE_ALGORITHMS_SRC "algorithms/*.cpp" "algorithms/*.h" )
FILE( GLOB GE_SRC "*.cpp" "*.h" )
ADD_LIBRARY( ge ${GE_SRC} ${GE_EXCEPTIONS_SRC} ${GE_ALGORITHMS_SRC} )
TARGET_LINK_LIBRARIES( ge common ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES} )
TARGET_LINK_LIBRARIES( ge common ${OPENGL_gl_LIBRARY} ${OPENSCENEGRAPH_LIBRARIES} )
# Unit tests
IF( OW_COMPILE_TESTS )
......
......@@ -28,24 +28,12 @@
#include "exceptions/WGEInitFailed.h"
WGEGraphicsWindow::WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata,
int x,
WGEGraphicsWindow::WGEGraphicsWindow( int x,
int y,
int width,
int height )
: m_GraphicsWindow( new osgViewer::GraphicsWindowEmbedded( x, y, width, height ) )
{
m_WindowData = wdata;
// initialize context
try
{
createContext( x, y, width, height );
}
catch( ... )
{
// use our own exceptions
throw WGEInitFailed( "Initialization of OpenGL graphics context failed." );
}
}
WGEGraphicsWindow::~WGEGraphicsWindow()
......@@ -53,72 +41,6 @@ WGEGraphicsWindow::~WGEGraphicsWindow()
// cleanup
}
osg::ref_ptr<osgViewer::GraphicsWindow> WGEGraphicsWindow::getGraphicsWindow()
{
return m_GraphicsWindow;
}
void WGEGraphicsWindow::createContext( int x, int y, int width, int height )
{
// Create traits for graphics contest request
osg::ref_ptr<osg::DisplaySettings> ds = osg::DisplaySettings::instance();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
// ensure correct $DISPLAY variable
traits->readDISPLAY();
if ( traits->displayNum < 0 )
{
traits->displayNum = 0;
}
// set a lot of values
traits->windowName = "OpenWalnut";
traits->screenNum = 0; // XXX is this a good idea?
traits->x = x;
traits->y = y;
traits->width = width;
traits->height = height;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
// traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
traits->inheritedWindowData = m_WindowData;
// Stereo
// TODO(ebaum): Stereo Mode: test whether it works
if ( ds->getStereo() )
{
switch( ds->getStereoMode() )
{
case( osg::DisplaySettings::QUAD_BUFFER ):
traits->quadBufferStereo = true;
break;
case( osg::DisplaySettings::VERTICAL_INTERLACE ):
case( osg::DisplaySettings::CHECKERBOARD ):
case( osg::DisplaySettings::HORIZONTAL_INTERLACE ):
traits->stencil = 8;
break;
default:
break;
}
}
// finally create graphics context and window
m_GraphicsContext = osg::GraphicsContext::createGraphicsContext( traits.get() );
m_GraphicsWindow = osg::ref_ptr<osgViewer::GraphicsWindow>(
static_cast<osgViewer::GraphicsWindow*>( m_GraphicsContext.get() ) );
// get around dearranged traits on X11 (MTCompositeViewer only)
traits->x = x;
traits->y = x;
traits->width = width;
traits->height = height;
}
void WGEGraphicsWindow::resize( int width, int height )
{
m_GraphicsWindow->getEventQueue()->windowResize( 0, 0, width, height );
......
......@@ -39,27 +39,19 @@ public:
/**
* Default constructor.
*
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEGraphicsWindow( osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height );
WGEGraphicsWindow( int x, int y, int width, int height );
/**
* Destructor.
*/
virtual ~WGEGraphicsWindow();
/**
* Getter for m_GraphicsWindow.
*
* \return the OSG GraphicsWindow instance.
*/
osg::ref_ptr<osgViewer::GraphicsWindow> getGraphicsWindow();
/**
* Event types for the keyEvent() handler.
*/
......@@ -110,30 +102,10 @@ public:
protected:
/**
* Creates a new OpenGL context in the calling thread. Needs to be called before any other OpenGL operation.
*
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
*/
void createContext( int x, int y, int width, int height );
/**
* OpenSceneGraph render window.
*/
osg::ref_ptr<osgViewer::GraphicsWindow> m_GraphicsWindow;
/**
* OpenSceneGraph render context.
*/
osg::ref_ptr<osg::GraphicsContext> m_GraphicsContext;
/**
* Widget window data.
*/
osg::ref_ptr<osg::Referenced> m_WindowData;
private:
};
......
......@@ -47,18 +47,17 @@
#include "WGEViewer.h"
WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
WGEViewer::WGEViewer( std::string name, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( wdata, x, y, width, height ),
: WGEGraphicsWindow( x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
{
try
{
m_View = osg::ref_ptr<osgViewer::View>( new osgViewer::View );
m_View = new osgViewer::Viewer();
m_View->setCamera( new WGECamera( width, height, projectionMode ) );
m_View->getCamera()->setGraphicsContext( m_GraphicsContext );
m_View->getCamera()->setGraphicsContext( m_GraphicsWindow.get() );
switch( projectionMode )
{
......@@ -139,6 +138,11 @@ void WGEViewer::setBgColor( WColor bgColor )
m_View->getCamera()->setClearColor( osg::Vec4( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 1. ) );
}
void WGEViewer::paint()
{
m_View->frame();
}
void WGEViewer::resize( int width, int height )
{
m_View->getEventQueue()->windowResize( 0, 0, width, height );
......
......@@ -62,7 +62,6 @@ public:
* Default constructor.
*
* \param name the name of the viewer
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
......@@ -70,7 +69,7 @@ public:
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y, int width, int height,
WGEViewer( std::string name, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
......@@ -78,6 +77,11 @@ public:
*/
virtual ~WGEViewer();
/**
* Repaints the contents.
*/
virtual void paint();
/**
* Updates size information. Also updates camera.
*
......@@ -169,7 +173,7 @@ protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
*/
osg::ref_ptr< osgViewer::View > m_View;
osg::ref_ptr< osgViewer::Viewer > m_View;
/**
* The name of the viewer.
......
......@@ -61,28 +61,6 @@ WGraphicsEngine::WGraphicsEngine():
m_shaderPath = "";
m_fontPath = "";
// initialize OSG render window
m_viewer = osg::ref_ptr<osgViewer::CompositeViewer>( new osgViewer::CompositeViewer() );
// ThreadingModel: enum with the following possibilities
//
// SingleThreaded
// CullDrawThreadPerContext
// ThreadPerContext
// DrawThreadPerContext
// CullThreadPerCameraDrawThreadPerContext
// ThreadPerCamera
// AutomaticSelection
bool multiThreadedViewers = true;
if( WPreferences::getPreference( "ge.multiThreadedViewers", &multiThreadedViewers ) && !multiThreadedViewers )
{
m_viewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
}
else
{
m_viewer->setThreadingModel( osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext );
}
// init resource manager ( it is a singleton and gets created during first "getResourceManager" request.
WGEResourceManager::getResourceManager();
}
......@@ -132,23 +110,15 @@ void WGraphicsEngine::setFontPath( std::string path )
WGEResourceManager::getResourceManager()->setFontPath( path );
}
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
boost::shared_ptr<WGEViewer> WGraphicsEngine::createViewer( std::string name, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode,
WColor bgColor )
{
// init the composite viewer if not already done
if ( m_viewer == osg::ref_ptr< osgViewer::CompositeViewer >() )
{
}
boost::shared_ptr<WGEViewer> viewer = boost::shared_ptr<WGEViewer>(
new WGEViewer( name, wdata, x, y, width, height, projectionMode ) );
new WGEViewer( name, x, y, width, height, projectionMode ) );
viewer->setBgColor( bgColor );
viewer->setScene( getScene() );
// finally add view
m_viewer->addView( viewer->getView() );
// store it in viewer list
boost::mutex::scoped_lock lock( m_viewersLock );
bool insertSucceeded = m_viewers.insert( make_pair( name, viewer ) ).second;
......@@ -186,17 +156,11 @@ boost::shared_ptr< WGEViewer > WGraphicsEngine::getViewer()
void WGraphicsEngine::threadMain()
{
WLogger::getLogger()->addLogMessage( "Starting Graphics Engine", "GE", LL_INFO );
m_viewer->startThreading();
m_viewer->run();
m_viewer->stopThreading();
}
void WGraphicsEngine::notifyStop()
{
WLogger::getLogger()->addLogMessage( "Stopping Graphics Engine", "GE", LL_INFO );
m_viewer->setDone( true );
}
void WGraphicsEngine::requestShaderReload()
......
......@@ -110,7 +110,6 @@ public:
* Creates a new viewer. Does basic initialization and sets the default scene.
*
* \param name the name of the viewer
* \param wdata the WindowData instance for the widget to use as render widget
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
......@@ -120,7 +119,7 @@ public:
* \return the new instance, ready to be used.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
boost::shared_ptr< WGEViewer > createViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata, int x, int y,
boost::shared_ptr< WGEViewer > createViewer( std::string name, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC,
WColor bgColor = WColor( .9, .9, .9 ) );
......
......@@ -206,6 +206,8 @@ std::string WShader::processShader( const std::string filename, bool optional, i
// this is the proper regular expression for includes. This also excludes commented includes
static const boost::regex re( "^[ ]*#[ ]*include[ ]+[\"<](.*)[\">].*" );
// this is an expression for the #version statement
static const boost::regex ver( "^[ ]*#[ ]*version[ ]+[123456789][0123456789]+.*$" );
// the input stream
std::string fn = ( boost::filesystem::path( m_shaderPath ) / filename ).file_string();
......@@ -217,7 +219,7 @@ std::string WShader::processShader( const std::string filename, bool optional, i
return "";
}
// file does not exists. Do not throw an exception to avoid OSG crash
// file does not exist. Do not throw an exception to avoid OSG crash
if ( level == 0 )
{
WLogger::getLogger()->addLogMessage( "Can't open shader file \"" + fn + "\".",
......@@ -235,8 +237,10 @@ std::string WShader::processShader( const std::string filename, bool optional, i
}
// go through each line and process includes
std::string line; // the current line
boost::smatch matches; // the list of matches
std::string line; // the current line
boost::smatch matches; // the list of matches
std::string versionLine; // the version
bool foundVersion = false;
while ( std::getline( input, line ) )
{
......@@ -244,6 +248,20 @@ std::string WShader::processShader( const std::string filename, bool optional, i
{
output << processShader( matches[1], false, level + 1 );
}
else if( boost::regex_match( line, ver ) ) // look for the #version statement
{
// there already was a version statement in this file
// this does not track multiple version statements through included files
if( foundVersion )
{
WLogger::getLogger()->addLogMessage( "Multiple version statements in shader file \"" + fn + "\".",
"WShader (" + filename + ")", LL_ERROR
);
return "";
}
versionLine = line;