Commit 40d11e56 authored by Stefan Philips's avatar Stefan Philips

[CHANGE] Adapt WSymmetricSphericalHarmonic to Eigen vector and matrix

parent 87e22617
......@@ -31,7 +31,7 @@
#include "WMath.h"
#include "WMatrix.h"
#include "WUnitSphereCoordinates.h"
#include "WValue.h"
#include "WVector3D.h"
/**
* Class for symmetric spherical harmonics
......@@ -50,7 +50,7 @@ public:
* Constructor.
* \param SHCoefficients the initial coefficients (stored like in the mentioned Descoteaux paper).
*/
explicit WSymmetricSphericalHarmonic( const WValue<double>& SHCoefficients );
explicit WSymmetricSphericalHarmonic( const WVector_2& SHCoefficients );
/**
* Destructor.
......@@ -73,17 +73,17 @@ public:
/**
* Returns the used coefficients (stored like in the mentioned 2007 Descoteaux paper).
*/
const WValue<double>& getCoefficients() const;
const WVector_2& getCoefficients() const;
/**
* Returns the coefficients for Schultz' SH base.
*/
WValue< double > getCoefficientsSchultz() const;
WVector_2 getCoefficientsSchultz() const;
/**
* Returns the coefficients for the complex base.
*/
WValue< std::complex< double > > getCoefficientsComplex() const;
WVectorComplex_2 getCoefficientsComplex() const;
/**
* Applies the Funk-Radon-Transformation. This is faster than matrix multiplication.
......@@ -91,7 +91,7 @@ public:
*
* \param frtMat the frt matrix as calculated by calcFRTMatrix()
*/
void applyFunkRadonTransformation( WMatrix< double > const& frtMat );
void applyFunkRadonTransformation( const WMatrix_2& frtMat );
/**
* Return the order of the spherical harmonic.
......@@ -125,7 +125,7 @@ public:
*
* \return The generalized fractional anisotropy.
*/
double calcGFA( WMatrix< double > const& B ) const;
double calcGFA( const WMatrix_2& B ) const;
/**
* This calculates the transformation/fitting matrix T like in the 2007 Descoteaux paper. The orientations are given as WVector3D.
......@@ -135,10 +135,10 @@ public:
* \param withFRT include the Funk-Radon-Transformation?
* \return Transformation matrix
*/
static WMatrix<double> getSHFittingMatrix( const std::vector< WVector3D >& orientations,
int order,
double lambda,
bool withFRT );
static WMatrix_2 getSHFittingMatrix( const std::vector< WVector3D >& orientations,
int order,
double lambda,
bool withFRT );
/**
* This calculates the transformation/fitting matrix T like in the 2007 Descoteaux paper. The orientations are given as WUnitSphereCoordinates .
......@@ -148,7 +148,7 @@ public:
* \param withFRT include the Funk-Radon-Transformation?
* \return Transformation matrix
*/
static WMatrix<double> getSHFittingMatrix( const std::vector< WUnitSphereCoordinates >& orientations,
static WMatrix_2 getSHFittingMatrix( const std::vector< WUnitSphereCoordinates >& orientations,
int order,
double lambda,
bool withFRT );
......@@ -159,7 +159,7 @@ public:
* \param order The order of the spherical harmonics intended to create
* \return The base Matrix B
*/
static WMatrix<double> calcBaseMatrix( const std::vector< WUnitSphereCoordinates >& orientations, int order );
static WMatrix_2 calcBaseMatrix( const std::vector< WUnitSphereCoordinates >& orientations, int order );
/**
* Calculates the base matrix B for the complex spherical harmonics.
......@@ -167,7 +167,7 @@ public:
* \param order The order of the spherical harmonics intended to create
* \return The base Matrix B
*/
static WMatrix< std::complex< double > > calcComplexBaseMatrix( std::vector< WUnitSphereCoordinates > const& orientations,
static WMatrixComplex_2 calcComplexBaseMatrix( std::vector< WUnitSphereCoordinates > const& orientations,
int order );
/**
......@@ -175,14 +175,14 @@ public:
* \param order The order of the spherical harmonic
* \return The smoothing matrix L
*/
static WMatrix<double> calcSmoothingMatrix( size_t order );
static WMatrix_2 calcSmoothingMatrix( size_t order );
/**
* Calculates the Funk-Radon-Transformation-Matrix P from the 2007 Descoteaux Paper "Regularized, Fast, and Robust Analytical Q-Ball Imaging"
* \param order The order of the spherical harmonic
* \return The Funk-Radon-Matrix P
*/
static WMatrix<double> calcFRTMatrix( size_t order );
static WMatrix_2 calcFRTMatrix( size_t order );
#ifdef OW_USE_OSSIM
/**
......@@ -191,8 +191,9 @@ public:
* \param order The order of the symmetric tensor.
* \param orientations A vector of at least (orderTensor+1) * (orderTensor+2) / 2 orientations.
*/
static WMatrix< double > calcSHToTensorSymMatrix( std::size_t order, const std::vector< WUnitSphereCoordinates >& orientations );
static WMatrix_2 calcSHToTensorSymMatrix( std::size_t order, const std::vector< WUnitSphereCoordinates >& orientations );
#endif // OW_USE_OSSIM
void normalize();
protected:
......@@ -201,7 +202,7 @@ private:
size_t m_order;
/** coefficients of the spherical harmonic */
WValue<double> m_SHCoefficients;
WVector_2 m_SHCoefficients;
};
#endif // WSYMMETRICSPHERICALHARMONIC_H
......@@ -27,10 +27,20 @@
#include <vector>
// the following block is only for the last termporarly test
// #include <boost/nondet_random.hpp>
// #include <boost/random.hpp>
// #include <boost/random/normal_distribution.hpp>
// #include <boost/random/uniform_real.hpp>
// #include <boost/random/linear_congruential.hpp>
// #include <boost/random/uniform_real.hpp>
// #include <boost/random/variate_generator.hpp>
#include <cxxtest/TestSuite.h>
#include "../WMatrix.h"
#include "../WValue.h"
#include "../WVector3D.h"
#include "../WGeometryFunctions.h"
#include "../WSymmetricSphericalHarmonic.h"
......@@ -51,8 +61,8 @@ public:
*/
void testCalcFRTMatrix( void )
{
WMatrix<double> result( WSymmetricSphericalHarmonic::calcFRTMatrix( 4 ) );
WMatrix<double> reference( 15, 15 );
WMatrix_2 result( WSymmetricSphericalHarmonic::calcFRTMatrix( 4 ) );
WMatrix_2 reference( 15, 15 );
// j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
// lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
reference( 0, 0 ) = 2.0 * piDouble;
......@@ -73,8 +83,8 @@ public:
*/
void testCalcSmoothingMatrix( void )
{
WMatrix<double> result( WSymmetricSphericalHarmonic::calcSmoothingMatrix( 4 ) );
WMatrix<double> reference( 15, 15 );
WMatrix_2 result( WSymmetricSphericalHarmonic::calcSmoothingMatrix( 4 ) );
WMatrix_2 reference( 15, 15 );
// j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
// lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
reference( 0, 0 ) = 0.0;
......@@ -96,7 +106,7 @@ public:
void testCalcSHtoTensorMatrix()
{
#ifdef OW_USE_OSSIM
WValue< double > w( 6 );
WVector_2 w( 6 );
for( int i = 0; i < 6; ++i )
{
w[ i ] = exp( i / 6.0 );
......@@ -114,11 +124,13 @@ public:
orientations.push_back( WUnitSphereCoordinates( WVector3D( 0.0, 0.0, -4.0 ).normalized() ) );
orientations.push_back( WUnitSphereCoordinates( WVector3D( 0.0, 4.0, 1.0 ).normalized() ) );
WMatrix< double > SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations );
WTensorSym< 2, 3, double > t( SHToTensor * w );
WMatrix_2 SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations );
// TODO(all): remove the WValue from the following line, when WTensorSym supports WVector_2
WTensorSym< 2, 3, double > t( WValue<double>( SHToTensor * w ) );
for( std::vector< WUnitSphereCoordinates >::iterator it = orientations.begin();
it != orientations.end(); ++it )
it != orientations.end();
++it )
{
TS_ASSERT_DELTA( i.getValue( *it ), evaluateSphericalFunction( t, it->getEuclidean() ), 0.001 );
}
......@@ -146,18 +158,18 @@ public:
}
grad.clear();
WValue< double > values( 15 );
WVector_2 values( 15 );
for( std::size_t i = 0; i < 15; ++i )
{
values[ i ] = i / 15.0;
}
WSymmetricSphericalHarmonic sh( values );
WValue< std::complex< double > > values2 = sh.getCoefficientsComplex();
WMatrix< std::complex< double > > complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 );
WVectorComplex_2 values2 = sh.getCoefficientsComplex();
WValue< std::complex< double > > res = complexBaseMatrix * values2;
WMatrixComplex_2 complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 );
WVectorComplex_2 res = complexBaseMatrix * values2;
for( std::size_t k = 0; k < orientations.size(); ++k )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment