Commit 8bd0398d authored by schurade's avatar schurade

[ADD] a property class for modules

parent 56a41bb0
//---------------------------------------------------------------------------
//
// 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 SIGNALSLIB_HPP_INCLUDED
#define SIGNALSLIB_HPP_INCLUDED
#if defined(signals) && defined(QOBJECTDEFS_H) && \
!defined(QT_MOC_CPP)
!defined( QT_MOC_CPP )
# undef signals
# define signals signals
#endif
......@@ -10,11 +35,11 @@
#include <boost/signal.hpp>
namespace boost
{
namespace signalslib = signals;
namespace signalslib = signals;
}
#if defined(signals) && defined(QOBJECTDEFS_H) && \
!defined(QT_MOC_CPP)
!defined( QT_MOC_CPP )
# undef signals
// Restore the macro definition of "signals", as it was
// defined by Qt's <qobjectdefs.h>.
......
......@@ -230,7 +230,7 @@ bool WKernel::findAppPath()
{
appPath[length] = '\0';
--length;
assert(length>=0);
assert( length >= 0 );
}
m_AppPath = appPath;
......@@ -239,31 +239,31 @@ bool WKernel::findAppPath()
m_shaderPath = shaderPath + "shaders/";
return true;
#elif defined(__APPLE__)
#elif defined( __APPLE__ )
char path[1024];
uint32_t size = sizeof(path);
if(_NSGetExecutablePath(path, &size) == 0)
uint32_t size = sizeof( path );
if(_NSGetExecutablePath( path, &size ) == 0 )
{
fprintf(stderr, "Executable path is %s\n", path);
int i= strlen(path);
while(path[i] != '/')
{
path[i] = '\0';
i--;
assert(i>=0);
}
fprintf(stderr, "Application path is %s\n", path);
m_AppPath = path;
std::string shaderPath( path );
m_shaderPath = shaderPath + "shaders/";
return true;
fprintf( stderr, "Executable path is %s\n", path );
int i= strlen( path );
while( path[i] != '/' )
{
path[i] = '\0';
i--;
assert( i >= 0 );
}
fprintf( stderr, "Application path is %s\n", path );
m_AppPath = path;
std::string shaderPath( path );
m_shaderPath = shaderPath + "shaders/";
return true;
}
else
{
fprintf(stderr, "buffer too small; need size %u\n", size);
assert(size <= sizeof(path));
fprintf( stderr, "buffer too small; need size %u\n", size );
assert( size <= sizeof( path ) );
}
#else
#error findAppPath not implemented for this platform
......
......@@ -50,7 +50,8 @@
#include "../../graphicsEngine/WShader.h"
WNavigationSliceModule::WNavigationSliceModule():
WModule()
WModule(),
m_properties()
{
// WARNING: initializing connectors inside the constructor will lead to an exception.
// Implement WModule::initializeConnectors instead.
......@@ -58,19 +59,19 @@ WNavigationSliceModule::WNavigationSliceModule():
// initialize members
std::string shaderPath = WKernel::getRunningKernel()->getGraphicsEngine()->getShaderPath();
m_shader = boost::shared_ptr< WShader > ( new WShader( "slice", shaderPath ) );
m_textureAssigned = false;
m_axialSlice = 80;
m_coronalSlice = 100;
m_sagittalSlice = 80;
m_properties.addBool( "textureAssigned", false );
m_properties.addInt( "axialPos", 80 );
m_properties.addInt( "coronalPos", 100 );
m_properties.addInt( "sagittalPos", 80 );
m_maxAxial = 160;
m_maxCoronal = 200;
m_maxSagittal = 160;
m_properties.addInt( "maxAxial", 160 );
m_properties.addInt( "maxCoronal", 200 );
m_properties.addInt( "maxSagittal", 160 );
m_showAxial = true;
m_showCoronal = true;
m_showSagittal = true;
m_properties.addBool( "showAxial", true );
m_properties.addBool( "showCoronal", true );
m_properties.addBool( "showSagittal", true );
}
WNavigationSliceModule::~WNavigationSliceModule()
......@@ -125,7 +126,7 @@ void WNavigationSliceModule::threadMain()
{
if ( WKernel::getRunningKernel()->getDataHandler()->getSubject(0)->getNumberOfDataSets() > 0 )
{
if ( !m_textureAssigned )
if ( !m_properties.getValue< bool >( "textureAssigned" ) )
{
boost::shared_ptr< WDataSetSingle > ds = boost::shared_dynamic_cast< WDataSetSingle >(
WKernel::getRunningKernel()->getDataHandler()->getSubject( 0 )->getDataSet( 0 ) );
......@@ -153,7 +154,7 @@ void WNavigationSliceModule::threadMain()
sliceState->setTextureAttributeAndModes( 0, texture3D, osg::StateAttribute::ON );
m_textureAssigned = true;
m_properties.setValue( "textureAssigned", true );
WKernel::getRunningKernel()->getGui()->addDatasetToBrowser( ds->getFileName(), 0 );
}
......@@ -168,9 +169,17 @@ void WNavigationSliceModule::threadMain()
void WNavigationSliceModule::createSlices()
{
float texAxial = ( float )m_axialSlice / ( float )m_maxAxial;
float texCoronal = ( float )m_coronalSlice / ( float )m_maxCoronal;
float texSagittal = ( float )m_sagittalSlice / ( float )m_maxSagittal;
float axialPos = ( float )( m_properties.getValue< int >( "axialPos" ) );
float coronalPos = ( float )( m_properties.getValue< int >( "coronalPos" ) );
float sagittalPos = ( float )( m_properties.getValue< int >( "sagittalPos" ) );
float maxAxial = ( float )( m_properties.getValue<int>( "maxAxial") );
float maxCoronal = ( float )( m_properties.getValue<int>( "maxCoronal") );
float maxSagittal = ( float )( m_properties.getValue<int>( "maxSagittal") );
float texAxial = axialPos / maxAxial;
float texCoronal = coronalPos / maxCoronal;
float texSagittal = sagittalPos / maxSagittal;
m_sliceNode = new osg::Geode();
......@@ -179,20 +188,20 @@ void WNavigationSliceModule::createSlices()
m_sliceNode->addDrawable( sliceGeometry );
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
sliceVertices->push_back( osg::Vec3( 0, m_coronalSlice, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, m_coronalSlice, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_coronalSlice, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_coronalSlice, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, 0, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, m_maxCoronal, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, m_maxCoronal, 0 ) );
sliceVertices->push_back( osg::Vec3( axialPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( axialPos, 0, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( axialPos, maxCoronal, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( axialPos, maxCoronal, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 0, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( 0, m_maxCoronal, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_maxCoronal, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, 0, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( 0, 0, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( 0, maxCoronal, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, maxCoronal, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, 0, sagittalPos ) );
sliceGeometry->setVertexArray( sliceVertices );
......@@ -245,27 +254,35 @@ void WNavigationSliceModule::createSlices()
void WNavigationSliceModule::updateSlices()
{
float texAxial = ( float )m_axialSlice / ( float )m_maxAxial;
float texCoronal = ( float )m_coronalSlice / ( float ) m_maxCoronal;
float texSagittal = ( float )m_sagittalSlice / ( float )m_maxSagittal;
float axialPos = ( float )( m_properties.getValue< int >( "axialPos" ) );
float coronalPos = ( float )( m_properties.getValue< int >( "coronalPos" ) );
float sagittalPos = ( float )( m_properties.getValue< int >( "sagittalPos" ) );
float maxAxial = ( float )( m_properties.getValue<int>( "maxAxial") );
float maxCoronal = ( float )( m_properties.getValue<int>( "maxCoronal") );
float maxSagittal = ( float )( m_properties.getValue<int>( "maxSagittal") );
float texAxial = axialPos / maxAxial;
float texCoronal = coronalPos / maxCoronal;
float texSagittal = sagittalPos / maxSagittal;
osg::Geometry* sliceGeometry = new osg::Geometry();
osg::Vec3Array* sliceVertices = new osg::Vec3Array;
sliceVertices->push_back( osg::Vec3( 0, m_coronalSlice, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, m_coronalSlice, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_coronalSlice, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_coronalSlice, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( maxAxial, coronalPos, 0 ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, 0, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, m_maxCoronal, m_maxSagittal ) );
sliceVertices->push_back( osg::Vec3( m_axialSlice, m_maxCoronal, 0 ) );
sliceVertices->push_back( osg::Vec3( axialPos, 0, 0 ) );
sliceVertices->push_back( osg::Vec3( axialPos, 0, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( axialPos, maxCoronal, maxSagittal ) );
sliceVertices->push_back( osg::Vec3( axialPos, maxCoronal, 0 ) );
sliceVertices->push_back( osg::Vec3( 0, 0, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( 0, m_maxCoronal, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, m_maxCoronal, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( m_maxAxial, 0, m_sagittalSlice ) );
sliceVertices->push_back( osg::Vec3( 0, 0, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( 0, maxCoronal, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, maxCoronal, sagittalPos ) );
sliceVertices->push_back( osg::Vec3( maxAxial, 0, sagittalPos ) );
sliceGeometry->setVertexArray( sliceVertices );
......@@ -305,17 +322,17 @@ void WNavigationSliceModule::updateSlices()
slice2->push_back( 9 );
slice2->push_back( 8 );
if ( m_showAxial )
if ( m_properties.getValue<bool>( "showAxial" ) )
{
sliceGeometry->addPrimitiveSet( slice2 );
}
if ( m_showCoronal )
if ( m_properties.getValue<bool>( "showCoronal" ) )
{
sliceGeometry->addPrimitiveSet( slice0 );
}
if ( m_showSagittal )
if ( m_properties.getValue<bool>( "showSagittal" ) )
{
sliceGeometry->addPrimitiveSet( slice1 );
}
......@@ -347,37 +364,37 @@ void WNavigationSliceModule::connectToGui()
void WNavigationSliceModule::sliderAxialMoved( int value )
{
m_axialSlice = value;
m_properties.setValue( "axialPos", value );
updateSlices();
}
void WNavigationSliceModule::sliderCoronalMoved( int value )
{
m_coronalSlice = value;
m_properties.setValue( "coronalPos", value );
updateSlices();
}
void WNavigationSliceModule::sliderSagittalMoved( int value )
{
m_sagittalSlice = value;
m_properties.setValue( "sagittalPos", value );
updateSlices();
}
void WNavigationSliceModule::buttonAxialChanged( bool check )
{
m_showAxial = check;
m_properties.setValue( "showAxial", check );
updateSlices();
}
void WNavigationSliceModule::buttonCoronalChanged( bool check )
{
m_showCoronal = check;
m_properties.setValue( "showCoronal", check );
updateSlices();
}
void WNavigationSliceModule::buttonSagittalChanged( bool check )
{
m_showSagittal = check;
m_properties.setValue( "showSagittal", check );
updateSlices();
}
......@@ -36,11 +36,12 @@
#include "../../kernel/WModuleInputData.hpp"
#include "../../graphicsEngine/WShader.h"
#include "../../kernel/WProperties.h"
// TODO(schurade): fix description
/**
* \par Description:
*
*
* Simple module for testing some WKernel functionality.
*/
class WNavigationSliceModule: public WModule
......@@ -87,14 +88,14 @@ protected:
*/
virtual void threadMain();
/**
/**
* Initialize the connectors this module is using.
*/
virtual void connectors();
/**
/**
* Receive DATA_CHANGE notifications.
*
*
* \param input the input connector that got the change signal. Typically it is one of the input connectors from this module.
* \param output the output connector that sent the signal. Not part of this module instance.
*/
......@@ -136,21 +137,10 @@ private:
/**
* TODO(schurade): add comment
*/
bool m_textureAssigned;
int m_axialSlice;
int m_coronalSlice;
int m_sagittalSlice;
WProperties m_properties;
int m_maxAxial;
int m_maxCoronal;
int m_maxSagittal;
bool m_showAxial;
bool m_showCoronal;
bool m_showSagittal;
/**
/**
* Input connector required by this module.
*/
boost::shared_ptr<WModuleInputData<std::list<boost::shared_ptr<WDataSet> > > > m_Input;
......
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