29 #include "WMVectorAlign.h"
30 #include "WMVectorAlign.xpm"
31 #include "core/dataHandler/WDataSetVector.h"
32 #include "core/kernel/WKernel.h"
37 WMVectorAlign::WMVectorAlign():
42 WMVectorAlign::~WMVectorAlign()
53 return WMVectorAlign_xpm;
58 return "Vector Align";
63 return "Aligns vectors of each grid cell, so they are aligned in same halfspace.";
70 "Dataset where vectors are aligned inside the halfspace" );
86 std::shared_ptr< WDataSetVector > alignVectors( std::shared_ptr< WDataSetVector > vectors )
88 size_t numVecs = vectors->getValueSet()->size();
89 std::vector< WVector3d > newData;
90 newData.reserve( numVecs );
91 for(
size_t i = 0; i < numVecs; ++i )
93 newData.push_back( vectors->getVectorAt( i ) );
96 std::shared_ptr< WGridRegular3D > grid = std::dynamic_pointer_cast< WGridRegular3D >( vectors->getGrid() );
102 std::shared_ptr< std::vector< double > > data(
new std::vector< double > );
104 for(
size_t i = 0; i < numVecs; ++i )
106 std::vector< size_t > neighbours = grid->getNeighbours( i );
107 for(
size_t j = 0; j < neighbours.size(); ++j )
110 if( neighbours[j] > i )
112 if( dot( newData[i], newData[ neighbours[j] ] ) < 0.0 )
116 newData[ neighbours[ j ] ] *= sign;
120 data->push_back( newData[i][0] );
121 data->push_back( newData[i][1] );
122 data->push_back( newData[i][2] );
124 std::shared_ptr< WValueSet< double > > values(
new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
125 return std::shared_ptr< WDataSetVector >(
new WDataSetVector( values, grid ) );
150 std::shared_ptr< WDataSetVector > vectors =
m_vectorIC->getData();
157 m_vectorOC->updateData( alignVectors( vectors ) );
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 vectors as values.
This module aligns vectors so that they are inside of the same halfspace by just mirroring their dire...
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
virtual void connectors()
Initialize the connectors this module is using.
std::shared_ptr< WModuleOutputData< WDataSetVector > > m_vectorOC
Output connector for the vector dataset.
virtual const std::string getDescription() const
Gives back a description of this module.
virtual const std::string getName() const
Gives back the name of this module.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_vectorIC
Input connector for the vector dataset.
virtual void moduleMain()
Entry point after loading the module.
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 properties()
Initialize the properties for this module.
virtual void requirements()
Initialize requirements 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 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.
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 infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.