1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
28
#include "core/kernel/WKernel.h"
29
#include "core/dataHandler/WDataHandler.h"
30
#include "core/graphicsEngine/WGEColormapping.h"
32
#include "WMFunctionalMRIViewer.h"
34
// This line is needed by the module loader to actually find your module. Do not remove. Do NOT add a ";" here.
35
W_LOADABLE_MODULE( WMFunctionalMRIViewer )
37
WMFunctionalMRIViewer::WMFunctionalMRIViewer():
42
WMFunctionalMRIViewer::~WMFunctionalMRIViewer()
47
boost::shared_ptr< WModule > WMFunctionalMRIViewer::factory() const
49
// See "src/modules/template/" for an extensively documented example.
50
return boost::shared_ptr< WModule >( new WMFunctionalMRIViewer() );
53
const char** WMFunctionalMRIViewer::getXPMIcon() const
57
const std::string WMFunctionalMRIViewer::getName() const
59
return "Functional MRI Viewer";
62
const std::string WMFunctionalMRIViewer::getDescription() const
64
return "Allows to select a point of time and to show the dataset at that point of time.";
67
void WMFunctionalMRIViewer::connectors()
69
m_input = boost::shared_ptr< WModuleInputData< WDataSetTimeSeries > >(
70
new WModuleInputData< WDataSetTimeSeries >( shared_from_this(),
71
"in", "A time series." )
74
m_output = boost::shared_ptr< WModuleOutputData< WDataSetScalar > >(
75
new WModuleOutputData< WDataSetScalar >( shared_from_this(),
76
"out", "The selected time slice." ) );
78
addConnector( m_input );
79
addConnector( m_output );
81
WModule::connectors();
84
void WMFunctionalMRIViewer::properties()
86
m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
88
m_time = m_properties->addProperty( "Time", "The current time.", 0.0, m_propCondition );
89
m_time->setMax( 1.0 );
90
m_time->setMin( 0.0 );
92
m_texScaleNormalized = m_properties->addProperty( "Norm. Tex Scale", "Use the same texture scaling for all textures.", true, m_propCondition );
94
WModule::properties();
97
void WMFunctionalMRIViewer::moduleMain()
99
m_moduleState.setResetable( true, true );
100
m_moduleState.add( m_propCondition );
104
while( !m_shutdownFlag() )
106
debugLog() << "Waiting.";
107
m_moduleState.wait();
109
boost::shared_ptr< WDataSetTimeSeries > inData = m_input->getData();
110
bool dataChanged = ( m_dataSet != inData );
111
if( ( dataChanged && inData ) || ( m_dataSet && m_time->changed() ) )
113
// remove old texture
114
if( m_dataSetAtTime )
116
m_properties->removeProperty( m_dataSetAtTime->getTexture()->getProperties() );
117
m_infoProperties->removeProperty( m_dataSetAtTime->getTexture()->getInformationProperties() );
118
WGEColormapping::deregisterTexture( m_dataSetAtTime->getTexture() );
119
m_dataSetAtTime.reset();
122
m_time->setMin( m_dataSet->getMinTime() );
123
m_time->setMax( m_dataSet->getMaxTime() );
124
m_time->ensureValidity( m_dataSet->getMinTime() );
125
float time = m_time->get( true );
128
s << m_dataSet->getFileName() << "_time" << time;
129
boost::shared_ptr< WDataSetScalar const > ds = m_dataSet->calcDataSetAtTime( time, s.str() );
130
// get rid of the const
131
m_dataSetAtTime = boost::shared_ptr< WDataSetScalar >( new WDataSetScalar( ds->getValueSet(), ds->getGrid() ) );
133
if( m_dataSetAtTime )
135
WGEColormapping::registerTexture( m_dataSetAtTime->getTexture(), s.str() );
136
m_properties->addProperty( m_dataSetAtTime->getTexture()->getProperties() );
137
m_infoProperties->addProperty( m_dataSetAtTime->getTexture()->getInformationProperties() );
138
if( m_texScaleNormalized->get( true ) )
140
m_dataSetAtTime->getTexture()->minimum()->set( static_cast< float >( m_dataSet->getMinValue() ) );
141
m_dataSetAtTime->getTexture()->scale()->set( static_cast< float >( m_dataSet->getMaxValue() - m_dataSet->getMinValue() ) );
144
m_output->updateData( m_dataSetAtTime );
148
if( m_dataSetAtTime )
150
m_properties->removeProperty( m_dataSetAtTime->getTexture()->getProperties() );
151
m_infoProperties->removeProperty( m_dataSetAtTime->getTexture()->getInformationProperties() );
152
WGEColormapping::deregisterTexture( m_dataSetAtTime->getTexture() );
153
m_dataSetAtTime.reset();