OpenWalnut  1.5.0dev
WOSSIMHelper_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WOSSIMHELPER_TEST_H
26 #define WOSSIMHELPER_TEST_H
27 
28 #include <cxxtest/TestSuite.h>
29 
30 #include "../WOSSIMHelper.h"
31 
32 /**
33  * Tests for WOSSIMHelper.
34  */
35 class WOSSIMHelperTest : public CxxTest::TestSuite
36 {
37 public:
38  /**
39  * Test ComputeSVD function of WOSSIMHelper
40  */
41  void testComputeSVD( void )
42  {
43 #ifdef OW_USE_OSSIM
44  const size_t nbRows = 3, nbCols = 3;
45  const double a = 1.2, b = 2.3, c = 3.4,
46  d = 4.5, e = 5.6, f = 6.7,
47  g = 3.4, h = 1.2, i = 7.0;
48  WMatrix< double > A( nbRows, nbCols );
49 
50  A( 0, 0 ) = a;
51  A( 0, 1 ) = b;
52  A( 0, 2 ) = c;
53  A( 1, 0 ) = d;
54  A( 1, 1 ) = e;
55  A( 1, 2 ) = f;
56  A( 2, 0 ) = g;
57  A( 2, 1 ) = h;
58  A( 2, 2 ) = i;
59 
60  WMatrix< double > U( nbRows, nbCols );
61  WMatrix< double > V( nbCols, nbCols );
62  WValue< double > S( nbCols );
63 
64  WOSSIMHelper::computeSVD( A, U, V, S );
65 
66  WMatrix< double > Sm( nbRows, nbCols );
67  Sm( 0, 0 ) = S[0];
68  Sm( 1, 1 ) = S[1];
69  Sm( 2, 2 ) = S[2];
70 
71  WMatrix<double> svd( U*Sm*V.transposed() );
72 
73  for( size_t row = 0; row < svd.getNbRows(); row++ )
74  {
75  for( size_t col = 0; col < svd.getNbCols(); col++ )
76  {
77  TS_ASSERT_DELTA( svd( row, col ), A( row, col ), 0.0001 );
78  }
79  }
80 #endif
81  }
82  /**
83  * Test pseudoInverse function of WOSSIMHelper
84  */
85 // void testPseudoInverse( void )
86 // {
87 // const size_t nbRows = 3, nbCols = 3;
88 // const double a = 1.2, b = 2.3, c = 3.4,
89 // d = 4.5, e = 5.6, f = 6.7,
90 // g = 3.4, h = 1.2, i = 7.0;
91 // WMatrix< double > A( nbRows, nbCols );
92 //
93 // A( 0, 0 ) = a;
94 // A( 0, 1 ) = b;
95 // A( 0, 2 ) = c;
96 // A( 1, 0 ) = d;
97 // A( 1, 1 ) = e;
98 // A( 1, 2 ) = f;
99 // A( 2, 0 ) = g;
100 // A( 2, 1 ) = h;
101 // A( 2, 2 ) = i;
102 //
103 // WMatrix<double> Ainvers( WOSSIMHelper::pseudoInverse( A ) );
104 // WMatrix<double> I( A*Ainvers );
105 //
106 // for( size_t row = 0; row < I.getNbRows(); row++ )
107 // {
108 // for( size_t col = 0; col < I.getNbCols(); col++ )
109 // {
110 // if( row == col )
111 // {
112 // TS_ASSERT_DELTA( I( row, col ), 1.0, 0.0001 );
113 // }
114 // else
115 // {
116 // TS_ASSERT_DELTA( I( row, col ), 0.0, 0.0001 );
117 // }
118 // }
119 // }
120 // }
121 };
122 
123 #endif // WOSSIMHELPER_TEST_H
size_t getNbRows() const
Get number of rows.
Definition: WMatrix.h:375
WMatrix transposed() const
Returns the transposed matrix.
Definition: WMatrix.h:447
size_t getNbCols() const
Get number of columns.
Definition: WMatrix.h:383
Tests for WOSSIMHelper.
void testComputeSVD(void)
Test ComputeSVD function of WOSSIMHelper.
Base class for all higher level values like tensors, vectors, matrices and so on.
Definition: WValue.h:41