OpenWalnut  1.5.0dev
WMDiffTensorScalars.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2015 OpenWalnut Community, Nemtics, BSV@Uni-Leipzig
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 
28 #include "WAD.h"
29 #include "WFA.h"
30 #include "WMD.h"
31 #include "WMDiffTensorScalars.h"
32 #include "WRA.h"
33 #include "WRD.h"
34 #include "WTensorTrace.h"
35 #include "core/kernel/WModuleFactory.h"
36 
37 W_LOADABLE_MODULE( WMDiffTensorScalars )
38 
40  : WModuleContainer( "Diffusion Tensor Scalars", "Computes various scalar measures for a given diffusion tensor field (2nd order)." ),
41  m_strategy( "Scalar indices derived from tensors.", "Select one algorithm" )
42 {
43  m_strategy.addStrategy( WTensorTrace::SPtr( new WFA() ) );
44  m_strategy.addStrategy( WTensorTrace::SPtr( new WRA() ) );
45  m_strategy.addStrategy( WTensorTrace::SPtr( new WAD() ) );
46  m_strategy.addStrategy( WTensorTrace::SPtr( new WMD() ) );
47  m_strategy.addStrategy( WTensorTrace::SPtr( new WRD() ) );
48  m_strategy.addStrategy( WTensorTrace::SPtr( new WTensorTrace() ) );
49 }
50 
52 {
53 }
54 
55 std::shared_ptr< WModule > WMDiffTensorScalars::factory() const
56 {
57  return std::shared_ptr< WModule >( new WMDiffTensorScalars() );
58 }
59 
61 {
62  m_tensorsIC = WModuleInputForwardData< WDataSetDTI >::createAndAdd( shared_from_this(), "tensorInput",
63  "DataSetDTI storing the tensor field" );
64 
65  // math: I do not know how to hide this connector in network editor, as it is for internal use only
66  m_evalsIC = WModuleInputData< WDataSetVector >::createAndAdd( shared_from_this(), "eigenValues",
67  "EigenValues from the internal ÉigenSystem module" );
68 
69  m_scalarOC = WModuleOutputData< WDataSetScalar >::createAndAdd( shared_from_this(), "scalars",
70  "The computed scalar dataset derived from the given tensor dataset" );
71 
73 }
74 
76 {
77  m_properties->addProperty( m_strategy.getProperties() );
78 
80 }
81 
83 {
85 
86  m_moduleState.setResetable( true, true );
87  m_moduleState.add( m_strategy.getProperties()->getUpdateCondition() );
88 
89  // math: for several measures we need the eigenvalues from our submodule. Once they are computed
90  // we need to proceed. Hence we need the dataChanged condition in our module state. But beware
91  // there is also the tensor data input giving us events for the module main loop.
92  m_moduleState.add( m_eigenSystem->getOutputConnector( "evalsOutput" )->getDataChangedCondition() );
93 
94  ready();
95 
96  while( !m_shutdownFlag() )
97  {
98  debugLog() << "Waiting...";
99 
101 
102  std::shared_ptr< WModuleOutputConnector > evalConnector = m_eigenSystem->getOutputConnector( "evalsOutput" );
104  std::shared_ptr< OCType > evalsOC = std::dynamic_pointer_cast< OCType >( evalConnector );
105  if( evalsOC )
106  {
107  m_evals = evalsOC->getData();
108  m_tensors = m_tensorsIC->getData();
109  }
110 
111  if( !m_tensors || !m_evals )
112  {
113  continue;
114  }
115 
116  // Strategy anwenden
117  debugLog() << "Start computing scalars...";
118 
119  WProgress::SPtr progress( new WProgress( "Creating Dataset", m_evals->getGrid()->size() ) );
120  m_progress->addSubProgress( progress );
121 
122  m_scalarOC->updateData( m_strategy()->operator()( progress, m_shutdownFlag, m_tensors, m_evals ) );
123 
124  progress->finish();
125  m_progress->removeSubProgress( progress );
126 
127  debugLog() << "Created scalar data done";
128 
129  if( m_shutdownFlag() )
130  {
131  break;
132  }
133  }
134 }
135 
137 {
138  // instantiation
140  "Eigen System" ) ); // NOLINT
141  add( m_eigenSystem );
142  m_eigenSystem->isReady().wait();
143 
144  // wiring
145  debugLog() << "Start wiring";
146  m_tensorsIC->forward( m_eigenSystem->getInputConnector( "tensorInput" ) );
147  debugLog() << "Wiring done";
148 
149  // add proporties of submodules
150  m_properties->addPropertyGroup( "EigenSystem", "Props" )->addProperty( m_eigenSystem->getProperties() );
151 }
Computes the AD (Axional Diffusivity) of a given Tensor.
Definition: WAD.h:41
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.
Computes the FA (Fractional Anisotropy, see: https://en.wikipedia.org/wiki/Fractional_anisotropy) of ...
Definition: WFA.h:49
Computes the MD (Mean Diffusivity) of a given Tensor.
Definition: WMD.h:41
Computes a scalar dataset for a given tensor dataset.
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::shared_ptr< WModule > m_eigenSystem
Submodule doing computation of eigenvalues and eigenvectors.
WStrategyHelper< WObjectNDIP< WDataSetDTIToScalar_I > > m_strategy
the strategy currently active.
std::shared_ptr< WDataSetDTI > m_tensors
Dataset for the Tensors.
virtual void initSubModules()
Create and initialize submodule instances, wires them and forward connectors as well as some properti...
std::shared_ptr< WModuleInputForwardData< WDataSetDTI > > m_tensorsIC
Input connector required by this module.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_evalsIC
Internal input connector for the Eigenvalues computed by the submodule EigenSystem.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_scalarOC
Output connector for the computed scalars.
WMDiffTensorScalars()
Default constructor.
std::shared_ptr< WDataSetVector > m_evals
Dataset for the Eigenvalues.
virtual void properties()
Initialize the properties for this module.
virtual ~WMDiffTensorScalars()
Destructor.
virtual void moduleMain()
Entry point after loading the module.
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.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this in data connector with proper type and add it to ...
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this in forward data connector with proper type and ad...
Class offering an instantiate-able data connection between modules.
static PtrType createAndAdd(std::shared_ptr< WModule > module, std::string name="", std::string description="")
Convenience method to create a new instance of this out data connector with proper type and add it to...
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
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
Definition: WModule.h:652
virtual void connectors()
Initialize connectors in this function.
Definition: WModule.cpp:208
std::shared_ptr< WObjectNDIP > SPtr
Shared ptr to an instance.
Definition: WObjectNDIP.h:47
Class managing progress inside of modules.
Definition: WProgress.h:42
std::shared_ptr< WProgress > SPtr
Shared pointer on a WProgress.
Definition: WProgress.h:48
Computes the RA (Relative Anisotropy) of a given Tensor.
Definition: WRA.h:48
Computes the RD (Relative Diffusivity) of a given Tensor.
Definition: WRD.h:41
WProperties::SPtr getProperties() const
Get this strategy selectors properties.
Computes the trace (sum of diagonal elements) of the tensor.
Definition: WTensorTrace.h:41
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.