OpenWalnut  1.5.0dev
WMProbTractDisplay.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 <string>
27 #include <vector>
28 
29 #include "WMProbTractDisplay.h"
30 #include "WMProbTractDisplay.xpm"
31 #include "core/common/WStringUtils.h"
32 #include "core/dataHandler/WDataSetScalar.h"
33 #include "core/kernel/WModuleFactory.h"
34 #include "core/kernel/WModuleInputForwardData.h"
35 
36 // This line is needed by the module loader to actually find your module.
37 W_LOADABLE_MODULE( WMProbTractDisplay )
38 
41 {
42 }
43 
45 {
46 }
47 
48 std::shared_ptr< WModule > WMProbTractDisplay::factory() const
49 {
50  return std::shared_ptr< WModule >( new WMProbTractDisplay() );
51 }
52 
53 const char** WMProbTractDisplay::getXPMIcon() const
54 {
55  return probtractdisplay_xpm;
56 }
57 
58 const std::string WMProbTractDisplay::getName() const
59 {
60  return "Probabilistic Tract Rendering with multi transparent iso surfaces.";
61 }
62 
63 const std::string WMProbTractDisplay::getDescription() const
64 {
65  return "This module display probabilistic DTI tractograms with iso surfaces.";
66 }
67 
69 {
71  "probTractInput",
72  "The probabilistic tractogram as scalar dataset." );
74 }
75 
77 {
79 }
80 
82 {
83  m_moduleState.setResetable( true, true );
84  m_moduleState.add( m_input->getDataChangedCondition() );
86  ready();
87  debugLog() << "Module is now ready.";
88  while( !m_shutdownFlag() )
89  {
90  debugLog() << "Waiting ...";
92 
93  if( m_shutdownFlag() )
94  {
95  break;
96  }
97  }
98 }
99 
101 {
102  static WColor colorInit[] = { defaultColor::GREEN, defaultColor::BLUE, defaultColor::RED }; // NOLINT curly braces
103  std::vector< WColor > preDefinedColors( colorInit, colorInit + sizeof colorInit / sizeof colorInit[ 0 ] );
104 
105  static int init[] = { 100, 30, 0 }; // NOLINT
106  std::vector< int > preDefinedOpacities( init, init + sizeof init / sizeof init[ 0 ] );
107 
108  WAssert( preDefinedOpacities.size() == preDefinedColors.size(), "preDefinedColors.size() many iso surfaces => so many colors are needed!" );
109 
110  // The reason for only having three iso surfaces is just simplicity, you may change it as you need, or even make it dynamically if you want
111  for( size_t i = 0; i < preDefinedOpacities.size(); ++i )
112  {
113  m_isoSurfaces.push_back( WModuleFactory::getModuleFactory()->create( WModuleFactory::getModuleFactory()->getPrototypeByName( "Isosurface" ) ) ); // NOLINT
114  add( m_isoSurfaces.back() );
115  m_isoSurfaces.back()->isReady().wait();
116 
117  // forward data
118  m_input->forward( m_isoSurfaces.back()->getInputConnector( "values" ) );
119 
120  // forward properties of interest, the reason for grouping is: property container cannot hold not-unique names
121  std::string isoSurfaceNum = string_utils::toString( i );
122  WPropGroup m_group = m_properties->addPropertyGroup( "Isosurface " + isoSurfaceNum, "Property group for isosurface " + isoSurfaceNum );
123  WPropDouble p0 = m_isoSurfaces.back()->getProperties()->getProperty( "Iso value" )->toPropDouble();
124  p0->setMax( 1000.0 );
125  p0->set( 1000.0 );
126  m_group->addProperty( p0 );
127  WPropInt p1 = m_isoSurfaces.back()->getProperties()->getProperty( "Opacity %" )->toPropInt();
128  p1->set( preDefinedOpacities[i] );
129  m_group->addProperty( p1 );
130  WPropColor p2 = m_isoSurfaces.back()->getProperties()->getProperty( "Surface color" )->toPropColor();
131  p2->set( preDefinedColors[i] );
132  m_group->addProperty( p2 );
133  }
134 }
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.
This module generates a visualization of probabilistic tracts using iso surfaces.
WMProbTractDisplay()
Default constructor.
virtual void moduleMain()
Entry point after loading the module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual const std::string getName() const
Gives back the name of this module.
std::shared_ptr< WModuleInputForwardData< WDataSetScalar > > m_input
Scalar dataset representing the probability field either in real numbers in [0,1] or gray values or j...
virtual void properties()
Initialize the properties for this module.
virtual ~WMProbTractDisplay()
Destructor.
virtual void connectors()
Initialize the connectors this module is using.
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...
std::vector< std::shared_ptr< WModule > > m_isoSurfaces
Submodules for the iso surface generation.
virtual const std::string getDescription() const
Gives back a description of this module.
void initSubModules()
In order to use sub modules we need to create, initialize (properties) and wire them.
Class able to contain other modules.
virtual void add(std::shared_ptr< WModule > module, bool run=true)
Add a module to this container and start it.
static SPtr getModuleFactory()
Returns instance of the module factory to use to create modules.
This is a simple class which forwards input data to input data connectors.
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
std::shared_ptr< WProperties > m_properties
The property object for the module.
Definition: WModule.h:640
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.
std::string toString(const T &value)
Convert a given value to a string.
Definition: WStringUtils.h:120