OpenWalnut
1.4.0
|
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 "../WValue.h" 00043 00044 #include "../WGeometryFunctions.h" 00045 #include "../WSymmetricSphericalHarmonic.h" 00046 #include "../WTensorSym.h" 00047 #include "../WTensorFunctions.h" 00048 00049 #include "WMatrixTraits.h" 00050 00051 /** 00052 * Testsuite for WSymmetricSphericalHarmonic. 00053 */ 00054 class WSymmetricSphericalHarmonicTest : public CxxTest::TestSuite 00055 { 00056 public: 00057 /** 00058 * testCalcFRTMatrix 00059 * 00060 */ 00061 void testCalcFRTMatrix( void ) 00062 { 00063 WMatrix<double> result( WSymmetricSphericalHarmonic< double >::calcFRTMatrix( 4 ) ); 00064 WMatrix<double> reference( 15, 15 ); 00065 reference.setZero(); 00066 // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00067 // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4 00068 reference( 0, 0 ) = 2.0 * piDouble; 00069 for( size_t i = 1; i <= 5; i++ ) 00070 { 00071 reference( i, i ) = -2.0 * piDouble * 1.0 / 2.0; 00072 } 00073 for( size_t i = 6; i <= 14; i++ ) 00074 { 00075 reference( i, i ) = 2.0 * piDouble * 3.0 / 8.0; 00076 } 00077 00078 for( size_t i = 0; i < 15; ++i ) 00079 { 00080 for( size_t j = 0; j < 15; ++j ) 00081 { 00082 TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 ); 00083 } 00084 } 00085 } 00086 00087 /** 00088 * testCalcSmoothingMatrix 00089 * 00090 */ 00091 void testCalcSmoothingMatrix( void ) 00092 { 00093 WMatrix<double> result( WSymmetricSphericalHarmonic< double >::calcSmoothingMatrix( 4 ) ); 00094 WMatrix<double> reference( 15, 15 ); 00095 reference.setZero(); 00096 // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00097 // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4 00098 reference( 0, 0 ) = 0.0; 00099 for( size_t i = 1; i <= 5; i++ ) 00100 { 00101 reference( i, i ) = 36.0; 00102 } 00103 for( size_t i = 6; i <= 14; i++ ) 00104 { 00105 reference( i, i ) = 400.0; 00106 } 00107 00108 for( size_t i = 0; i < 15; ++i ) 00109 { 00110 for( size_t j = 0; j < 15; ++j ) 00111 { 00112 TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 ); 00113 } 00114 } 00115 } 00116 00117 // TODO(reichenbach, philips): repair the following to tests 00118 /** 00119 * The matrix calculated by the calcSHToTensorSymMatrix function should produce tensors that 00120 * evaluate to the same values as the respective spherical harmonics. 00121 */ 00122 // void testCalcSHtoTensorMatrix() 00123 // { 00124 // WValue<double> w( 6 ); 00125 // for( int i = 0; i < 6; ++i ) 00126 // { 00127 // w[ i ] = exp( i / 6.0 ); 00128 // } 00129 00130 // WSymmetricSphericalHarmonic i( w ); 00131 00132 // std::vector< WUnitSphereCoordinates > orientations; 00133 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 0.0, 0.0 ) ) ) ); 00134 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.6, -0.1, 0.2 ) ) ) ); 00135 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 1.0, 1.0 ) ) ) ); 00136 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( -0.1, -0.3, 0.5 ) ) ) ); 00137 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, 0.676676 ) ) ) ); 00138 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, -0.676676 ) ) ) ); 00139 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 0.0, -4.0 ) ) ) ); 00140 // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 4.0, 1.0 ) ) ) ); 00141 00142 // WMatrix<double> SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations ); 00143 // // TODO(all): remove the WValue from the following line, when WTensorSym supports WVector_2 00144 // WTensorSym< 2, 3, double > t( WValue<double>( SHToTensor * w ) ); 00145 00146 // for( std::vector< WUnitSphereCoordinates >::iterator it = orientations.begin(); 00147 // it != orientations.end(); 00148 // ++it ) 00149 // { 00150 // TS_ASSERT_DELTA( i.getValue( *it ), evaluateSphericalFunction( t, it->getEuclidean() ), 0.001 ); 00151 // } 00152 // } 00153 00154 /** 00155 * Test complex SH coefficient conversion. 00156 */ 00157 // void testComplex() 00158 // { 00159 // // calc a conversion matrix 00160 // std::vector< WVector3d > grad; 00161 // std::vector< unsigned int > edges; 00162 // tesselateIcosahedron( &grad, &edges, 3 ); 00163 // edges.clear(); 00164 00165 // std::vector< WUnitSphereCoordinates > orientations; 00166 // for( std::size_t i = 0; i < grad.size(); ++i ) 00167 // { 00168 // if( grad[ i ][ 0 ] > 0.0 ) 00169 // { 00170 // orientations.push_back( WUnitSphereCoordinates( grad[ i ] ) ); 00171 // } 00172 // } 00173 // grad.clear(); 00174 00175 // WVector_2 values( 15 ); 00176 // for( std::size_t i = 0; i < 15; ++i ) 00177 // { 00178 // values[ i ] = i / 15.0; 00179 // } 00180 // WSymmetricSphericalHarmonic sh( values ); 00181 00182 // WVectorComplex_2 values2 = sh.getCoefficientsComplex(); 00183 00184 // WMatrixComplex_2 complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 ); 00185 00186 // WVectorComplex_2 res = complexBaseMatrix * values2; 00187 00188 // for( std::size_t k = 0; k < orientations.size(); ++k ) 00189 // { 00190 // TS_ASSERT_DELTA( res[ k ].imag(), 0.0, 1e-15 ); 00191 // TS_ASSERT_DELTA( res[ k ].real(), sh.getValue( orientations[ k ] ), 1e-15 ); 00192 // } 00193 // } 00194 }; 00195 00196 #endif // WSYMMETRICSPHERICALHARMONIC_TEST_H