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

[MERGE]

parents b544eae8 d70127d1
......@@ -77,3 +77,41 @@ void WProjectFileIO::addWarning( std::string 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 @@
#include <string>
#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
* 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:
*/
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:
/**
* List of errors if any.
......
......@@ -34,8 +34,8 @@
#include <boost/filesystem.hpp>
#include "WStringUtils.h"
#include "math/linearAlgebra/WLinearAlgebra.h"
#include "math/linearAlgebra/WMatrixFixed.h"
#include "math/linearAlgebra/WPosition.h"
#include "math/linearAlgebra/WVectorFixed.h"
#include "math/WInterval.h"
#include "WAssert.h"
......
......@@ -27,11 +27,9 @@
#include <stdint.h>
#include <iostream>
#include <list>
#include <set>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>
......
......@@ -25,14 +25,12 @@
#ifndef WTHREADEDJOBS_H
#define WTHREADEDJOBS_H
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include "WException.h"
#include "WFlag.h"
#include "WLogger.h"
/**
* \class WThreadedJobs
......
......@@ -33,11 +33,10 @@ class WException;
/**
* Enum of all possible signals WThreadedRunner instances can emit.
*/
typedef enum
enum THREAD_SIGNAL
{
WTHREAD_ERROR // error during execution
}
THREAD_SIGNAL;
};
// **************************************************************************************************************************
// Types
......
......@@ -28,7 +28,7 @@
#include <vector>
#include "../math/WLine.h"
#include "../math/linearAlgebra/WLinearAlgebra.h"
#include "../math/linearAlgebra/WPosition.h"
class WFiberTest;
......
......@@ -30,7 +30,7 @@
#include <cxxtest/TestSuite.h>
#include "../../math/linearAlgebra/WLinearAlgebra.h"
#include "../../math/linearAlgebra/WPosition.h"
#include "../WFiber.h"
#include "WFiberTraits.h"
......
......@@ -30,7 +30,7 @@
#include <vector>
#include "../WAssert.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WVectorFixed.h"
namespace utility
{
......
......@@ -37,7 +37,8 @@
#include "../WStringUtils.h"
#include "WLine.h"
#include "WPolynomialEquationSolvers.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WPosition.h"
#include "linearAlgebra/WVectorFixed.h"
WLine::WLine( const std::vector< WPosition > &points )
: WMixinVector< WPosition >( points )
......
......@@ -25,14 +25,12 @@
#ifndef WLINE_H
#define WLINE_H
#include <algorithm>
#include <iostream>
#include <vector>
#include "../WBoundingBox.h"
#include "../WMixinVector.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WPosition.h"
// forward declarations
class WLineTest;
......
......@@ -24,14 +24,12 @@
#include <vector>
#include <Eigen/SVD>
#include "../WAssert.h"
#include "../WLimits.h"
#include "WLinearAlgebraFunctions.h"
#include "WMatrix.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WVectorFixed.h"
WVector3d multMatrixWithVector3D( WMatrix<double> mat, WVector3d vec )
{
......@@ -292,34 +290,3 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v )
}
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 @@
#ifndef WLINEARALGEBRAFUNCTIONS_H
#define WLINEARALGEBRAFUNCTIONS_H
#include <Eigen/Core>
#include <Eigen/SVD>
#include "WMatrix.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WPosition.h"
template< typename > class WMatrix;
......@@ -92,22 +94,60 @@ bool linearIndependent( const WVector3d& u, const WVector3d& v );
*
* A=U*S*V^T
*
* \tparam T The data type.
* \param A Input Matrix
* \param U Output Matrix
* \param S Output of the entries in the diagonal 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.
*
* \tparam T The data type.
* \param input Matrix to invert
*
* \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
......@@ -24,7 +24,8 @@
#include "WMath.h"
#include "WPlane.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WPosition.h"
#include "linearAlgebra/WVectorFixed.h"
#include "../WAssert.h"
#include "../WLimits.h"
......
......@@ -31,7 +31,7 @@
#include "WLine.h"
#include "WPlane.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WPosition.h"
/**
* Classes and functions of math module of OpenWalnut.
......
......@@ -30,7 +30,8 @@
#include <osg/Matrix>
#include "WValue.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WMatrixFixed.h"
#include "linearAlgebra/WVectorFixed.h"
#include "../WDefines.h"
......@@ -79,6 +80,20 @@ public:
*/
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.
* \return Reference to the current matrix which is identity matrix now.
......@@ -130,11 +145,14 @@ public:
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.
*/
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.
......@@ -210,6 +228,14 @@ public:
protected:
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).
};
......@@ -251,16 +277,20 @@ template< typename T > WMatrix< T >::WMatrix( const WMatrix4d& newMatrix )
template< typename T > WMatrix< T >::WMatrix( const Eigen::MatrixXd& newMatrix )
: WValue< T >( newMatrix.cols() * newMatrix.rows() )
{
m_nbCols = static_cast< size_t >( newMatrix.cols() );
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 ) );
}
}
copyFromEigenMatrix< double >( newMatrix );
}
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
{
......@@ -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 col = 0; col < matrix.cols(); ++col )
{
matrix( row, col ) = ( *this )( row, col );
matrix( row, col ) = static_cast< EigenDataType >( ( *this )( row, col ) );
}
}
return matrix;
}
/**
* Makes the matrix contain the identity matrix, i.e. 1 on the diagonal.
*/
......@@ -494,6 +526,20 @@ template< typename T > bool WMatrix< T >::isIdentity( T delta ) const
return true;
}
template< typename T >
template< typename EigenDataType >
void WMatrix< T >::copyFromEigenMatrix( const Eigen::Matrix< EigenDataType, Eigen::Dynamic, Eigen::Dynamic >& newMatrix )
{
m_nbCols = static_cast< size_t >( newMatrix.cols() );
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 >
inline std::ostream& operator<<( std::ostream& os, const WMatrix< T >& m )
{
......
......@@ -27,7 +27,7 @@
#ifdef OW_USE_OSSIM
#include <algorithm>
#include <iostream>
// #include <iostream>
#include <vector>
#include <matrix/newmat.h>
......
......@@ -27,7 +27,7 @@
#include <boost/shared_ptr.hpp>
#include "../../common/math/WLinearAlgebraFunctions.h"
#include "../../common/math/linearAlgebra/WLinearAlgebra.h"
#include "../../common/math/linearAlgebra/WVectorFixed.h"
#include "../../common/WAssert.h"
#include "../../common/WLimits.h"
......
......@@ -31,7 +31,7 @@
#include "../../dataHandler/WGridRegular3D.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "linearAlgebra/WVectorFixed.h"
/**
* Represents a plane with a normal vector and a position in space.
......
......@@ -26,7 +26,6 @@
#define WPOLYNOMIALEQUATIONSOLVERS_H
#include <complex>
#include <iostream>
#include <sstream>
#include <utility>
......
......@@ -22,531 +22,5 @@
//
//---------------------------------------------------------------------------
#include <stdint.h>
#include <cmath>
#include <vector>
#include <boost/math/special_functions/spherical_harmonic.hpp>
#include "core/common/WLogger.h"
#include "core/common/math/WGeometryFunctions.h"
#include "../exceptions/WPreconditionNotMet.h"
#include "linearAlgebra/WLinearAlgebra.h"
#include "WLinearAlgebraFunctions.h"
#include "WMatrix.h"
#include "WTensorSym.h"
#include "WUnitSphereCoordinates.h"
#include "WSymmetricSphericalHarmonic.h"
WSymmetricSphericalHarmonic::WSymmetricSphericalHarmonic() :
m_order( 0 ),
m_SHCoefficients( 0 )
{
}
WSymmetricSphericalHarmonic::WSymmetricSphericalHarmonic( const WValue<double>& SHCoefficients ) :
m_SHCoefficients( SHCoefficients )
{
// calculate order from SHCoefficients.size:
// - this is done by reversing the R=(l+1)*(l+2)/2 formula from the Descoteaux paper
double q = std::sqrt( 0.25 + 2.0 * static_cast<double>( m_SHCoefficients.size() ) ) - 1.5;
m_order = static_cast<size_t>( q );
}
WSymmetricSphericalHarmonic::~WSymmetricSphericalHarmonic()
{
}
double WSymmetricSphericalHarmonic::getValue( double theta, double phi ) const
{
double result = 0.0;
int j = 0;
const double rootOf2 = std::sqrt( 2.0 );
for( int k = 0; k <= static_cast<int>( m_order ); k+=2 )
{
// m = 1 .. k
for( int m = 1; m <= k; m++ )
{
j = ( k*k+k+2 ) / 2 + m;
result += m_SHCoefficients[ j-1 ] * rootOf2 *
static_cast<double>( std::pow( -1.0, m+1 ) ) * boost::math::spherical_harmonic_i( k, m, theta, phi );
}
// m = 0
result += m_SHCoefficients[ ( k*k+k+2 ) / 2 - 1 ] * boost::math::spherical_harmonic_r( k, 0, theta, phi );
// m = -k .. -1
for( int m = -k; m < 0; m++ )
{
j = ( k*k+k+2 ) / 2 + m;
result += m_SHCoefficients[ j-1 ] * rootOf2 * boost::math::spherical_harmonic_r( k, -m, theta, phi );
}
}
return result;
}
double WSymmetricSphericalHarmonic::getValue( const WUnitSphereCoordinates& coordinates ) const
{
return getValue( coordinates.getTheta(), coordinates.getPhi() );
}
const WValue<double>& WSymmetricSphericalHarmonic::getCoefficients() const
{
return m_SHCoefficients;
}