Commit 6a22740f authored by Mathias Goldau's avatar Mathias Goldau

[MERGE]

parents b544eae8 d70127d1
...@@ -77,3 +77,41 @@ void WProjectFileIO::addWarning( std::string description ) ...@@ -77,3 +77,41 @@ void WProjectFileIO::addWarning( std::string description )
m_warnings.push_back( description ); m_warnings.push_back( description );
} }
void WProjectFileIO::printProperties( std::ostream& output, boost::shared_ptr< WProperties > props, std::string indent, //NOLINT
std::string prefix, unsigned int index, std::string indexPrefix )
{
// lock, unlocked if l looses focus
WProperties::PropertySharedContainerType::ReadTicket l = props->getProperties();
output << indent << "// Property Group: " << props->getName() << std::endl;
// iterate of them and print them to output
for( WProperties::PropertyConstIterator iter = l->get().begin(); iter != l->get().end(); ++iter )
{
// information properties do not get written
if( ( *iter )->getPurpose () == PV_PURPOSE_INFORMATION )
{
continue;
}
if( ( *iter )->getType() != PV_GROUP )
{
output << indent + " " << "PROPERTY:(" << indexPrefix << index << "," << prefix + ( *iter )->getName() << ")="
<< ( *iter )->getAsString() << std::endl;
}
else
{
// it is a group -> recursively print it
if( prefix.empty() )
{
printProperties( output, ( *iter )->toPropGroup(), indent + " ", ( *iter )->getName() + "/", index, indexPrefix );
}
else
{
printProperties( output, ( *iter )->toPropGroup(), indent + " ", prefix + ( *iter )->getName() + "/", index, indexPrefix );
}
}
}
output << indent << "// Property Group END: " << props->getName() << std::endl;
}
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "WProperties.h"
/** /**
* A base class for all parts of OpenWalnut which can be serialized to a project file. It is used by WProjectFile to actually parse the file line * A base class for all parts of OpenWalnut which can be serialized to a project file. It is used by WProjectFile to actually parse the file line
* by line. Derive from this class if you write your own parser and use it to fill your internal data structures. But write it in a very * by line. Derive from this class if you write your own parser and use it to fill your internal data structures. But write it in a very
...@@ -117,6 +119,18 @@ protected: ...@@ -117,6 +119,18 @@ protected:
*/ */
void addWarning( std::string description ); void addWarning( std::string description );
/**
* Recursively prints the properties and nested properties.
*
* \param output the output stream to print to
* \param props the properties to recursively print
* \param indent the indentation level
* \param prefix the prefix (name prefix of property)
* \param index the ID to use
* \param indexPrefix use this to add a prefix to the index
*/
void printProperties( std::ostream& output, boost::shared_ptr< WProperties > props, std::string indent, //NOLINT ( non-const ref )
std::string prefix, unsigned int index, std::string indexPrefix = "" );
private: private:
/** /**
* List of errors if any. * List of errors if any.
......
...@@ -34,8 +34,8 @@ ...@@ -34,8 +34,8 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "WStringUtils.h" #include "WStringUtils.h"
#include "math/linearAlgebra/WLinearAlgebra.h"
#include "math/linearAlgebra/WMatrixFixed.h" #include "math/linearAlgebra/WMatrixFixed.h"
#include "math/linearAlgebra/WPosition.h"
#include "math/linearAlgebra/WVectorFixed.h" #include "math/linearAlgebra/WVectorFixed.h"
#include "math/WInterval.h" #include "math/WInterval.h"
#include "WAssert.h" #include "WAssert.h"
......
...@@ -27,11 +27,9 @@ ...@@ -27,11 +27,9 @@
#include <stdint.h> #include <stdint.h>
#include <iostream>
#include <list> #include <list>
#include <set> #include <set>
#include <string> #include <string>
#include <vector>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
......
...@@ -25,14 +25,12 @@ ...@@ -25,14 +25,12 @@
#ifndef WTHREADEDJOBS_H #ifndef WTHREADEDJOBS_H
#define WTHREADEDJOBS_H #define WTHREADEDJOBS_H
#include <iostream>
#include <string> #include <string>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include "WException.h" #include "WException.h"
#include "WFlag.h" #include "WFlag.h"
#include "WLogger.h"
/** /**
* \class WThreadedJobs * \class WThreadedJobs
......
...@@ -33,11 +33,10 @@ class WException; ...@@ -33,11 +33,10 @@ class WException;
/** /**
* Enum of all possible signals WThreadedRunner instances can emit. * Enum of all possible signals WThreadedRunner instances can emit.
*/ */
typedef enum enum THREAD_SIGNAL
{ {
WTHREAD_ERROR // error during execution WTHREAD_ERROR // error during execution
} };
THREAD_SIGNAL;
// ************************************************************************************************************************** // **************************************************************************************************************************
// Types // Types
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <vector> #include <vector>
#include "../math/WLine.h" #include "../math/WLine.h"
#include "../math/linearAlgebra/WLinearAlgebra.h" #include "../math/linearAlgebra/WPosition.h"
class WFiberTest; class WFiberTest;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <cxxtest/TestSuite.h> #include <cxxtest/TestSuite.h>
#include "../../math/linearAlgebra/WLinearAlgebra.h" #include "../../math/linearAlgebra/WPosition.h"
#include "../WFiber.h" #include "../WFiber.h"
#include "WFiberTraits.h" #include "WFiberTraits.h"
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include <vector> #include <vector>
#include "../WAssert.h" #include "../WAssert.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WVectorFixed.h"
namespace utility namespace utility
{ {
......
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
#include "../WStringUtils.h" #include "../WStringUtils.h"
#include "WLine.h" #include "WLine.h"
#include "WPolynomialEquationSolvers.h" #include "WPolynomialEquationSolvers.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WPosition.h"
#include "linearAlgebra/WVectorFixed.h"
WLine::WLine( const std::vector< WPosition > &points ) WLine::WLine( const std::vector< WPosition > &points )
: WMixinVector< WPosition >( points ) : WMixinVector< WPosition >( points )
......
...@@ -25,14 +25,12 @@ ...@@ -25,14 +25,12 @@
#ifndef WLINE_H #ifndef WLINE_H
#define WLINE_H #define WLINE_H
#include <algorithm>
#include <iostream>
#include <vector> #include <vector>
#include "../WBoundingBox.h" #include "../WBoundingBox.h"
#include "../WMixinVector.h" #include "../WMixinVector.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WPosition.h"
// forward declarations // forward declarations
class WLineTest; class WLineTest;
......
...@@ -24,14 +24,12 @@ ...@@ -24,14 +24,12 @@
#include <vector> #include <vector>
#include <Eigen/SVD>
#include "../WAssert.h" #include "../WAssert.h"
#include "../WLimits.h" #include "../WLimits.h"
#include "WLinearAlgebraFunctions.h" #include "WLinearAlgebraFunctions.h"
#include "WMatrix.h" #include "WMatrix.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WVectorFixed.h"
WVector3d multMatrixWithVector3D( WMatrix<double> mat, WVector3d vec ) WVector3d multMatrixWithVector3D( WMatrix<double> mat, WVector3d vec )
{ {
...@@ -292,34 +290,3 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v ) ...@@ -292,34 +290,3 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v )
} }
return true; return true;
} }
void computeSVD( const WMatrix<double>& A,
WMatrix<double>& U,
WMatrix<double>& V,
WValue<double>& S )
{
Eigen::MatrixXd eigenA( A );
Eigen::JacobiSVD<Eigen::MatrixXd> svd( eigenA, Eigen::ComputeFullU | Eigen::ComputeFullV );
U = WMatrix<double>( svd.matrixU() );
V = WMatrix<double>( svd.matrixV() );
S = WValue<double>( svd.singularValues() );
}
WMatrix<double> pseudoInverse( const WMatrix<double>& input )
{
// calc pseudo inverse
WMatrix<double> U( input.getNbRows(), input.getNbCols() );
WMatrix<double> V( input.getNbCols(), input.getNbCols() );
WValue<double> Svec( input.size() );
computeSVD( input, U, V, Svec );
// create diagonal matrix S
WMatrix<double> S( input.getNbCols(), input.getNbCols() );
S.setZero();
for( size_t i = 0; i < Svec.size() && i < S.getNbRows() && i < S.getNbCols(); i++ )
{
S( i, i ) = ( Svec[ i ] == 0.0 ) ? 0.0 : 1.0 / Svec[ i ];
}
return WMatrix<double>( V*S*U.transposed() );
}
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
#ifndef WLINEARALGEBRAFUNCTIONS_H #ifndef WLINEARALGEBRAFUNCTIONS_H
#define WLINEARALGEBRAFUNCTIONS_H #define WLINEARALGEBRAFUNCTIONS_H
#include <Eigen/Core>
#include <Eigen/SVD>
#include "WMatrix.h" #include "WMatrix.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WPosition.h"
template< typename > class WMatrix; template< typename > class WMatrix;
...@@ -92,22 +94,60 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v ); ...@@ -92,22 +94,60 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v );
* *
* A=U*S*V^T * A=U*S*V^T
* *
* \tparam T The data type.
* \param A Input Matrix * \param A Input Matrix
* \param U Output Matrix * \param U Output Matrix
* \param S Output of the entries in the diagonal matrix * \param S Output of the entries in the diagonal matrix
* \param V Output Matrix * \param V Output Matrix
* *
*/ */
void computeSVD( const WMatrix<double>& A, WMatrix<double>& U, WMatrix<double>& V, WValue<double>& S ); template< typename T >
void computeSVD( const WMatrix< T >& A, WMatrix< T >& U, WMatrix< T >& V, WValue< T >& S );
/** /**
* Calculates for a matrix the pseudo inverse. * Calculates for a matrix the pseudo inverse.
* *
* \tparam T The data type.
* \param input Matrix to invert * \param input Matrix to invert
* *
* \return Inverted Matrix * \return Inverted Matrix
* *
*/ */
WMatrix<double> pseudoInverse( const WMatrix<double>& input ); template< typename T >
WMatrix< T > pseudoInverse( const WMatrix< T >& input );
template< typename T >
void computeSVD( const WMatrix< T >& A,
WMatrix< T >& U,
WMatrix< T >& V,
WValue< T >& S )
{
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > eigenA( A );
Eigen::JacobiSVD< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > > svd( eigenA, Eigen::ComputeFullU | Eigen::ComputeFullV );
U = WMatrix< T >( svd.matrixU() );
V = WMatrix< T >( svd.matrixV() );
S = WValue< T >( svd.singularValues() );
}
template< typename T >
WMatrix< T > pseudoInverse( const WMatrix< T >& input )
{
// calc pseudo inverse
WMatrix< T > U( input.getNbRows(), input.getNbCols() );
WMatrix< T > V( input.getNbCols(), input.getNbCols() );
WValue< T > Svec( input.size() );
computeSVD( input, U, V, Svec );
// create diagonal matrix S
WMatrix< T > S( input.getNbCols(), input.getNbCols() );
S.setZero();
for( size_t i = 0; i < Svec.size() && i < S.getNbRows() && i < S.getNbCols(); i++ )
{
S( i, i ) = ( Svec[ i ] == 0.0 ) ? 0.0 : 1.0 / Svec[ i ];
}
return WMatrix< T >( V*S*U.transposed() );
}
#endif // WLINEARALGEBRAFUNCTIONS_H #endif // WLINEARALGEBRAFUNCTIONS_H
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
#include "WMath.h" #include "WMath.h"
#include "WPlane.h" #include "WPlane.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WPosition.h"
#include "linearAlgebra/WVectorFixed.h"
#include "../WAssert.h" #include "../WAssert.h"
#include "../WLimits.h" #include "../WLimits.h"
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "WLine.h" #include "WLine.h"
#include "WPlane.h" #include "WPlane.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WPosition.h"
/** /**
* Classes and functions of math module of OpenWalnut. * Classes and functions of math module of OpenWalnut.
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
#include <osg/Matrix> #include <osg/Matrix>
#include "WValue.h" #include "WValue.h"
#include "linearAlgebra/WLinearAlgebra.h" #include "linearAlgebra/WMatrixFixed.h"
#include "linearAlgebra/WVectorFixed.h"
#include "../WDefines.h" #include "../WDefines.h"
...@@ -79,6 +80,20 @@ public: ...@@ -79,6 +80,20 @@ public:
*/ */
WMatrix( const Eigen::MatrixXd& newMatrix ); // NOLINT WMatrix( const Eigen::MatrixXd& newMatrix ); // NOLINT
/**
* Copies the specified Eigen::MatrixXf.
*
* \param newMatrix the Eigen::MatrixXf matrix to copy
*/
WMatrix( const Eigen::MatrixXf& newMatrix ); // NOLINT
/**
* Copies the specified Eigen::MatrixXi.
*
* \param newMatrix the Eigen::MatrixXi matrix to copy
*/
WMatrix( const Eigen::MatrixXi& newMatrix ); // NOLINT
/** /**
* Makes the matrix contain the identity matrix, i.e. 1 on the diagonal. * Makes the matrix contain the identity matrix, i.e. 1 on the diagonal.
* \return Reference to the current matrix which is identity matrix now. * \return Reference to the current matrix which is identity matrix now.
...@@ -130,11 +145,14 @@ public: ...@@ -130,11 +145,14 @@ public:
operator osg::Matrixd() const; operator osg::Matrixd() const;
/** /**
* Cast this matrix to an Eigen::MatrixXd matrix. * Cast this matrix to an Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic >() matrix.
*
* \tparam EigenDataType Data type of Eigen matrix.
* *
* \return casted matrix. * \return casted matrix.
*/ */
operator Eigen::MatrixXd() const; template< typename EigenDataType >
operator Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic >() const;
/** /**
* Compares two matrices and returns true if they are equal. * Compares two matrices and returns true if they are equal.
...@@ -210,6 +228,14 @@ public: ...@@ -210,6 +228,14 @@ public:
protected: protected:
private: private:
/**
* This function is used by the constructors that have the different Eigen::MatrixX types as parameter.
* \tparam EigenDataType The data type which is used by the Eigen matrix.
* \param newMatrix The source matrix.
*/
template< typename EigenDataType >
void copyFromEigenMatrix( const Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic >& newMatrix );
size_t m_nbCols; //!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols). size_t m_nbCols; //!< Number of columns of the matrix. The number of rows will be computed by (size/m_nbCols).
}; };
...@@ -251,16 +277,20 @@ template< typename T > WMatrix< T >::WMatrix( const WMatrix4d& newMatrix ) ...@@ -251,16 +277,20 @@ template< typename T > WMatrix< T >::WMatrix( const WMatrix4d& newMatrix )
template< typename T > WMatrix< T >::WMatrix( const Eigen::MatrixXd& newMatrix ) template< typename T > WMatrix< T >::WMatrix( const Eigen::MatrixXd& newMatrix )
: WValue< T >( newMatrix.cols() * newMatrix.rows() ) : WValue< T >( newMatrix.cols() * newMatrix.rows() )
{ {
m_nbCols = static_cast< size_t >( newMatrix.cols() ); copyFromEigenMatrix< double >( newMatrix );
for( int row = 0; row < newMatrix.rows(); ++row )
{
for( int col = 0; col < newMatrix.cols(); ++col )
{
( *this )( row, col ) = static_cast< T >( newMatrix( row, col ) );
}
}
} }
template< typename T > WMatrix< T >::WMatrix( const Eigen::MatrixXf& newMatrix )
: WValue< T >( newMatrix.cols() * newMatrix.rows() )
{
copyFromEigenMatrix< float >( newMatrix );
}
template< typename T > WMatrix< T >::WMatrix( const Eigen::MatrixXi& newMatrix )
: WValue< T >( newMatrix.cols() * newMatrix.rows() )
{
copyFromEigenMatrix< int >( newMatrix );
}
template< typename T > WMatrix< T >::operator WMatrix4d() const template< typename T > WMatrix< T >::operator WMatrix4d() const
{ {
...@@ -301,19 +331,21 @@ template< typename T > WMatrix< T >::operator osg::Matrixd() const ...@@ -301,19 +331,21 @@ template< typename T > WMatrix< T >::operator osg::Matrixd() const
} }
} }
template< typename T > WMatrix< T >::operator Eigen::MatrixXd() const template< typename T >
template< typename EigenDataType > WMatrix< T >::operator Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic >() const
{ {
Eigen::MatrixXd matrix( this->getNbRows(), this->getNbCols() ); Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic > matrix( this->getNbRows(), this->getNbCols() );
for( int row = 0; row < matrix.rows(); ++row ) for( int row = 0; row < matrix.rows(); ++row )
{ {
for( int col = 0; col < matrix.cols(); ++col ) for( int col = 0; col < matrix.cols(); ++col )
{ {
matrix( row, col ) = ( *this )( row, col ); matrix( row, col ) = static_cast< EigenDataType >( ( *this )( row, col ) );
} }
} }
return matrix; return matrix;
} }