34 #include "WMApplyMask.h"
35 #include "WMApplyMask.xpm"
36 #include "core/common/WAssert.h"
37 #include "core/common/WProgress.h"
38 #include "core/kernel/WKernel.h"
58 return std::shared_ptr< WModule >(
new WMApplyMask() );
63 return apply_mask_xpm;
73 return "Applies a mask to a data set, i.e. sets all voxels to zero which are zero in the mask.";
96 debugLog() <<
"Waiting for data ...";
103 case W_DT_UNSIGNED_CHAR:
105 std::shared_ptr< WValueSet< unsigned char > > vals;
106 vals = std::dynamic_pointer_cast< WValueSet< unsigned char > >( ( *m_dataSet ).getValueSet() );
107 WAssert( vals,
"Data type and data type indicator must fit." );
113 std::shared_ptr< WValueSet< int16_t > > vals;
114 vals = std::dynamic_pointer_cast< WValueSet< int16_t > >( ( *m_dataSet ).getValueSet() );
115 WAssert( vals,
"Data type and data type indicator must fit." );
119 case W_DT_SIGNED_INT:
121 std::shared_ptr< WValueSet< int32_t > > vals;
122 vals = std::dynamic_pointer_cast< WValueSet< int32_t > >( ( *m_dataSet ).getValueSet() );
123 WAssert( vals,
"Data type and data type indicator must fit." );
129 std::shared_ptr< WValueSet< float > > vals;
130 vals = std::dynamic_pointer_cast< WValueSet< float > >( ( *m_dataSet ).getValueSet() );
131 WAssert( vals,
"Data type and data type indicator must fit." );
137 std::shared_ptr< WValueSet< double > > vals;
138 vals = std::dynamic_pointer_cast< WValueSet< double > >( ( *m_dataSet ).getValueSet() );
139 WAssert( vals,
"Data type and data type indicator must fit." );
144 throw WException( std::string(
"Data type of value set not supported by this module." ) );
157 shared_from_this(),
"dataSet",
"The dataset to apply the mask to." ) );
163 m_maskInput = std::shared_ptr< WModuleInputData< WDataSetScalar > >(
165 "The mask applied to the data." ) );
171 m_output = std::shared_ptr< WModuleOutputData< WDataSetScalar > >(
173 "The filtered data set." ) );
189 std::shared_ptr< WValueSetBase > maskBase =
m_mask->getValueSet();
190 std::shared_ptr< WValueSet< float > > mask = std::dynamic_pointer_cast< WValueSet< float > >( maskBase );
194 throw WException( std::string(
"Mask is not of type float." ) );
197 std::shared_ptr< WProgress > progress(
new WProgress(
"Apply Mask", valSet->size() ) );
200 std::shared_ptr< std::vector< T > > newVals(
new std::vector< T >( valSet->size() ) );
201 for(
size_t i = 0; i < valSet->size(); ++i )
204 if( mask->getScalar( i ) == 0 )
210 ( *newVals )[i] = valSet->getScalar( i );
215 std::shared_ptr< WValueSet< T > > valueSet;
216 valueSet = std::shared_ptr< WValueSet< T > >(
new WValueSet< T >( 0, 1, newVals, type ) );
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 data set type contains scalars as values.
Set all voxels in a dataset to zero if the other dataset is zero there.
WMApplyMask()
Standard constructor.
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< WDataSetScalar > m_dataSet
Pointer providing access to the data set in the whole module.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_dataInput
Input connector for getting the data.
virtual void moduleMain()
Entry point after loading the module.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WDataSetScalar > m_mask
Pointer providing access to the mask in the whole module.
void applyMask(std::shared_ptr< WValueSet< T > > valSet, dataType type)
Apply the mask to the data.
virtual const std::string getName() const
Gives back the name of this module.
virtual const std::string getDescription() const
Gives back a description of this module.
~WMApplyMask()
Destructor.
std::shared_ptr< WModuleInputData< WDataSetScalar > > m_maskInput
Input connector for getting the mask.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The only output of this mask module.
std::shared_ptr< WDataSetScalar > m_dataSetOut
Pointer providing access to the resulting data set in the whole module.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
void removeConnectors()
Removes all connectors properly.
void addConnector(std::shared_ptr< WModuleInputConnector > con)
Adds the specified connector to the list of inputs.
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
virtual void connectors()
Initialize connectors in this function.
Class managing progress inside of modules.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...