OpenWalnut  1.5.0dev
WMFiberResampling.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 <cmath>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #include <core/common/WPropertyHelper.h>
31 #include <core/common/WStrategyHelper.h>
32 #include <core/common/math/WMath.h>
33 #include <core/dataHandler/WDataHandler.h>
34 #include <core/kernel/WKernel.h>
35 
36 #include "WMFiberResampling.h"
37 #include "WMFiberResampling.xpm"
38 #include "WResampleByMaxPoints.h"
39 #include "WResampleByNumPoints.h"
40 #include "WResampleBySegLength.h"
41 #include "WResampleBySegLengthKeepShortFibers.h"
42 
43 W_LOADABLE_MODULE( WMFiberResampling )
44 
46  WModule(),
47  m_strategy( "Fiber Resampling Algorithms", "Select one algorithm to resample fibers", NULL,
48  "FiberResampling", "A list of all known resampling strategies" )
49 {
50  m_strategy.addStrategy( WResampleByNumPoints::SPtr( new WResampleByNumPoints() ) );
51  m_strategy.addStrategy( WResampleBySegLength::SPtr( new WResampleBySegLength() ) );
52  m_strategy.addStrategy( WResampleBySegLength::SPtr( new WResampleBySegLengthKeepShortFibers() ) );
53  m_strategy.addStrategy( WResampleByMaxPoints::SPtr( new WResampleByMaxPoints() ) );
54 }
55 
57 {
58 }
59 
60 std::shared_ptr< WModule > WMFiberResampling::factory() const
61 {
62  return std::shared_ptr< WModule >( new WMFiberResampling() );
63 }
64 
65 const char** WMFiberResampling::getXPMIcon() const
66 {
67  return WMFiberResampling_xpm;
68 }
69 
70 const std::string WMFiberResampling::getName() const
71 {
72  return "Fiber Re-Sampling";
73 }
74 
75 const std::string WMFiberResampling::getDescription() const
76 {
77  return "This module can re-sample a fiber dataset and ensure equal segment lengths.";
78 }
79 
81 {
82  m_fiberIC = WModuleInputData< WDataSetFibers >::createAndAdd( shared_from_this(), "fibers", "The line data to resample." );
83  m_fiberOC = WModuleOutputData< WDataSetFibers >::createAndAdd( shared_from_this(), "resampledFibers", "The resampled fiber dataset." );
84 
86 }
87 
89 {
90  m_properties->addProperty( m_strategy.getProperties() );
91 
93 }
94 
96 {
97  m_moduleState.setResetable( true, true );
98  m_moduleState.add( m_fiberIC->getDataChangedCondition() );
99  m_moduleState.add( m_strategy.getProperties()->getUpdateCondition() );
100 
101  ready();
102 
103  while( !m_shutdownFlag() )
104  {
105  debugLog() << "Waiting ...";
107 
108  if( m_shutdownFlag() )
109  {
110  break;
111  }
112 
113  WDataSetFibers::SPtr fibers = m_fiberIC->getData();
114 
115  if( !fibers )
116  {
117  continue;
118  }
119 
120  WProgress::SPtr progress( new WProgress( "Resampling Fibers", fibers->size() ) );
121  m_progress->addSubProgress( progress );
122  debugLog() << "Start resampling";
123  m_fiberOC->updateData( m_strategy()->operator()( progress, m_shutdownFlag, fibers ) );
124  progress->finish();
125  m_progress->removeSubProgress( progress );
126  debugLog() << "Finished resampling";
127  }
128 }
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.
std::shared_ptr< WDataSetFibers > SPtr
Pointer to dataset.
This modules takes a fiber dataset and samples it in regular steps.
std::shared_ptr< WModuleOutputData< WDataSetFibers > > m_fiberOC
The output connector used to provide the calculated data to other modules.
WStrategyHelper< WObjectNDIP< WResampling_I > > m_strategy
Strategies for coloring fibers.
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...
WMFiberResampling()
Default constructor.
virtual ~WMFiberResampling()
Destructor.
std::shared_ptr< WModuleInputData< WDataSetFibers > > m_fiberIC
The fiber dataset which is going to be filtered.
virtual const std::string getName() const
Gives back the name of this module.
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void moduleMain()
Entry point after loading the module.
virtual void properties()
Initialize the properties for this module.
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 out data connector with proper type and add it to...
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
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
Resamples fibers so no fiber has more than the given number of Points.
Resamples fibers to have a given number of points afterwards.
Resamples fibers by segment length.
WProperties::SPtr getProperties() const
Get this strategy selectors properties.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.