Commit 42b8afe2 authored by schurade's avatar schurade
Browse files

[CHANGE] more work on gui<->dataset stuff

parent 5c071db4
......@@ -74,3 +74,13 @@ void WDataHandler::loadDataSets( std::vector< std::string > fileNames )
}
}
}
void WDataHandler::signalLoadFinished( boost::shared_ptr< WDataSet > data )
{
m_signalAddDataset( data );
}
boost::signal1< void, boost::shared_ptr< WDataSet > >* WDataHandler::getSignalAddDataset()
{
return &m_signalAddDataset;
}
......@@ -29,8 +29,11 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include "../gui/qt4/signalslib.hpp"
#include <boost/enable_shared_from_this.hpp>
#include "WDataSet.h"
class WSubject;
/**
......@@ -79,6 +82,16 @@ public:
*/
void loadDataSets( std::vector< std::string > fileNames );
/**
* is called from a loader object and signals a pointer to the loaded object
*/
void signalLoadFinished( boost::shared_ptr< WDataSet > data );
/**
*
*/
boost::signal1< void, boost::shared_ptr< WDataSet > >* getSignalAddDataset();
protected:
private:
......@@ -86,6 +99,11 @@ private:
* A container for all WSubjects.
*/
std::vector< boost::shared_ptr< WSubject > > m_subjects;
/**
* boost signal object for signaling the addition of a dataset to the datahandler
*/
boost::signal1< void, boost::shared_ptr< WDataSet > > m_signalAddDataset;
};
/**
......
......@@ -56,4 +56,6 @@ void WLoader::commitDataSet( boost::shared_ptr< WDataSet > data )
subject = m_dataHandler->getSubject( 0 );
}
subject->addDataSet( data );
m_dataHandler->signalLoadFinished( data );
}
......@@ -48,10 +48,15 @@ public:
virtual bool isInitalized() = 0;
/**
*
* adds a dataset to the dataset browser for a give subject
*/
virtual void addDatasetToBrowser( boost::shared_ptr< WModule > module, int subjectId ) = 0;
/**
* returns a vector of pointers to the loaded datasets for a given subject
*/
virtual std::vector< boost::shared_ptr< WModule > >getDataSetList( int subjectId ) = 0;
/**
* getter functions for all signals provided by the gui
*/
......
......@@ -73,6 +73,10 @@ void WQt4Gui::addDatasetToBrowser( boost::shared_ptr< WModule > module, int subj
m_gui->getDatasetBrowser()->addDataset( module, subjectId );
}
std::vector< boost::shared_ptr< WModule > >WQt4Gui::getDataSetList( int subjectId )
{
return m_gui->getDatasetBrowser()->getDataSetList( subjectId );
}
bool WQt4Gui::isInitalized()
{
......
......@@ -57,6 +57,11 @@ public:
void addDatasetToBrowser( boost::shared_ptr< WModule > module, int subjectId );
/**
* returns a vector of pointers to the loaded datasets for a given subject
*/
virtual std::vector< boost::shared_ptr< WModule > >getDataSetList( int subjectId );
/**
* getter functions for the signales proved by the gui
*/
......
......@@ -25,6 +25,7 @@
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <QtCore/QList>
......@@ -214,3 +215,23 @@ void WQtDatasetBrowser::slotSetStringProperty( std::string name, std::string val
m_treeWidget->selectedItems().at( 0 )->setText( 0, QString( value.c_str() ) );
}
}
std::vector< boost::shared_ptr< WModule > >WQtDatasetBrowser::getDataSetList( int subjectId )
{
std::vector< boost::shared_ptr< WModule > >moduleList;
if ( m_treeWidget->invisibleRootItem()->childCount() < subjectId + 1)
{
return moduleList;
}
int count = m_treeWidget->invisibleRootItem()->child( subjectId )->childCount();
for ( int i = 0 ; i < count ; ++i )
{
moduleList.push_back( ( ( WQtDatasetTreeItem* )
m_treeWidget->invisibleRootItem()->child( subjectId )->child( i ) )->getModule() );
}
return moduleList;
}
......@@ -26,6 +26,7 @@
#define WQTDATASETBROWSER_H
#include <string>
#include <vector>
#include <QtGui/QDockWidget>
#include <QtGui/QTabWidget>
......@@ -35,6 +36,7 @@
#include "WQtDSBWidget.h"
#include "WQtSubjectTreeItem.h"
#include "WQtTreeWidget.h"
/**
* container widget for a tree widget with context menu and some control widgets
*/
......@@ -72,6 +74,12 @@ public:
*/
WQtDatasetTreeItem* addDataset( boost::shared_ptr< WModule > module, int subjectId = 0 );
/**
* returns a vector of pointers to the loaded datasets for a given subject
*/
std::vector< boost::shared_ptr< WModule > >getDataSetList( int subjectId );
/**
* helper funtion to connect all qt widgets with their functions
*/
......
......@@ -200,6 +200,8 @@ void WKernel::init()
// initialize Datahandler
m_dataHandler = boost::shared_ptr<WDataHandler>( new WDataHandler() );
m_dataHandler->getSignalAddDataset()->connect( boost::bind( &WKernel::slotFinishLoadData, this, _1 ) );
}
bool WKernel::findAppPath()
......@@ -284,13 +286,17 @@ bool WKernel::isFinishRequested() const
void WKernel::doLoadDataSets( std::vector< std::string > fileNames )
{
m_dataHandler->loadDataSets( fileNames );
}
boost::shared_ptr< WModule > module = boost::shared_ptr< WModule >( new WDataModule<int>() );
void WKernel::slotFinishLoadData( boost::shared_ptr< WDataSet > dataSet )
{
boost::shared_ptr< WModule > module = boost::shared_ptr< WModule >( new WDataModule<int>( dataSet ) );
module->getProperties()->addBool( "interpolation", true );
module->getProperties()->addBool( "active", false );
module->getProperties()->addInt( "threshold", 20 );
module->getProperties()->addInt( "alpha", 70 );
module->getProperties()->addBool( "active", true );
module->getProperties()->addInt( "threshold", 0 );
module->getProperties()->addInt( "alpha", 100 );
module->getProperties()->setValue( "name", dataSet->getFileName() );
m_gui->addDatasetToBrowser( module, 0 );
}
......
......@@ -183,6 +183,11 @@ private:
*/
bool findAppPath();
/**
*
*/
void slotFinishLoadData( boost::shared_ptr< WDataSet > );
/**
* Number of arguments given to application.
*/
......
......@@ -173,3 +173,4 @@ WProperties* WModule::getProperties()
void WModule::connectToGui()
{
}
......@@ -34,6 +34,10 @@
#include "../common/WThreadedRunner.h"
#include "WModuleConnectorSignals.h"
#include "../dataHandler/WDataSet.h"
#include "../dataHandler/WDataSetSingle.h"
#include "../dataHandler/WValueSet.hpp"
#include "WProperties.h"
class WModuleConnector;
......@@ -217,7 +221,7 @@ protected:
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output );
/**
/**
* the property object for the module
*/
WProperties m_properties;
......
......@@ -29,12 +29,13 @@
#include <boost/shared_ptr.hpp>
#include <osg/Texture3D>
#include "../../kernel/WKernel.h"
#include "../../kernel/WModule.h"
#include "../../kernel/WModuleConnector.h"
#include "../../kernel/WModuleOutputData.hpp"
#include "../../dataHandler/WDataSet.h"
/**
* Module for encapsulating WDataSets. It can encapsulate almost everything, but is intended to be used with WDataSets and its
......@@ -49,7 +50,13 @@ public:
* \par Description
* Default constructor.
*/
WDataModule();
// WDataModule();
/**
* \par Description
* constructor with dataset
*/
explicit WDataModule( boost::shared_ptr< WDataSet > dataSet );
/**
* \par Description
......@@ -71,6 +78,21 @@ public:
*/
virtual const std::string getDescription() const;
/**
* setter for the asociated dataset
*/
virtual void setDataSet( boost::shared_ptr< WDataSet > dataSet );
/**
* getter for the dataset
*/
virtual boost::shared_ptr< WDataSet > getDataSet();
/**
* getter for the 3d texture, which will be created on demand
*/
virtual osg::Texture3D* getTexture3D();
protected:
/**
......@@ -93,23 +115,60 @@ protected:
virtual void notifyDataChange( boost::shared_ptr<WModuleConnector> input,
boost::shared_ptr<WModuleConnector> output );
/**
* Creates a 3d texture from a dataset. This function will be overloaded for the
* various data types. A template function is not recommended due to the different commands
* in the image creation.
*
* TODO(schurade): create other functions once dataset meta data is available again
*
* \param source Pointer to the raw data of a dataset
* \param components Number of values used in a Voxel, usually 1, 3 or 4
* \return Pointer to a new texture3D
*/
osg::Texture3D* createTexture3D( int8_t* source, int components = 1 );
private:
/**
* The only output of this data module.
*/
boost::shared_ptr<WModuleOutputData<T> > m_output;
/**
* pointer to the dataset
*/
boost::shared_ptr< WDataSet > m_dataSet;
/**
* pointer to the 3d texture
*/
osg::Texture3D* m_texture3D;
};
// TODO(schurade, ebaum): do we still need/want that constructor?
// template < typename T >
// WDataModule<T>::WDataModule():
// WModule()
// {
// // WARNING: initializing connectors inside the constructor will lead to an exception.
// // Implement WModule::initializeConnectors instead.
//
// // initialize members
// m_properties.addString( "name", "not initialized" );
// }
template < typename T >
WDataModule<T>::WDataModule():
WDataModule<T>::WDataModule( boost::shared_ptr< WDataSet > dataSet ):
WModule()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
// initialize members
m_dataSet = dataSet;
m_texture3D = 0;
m_properties.addString( "name", "not initialized" );
}
......@@ -167,5 +226,57 @@ void WDataModule<T>::threadMain()
// clean up stuff
}
template < typename T >
void WDataModule<T>::setDataSet( boost::shared_ptr< WDataSet > dataSet )
{
m_dataSet = dataSet;
}
template < typename T >
boost::shared_ptr< WDataSet > WDataModule<T>::getDataSet()
{
return m_dataSet;
}
template < typename T >
osg::Texture3D* WDataModule<T>::getTexture3D()
{
if ( !m_texture3D )
{
boost::shared_ptr< WDataSetSingle > ds = boost::shared_dynamic_cast< WDataSetSingle >( m_dataSet );
boost::shared_ptr< WValueSet< int8_t > > vs = boost::shared_dynamic_cast< WValueSet< int8_t > >( ds->getValueSet() );
int8_t* source = const_cast< int8_t* > ( vs->rawData() );
m_texture3D = createTexture3D( source );
}
return m_texture3D;
}
template < typename T >
osg::Texture3D* WDataModule<T>::createTexture3D( int8_t* source, int components )
{
if ( components == 1)
{
osg::ref_ptr< osg::Image > ima = new osg::Image;
ima->allocateImage( 160, 200, 160, GL_LUMINANCE, GL_UNSIGNED_BYTE );
unsigned char* data = ima->data();
for ( unsigned int i = 0; i < 160* 200* 160 ; ++i )
{
data[i] = source[i];
}
osg::Texture3D* texture3D = new osg::Texture3D;
texture3D->setFilter( osg::Texture3D::MIN_FILTER, osg::Texture3D::LINEAR );
texture3D->setFilter( osg::Texture3D::MAG_FILTER, osg::Texture3D::LINEAR );
texture3D->setWrap( osg::Texture3D::WRAP_R, osg::Texture3D::REPEAT );
texture3D->setImage( ima );
texture3D->setResizeNonPowerOfTwoHint( false );
return texture3D;
}
return 0;
}
#endif // WDATAMODULE_H
......@@ -32,7 +32,6 @@
#include <osg/Group>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture3D>
#include "boost/smart_ptr.hpp"
......@@ -46,6 +45,7 @@
#include "../../dataHandler/WDataSetSingle.h"
#include "../../dataHandler/WSubject.h"
#include "../../dataHandler/WValueSet.hpp"
#include "../data/WDataModule.hpp"
#include "../../graphicsEngine/WShader.h"
......@@ -126,28 +126,21 @@ void WNavigationSliceModule::threadMain()
// Since the modules run in a separate thread: such loops are possible
while ( !m_FinishRequested )
{
if ( WKernel::getRunningKernel()->getDataHandler()->getNumberOfSubjects() > 0 )
if ( !m_properties.getValue< bool >( "textureAssigned" ) && WKernel::getRunningKernel()->getGui()->isInitalized() )
{
if ( WKernel::getRunningKernel()->getDataHandler()->getSubject(0)->getNumberOfDataSets() > 0 )
std::vector< boost::shared_ptr< WModule > > datasetList = WKernel::getRunningKernel()->getGui()->getDataSetList( 0 );
if ( datasetList.size() > 0 )
{
if ( !m_properties.getValue< bool >( "textureAssigned" ) )
for ( size_t i = 0; i < datasetList.size(); ++i)
{
boost::shared_ptr< WDataSetSingle > ds = boost::shared_dynamic_cast< WDataSetSingle >(
WKernel::getRunningKernel()->getDataHandler()->getSubject( 0 )->getDataSet( 0 ) );
boost::shared_ptr< WValueSet< int8_t > > vs = boost::shared_dynamic_cast< WValueSet<
int8_t > >( ds->getValueSet() );
int8_t* source = const_cast< int8_t* > ( vs->rawData() );
osg::Texture3D* texture3D = WKernel::getRunningKernel()->getGraphicsEngine()->createTexture3D( source );
osg::Texture3D* texture3D = boost::shared_dynamic_cast<WDataModule<int> >( datasetList[i] )->getTexture3D();
osg::StateSet* sliceState = m_sliceNode->getOrCreateStateSet();
sliceState->setTextureAttributeAndModes( 0, texture3D, osg::StateAttribute::ON );
m_properties.setValue( "textureAssigned", true );
// WKernel::getRunningKernel()->getGui()->addDatasetToBrowser( ds->getFileName(), 0 );
sliceState->setTextureAttributeAndModes( i, texture3D, osg::StateAttribute::ON );
}
m_properties.setValue( "textureAssigned", true );
}
}
// do fancy stuff
......
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