33 #include <boost/variant.hpp>
35 #include "WMVectorOperator.h"
36 #include "WMVectorOperator.xpm"
37 #include "core/common/WAssert.h"
38 #include "core/common/WProgress.h"
39 #include "core/common/WStringUtils.h"
40 #include "core/common/WTypeTraits.h"
41 #include "core/common/exceptions/WTypeMismatch.h"
42 #include "core/common/math/linearAlgebra/WVectorFixed.h"
43 #include "core/dataHandler/WDataHandler.h"
44 #include "core/dataHandler/WDataHandlerEnums.h"
45 #include "core/dataHandler/WGridRegular3D.h"
46 #include "core/dataHandler/exceptions/WDHValueSetMismatch.h"
47 #include "core/kernel/WKernel.h"
71 return WMVectorOperator_xpm;
76 return "Vector Operator";
81 return "Applies an selected operator on a specified vector field.";
100 m_operations->addItem(
"Length",
"Length of the vector." );
101 m_operations->addItem(
"Curvature",
"Curvature at each voxel." );
111 template<
typename T >
117 return length( vec );
120 template<
typename T >
132 WVector3d L2 = ( vec.
x() * dx ) + ( vec.
y() * dy ) + ( vec.
z() * dz );
135 return length( cross( vec, L2 ) ) / ( l * l * l );
152 size_t getId(
size_t xDim,
size_t yDim,
size_t ,
size_t x,
size_t y,
size_t z,
size_t offset = 0,
size_t elements = 1 )
154 return offset + ( elements * ( z * xDim * yDim + y * xDim + x ) );
160 class VisitorVSetA:
public boost::static_visitor< std::shared_ptr< WValueSetBase > >
169 VisitorVSetA( std::shared_ptr< WGridRegular3D > grid,
size_t opIdx = 0 ):
170 boost::static_visitor< result_type >(),
184 template <
typename T >
188 std::vector< T > data;
189 data.resize( vsetA->size() );
201 op = &opCurvature< T >;
210 size_t nX =
m_grid->getNbCoordsX();
211 size_t nY =
m_grid->getNbCoordsY();
212 size_t nZ =
m_grid->getNbCoordsZ();
216 for(
size_t z = 1; z < nZ - 1; z++ )
218 for(
size_t y = 1; y < nY - 1; y++ )
220 for(
size_t x = 1; x < nX - 1; x++ )
223 size_t idx = getId( nX, nY, nZ, x, y, z );
224 WVector3d vec = vsetA->getVector3D( idx );
227 WVector3d mx = vsetA->getVector3D( getId( nX, nY, nZ, x - 1, y, z ) );
228 WVector3d px = vsetA->getVector3D( getId( nX, nY, nZ, x + 1, y, z ) );
229 WVector3d my = vsetA->getVector3D( getId( nX, nY, nZ, x, y - 1, z ) );
230 WVector3d py = vsetA->getVector3D( getId( nX, nY, nZ, x, y + 1, z ) );
231 WVector3d mz = vsetA->getVector3D( getId( nX, nY, nZ, x, y, z - 1 ) );
232 WVector3d pz = vsetA->getVector3D( getId( nX, nY, nZ, x, y, z + 1 ) );
234 data[ idx ] = op( vec, mx, px, my, py, mz, pz );
240 for(
size_t z = 0; z < 2; z++ )
242 for(
size_t y = 1; y < 2; y++ )
244 for(
size_t x = 1; x < 2; x++ )
246 size_t idx = getId( nX, nY, nZ, x * ( nX - 1 ), y * ( nY - 1 ), z * ( nZ - 1 ) );
255 std::shared_ptr< std::vector< T > >(
256 new std::vector< T >( data ) ),
263 std::shared_ptr< WGridRegular3D >
m_grid;
298 std::shared_ptr< WDataSetVector > dataSetA =
m_inputA->getData();
305 std::shared_ptr< WValueSetBase > valueSetA = dataSetA->getValueSet();
308 std::shared_ptr< WProgress > prog = std::shared_ptr< WProgress >(
309 new WProgress(
"Applying operator on data" ) );
314 std::shared_ptr< WValueSetBase > newValueSet = valueSetA->applyFunction(
VisitorVSetA(
315 std::dynamic_pointer_cast< WGridRegular3D >( dataSetA->getGrid() ), s )
Visitor for discriminating the type of the first valueset.
std::shared_ptr< WGridRegular3D > m_grid
The underlying grid.
result_type operator()(const WValueSet< T > *const &vsetA) const
Called by boost::varying during static visiting.
VisitorVSetA(std::shared_ptr< WGridRegular3D > grid, size_t opIdx=0)
Create visitor instance.
size_t m_opIdx
The operator index.
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 scalars as values.
A class containing a list of named items.
This class represents a subset of a WItemSelection.
Operators for processing two WDataSetScalar.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
std::shared_ptr< WModuleOutputData< WDataSetScalar > > m_output
The only output of this filter module.
WPropSelection m_opSelection
The currently selected operation.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WMVectorOperator()
Standard constructor.
~WMVectorOperator()
Destructor.
virtual const std::string getName() const
Gives back the name of this module.
std::shared_ptr< WItemSelection > m_operations
A list of operations that are possible.
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.
std::shared_ptr< WModuleInputData< WDataSetVector > > m_inputA
Input connector required by this module.
virtual void connectors()
Initialize the connectors this module is using.
virtual const std::string getDescription() const
Gives back a description of this module.
ValueT & z()
Access z element of vector.
double ValueType
The integral type used in this matrix.
ValueT & y()
Access y element of vector.
ValueT & x()
Access x element of vector.
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.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
An object that knows an appropriate dataType flag for the typename T.