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

[CHANGE] - restructured WMData to now get the filename via method instead of a...

[CHANGE] - restructured WMData to now get the filename via method instead of a property. Doing this, the project file loader now supports module containers
parent 570c21f5
......@@ -32,7 +32,7 @@ WQtDatasetTreeItem::WQtDatasetTreeItem( QTreeWidgetItem * parent, boost::shared_
: WQtTreeItem( parent, DATASET, module )
{
// replace the name by the filename
boost::shared_ptr< WPropertyBase > p = module->getProperties()->findProperty( "filename" );
boost::shared_ptr< WPropertyBase > p = module->getProperties()->findProperty( "Name" );
m_name = "Dataset";
if ( p.get() )
{
......
......@@ -63,11 +63,8 @@ void WBatchLoader::threadMain()
WModuleFactory::getModuleFactory()->getPrototypeByName( "Data Module" )
);
boost::shared_ptr< WPropertyBase > p = mod->getProperties()->findProperty( "filename" );
if ( p.get() )
{
p->toPropFilename()->set( *iter );
}
// set the filename
boost::shared_static_cast< WMData >( mod )->setFilename( *iter );
m_targetContainer->add( mod );
// serialize loading of a couple of data sets
......
......@@ -34,7 +34,6 @@
#include "../modules/clusterSlicer/WMClusterSlicer.h"
#include "../modules/connectomeView/WMConnectomeView.h"
#include "../modules/coordinateSystem/WMCoordinateSystem.h"
#include "../modules/data/WMData.h" // this is the ONLY module with a special meaning.
#include "../modules/dataTypeConversion/WMDataTypeConversion.h"
#include "../modules/deterministicFTMori/WMDeterministicFTMori.h"
#include "../modules/directVolumeRendering/WMDirectVolumeRendering.h"
......
......@@ -31,6 +31,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include "../modules/data/WMData.h" // this is the ONLY module with a special meaning. Every one knowing the factory also knows this
#include "WModule.h"
/**
......
......@@ -78,6 +78,7 @@ void WModuleProjectFileCombiner::parse()
// this is the proper regular expression for modules
static const boost::regex modRe( "^MODULE:([0-9]*):(.*)$" );
static const boost::regex dataRe( "^DATA:([0-9]*):(.*)$" );
static const boost::regex conRe( "^CONNECTION:\\(([0-9]*),(.*)\\)->\\(([0-9]*),(.*)\\)$" );
static const boost::regex propRe( "^PROPERTY:\\(([0-9]*),(.*)\\)=(.*)$" );
static const boost::regex commentRe( "^//.*$" );
......@@ -100,16 +101,52 @@ void WModuleProjectFileCombiner::parse()
// create a module instance
boost::shared_ptr< WModule > proto = WModuleFactory::getModuleFactory()-> isPrototypeAvailable( matches[2] );
// data modules are not allowed here
if ( !proto )
{
wlog::error( "Project Loader" ) << "There is no prototype available for module \"" << matches[2] << "\". Skipping.";
}
else if ( proto->getType() == MODULE_DATA )
{
wlog::error( "Project Loader" ) << "Data modules are not allowed to be specified in a \"MODULE\" Statement." <<
" Use the \"DATA\" statement instead. Skipping.";
}
else
{
boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
m_modules.insert( ModuleID( boost::lexical_cast< unsigned int >( matches[1] ), module ) );
}
}
else if ( boost::regex_match( line, matches, dataRe ) )
{
// it is a dataset line
// matches[1] is the ID
// matches[2] is the filename
wlog::debug( "Project Loader [Parser]" ) << "Line " << i << ": Data \"" << matches[2] << "\" with ID " << matches[1];
// create a module instance
boost::shared_ptr< WModule > proto = WModuleFactory::getModuleFactory()-> isPrototypeAvailable( "Data Module" );
if ( !proto )
{
wlog::error( "Project Loader" ) << "There is no prototype available for module \"" << "Data Module" << "\"."
<< " This should not happen!. Skipping.";
}
else
{
std::string parameter = std::string( matches[2] );
boost::shared_ptr< WModule > module = WModuleFactory::getModuleFactory()->create( proto );
if ( parameter.empty() )
{
wlog::error( "Project Loader" ) << "Data modules need an additional filename parameter. Skipping.";
}
else
{
boost::shared_static_cast< WMData >( module )->setFilename( parameter );
m_modules.insert( ModuleID( boost::lexical_cast< unsigned int >( matches[1] ), module ) );
}
}
}
else if ( boost::regex_match( line, matches, conRe ) )
{
// it is a connector line
......@@ -146,6 +183,29 @@ void WModuleProjectFileCombiner::parse()
void WModuleProjectFileCombiner::apply()
{
// now add each module to the target container
for ( std::map< unsigned int, boost::shared_ptr< WModule > >::const_iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
m_container->add( ( *iter ).second );
}
// now wait for the modules to get ready. We could have waited for this in the previous loop, but a long loading module would block others.
// -> so we wait after adding and starting them
for ( std::map< unsigned int, boost::shared_ptr< WModule > >::iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
( *iter ).second->isReadyOrCrashed().wait();
// if isReady now is false, the module has crashed before it got ready -> remove the module from the list
if ( ( *iter ).second->isCrashed()() )
{
wlog::warn( "Project Loader" ) << "In the module with ID "
<< ( *iter ).first
<< " a problem occurred. Connections and properties relating to this"
<< " module will fail.";
m_modules.erase( iter );
}
}
// now, as we have created the modules, we need to set the properties for each of it.
for ( std::list< PropertyValue >::const_iterator iter = m_properties.begin(); iter != m_properties.end(); ++iter )
{
......@@ -173,29 +233,6 @@ void WModuleProjectFileCombiner::apply()
}
}
// now add each module to the target container
for ( std::map< unsigned int, boost::shared_ptr< WModule > >::const_iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
m_container->add( ( *iter ).second );
}
// now wait for the modules to get ready. We could have waited for this in the previous loop, but a long loading module would block others.
// -> so we wait after adding and starting them
for ( std::map< unsigned int, boost::shared_ptr< WModule > >::iterator iter = m_modules.begin(); iter != m_modules.end(); ++iter )
{
( *iter ).second->isReadyOrCrashed().wait();
// if isReady now is false, the module has crashed before it got ready -> remove the module from the list
if ( ( *iter ).second->isCrashed()() )
{
wlog::warn( "Project Loader" ) << "In the module with ID "
<< ( *iter ).first
<< " a problem occurred. Connections and properties relating to this"
<< " module will fail.";
m_modules.erase( iter );
}
}
// and finally, connect them all together
for ( std::list< Connection >::const_iterator iter = m_connections.begin(); iter != m_connections.end(); ++iter )
{
......
......@@ -48,9 +48,6 @@
#include "../../kernel/WKernel.h"
#include "../../graphicsEngine/WShader.h"
#include "../data/WMData.h"
WMConnectomeView::WMConnectomeView():
WModuleContainer( "Connectome View", "Connectome View allows connectome data to be displayed in the context of MRI data." ),
m_dataSet()
......
......@@ -29,7 +29,6 @@
#include <osg/Geometry>
#include "../../kernel/WKernel.h"
#include "../data/WMData.h"
#include "WMCoordinateSystem.h"
#include "coordinateSystem.xpm"
......
......@@ -48,6 +48,7 @@
WMData::WMData():
WModule(),
m_fileNameSet( false ),
m_isTexture()
{
// initialize members
......@@ -83,6 +84,20 @@ boost::shared_ptr< WDataSet > WMData::getDataSet()
return m_dataSet;
}
void WMData::setFilename( boost::filesystem::path fname )
{
if ( !m_fileNameSet )
{
m_fileNameSet = true;
m_fileName = fname;
}
}
boost::filesystem::path WMData::getFilename() const
{
return m_fileName;
}
MODULE_TYPE WMData::getType() const
{
return MODULE_DATA;
......@@ -106,8 +121,6 @@ void WMData::properties()
{
// properties
// filename of file to load and handle
m_filename = m_properties->addProperty( "filename", "The file to load.", WKernel::getAppPathObject(), true );
m_dataName = m_properties->addProperty( "Name", "The name of the dataset.", std::string( "" ) );
// use this callback for the other properties
......@@ -193,8 +206,10 @@ void WMData::notifyStop()
void WMData::moduleMain()
{
WAssert( m_fileNameSet, "No filename specified." );
using wiotools::getSuffix;
std::string fileName = m_filename->get().string();
std::string fileName = m_fileName.string();
debugLog() << "Loading data from \"" << fileName << "\".";
m_dataName->set( fileName );
......@@ -208,7 +223,6 @@ void WMData::moduleMain()
|| suffix == ".edf" )
{
// hide other properties since they make no sense fo these data set types.
m_filename->setHidden();
m_interpolation->setHidden();
m_threshold->setHidden();
m_opacity->setHidden();
......@@ -256,13 +270,11 @@ void WMData::moduleMain()
WAssert( false, "WDataSetSingle needed at this position." );
}
}
//#ifndef _MSC_VER
else if( suffix == ".edf" )
{
WLoaderBiosig biosigLoader( fileName );
m_dataSet = biosigLoader.load();
}
//#endif
else if( suffix == ".asc" )
{
WLoaderEEGASCII eegAsciiLoader( fileName );
......
......@@ -97,6 +97,24 @@ public:
*/
virtual MODULE_TYPE getType() const;
/**
* Sets the filename of the file to load. If this method is called multiple times it has no effect. It has to be called right after
* construction BEFORE running the data module.
*
* \note The reason for using this method to set the filename instead of a property is, that a property gets set AFTER ready(), but this (and
* only this module) needs it before ready got called.
*
* \param fname the name of the file
*/
virtual void setFilename( boost::filesystem::path fname );
/**
* Gets the path of the file that has been loaded. It always is the value which has been set during the FIRST call of setFilename.
*
* \return the path of the file that has been loaded.
*/
virtual boost::filesystem::path getFilename() const;
protected:
/**
* \par Description
......@@ -139,9 +157,14 @@ protected:
virtual void notifyStop();
/**
* The filename to load.
* The filename of the dataset to load.
*/
boost::filesystem::path m_fileName;
/**
* true if the m_fileName has been set earlier.
*/
WPropFilename m_filename;
bool m_fileNameSet;
/**
* The name of the dataset. Usually the filename.
......@@ -158,7 +181,6 @@ protected:
*/
WPropInt m_colorMap;
/**
* Threshold value for this data.
*/
......
......@@ -38,7 +38,6 @@
#include "../../kernel/WKernel.h"
#include "../../common/math/WPosition.h"
#include "../../common/math/WVector3D.h"
#include "../data/WMData.h"
#include "WMDataTypeConversion.h"
#include "datatypeconversion.xpm"
......
......@@ -64,7 +64,7 @@ const char** WMDistanceMapIsosurface::getXPMIcon() const
return distancemapIsosurface_xpm;
}
void WMDistanceMapIsosurface::moduleMain()
void WMDistanceMapIsosurface::moduleSetup()
{
//////////////////////////////////////////////////////////////////////////////////
// Marching Cubes
......@@ -96,8 +96,8 @@ void WMDistanceMapIsosurface::moduleMain()
// create a new instance of WMDistanceMap
// NOTE: as the distance map is a "local" module, we can't use the module factory (as WMDistanceMap is not a prototype there).
// The initialization of the module has to be done by the ModuleFactory to ensure proper initialization.
m_distanceMapModule = boost::shared_ptr< WModule >( new WMDistanceMap() );
// The initialization of the module has to be done by the ModuleFactory to ensure proper initialization.
WModuleFactory::initializeModule( m_distanceMapModule );
// add it to the container
......@@ -126,8 +126,18 @@ void WMDistanceMapIsosurface::moduleMain()
// we want the container input connector "in" to be connected to the input of WMDistanceMap
m_input->forward( m_distanceMapModule->getInputConnector( "in" ) );
}
void WMDistanceMapIsosurface::moduleMain()
{
//////////////////////////////////////////////////////////////////////////////////
// Initialize the modules whose properties we want to forward.
//////////////////////////////////////////////////////////////////////////////////
moduleSetup();
//////////////////////////////////////////////////////////////////////////////////
// Done!
// Done! Modules are set up.
//////////////////////////////////////////////////////////////////////////////////
// signal ready state
......@@ -166,6 +176,11 @@ void WMDistanceMapIsosurface::connectors()
WModule::connectors();
}
void WMDistanceMapIsosurface::properties()
{
// this module's properties get added during moduleMain.
}
void WMDistanceMapIsosurface::activate()
{
m_marchingCubesModule->getProperties()->getProperty( "active" )->toPropBool()->set( m_active->get() );
......
......@@ -80,11 +80,21 @@ protected:
*/
virtual void connectors();
/**
* Initialize the properties for this module.
*/
virtual void properties();
/**
* Callback for m_active. Overwrite this in your modules to handle m_active changes separately.
*/
virtual void activate();
/**
* Setup the modules
*/
virtual void moduleSetup();
private:
WPropDouble m_isoValueProp; //!< Property holding the value for the distance.
......
......@@ -38,7 +38,6 @@
#include "../../kernel/WKernel.h"
#include "../../common/math/WPosition.h"
#include "../../common/math/WVector3D.h"
#include "../data/WMData.h"
#include "WMGaussFiltering.h"
#include "gaussfiltering.xpm"
......
......@@ -52,8 +52,6 @@
#include "../../dataHandler/WDataTexture3D.h"
#include "../../kernel/WKernel.h"
#include "../data/WMData.h"
#include "WMMarchingCubes.h"
......
......@@ -51,7 +51,6 @@
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
#include "../../kernel/WModuleInputData.h"
#include "../data/WMData.h"
#include "WMNavSlices.h"
#include "navslices.xpm"
......
......@@ -38,7 +38,6 @@
#include "../../kernel/WKernel.h"
#include "../../common/math/WPosition.h"
#include "../../common/math/WVector3D.h"
#include "../data/WMData.h"
#include "../../dataHandler/io/nifti/nifti1_io.h"
#include "WMWriteNIfTI.h"
......
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