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 WOSSIMHELPER_TEST_H 00026 #define WOSSIMHELPER_TEST_H 00027 00028 #include <cxxtest/TestSuite.h> 00029 00030 #include "../WOSSIMHelper.h" 00031 00032 /** 00033 * Tests for WOSSIMHelper. 00034 */ 00035 class WOSSIMHelperTest : public CxxTest::TestSuite 00036 { 00037 public: 00038 /** 00039 * Test ComputeSVD function of WOSSIMHelper 00040 */ 00041 void testComputeSVD( void ) 00042 { 00043 #ifdef OW_USE_OSSIM 00044 const size_t nbRows = 3, nbCols = 3; 00045 const double a = 1.2, b = 2.3, c = 3.4, 00046 d = 4.5, e = 5.6, f = 6.7, 00047 g = 3.4, h = 1.2, i = 7.0; 00048 WMatrix< double > A( nbRows, nbCols ); 00049 00050 A( 0, 0 ) = a; 00051 A( 0, 1 ) = b; 00052 A( 0, 2 ) = c; 00053 A( 1, 0 ) = d; 00054 A( 1, 1 ) = e; 00055 A( 1, 2 ) = f; 00056 A( 2, 0 ) = g; 00057 A( 2, 1 ) = h; 00058 A( 2, 2 ) = i; 00059 00060 WMatrix< double > U( nbRows, nbCols ); 00061 WMatrix< double > V( nbCols, nbCols ); 00062 WValue< double > S( nbCols ); 00063 00064 WOSSIMHelper::computeSVD( A, U, V, S ); 00065 00066 WMatrix< double > Sm( nbRows, nbCols ); 00067 Sm( 0, 0 ) = S[0]; 00068 Sm( 1, 1 ) = S[1]; 00069 Sm( 2, 2 ) = S[2]; 00070 00071 WMatrix<double> svd( U*Sm*V.transposed() ); 00072 00073 for( size_t row = 0; row < svd.getNbRows(); row++ ) 00074 { 00075 for( size_t col = 0; col < svd.getNbCols(); col++ ) 00076 { 00077 TS_ASSERT_DELTA( svd( row, col ), A( row, col ), 0.0001 ); 00078 } 00079 } 00080 #endif 00081 } 00082 /** 00083 * Test pseudoInverse function of WOSSIMHelper 00084 */ 00085 // void testPseudoInverse( void ) 00086 // { 00087 // const size_t nbRows = 3, nbCols = 3; 00088 // const double a = 1.2, b = 2.3, c = 3.4, 00089 // d = 4.5, e = 5.6, f = 6.7, 00090 // g = 3.4, h = 1.2, i = 7.0; 00091 // WMatrix< double > A( nbRows, nbCols ); 00092 // 00093 // A( 0, 0 ) = a; 00094 // A( 0, 1 ) = b; 00095 // A( 0, 2 ) = c; 00096 // A( 1, 0 ) = d; 00097 // A( 1, 1 ) = e; 00098 // A( 1, 2 ) = f; 00099 // A( 2, 0 ) = g; 00100 // A( 2, 1 ) = h; 00101 // A( 2, 2 ) = i; 00102 // 00103 // WMatrix<double> Ainvers( WOSSIMHelper::pseudoInverse( A ) ); 00104 // WMatrix<double> I( A*Ainvers ); 00105 // 00106 // for( size_t row = 0; row < I.getNbRows(); row++ ) 00107 // { 00108 // for( size_t col = 0; col < I.getNbCols(); col++ ) 00109 // { 00110 // if( row == col ) 00111 // { 00112 // TS_ASSERT_DELTA( I( row, col ), 1.0, 0.0001 ); 00113 // } 00114 // else 00115 // { 00116 // TS_ASSERT_DELTA( I( row, col ), 0.0, 0.0001 ); 00117 // } 00118 // } 00119 // } 00120 // } 00121 }; 00122 00123 #endif // WOSSIMHELPER_TEST_H