OpenWalnut 1.3.1
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WSYMMETRICSPHERICALHARMONIC_TEST_H 00026 #define WSYMMETRICSPHERICALHARMONIC_TEST_H 00027 00028 #include <vector> 00029 00030 // the following block is only for the last termporarly test 00031 // #include <boost/nondet_random.hpp> 00032 // #include <boost/random.hpp> 00033 // #include <boost/random/normal_distribution.hpp> 00034 // #include <boost/random/uniform_real.hpp> 00035 // #include <boost/random/linear_congruential.hpp> 00036 // #include <boost/random/uniform_real.hpp> 00037 // #include <boost/random/variate_generator.hpp> 00038 00039 #include <cxxtest/TestSuite.h> 00040 00041 #include "../WMatrix.h" 00042 #include "../linearAlgebra/WLinearAlgebra.h" 00043 #include "../WValue.h" 00044 00045 #include "../WGeometryFunctions.h" 00046 #include "../WSymmetricSphericalHarmonic.h" 00047 #include "../WTensorSym.h" 00048 #include "../WTensorFunctions.h" 00049 00050 #include "WMatrixTraits.h" 00051 00052 /** 00053 * Testsuite for WPosition. 00054 */ 00055 class WSymmetricSphericalHarmonicTest : public CxxTest::TestSuite 00056 { 00057 public: 00058 /** 00059 * testCalcFRTMatrix 00060 * 00061 */ 00062 void testCalcFRTMatrix( void ) 00063 { 00064 WMatrix<double> result( WSymmetricSphericalHarmonic::calcFRTMatrix( 4 ) ); 00065 WMatrix<double> reference( 15, 15 ); 00066 reference.setZero(); 00067 // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00068 // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4 00069 reference( 0, 0 ) = 2.0 * piDouble; 00070 for( size_t i = 1; i <= 5; i++ ) 00071 { 00072 reference( i, i ) = -2.0 * piDouble * 1.0 / 2.0; 00073 } 00074 for( size_t i = 6; i <= 14; i++ ) 00075 { 00076 reference( i, i ) = 2.0 * piDouble * 3.0 / 8.0; 00077 } 00078 00079 for( size_t i = 0; i < 15; ++i ) 00080 { 00081 for( size_t j = 0; j < 15; ++j ) 00082 { 00083 TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 ); 00084 } 00085 } 00086 } 00087 00088 /** 00089 * testCalcSmoothingMatrix 00090 * 00091 */ 00092 void testCalcSmoothingMatrix( void ) 00093 { 00094 WMatrix<double> result( WSymmetricSphericalHarmonic::calcSmoothingMatrix( 4 ) ); 00095 WMatrix<double> reference( 15, 15 ); 00096 reference.setZero(); 00097 // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00098 // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4 00099 reference( 0, 0 ) = 0.0; 00100 for( size_t i = 1; i <= 5; i++ ) 00101 { 00102 reference( i, i ) = 36.0; 00103 } 00104 for( size_t i = 6; i <= 14; i++ ) 00105 { 00106 reference( i, i ) = 400.0; 00107 } 00108 00109 for( size_t i = 0; i < 15; ++i ) 00110 { 00111 for( size_t j = 0; j < 15; ++j ) 00112 { 00113 TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 ); 00114 } 00115 } 00116 } 00117 00118 // TODO(reichenbach, philips): repair the following to tests 00119 /** 00120 * The matrix calculated by the calcSHToTensorSymMatrix function should produce tensors that 00121 * evaluate to the same values as the respective spherical harmonics. 00122 */ 00123 // void testCalcSHtoTensorMatrix() 00124 // { 00125 // WValue<double> w( 6 ); 00126 // for( int i = 0; i < 6; ++i ) 00127 // { 00128 // w[ i ] = exp( i / 6.0 ); 00129 // } 00130 00131 // WSymmetricSphericalHarmonic i( w ); 00132 00133 // std::vector< WUnitSphereCoordinates > orientations; 00134 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 0.0, 0.0 ) ) ) ); 00135 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.6, -0.1, 0.2 ) ) ) ); 00136 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 1.0, 1.0 ) ) ) ); 00137 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( -0.1, -0.3, 0.5 ) ) ) ); 00138 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, 0.676676 ) ) ) ); 00139 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, -0.676676 ) ) ) ); 00140 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 0.0, -4.0 ) ) ) ); 00141 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 4.0, 1.0 ) ) ) ); 00142 00143 // WMatrix<double> SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations ); 00144 // // TODO(all): remove the WValue from the following line, when WTensorSym supports WVector_2 00145 // WTensorSym< 2, 3, double > t( WValue<double>( SHToTensor * w ) ); 00146 00147 // for( std::vector< WUnitSphereCoordinates >::iterator it = orientations.begin(); 00148 // it != orientations.end(); 00149 // ++it ) 00150 // { 00151 // TS_ASSERT_DELTA( i.getValue( *it ), evaluateSphericalFunction( t, it->getEuclidean() ), 0.001 ); 00152 // } 00153 // } 00154 00155 /** 00156 * Test complex SH coefficient conversion. 00157 */ 00158 // void testComplex() 00159 // { 00160 // // calc a conversion matrix 00161 // std::vector< WVector3d > grad; 00162 // std::vector< unsigned int > edges; 00163 // tesselateIcosahedron( &grad, &edges, 3 ); 00164 // edges.clear(); 00165 00166 // std::vector< WUnitSphereCoordinates > orientations; 00167 // for( std::size_t i = 0; i < grad.size(); ++i ) 00168 // { 00169 // if( grad[ i ][ 0 ] > 0.0 ) 00170 // { 00171 // orientations.push_back( WUnitSphereCoordinates( grad[ i ] ) ); 00172 // } 00173 // } 00174 // grad.clear(); 00175 00176 // WVector_2 values( 15 ); 00177 // for( std::size_t i = 0; i < 15; ++i ) 00178 // { 00179 // values[ i ] = i / 15.0; 00180 // } 00181 // WSymmetricSphericalHarmonic sh( values ); 00182 00183 // WVectorComplex_2 values2 = sh.getCoefficientsComplex(); 00184 00185 // WMatrixComplex_2 complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 ); 00186 00187 // WVectorComplex_2 res = complexBaseMatrix * values2; 00188 00189 // for( std::size_t k = 0; k < orientations.size(); ++k ) 00190 // { 00191 // TS_ASSERT_DELTA( res[ k ].imag(), 0.0, 1e-15 ); 00192 // TS_ASSERT_DELTA( res[ k ].real(), sh.getValue( orientations[ k ] ), 1e-15 ); 00193 // } 00194 // } 00195 }; 00196 00197 #endif // WSYMMETRICSPHERICALHARMONIC_TEST_H