toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] tag/src five_point.cpp five_point_buildmatrix.cpp


From: Gerhard Reitmayr
Subject: [Toon-members] tag/src five_point.cpp five_point_buildmatrix.cpp
Date: Wed, 22 Apr 2009 20:47:47 +0000

CVSROOT:        /cvsroot/toon
Module name:    tag
Changes by:     Gerhard Reitmayr <gerhard>      09/04/22 20:47:47

Modified files:
        src            : five_point.cpp five_point_buildmatrix.cpp 

Log message:
        working five point, needs polynomial solver

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/tag/src/five_point.cpp?cvsroot=toon&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/tag/src/five_point_buildmatrix.cpp?cvsroot=toon&r1=1.1&r2=1.2

Patches:
Index: five_point.cpp
===================================================================
RCS file: /cvsroot/toon/tag/src/five_point.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- five_point.cpp      22 Apr 2009 19:59:36 -0000      1.2
+++ five_point.cpp      22 Apr 2009 20:47:47 -0000      1.3
@@ -13,6 +13,8 @@
 //CCMath's polyroot
 extern "C" int plrt(double *cof,int n,Cpx *root,double ra,double rb);
 
+namespace tag {
+
 void build_matrix(const Vector<9>& X, const Vector<9>& Y, const Vector<9>& Z, 
const Vector<9>& W, Matrix<10,20>& R);
 
 Vector<9> stack_points(const Vector<3>&p, const Vector<3>& q)
@@ -47,7 +49,7 @@
 
 template<int N> double polyval(const Vector<N>& v, double x)
 {
-       double val;
+       double val = 0;
        for(int i=v.size()-1; i > 0; i--)
        {
                val += v[i];    
@@ -63,8 +65,6 @@
        return Matrix<3, 3, double, Reference::RowMajor>(&v[0]);
 }
 
-namespace tag {
-
 vector<Matrix<3> > five_point(array<pair<Vector<3>, Vector<3> >, 5> points)
 {
        //Equations numbers are given with reference to:
@@ -96,8 +96,6 @@
        for(int i=0; i < 5; i++)
                Q[i] = stack_points(points[i].first, points[i].second);
        
-       cout << "Q\n" << Q << endl;
-       
        SVD<9, 9> svd_Q(Q);
 
        //The null-space it the last 4 rows of svd_Q.get_VT()
@@ -108,38 +106,14 @@
        Vector<9> Z = svd_Q.get_VT()[7];
        Vector<9> W = svd_Q.get_VT()[8];
 
-    cout << "X\t" << X << "\t\t Q * X\t" << Q * X << endl;
-    cout << "Y\t" << Y << "\t\t Q * Y\t" << Q * Y << endl;
-    cout << "Z\t" << Z << "\t\t Q * Z\t" << Q * Z << endl;
-    cout << "W\t" << W << "\t\t Q * W\t" << Q * W << endl;
-
-
-X = makeVector( -0.3508458,   0.4252379 ,  0.1214881 , -0.1338175 ,  0.1639596 
,  0.6245507 ,  -0.4360203 , -0.2116077 , -0.1075906 );
-Y = makeVector(  -0.0081994,   0.6219738,  -0.3402116 , -0.3747868 ,  
0.3759810 , -0.2746115 ,  0.3076462 ,  0.0462667 ,  0.2081162 );
-Z = makeVector(  -0.3009486,   0.2482359,   0.5399394  , 0.0511941 , 
-0.0154038 , -0.3929876 , -0.2147039 ,  0.5882101 , -0.0829940 );
-W = makeVector(  -0.6655390,  -0.0115146,  -0.4274621  , 0.4664177 , 
-0.1470300  , 0.1107449 ,  0.2253744 ,  0.1945985 ,  0.1846930 );
-
-
-    cout << "nullspace new\n";
-    cout << "X\t" << X << "\t\t Q * X\t" << Q * X << endl;
-    cout << "Y\t" << Y << "\t\t Q * Y\t" << Q * Y << endl;
-    cout << "Z\t" << Z << "\t\t Q * Z\t" << Q * Z << endl;
-    cout << "W\t" << W << "\t\t Q * W\t" << Q * W << endl;
-
-
        
        Matrix<10,20> R;
        build_matrix(X, Y, Z, W, R);
 
-    cout << "R\n" << R << endl;
-    Matrix<10,20> R_copy = R;
-
 
        //Columns are:
-       // x^3 y^3 x^2y xy^2 x^2z x^2 y^2 x^2z y^2 xyz xy | z^2x zx x    z^2y 
zy y   z^3 z^2 z 1 
        gauss_jordan(R);
 
-    cout << "R Jordan\n" << R << endl;
 
        //Build the B matrix (Eqn 13 1/2)
        //Polynomials of degree N are stored in a Vector<N+1> with Vector[0] as 
the coefficient of 1.
@@ -176,8 +150,8 @@
        //b_22 is <l> coefficients of 1
        //b_32 is <R> coefficients of 1
        Vector<5> b_13 = makeVector(R[4][19], R[4][18], R[4][17], R[4][16], 0) 
- makeVector(0, R[5][19], R[5][18], R[5][17], R[5][16]);
-       Vector<5> b_23 = makeVector(R[6][19], R[6][18], R[6][17], R[6][16], 0) 
- makeVector(0, R[5][19], R[7][18], R[7][17], R[7][16]);
-       Vector<5> b_33 = makeVector(R[8][19], R[8][18], R[8][17], R[8][16], 0) 
- makeVector(0, R[5][19], R[9][18], R[9][17], R[9][16]);
+       Vector<5> b_23 = makeVector(R[6][19], R[6][18], R[6][17], R[6][16], 0) 
- makeVector(0, R[7][19], R[7][18], R[7][17], R[7][16]);
+       Vector<5> b_33 = makeVector(R[8][19], R[8][18], R[8][17], R[8][16], 0) 
- makeVector(0, R[9][19], R[9][18], R[9][17], R[9][16]);
 
        //Compute the Determinant of B using expansion by minors
        //Not quite Eqn 24--28. Nister uses col/row not row/col
@@ -191,9 +165,6 @@
        //The polynomial is...
        Vector<11> n = poly_mul(p1, b_31) + poly_mul(p2, b_32) + poly_mul(p3, 
b_33);
 
-    cout << "poly\t" << n << endl;
-
-       Cpx roots[10];  
        
        //Use the CCMath root finder.
        //-1, 1 seem to work OK.
@@ -201,16 +172,13 @@
        // Return value means:
        // 0 -> normal exit
     // m>0 -> convergence failure for roots k<m
-       int num = plrt(&n[0], 10, roots, 40, -10);
+       Cpx roots[10];  
+       int num = plrt(&n[0], 10, roots, 1, -1);
 
        vector<Matrix<3> > Es;
 
-    cout << "roots\t" << num << endl;
-
        for(int i=num; i < 10; i++)
        {
-           cout <<  roots[i].re << "\t" << roots[i].im << endl;
-       
                if(abs(roots[i].im) < 1e-10)
                {
                        double z = roots[i].re;
@@ -230,13 +198,6 @@
                        double y = polyval(p2, z)/polyval(p3,z);
 
                        Es.push_back(x * as_matrix(X) + y*as_matrix(Y) + 
z*as_matrix(Z) + as_matrix(W));
-#if 1          
-                       Vector<20> coeffs = makeVector(x*x*x, y*y*y, x*x*y, 
x*y*y, x*x*z, x*x, y*y*z, y*y, x*y*z, x*y, x*z*z, x*z, x, y*z*z, y*z, y, z*z*z, 
z*z, z, 1);
-                       cout << R_copy * coeffs << endl;
-                       cout << R * coeffs << endl;
-                       cout << endl;
-
-#endif
                }
        }
 
@@ -244,5 +205,3 @@
 }
 
 }
-
-

Index: five_point_buildmatrix.cpp
===================================================================
RCS file: /cvsroot/toon/tag/src/five_point_buildmatrix.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- five_point_buildmatrix.cpp  22 Apr 2009 17:05:25 -0000      1.1
+++ five_point_buildmatrix.cpp  22 Apr 2009 20:47:47 -0000      1.2
@@ -2,6 +2,8 @@
 
 using namespace TooN;
 
+namespace tag {
+
 void build_matrix(const Vector<9>& X, const Vector<9>& Y, const Vector<9>& Z, 
const Vector<9>& W, Matrix<10,20>& R)
 {
      const double t1 = X[0]*X[0];
@@ -741,3 +743,5 @@
       R[9][19] = -t3154*W[4]+t3152*W[5]-t3164*W[7]+t3162*W[8]-t3146*W[8]+t3144*
 W[7];
 }
+
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]