~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/modules/functionalMRIViewer/WMFunctionalMRIViewer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV-Leipzig and CNCF-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#include <string>
 
26
#include <sstream>
 
27
 
 
28
#include "core/kernel/WKernel.h"
 
29
#include "core/dataHandler/WDataHandler.h"
 
30
#include "core/graphicsEngine/WGEColormapping.h"
 
31
 
 
32
#include "WMFunctionalMRIViewer.h"
 
33
 
 
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 )
 
36
 
 
37
WMFunctionalMRIViewer::WMFunctionalMRIViewer():
 
38
    WModule()
 
39
{
 
40
}
 
41
 
 
42
WMFunctionalMRIViewer::~WMFunctionalMRIViewer()
 
43
{
 
44
    // Cleanup!
 
45
}
 
46
 
 
47
boost::shared_ptr< WModule > WMFunctionalMRIViewer::factory() const
 
48
{
 
49
    // See "src/modules/template/" for an extensively documented example.
 
50
    return boost::shared_ptr< WModule >( new WMFunctionalMRIViewer() );
 
51
}
 
52
 
 
53
const char** WMFunctionalMRIViewer::getXPMIcon() const
 
54
{
 
55
    return NULL;
 
56
}
 
57
const std::string WMFunctionalMRIViewer::getName() const
 
58
{
 
59
    return "Functional MRI Viewer";
 
60
}
 
61
 
 
62
const std::string WMFunctionalMRIViewer::getDescription() const
 
63
{
 
64
    return "Allows to select a point of time and to show the dataset at that point of time.";
 
65
}
 
66
 
 
67
void WMFunctionalMRIViewer::connectors()
 
68
{
 
69
    m_input = boost::shared_ptr< WModuleInputData< WDataSetTimeSeries > >(
 
70
                            new WModuleInputData< WDataSetTimeSeries >( shared_from_this(),
 
71
                                "in", "A time series." )
 
72
            );
 
73
 
 
74
    m_output = boost::shared_ptr< WModuleOutputData< WDataSetScalar > >(
 
75
                            new WModuleOutputData< WDataSetScalar >( shared_from_this(),
 
76
                                "out", "The selected time slice." ) );
 
77
 
 
78
    addConnector( m_input );
 
79
    addConnector( m_output );
 
80
 
 
81
    WModule::connectors();
 
82
}
 
83
 
 
84
void WMFunctionalMRIViewer::properties()
 
85
{
 
86
    m_propCondition = boost::shared_ptr< WCondition >( new WCondition() );
 
87
 
 
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 );
 
91
 
 
92
    m_texScaleNormalized = m_properties->addProperty( "Norm. Tex Scale", "Use the same texture scaling for all textures.", true, m_propCondition );
 
93
 
 
94
    WModule::properties();
 
95
}
 
96
 
 
97
void WMFunctionalMRIViewer::moduleMain()
 
98
{
 
99
    m_moduleState.setResetable( true, true );
 
100
    m_moduleState.add( m_propCondition );
 
101
 
 
102
    ready();
 
103
 
 
104
    while( !m_shutdownFlag() )
 
105
    {
 
106
        debugLog() << "Waiting.";
 
107
        m_moduleState.wait();
 
108
 
 
109
        boost::shared_ptr< WDataSetTimeSeries > inData = m_input->getData();
 
110
        bool dataChanged = ( m_dataSet != inData );
 
111
        if( ( dataChanged && inData ) || ( m_dataSet && m_time->changed() ) )
 
112
        {
 
113
            // remove old texture
 
114
            if( m_dataSetAtTime )
 
115
            {
 
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();
 
120
            }
 
121
            m_dataSet = inData;
 
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 );
 
126
 
 
127
            std::stringstream s;
 
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() ) );
 
132
 
 
133
            if( m_dataSetAtTime )
 
134
            {
 
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 ) )
 
139
                {
 
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() ) );
 
142
                }
 
143
            }
 
144
            m_output->updateData( m_dataSetAtTime );
 
145
        }
 
146
    }
 
147
 
 
148
    if( m_dataSetAtTime )
 
149
    {
 
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();
 
154
    }
 
155
}