core/vgl/algo/vgl_h_matrix_2d_compute_4point.cxx
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_2d_compute_4point.cxx
00002 #include "vgl_h_matrix_2d_compute_4point.h"
00003 //:
00004 // \file
00005 #include <vnl/vnl_inverse.h>
00006 #include <vcl_cassert.h>
00007 
00008 //-----------------------------------------------------------------------------
00009 //
00010 //: Compute a plane-plane projectivity using 4 point correspondences.
00011 // Returns false if the calculation fails or there are fewer than four point
00012 // matches in the list.
00013 //
00014 // The algorithm determines the transformation $H_i$ from each pointset to the
00015 // canonical projective basis (see h_matrix_2d::projective_basis), and
00016 // returns the combined transform $H = H_2^{-1} H_1$.
00017 bool vgl_h_matrix_2d_compute_4point::compute_p(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00018                                                vcl_vector<vgl_homg_point_2d<double> > const& points2,
00019                                                vgl_h_matrix_2d<double>& H)
00020 {
00021   vgl_h_matrix_2d<double> H1, H2;
00022   if (!H1.projective_basis(points1))
00023     return false;
00024   if (!H2.projective_basis(points2))
00025     return false;
00026   H.set(vnl_inverse(H2.get_matrix()) * H1.get_matrix());
00027   return true;
00028 }
00029 
00030 //-----------------------------------------------------------------------------
00031 //
00032 //: Compute a plane-plane projectivity using 4 line correspondences.
00033 // Returns false if the calculation fails or there are fewer than four line
00034 // matches in the list.
00035 //
00036 // Implementation is the dual of the implementation of compute_p()
00037 bool vgl_h_matrix_2d_compute_4point::compute_l(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00038                                                vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00039                                                vgl_h_matrix_2d<double>& H)
00040 {
00041   vgl_h_matrix_2d<double> H1, H2;
00042   if (!H1.projective_basis(lines1))
00043     return false;
00044   if (!H2.projective_basis(lines2))
00045     return false;
00046   H.set(vnl_inverse(H2.get_matrix()) * H1.get_matrix());
00047   return true;
00048 }
00049 
00050 bool vgl_h_matrix_2d_compute_4point::compute_l(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00051                                                vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00052                                                vcl_vector<double> const&,
00053                                                vgl_h_matrix_2d<double>& H)
00054 {
00055   vgl_h_matrix_2d<double> H1, H2;
00056   if (!H1.projective_basis(lines1))
00057     return false;
00058   if (!H2.projective_basis(lines2))
00059     return false;
00060   H.set(vnl_inverse(H2.get_matrix()) * H1.get_matrix());
00061   return true;
00062 }
00063 
00064 bool vgl_h_matrix_2d_compute_4point::compute_pl(vcl_vector<vgl_homg_point_2d<double> > const& /*points1*/,
00065                                                 vcl_vector<vgl_homg_point_2d<double> > const& /*points2*/,
00066                                                 vcl_vector<vgl_homg_line_2d<double> > const& /*lines1*/,
00067                                                 vcl_vector<vgl_homg_line_2d<double> > const& /*lines2*/,
00068                                                 vgl_h_matrix_2d<double>& )
00069 {
00070   assert(!"vgl_h_matrix_2d_compute_4point::compute_pl() NYI");
00071   return false;
00072 }