core/vgl/algo/vgl_h_matrix_1d_compute_linear.cxx
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_1d_compute_linear.cxx
00002 #include "vgl_h_matrix_1d_compute_linear.h"
00003 #include <vcl_cassert.h>
00004 #include <vnl/algo/vnl_svd.h>
00005 
00006 //********************************************************************************
00007 //
00008 //
00009 //
00010 //********************************************************************************
00011 
00012 bool vgl_h_matrix_1d_compute_linear::
00013 compute_cool_homg(const vcl_vector<vgl_homg_point_1d<double> >&P,
00014                   const vcl_vector<vgl_homg_point_1d<double> >&Q,
00015                   vgl_h_matrix_1d<double>& M)
00016 {
00017   unsigned N=P.size(); assert(N==Q.size());
00018   vnl_matrix<double> D(N,4);
00019   for (unsigned i=0;i<N;i++) {
00020     D(i,0)=P[i].x()*Q[i].w();
00021     D(i,1)=P[i].w()*Q[i].w();
00022     D(i,2)=-P[i].x()*Q[i].x();
00023     D(i,3)=-P[i].w()*Q[i].x();
00024   }
00025   vnl_svd<double> svd(D);
00026   M.set(svd.nullvector().data_block());
00027   return true;
00028 }