OpenWalnut  1.5.0dev
WMFunctionalMRIViewer.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-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 <memory>
26 #include <sstream>
27 #include <string>
28 
29 #include "WMFunctionalMRIViewer.h"
30 #include "core/dataHandler/WDataHandler.h"
31 #include "core/graphicsEngine/WGEColormapping.h"
32 #include "core/kernel/WKernel.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 
38  WModule()
39 {
40 }
41 
43 {
44  // Cleanup!
45 }
46 
47 std::shared_ptr< WModule > WMFunctionalMRIViewer::factory() const
48 {
49  // See "src/modules/template/" for an extensively documented example.
50  return std::shared_ptr< WModule >( new WMFunctionalMRIViewer() );
51 }
52 
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 one to select a point of time and to show the dataset at that point of time.";
65 }
66 
68 {
69  m_input = std::shared_ptr< WModuleInputData< WDataSetTimeSeries > >(
70  new WModuleInputData< WDataSetTimeSeries >( shared_from_this(),
71  "in", "A time series." )
72  );
73 
74  m_output = std::shared_ptr< WModuleOutputData< WDataSetScalar > >(
75  new WModuleOutputData< WDataSetScalar >( shared_from_this(),
76  "out", "The selected time slice." ) );
77 
80 
82 }
83 
85 {
86  m_propCondition = std::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 
95 }
96 
98 {
99  m_moduleState.setResetable( true, true );
101 
102  ready();
103 
104  while( !m_shutdownFlag() )
105  {
106  debugLog() << "Waiting.";
108 
109  std::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() );
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  std::shared_ptr< WDataSetScalar const > ds = m_dataSet->calcDataSetAtTime( time, s.str() );
130  // get rid of the const
131  m_dataSetAtTime = std::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() );
153  m_dataSetAtTime.reset();
154  }
155 }
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42
This data set type contains scalars as values.
static void registerTexture(osg::ref_ptr< WGETexture3D > texture, std::string name="")
Register the specified texture to the colormapper.
static void deregisterTexture(osg::ref_ptr< WGETexture3D > texture)
De-register the specified texture to the colormapper.
Views a time series at different points in time.
std::shared_ptr< WDataSetTimeSeries > m_dataSet
The current input.
std::shared_ptr< WDataSetScalar > m_dataSetAtTime
The dataset at the current time.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
virtual void moduleMain()
Entry point after loading the module.
WPropBool m_texScaleNormalized
True, iff all textures should be scaled to the same intervall.
virtual ~WMFunctionalMRIViewer()
Standard destructor.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropDouble m_time
The current time.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleInputData< WDataSetTimeSeries > > m_input
The input connector for the time series.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The output connector for the currently selected time slice.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
std::shared_ptr< WCondition > m_propCondition
A condition for property changes.
virtual void properties()
Initialize the properties for this module.
virtual const std::string getName() const
Gives back the name of this module.
WMFunctionalMRIViewer()
Standard constructor.
Class offering an instantiate-able data connection between modules.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
Definition: WModule.cpp:575
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
Definition: WModule.cpp:108
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
Definition: WModule.h:647
void ready()
Call this whenever your module is ready and can react on property changes.
Definition: WModule.cpp:505
WConditionSet m_moduleState
The internal state of the module.
Definition: WModule.h:703
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.