33 #include <boost/variant.hpp>
35 #include "WMVectorNormalize.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 Normalize";
74 return "Normalize a vector field.";
101 class VisitorVSetA:
public boost::static_visitor< std::shared_ptr< WValueSetBase > >
110 boost::static_visitor< result_type >(),
123 template <
typename T >
127 std::vector< T > data;
128 data.resize( vsetA->rawSize() );
132 for(
size_t i = 0; i < vsetA->size(); ++i )
135 double x = vsetA->getScalar( ( i * 3 ) + 0 );
136 double y = vsetA->getScalar( ( i * 3 ) + 1 );
137 double z = vsetA->getScalar( ( i * 3 ) + 2 );
139 double len = sqrt( ( x * x ) + ( y * y ) + ( z * z ) );
142 data[ ( i * 3 ) + 0 ] = 0;
143 data[ ( i * 3 ) + 1 ] = 0;
144 data[ ( i * 3 ) + 2 ] = 0;
149 data[ ( i * 3 ) + 0 ] =
static_cast< T
>( x / len );
150 data[ ( i * 3 ) + 1 ] =
static_cast< T
>( y / len );
151 data[ ( i * 3 ) + 2 ] =
static_cast< T
>( z / len );
157 std::shared_ptr< std::vector< T > >(
158 new std::vector< T >( data ) ),
195 std::shared_ptr< WDataSetVector > dataSetA =
m_inputA->getData();
200 std::shared_ptr< WValueSetBase > valueSetA = dataSetA->getValueSet();
203 std::shared_ptr< WProgress > prog = std::shared_ptr< WProgress >(
204 new WProgress(
"Applying operator on data" ) );
209 std::shared_ptr< WValueSetBase > newValueSet = valueSetA->applyFunction(
VisitorVSetA(
m_zeroTol->get(
true ) ) );
Visitor for discriminating the type of the first valueset.
result_type operator()(const WValueSet< T > *const &vsetA) const
Called by boost::varying during static visiting.
double m_zeroTol
Zero tollerance.
VisitorVSetA(double zeroTol)
Create visitor instance.
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.
This data set type contains vectors as values.
Operator for normalizing vectors.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WDataSetVector > > m_output
The only output of this filter module.
virtual void properties()
Initialize the properties for this module.
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.
~WMVectorNormalize()
Destructor.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_inputA
Input connector required by this module.
virtual void moduleMain()
Entry point after loading the module.
WPropDouble m_zeroTol
Zero Tollerance.
WMVectorNormalize()
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...
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.
std::shared_ptr< WProperties > m_properties
The property object for the module.
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.
An object that knows an appropriate dataType flag for the typename T.