29 #include "WMEigenSystem.h"
30 #include "WMEigenSystem.xpm"
31 #include "core/dataHandler/WDataSetDTI.h"
32 #include "core/dataHandler/WDataSetVector.h"
33 #include "core/kernel/WKernel.h"
34 #include "core/kernel/WModuleInputData.h"
35 #include "core/kernel/WModuleOutputData.h"
58 return WMEigenSystem_xpm;
62 return "Eigen System";
69 return "No documentation yet. "
70 "The best person to ask for documenation is probably the modules's creator, i.e. \"math\"";
93 std::shared_ptr< WItemSelection > strategies(
new WItemSelection() );
94 strategies->addItem(
"LibEigen",
"Eigensystem is computed via libEigen and its SelfAdjointEigenSolver" );
95 strategies->addItem(
"Jacobi",
"Self implemented Jacobi iterative eigen decomposition" );
97 strategies->getSelectorFirst() );
128 std::shared_ptr< WDataSetDTI > tensors =
m_tensorIC->getData();
139 resetProgress( tensors->getValueSet()->size(),
"Compute eigen system" );
141 infoLog() <<
"Computing eigen systems...";
149 if( tensors->getValueSet()->getDataType() == W_DT_DOUBLE )
159 infoLog() <<
"Computing eigen systems done.";
166 WAssert( es,
"Bug: updating the output with no data makes no sense." );
167 std::shared_ptr< const WValueSet< double > > vs = std::dynamic_pointer_cast< WValueSet< double > >( es->getValueSet() );
168 WAssert( vs,
"Bug: invalid value-set from WThreadedPerVoxelOperation dataset" );
169 std::shared_ptr< WGrid > grid = es->getGrid();
171 typedef std::shared_ptr< std::vector< double > > DataPointer;
172 std::vector< DataPointer > vecdata;
173 vecdata.push_back( DataPointer(
new std::vector< double >( vs->size() * 3 ) ) );
174 vecdata.push_back( DataPointer(
new std::vector< double >( vs->size() * 3 ) ) );
175 vecdata.push_back( DataPointer(
new std::vector< double >( vs->size() * 3 ) ) );
176 vecdata.push_back( DataPointer(
new std::vector< double >( vs->size() * 3 ) ) );
177 std::vector< DataPointer > valdata;
178 valdata.push_back( DataPointer(
new std::vector< double >( vs->size() ) ) );
179 valdata.push_back( DataPointer(
new std::vector< double >( vs->size() ) ) );
180 valdata.push_back( DataPointer(
new std::vector< double >( vs->size() ) ) );
182 for(
size_t i = 0; i < vs->size(); ++i )
186 ( *vecdata[0] )[ i * 3 ] = sys[0];
187 ( *valdata[0] )[ i ] = sys[0];
188 ( *vecdata[0] )[ i * 3 + 1] = sys[4];
189 ( *valdata[1] )[ i ] = sys[4];
190 ( *vecdata[0] )[ i * 3 + 2] = sys[8];
191 ( *valdata[2] )[ i ] = sys[8];
193 ( *vecdata[1] )[ i * 3 ] = sys[1];
194 ( *vecdata[1] )[ i * 3 + 1] = sys[2];
195 ( *vecdata[1] )[ i * 3 + 2] = sys[3];
197 ( *vecdata[2] )[ i * 3 ] = sys[5];
198 ( *vecdata[2] )[ i * 3 + 1] = sys[6];
199 ( *vecdata[2] )[ i * 3 + 2] = sys[7];
201 ( *vecdata[3] )[ i * 3 ] = sys[9];
202 ( *vecdata[3] )[ i * 3 + 1] = sys[10];
203 ( *vecdata[3] )[ i * 3 + 2] = sys[11];
205 typedef std::shared_ptr< WDataSetVector > PDSV;
206 typedef std::shared_ptr< WDataSetScalar > PDSS;
208 typedef std::shared_ptr< WVSDBL > PWVSDBL;
222 jacobiEigenvector3D( m, &sys );
223 boost::array< double, 12 > result = { { sys[0].first, sys[0].second[0],
226 sys[1].first, sys[1].second[0],
229 sys[2].first, sys[2].second[0],
231 sys[2].second[2] } };
238 m( 0, 0 ) =
static_cast< double >( input[ 0 ] );
239 m( 0, 1 ) =
static_cast< double >( input[ 1 ] );
240 m( 0, 2 ) =
static_cast< double >( input[ 2 ] );
241 m( 1, 1 ) =
static_cast< double >( input[ 3 ] );
242 m( 1, 2 ) =
static_cast< double >( input[ 4 ] );
243 m( 2, 2 ) =
static_cast< double >( input[ 5 ] );
253 m( 0, 0 ) =
static_cast< double >( input[ 0 ] );
254 m( 0, 1 ) =
static_cast< double >( input[ 1 ] );
255 m( 0, 2 ) =
static_cast< double >( input[ 2 ] );
256 m( 1, 1 ) =
static_cast< double >( input[ 3 ] );
257 m( 1, 2 ) =
static_cast< double >( input[ 4 ] );
258 m( 2, 2 ) =
static_cast< double >( input[ 5 ] );
268 m << input[0], input[1], input[2],
269 input[1], input[3], input[4],
270 input[2], input[4], input[5];
278 m << input[0], input[1], input[2],
279 input[1], input[3], input[4],
280 input[2], input[4], input[5];
287 Eigen::SelfAdjointEigenSolver< Eigen::Matrix3d > es( m );
288 const Eigen::Matrix3d &evecs = es.eigenvectors();
289 const Eigen::Vector3d &evals = es.eigenvalues();
290 boost::array< double, 12 > result = { { evals( 0 ), evecs( 0, 0 ),
293 evals( 1 ), evecs( 0, 1 ),
296 evals( 2 ), evecs( 0, 2 ),
317 debugLog() <<
"Stopping eigencomputation.";
319 if( s != W_THREADS_FINISHED && s != W_THREADS_ABORTED )
324 WAssert( s == W_THREADS_FINISHED || s == W_THREADS_ABORTED,
"" );
334 if( tensors->getValueSet()->getDataType() == W_DT_DOUBLE )
346 WAssert( 0,
"Bug: Invalid strategy for eigen decomposition selected!" );
351 else if( tensors->getValueSet()->getDataType() == W_DT_FLOAT )
363 WAssert( 0,
"Bug: Invalid strategy for eigen decomposition selected!" );
370 errorLog() <<
"Input data does not contain floating point values, skipping.";
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void remove(std::shared_ptr< WCondition > condition)
Removes the specified condition.
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.
This data set type contains vectors as values.
A class containing a list of named items.
Computes the eigensystem of a second order tensor field.
void resetProgress(std::size_t todo, std::string name)
Resets the current progress to 0.
std::vector< std::shared_ptr< WModuleOutputData< WDataSetScalar > > > m_evalOutputs
Output scalar field , each for an eigenvalue field.
virtual void moduleMain()
Entry point after loading the module.
std::shared_ptr< TPVOFloat > m_eigenOperationFloat
the functor used for the calculation of the eigenvectors
virtual void requirements()
Initialize requirements for this 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...
WThreadedFunction< TPVOFloat > EigenFunctionTypeFloat
the thread pool type for the eigencomputation (float input)
std::shared_ptr< WProgress > m_currentProgress
Indicating current work progress.
WThreadedPerVoxelOperation< double, 6, double, 12 > TPVODouble
the threaded per-voxel function for the eigenvector computation (double input)
virtual const std::string getDescription() const
Gives back a description of this module.
TPVOFloat::OutTransmitType const eigenSolverFloat(TPVOFloat::TransmitType const &input)
Computes the eigen system for double input parameters via using applyEigenSolver.
boost::array< double, 12 > computeEigenSystem(WTensorSym< 2, 3, double > const &m) const
Is used by every thread to compute the eigensystem for the given tensor.
boost::array< double, 12 > applyEigenSolver(const Eigen::Matrix3d &m) const
Copies the eigenvalues and eigenvectors from the libEigen output format into the double array.
virtual void connectors()
Initialize the connectors this module is using.
TPVOFloat::OutTransmitType const eigenFuncFloat(TPVOFloat::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
TPVODouble::OutTransmitType const eigenSolverDouble(TPVODouble::TransmitType const &input)
Computes the eigen system for double input parameters via using applyEigenSolver.
virtual ~WMEigenSystem()
Destructs this module.
std::shared_ptr< WModuleInputData< WDataSetDTI > > m_tensorIC
Input tensor field.
std::shared_ptr< WThreadedFunctionBase > m_eigenPool
The threadpool for the eigenvector computation.
WPropSelection m_strategySelector
List for selecting the strategy.
std::vector< EigenOutputConnector > m_evecOutputs
Ouput vector field for principal eigenvectors as well as one for all eigenvalues at once.
WThreadedPerVoxelOperation< float, 6, double, 12 > TPVOFloat
the threaded per-voxel function for the eigenvector computation (float input)
virtual const std::string getName() const
Gives back the name of this module.
void resetEigenFunction(std::shared_ptr< WDataSetDTI > tensors)
Resets the threaded function/threadpool.
virtual void properties()
Initialize the properties for this module.
void updateOCs(std::shared_ptr< const WDataSetSingle > es)
Update the output connectors out of the computed eigensystem field.
WMEigenSystem()
Constructs a new module for eigensystem computation.
std::shared_ptr< TPVODouble > m_eigenOperationDouble
the functor used for the calculation of the eigenvectors
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
TPVODouble::OutTransmitType const eigenFuncDouble(TPVODouble::TransmitType const &input)
The function that computes the eigenvectors from the input tensor field.
WThreadedFunction< TPVODouble > EigenFunctionTypeDouble
the thread pool type for the eigencomputation (double input)
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.
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.
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.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
Class managing progress inside of modules.
Implements a symmetric tensor that has the same number of components in every direction.
boost::array< Output_T, numOutputs > OutTransmitType
the output type for the per-voxel operation
ValueSetType::SubArray const TransmitType
the input type for the per-voxel operation
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
Base Class for all value set types.
Base class for all higher level values like tensors, vectors, matrices and so on.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.