Commit d18f57c7 authored by Alexander Wiebel's avatar Alexander Wiebel

[MERGE] had to fix some things in WMMarchingCubes

parents 9427f742 0462dbaf
......@@ -513,11 +513,15 @@ template < typename T >
void WPropertyVariable< T >::removeConstraints( PROPERTYCONSTRAINT_TYPE type )
{
boost::unique_lock< boost::shared_mutex > lock = boost::unique_lock< boost::shared_mutex >( m_constraintsLock );
for ( constraintIterator it = m_constraints.begin(); it != m_constraints.end(); ++it )
for ( constraintIterator it = m_constraints.begin(); it != m_constraints.end(); )
{
if ( ( *it )->getType() == type )
{
m_constraints.erase( it );
m_constraints.erase( it++ );
}
else
{
++it;
}
}
lock.unlock();
......
......@@ -119,10 +119,19 @@ void WThreadedRunner::yield() const
#endif
}
void WThreadedRunner::sleep( const int t ) const
void WThreadedRunner::sleep( const int32_t t ) const
{
#if USE_BOOST_THREADS
boost::this_thread::sleep( boost::posix_time::seconds( t ) );
#else
m_Thread->microSleep( 1000000 * t );
#endif
}
void WThreadedRunner::msleep( const int32_t t ) const
{
#if USE_BOOST_THREADS
boost::this_thread::sleep( boost::posix_time::microseconds( t ) );
#else
m_Thread->microSleep( t );
#endif
......
......@@ -25,6 +25,8 @@
#ifndef WTHREADEDRUNNER_H
#define WTHREADEDRUNNER_H
#include <stdint.h>
#ifdef _WIN32
#define USE_BOOST_THREADS 0
#else
......@@ -127,7 +129,14 @@ protected:
*
* \param t time to sleep in seconds.
*/
void sleep( const int t ) const;
void sleep( const int32_t t ) const;
/**
* Sets thread asleep.
*
* \param t time to sleep in microseconds.
*/
void msleep( const int32_t t ) const;
/**
* Let the thread sleep until a stop request was given.
......
......@@ -94,6 +94,11 @@ void WDataTexture3D::setGloballyActive( bool active )
}
}
boost::shared_ptr< WGridRegular3D > WDataTexture3D::getGrid() const
{
return m_grid;
}
osg::ref_ptr< osg::Texture3D > WDataTexture3D::getTexture()
{
if ( !m_texture )
......
......@@ -127,6 +127,14 @@ public:
*/
boost::shared_ptr< WCondition > getChangeCondition();
/**
* The texture got created using this grid. It can help to translate coordinates into the texture coordinate space relating to
* the grid.
*
* \return the grid.
*/
boost::shared_ptr< WGridRegular3D > getGrid() const;
protected:
/**
......
......@@ -85,16 +85,6 @@ public:
*/
virtual int run() = 0;
/**
* returns a vector of pointers to the loaded datasets for a given subject.
*
* \param subjectId the ID of the subject to get the list for.
* \param onlyTextures true if only textures should be returned.
*
* \return list of datasets.
*/
virtual std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false ) = 0;
/**
* Instruct the MainWindow to open a new custom widget.
*
......
......@@ -180,11 +180,6 @@ void WQt4Gui::slotActivateDatasetOrModuleInBrowser( boost::shared_ptr< WModule >
QCoreApplication::postEvent( m_mainWindow, new WModuleReadyEvent( module ) );
}
std::vector< boost::shared_ptr< WDataSet > > WQt4Gui::getDataSetList( int subjectId, bool onlyTextures )
{
return m_mainWindow->getDatasetBrowser()->getDataSetList( subjectId, onlyTextures );
}
boost::shared_ptr< WModule > WQt4Gui::getSelectedModule()
{
return m_mainWindow->getDatasetBrowser()->getSelectedModule();
......
......@@ -66,16 +66,6 @@ public:
*/
virtual int run();
/**
* returns a vector of pointers to the loaded datasets for a given subject.
*
* \param subjectId the ID of the subject to get the list for.
* \param onlyTextures true if only textures should be returned.
*
* \return list of datasets.
*/
virtual std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false );
/**
* returns a pointer to the selected module in the dataset browser
*
......
......@@ -436,33 +436,6 @@ void WQtDatasetBrowser::addTabWidgetContent( WQtDSBWidget* content )
m_tabWidget->addTab( sa, content->getName() );
}
std::vector< boost::shared_ptr< WDataSet > > WQtDatasetBrowser::getDataSetList( int subjectId, bool onlyTextures )
{
int c = getFirstSubject();
std::vector< boost::shared_ptr< WDataSet > >moduleList;
if ( m_treeWidget->invisibleRootItem()->childCount() < subjectId + c)
{
return moduleList;
}
int count = m_treeWidget->invisibleRootItem()->child( subjectId + c )->childCount();
for ( int i = 0 ; i < count ; ++i )
{
boost::shared_ptr< WMData > dm = boost::shared_dynamic_cast< WMData >( ( static_cast< WQtDatasetTreeItem* >(
m_treeWidget->invisibleRootItem()->child( subjectId + c )->child( i ) ) )->getModule() );
if ( dm->isReady()() && ( !onlyTextures || dm->getDataSet()->isTexture() ) )
{
if ( dm->getProperties2()->getProperty( "active" )->toPropBool()->get() )
{
moduleList.push_back( dm->getDataSet() );
}
}
}
return moduleList;
}
void WQtDatasetBrowser::moveTreeItemDown()
{
m_treeWidget->moveTreeItemDown();
......
......@@ -116,16 +116,6 @@ public:
*/
void addModule2( boost::shared_ptr< WModule > module, int subjectId = 0 );
/**
* Returns a vector of pointers to the loaded datasets for a given subject.
*
* \param subjectId The ID of the subject to get the list for.
* \param onlyTextures True if only textures should be returned.
*
* \return the list of datasets.
*/
std::vector< boost::shared_ptr< WDataSet > > getDataSetList( int subjectId, bool onlyTextures = false );
/**
* helper funtion to connect all qt widgets with their functions
*/
......
......@@ -41,6 +41,7 @@
#include "../dataHandler/WDataHandler.h"
#include "../common/WPreferences.h"
#include "../common/WStringUtils.h"
#include "../common/WThreadedRunner.h"
#include "WModule.h"
#include "WBatchLoader.h"
#include "WModuleFactory.h"
......
......@@ -34,7 +34,6 @@
#include "../common/WFlag.h"
#include "../common/WLogger.h"
#include "../common/WThreadedRunner.h"
#include "../graphicsEngine/WGraphicsEngine.h"
#include "../gui/WGUI.h"
#include "../modules/fiberDisplay/WROIManagerFibers.h"
......@@ -42,6 +41,8 @@
#include "WModuleContainer.h"
#include "WModuleFactory.h"
class WThreadedRunner;
/**
* \defgroup kernel Kernel
*
......@@ -116,7 +117,8 @@ public:
void loadDataSetsSynchronously( std::vector< std::string > fileNames );
/**
* Function combines to modules. This is a simple alias for "getRootContainer()->applyModule".
* Function combines to modules. This is a simple alias for "getRootContainer()->applyModule". It runs synchronously, which
* could freeze the calling thread for a couple of time.
*
* \param applyOn the module which already has to be in the container and to apply the other one on.
* \param prototype the prototype of the module to apply on the other one specified.
......
......@@ -279,7 +279,8 @@ boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< W
return applyModule( applyOn, WModuleFactory::getModuleFactory()->getPrototypeByName( what ) );
}
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn, boost::shared_ptr< WModule > prototype )
boost::shared_ptr< WModule > WModuleContainer::applyModule( boost::shared_ptr< WModule > applyOn,
boost::shared_ptr< WModule > prototype )
{
// is this module already associated with another container?
if ( applyOn->isAssociated()() && ( applyOn->getAssociatedContainer() != shared_from_this() ) )
......
......@@ -118,7 +118,8 @@ public:
virtual void addDefaultNotifier( MODULE_SIGNAL signal, t_ModuleGenericSignalHandlerType notifier );
/**
* Function combines to modules.
* Function combines two modules. This runs synchronously. It might take some time to finish since combination of modules is
* allowed only with modules marked as "ready" which might take some time.
*
* \param applyOn the module which already has to be in the container and to apply the other one on.
* \param what the prototype name of the module to apply on the other one specified.
......@@ -128,7 +129,8 @@ public:
virtual boost::shared_ptr< WModule > applyModule( boost::shared_ptr< WModule > applyOn, std::string what );
/**
* Function combines to modules.
* Function combines two modules. This runs synchronously. It might take some time to finish since combination of modules is
* allowed only with modules marked as "ready" which might take some time.
*
* \param applyOn the module which already has to be in the container and to apply the other one on.
* \param prototype the prototype of the module to apply on the other one specified.
......
......@@ -263,7 +263,17 @@ osg::ref_ptr<osg::Geometry> WMCoordinateSystem::createGeometryNode()
void WMCoordinateSystem::findBoundingBox()
{
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
// TODO(schurade): getDataSetList is obsolete.
// Use
//
// std::vector< boost::shared_ptr< WDataTexture3D > > tex = WDataHandler::getDefaultSubject()->getDataTextures( true )
// for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
// {
// std::pair< wmath::WPosition, wmath::WPosition > bb = ( *iter )->getGrid()->getBoundingBox();
// ...
// }
std::vector< boost::shared_ptr< WDataSet > > dsl; // = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
if ( dsl.size() > 0 )
{
......
......@@ -46,6 +46,7 @@
#include "../../common/WProgress.h"
#include "../../common/WPreferences.h"
#include "../../math/WVector3D.h"
#include "../../dataHandler/WDataHandler.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WGridRegular3D.h"
#include "../../dataHandler/WDataTexture3D.h"
......@@ -114,6 +115,11 @@ void WMMarchingCubes::moduleMain()
// signal ready state
ready();
// now, to watch changing/new textures use WSubject's change condition
boost::signals2::connection con = WDataHandler::getDefaultSubject()->getChangeCondition()->subscribeSignal(
boost::bind( &WMMarchingCubes::notifyTextureChange, this )
);
// loop until the module container requests the module to quit
while ( !m_shutdownFlag() )
{
......@@ -759,31 +765,34 @@ void WMMarchingCubes::renderMesh( WTriangleMesh* mesh )
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", 100 ) ) );
}
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
if ( dsl.size() > 0 )
{
for ( int i = 0; i < 10; ++i )
{
m_typeUniforms[i]->set( 0 );
}
// NOTE: the following code should not be necessary. The update callback does this job just before the mesh is rendered
// initially. Just set the texture changed flag to true. If this however might be needed use WSubject::getDataTextures.
m_textureChanged = true;
//std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );*/
//if ( dsl.size() > 0 )
//{
//for ( int i = 0; i < 10; ++i )
//{
//m_typeUniforms[i]->set( 0 );
//}
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
{
osg::ref_ptr<osg::Texture3D> texture3D = dsl[i]->getTexture()->getTexture();
//int c = 0;
//for ( size_t i = 0; i < dsl.size(); ++i )
//{
//osg::ref_ptr<osg::Texture3D> texture3D = dsl[i]->getTexture()->getTexture();
state->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
//state->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
float t = dsl[i]->getTexture()->getThreshold()/ 100.0;
float a = dsl[i]->getTexture()->getAlpha();
//float t = dsl[i]->getTexture()->getThreshold()/ 100.0;
//float a = dsl[i]->getTexture()->getAlpha();
m_typeUniforms[c]->set( boost::shared_dynamic_cast<WDataSetSingle>( dsl[i] )->getValueSet()->getDataType() );
m_thresholdUniforms[c]->set( t );
m_alphaUniforms[c]->set( a );
//m_typeUniforms[c]->set( boost::shared_dynamic_cast<WDataSetSingle>( dsl[i] )->getValueSet()->getDataType() );
//m_thresholdUniforms[c]->set( t );
//m_alphaUniforms[c]->set( a );
++c;
}
}
//++c;
//}
//}
m_shader = osg::ref_ptr< WShader > ( new WShader( "surface" ) );
m_shader->apply( m_geode );
......@@ -809,6 +818,10 @@ int myIsfinite( double number )
#endif
}
void WMMarchingCubes::notifyTextureChange()
{
m_textureChanged = true;
}
// TODO(wiebel): MC move this to a separate module in the future
bool WMMarchingCubes::save( std::string fileName, const WTriangleMesh& triMesh ) const
......@@ -992,12 +1005,8 @@ WTriangleMesh WMMarchingCubes::load( std::string fileName )
return triMesh;
}
void WMMarchingCubes::updateTextures()
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
if ( m_active->get() )
{
m_geode->setNodeMask( 0xFFFFFFFF );
......@@ -1007,40 +1016,47 @@ void WMMarchingCubes::updateTextures()
m_geode->setNodeMask( 0x0 );
}
if ( ( m_opacityProp->changed() || m_useTextureProp->changed() ) && WKernel::getRunningKernel()->getGui()->isInitialized()() )
if ( m_textureChanged || m_opacityProp->changed() || m_useTextureProp->changed() )
{
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
m_textureChanged = false;
// grab a list of data textures
std::vector< boost::shared_ptr< WDataTexture3D > > tex = WDataHandler::getDefaultSubject()->getDataTextures( true );
if ( dsl.size() > 0 )
if ( tex.size() > 0 )
{
osg::StateSet* rootState = m_geode ->getOrCreateStateSet();
// reset all uniforms
for ( int i = 0; i < 10; ++i )
{
m_typeUniforms[i]->set( 0 );
}
osg::StateSet* state = m_geode->getOrCreateStateSet();
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_useTextureProp->get( true ) ) ) );
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useTexture", m_useTextureProp->get( true ) ) ) );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "useLighting", m_shaderUseLighting ) ) );
if( m_shaderUseTransparency )
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", m_opacityProp->get( true ) ) ) );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", m_opacityProp->get( true ) ) ) );
}
else
{
state->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", 100 ) ) );
rootState->addUniform( osg::ref_ptr<osg::Uniform>( new osg::Uniform( "opacity", 100 ) ) );
}
// for each texture -> apply
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
osg::ref_ptr<osg::Texture3D> texture3D = dsl[i]->getTexture()->getTexture();
state->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
osg::ref_ptr<osg::Texture3D> texture3D = ( *iter )->getTexture();
rootState->setTextureAttributeAndModes( c, texture3D, osg::StateAttribute::ON );
float t = dsl[i]->getTexture()->getThreshold()/ 100.0;
float a = dsl[i]->getTexture()->getAlpha();
// set threshold/opacity as uniforms
float t = ( *iter )->getThreshold() / 255.0;
float a = ( *iter )->getAlpha();
m_typeUniforms[c]->set( boost::shared_dynamic_cast<WDataSetSingle>( dsl[i] )->getValueSet()->getDataType() );
m_typeUniforms[c]->set( ( *iter )->getDataType() );
m_thresholdUniforms[c]->set( t );
m_alphaUniforms[c]->set( a );
......@@ -1048,6 +1064,5 @@ void WMMarchingCubes::updateTextures()
}
}
}
slock.unlock();
}
......@@ -180,6 +180,16 @@ private:
WPropInt m_opacityProp; //!< Property holding the opacity valueassigned to the surface
WPropBool m_useTextureProp; //!< Property indicating whether to use texturing with scalar data sets.
/**
* Used as callback which simply sets m_textureChanged to true. Called by WSubject whenever the datasets change.
*/
void notifyTextureChange();
/**
* True when textures haven changed.
*/
bool m_textureChanged;
/**
* This condition denotes whether we need to recompute the surface
*/
......
......@@ -214,9 +214,10 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
std::vector< boost::shared_ptr< WDataSet > > dsl = WKernel::getRunningKernel()->getGui()->getDataSetList( 0, true );
// grab a list of data textures
std::vector< boost::shared_ptr< WDataTexture3D > > tex = WDataHandler::getDefaultSubject()->getDataTextures( true );
if ( dsl.size() > 0 )
if ( tex.size() > 0 )
{
switch ( slice )
{
......@@ -229,10 +230,9 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
sliceGeometry->setVertexArray( sliceVertices );
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >(
boost::shared_dynamic_cast< WDataSetSingle >( dsl[i] )->getGrid() );
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
float maxX = ( float )( grid->getNbCoordsX() );
float maxY = ( float )( grid->getNbCoordsY() );
......@@ -265,10 +265,9 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
sliceGeometry->setVertexArray( sliceVertices );
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >(
boost::shared_dynamic_cast< WDataSetSingle >( dsl[i] )->getGrid() );
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
float maxX = ( float )( grid->getNbCoordsX() );
float maxY = ( float )( grid->getNbCoordsY() );
......@@ -299,11 +298,12 @@ osg::ref_ptr<osg::Geometry> WMNavSlices::createGeometry( int slice )
sliceVertices->push_back( osg::Vec3( maxDim, maxDim, zPos ) );
sliceVertices->push_back( osg::Vec3( maxDim, 0, zPos ) );
sliceGeometry->setVertexArray( sliceVertices );
int c = 0;
for ( size_t i = 0; i < dsl.size(); ++i )
for ( std::vector< boost::shared_ptr< WDataTexture3D > >::const_iterator iter = tex.begin(); iter != tex.end(); ++iter )
{
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >(
boost::shared_dynamic_cast< WDataSetSingle >( dsl[i] )->getGrid() );
boost::shared_ptr< WGridRegular3D > grid = ( *iter )->getGrid();
float maxX = ( float )( grid->getNbCoordsX() );
float maxY = ( float )( grid->getNbCoordsY() );
......@@ -448,9 +448,6 @@ void WMNavSlices::updateGeometry()
void WMNavSlices::updateTextures()
{
boost::shared_lock<boost::shared_mutex> slock;
slock = boost::shared_lock<boost::shared_mutex>( m_updateLock );
if ( m_textureChanged )
{
m_textureChanged = false;
......@@ -486,7 +483,6 @@ void WMNavSlices::updateTextures()
}
}
}
slock.unlock();
}
void WMNavSlices::initUniforms( osg::StateSet* rootState )
......
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