OpenWalnut  1.5.0dev
WMReadSphericalHarmonics.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 
28 #include "WMReadSphericalHarmonics.h"
29 #include "WMReadSphericalHarmonics.xpm"
30 #include "core/common/WPathHelper.h"
31 #include "core/dataHandler/WDataHandlerEnums.h"
32 #include "core/graphicsEngine/WGERequirement.h"
33 #include "core/kernel/WKernel.h"
34 #include "io/WReaderNIfTI.h"
35 
36 WMReadSphericalHarmonics::WMReadSphericalHarmonics():
37  WModule()
38 {
39 }
40 
41 WMReadSphericalHarmonics::~WMReadSphericalHarmonics()
42 {
43 }
44 
45 std::shared_ptr< WModule > WMReadSphericalHarmonics::factory() const
46 {
47  return std::shared_ptr< WModule >( new WMReadSphericalHarmonics() );
48 }
49 
51 {
52  return WMReadSphericalHarmonics_xpm;
53 }
54 const std::string WMReadSphericalHarmonics::getName() const
55 {
56  // Specify your module name here. This name must be UNIQUE!
57  return "Read Spherical Harmonics";
58 }
59 
61 {
62  return "This modules loads data from vectors in NIfTI files as SphericalHarmonicsDatasets.";
63 }
64 
66 {
67  m_output= std::shared_ptr< WModuleOutputData< WDataSetSphericalHarmonics > >( new WModuleOutputData< WDataSetSphericalHarmonics >(
68  shared_from_this(), "Spherical Harmonics", "A loaded spherical harmonics dataset." )
69  );
71 
73 }
74 
76 {
77  m_propCondition = std::shared_ptr< WCondition >( new WCondition() );
78  m_dataFile = m_properties->addProperty( "NIfTI file", "", WPathHelper::getAppPath() );
79  m_readTriggerProp = m_properties->addProperty( "Do read", "Press!", WPVBaseTypes::PV_TRIGGER_READY, m_propCondition );
81 
83 }
84 
86 {
87  m_requirements.push_back( new WGERequirement() );
88 }
89 
91 {
93  ready();
94  while( !m_shutdownFlag() )
95  {
97 
98  if( m_shutdownFlag() )
99  {
100  break;
101  }
102  std::string fileName = m_dataFile->get().string();
103 
104  std::shared_ptr< WProgress > progress;
105  progress = std::shared_ptr< WProgress >( new WProgress( "Reading ...", 2 ) );
106  m_progress->addSubProgress( progress );
107 
108  WReaderNIfTI niiLoader( fileName );
109  std::shared_ptr< WDataSet > data;
110  data = niiLoader.load( W_DATASET_SPHERICALHARMONICS );
111 
112  ++*progress;
113 
114  if( data )
115  {
116  m_data = std::dynamic_pointer_cast< WDataSetSphericalHarmonics >( data );
117  if( m_data )
118  {
119  m_runtimeName->set( string_utils::tokenize( fileName, "/" ).back() );
120  m_output->updateData( m_data );
121  }
122  }
124 
125  progress->finish();
126  }
127 }
virtual void wait() const
Wait for the condition.
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 requirement ensures an up and running WGE.
This module loads spherical harmonics data given as vectors of coefficients from NIfTI files.
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 const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropTrigger m_readTriggerProp
This property triggers the actual reading,.
virtual void properties()
Initialize the properties for this module.
virtual void requirements()
Initialize requirements for this module.
virtual const std::string getName() const
Gives back the name of this module.
WPropFilename m_dataFile
The data will be read from this file.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void moduleMain()
Entry point after loading the module.
virtual const std::string getDescription() const
Gives back a description of this module.
std::shared_ptr< WDataSetSphericalHarmonics > m_data
This triangle mesh is provided as output through the connector.
std::shared_ptr< WModuleOutputData< WDataSetSphericalHarmonics > > m_output
Ouput connector provided by this module.
virtual void connectors()
Initialize the connectors this module is using.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
Definition: WModule.h:72
Requirements m_requirements
The list of requirements.
Definition: WModule.h:754
virtual void properties()
Initialize properties in this function.
Definition: WModule.cpp:212
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
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
WPropString m_runtimeName
This property holds a user specified name for the current module instance.
Definition: WModule.h:728
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
static boost::filesystem::path getAppPath()
The path where the binary file resides in.
Definition: WPathHelper.cpp:93
Class managing progress inside of modules.
Definition: WProgress.h:42
Reader for the NIfTI file format.
Definition: WReaderNIfTI.h:43
virtual std::shared_ptr< WDataSet > load(DataSetType dataSetType=W_DATASET_NONE)
Loads the dataset.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.
std::vector< std::string > tokenize(const std::string &source, const std::string &delim=WHITESPACE, bool compress=true)
Splits the given string into a vector of strings (so called tokens).