33 #include <boost/variant.hpp>
35 #include "WMVectorScale.h"
36 #include "core/common/WAssert.h"
37 #include "core/common/WProgress.h"
38 #include "core/common/WStringUtils.h"
39 #include "core/common/WTypeTraits.h"
40 #include "core/common/exceptions/WTypeMismatch.h"
41 #include "core/dataHandler/WDataHandler.h"
42 #include "core/dataHandler/WDataHandlerEnums.h"
43 #include "core/dataHandler/WGridRegular3D.h"
44 #include "core/dataHandler/exceptions/WDHValueSetMismatch.h"
45 #include "core/kernel/WKernel.h"
69 return "Vector Scaling";
74 return "Scales the given vector field by the given scalar field.";
100 template<
typename VSetAType >
101 class VisitorVSetB:
public boost::static_visitor< std::shared_ptr< WValueSetBase > >
111 boost::static_visitor< result_type >(),
124 template <
typename VSetBType >
131 std::vector< ResultT > data;
140 const VSetBType* b = vsetB->rawData();
141 for(
size_t i = 0; i < vsetB->rawSize(); ++i )
144 data[ vi + 0 ] =
static_cast< ResultT
>( a[ vi + 0 ] ) *
static_cast< ResultT
>( b[ i ] );
145 data[ vi + 1 ] =
static_cast< ResultT
>( a[ vi + 1 ] ) *
static_cast< ResultT
>( b[ i ] );
146 data[ vi + 2 ] =
static_cast< ResultT
>( a[ vi + 2 ] ) *
static_cast< ResultT
>( b[ i ] );
150 std::shared_ptr< WValueSet< ResultT > > result = std::shared_ptr< WValueSet< ResultT > >(
153 std::shared_ptr< std::vector< ResultT > >(
new std::vector< ResultT >( data ) ),
169 class VisitorVSetA:
public boost::static_visitor< std::shared_ptr< WValueSetBase > >
178 boost::static_visitor< result_type >(),
191 template <
typename T >
233 std::shared_ptr< WDataSetVector > dataSetA =
m_inputA->getData();
234 std::shared_ptr< WDataSetScalar > dataSetB =
m_inputB->getData();
235 if( !dataSetA || !dataSetB )
244 std::shared_ptr< WValueSetBase > valueSetA = dataSetA->getValueSet();
245 std::shared_ptr< WValueSetBase > valueSetB = dataSetB->getValueSet();
248 std::shared_ptr< WProgress > prog = std::shared_ptr< WProgress >(
249 new WProgress(
"Applying operator on data" ) );
256 bool match = ( valueSetA->rawSize() == 3 * valueSetB->rawSize() );
259 errorLog() <<
"Rawsize Mismatch: " << valueSetA->rawSize() <<
" != 3 * " << valueSetB->rawSize();
264 std::shared_ptr< WValueSetBase > newValueSet;
266 newValueSet = valueSetA->applyFunction( visitor );
Visitor for discriminating the type of the first valueset.
VisitorVSetA(WValueSetBase *vsetB)
Create visitor instance.
result_type operator()(const WValueSet< T > *const &vsetA) const
Called by boost::varying during static visiting.
WValueSetBase * m_vsetB
The valueset where to cascade.
The second visitor which got applied to the second value set.
result_type operator()(const WValueSet< VSetBType > *const &vsetB) const
Visitor on the second valueset.
const WValueSet< VSetAType > *const m_vsetA
The first valueset.
VisitorVSetB(const WValueSet< VSetAType > *const vsetA)
Creates visitor for the second level of cascading.
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.
Class to encapsulate boost::condition_variable_any.
An exception that should be used whenever two valuesets are used which need to be of same size,...
This data set type contains vectors as values.
Operators for processing a vector with a WDataSetScalar.
~WMVectorScale()
Destructor.
WMVectorScale()
Standard constructor.
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< WModuleInputData< WDataSetScalar > > m_inputB
Input connector required by this module.
virtual const std::string getName() const
Gives back the name of this module.
virtual void properties()
Initialize the properties for this module.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
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 void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_inputA
Input connector required by this module.
std::shared_ptr< WModuleOutputData< WDataSetVector > > m_output
The only output of this filter module.
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.
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 ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
wlog::WStreamedLogger errorLog() const
Logger instance for comfortable error logging.
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.
Abstract base class to all WValueSets.
Func_T::result_type applyFunction(Func_T const &func)
Apply a function object to this valueset.
const T * rawData() const
Sometimes we need raw access to the data array, for e.g.
virtual size_t rawSize() const
dataType
Data types and number values taken from the nifti1.h, at this point it's unknown if it makes sense to...
An object that knows an appropriate dataType flag for the typename T.