core/vgl/algo/vgl_h_matrix_2d_compute.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_h_matrix_2d_compute.h
00002 #ifndef vgl_h_matrix_2d_compute_h_
00003 #define vgl_h_matrix_2d_compute_h_
00004 //:
00005 // \file
00006 // \brief contains class vgl_h_matrix_2d_compute
00007 //
00008 // Abstract interface for classes that compute plane-to-plane
00009 // projectivities from point and line correspondences.
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   08-02-98 FSM
00014 //      1. Added virtual compute methods that actually take arguments :
00015 //         generic estimator using points, lines or both.
00016 //      2. Obsoleted bool compute(vgl_h_matrix_2d<double>  *). So don't use it!
00017 //      3. made arguments to compute method 'const ... &',
00018 //         thereby potentially breaking the code of certain other people.
00019 //
00020 //   Mar 24, 2003 JLM Modifications to move to vgl algo
00021 //   May 15, 2003 JLM Added a weighted least squares interface for computing
00022 //                a homography from line correspondences.
00023 //   Jun 23, 2003 Peter Vanroose - made compute_pl() etc. pure virtual
00024 // \endverbatim
00025 #include <vcl_vector.h>
00026 #include <vgl/vgl_homg_point_2d.h>
00027 #include <vgl/vgl_homg_line_2d.h>
00028 #include <vgl/algo/vgl_h_matrix_2d.h>
00029 
00030 class vgl_h_matrix_2d_compute
00031 {
00032  public:
00033   vgl_h_matrix_2d_compute() : verbose_(false) {}
00034   virtual ~vgl_h_matrix_2d_compute() {}
00035 
00036   // set this to true for verbose run-time information
00037   void verbose(bool v) { verbose_ = v; }
00038 
00039   // fsm
00040   virtual int minimum_number_of_correspondences() const = 0;
00041 
00042   // Compute methods :
00043   //
00044   // Some use point correspondences, some use line
00045   // correspondences, some use both. They are implemented
00046   // in terms of the pure virtual compute_(p|l|pl) methods.
00047 
00048   //: homography from matched points
00049   bool compute(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00050                vcl_vector<vgl_homg_point_2d<double> > const& points2,
00051                vgl_h_matrix_2d<double>& H)
00052   {
00053     return compute_p(points1, points2, H);
00054   }
00055 
00056  //: homography from matched lines
00057   bool compute(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00058                vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00059                vgl_h_matrix_2d<double>& H)
00060   {
00061     return compute_l(lines1, lines2, H);
00062   }
00063 
00064  //: homography from matched lines with a weight vector
00065   bool compute(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00066                vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00067                vcl_vector<double> const& weights,
00068                vgl_h_matrix_2d<double>& H)
00069   {
00070     return compute_l(lines1, lines2, weights, H);
00071   }
00072 
00073   //: homography from matched points and lines
00074   bool compute(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00075                vcl_vector<vgl_homg_point_2d<double> > const& points2,
00076                vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00077                vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00078                vgl_h_matrix_2d<double>& H)
00079   {
00080     return compute_pl(points1, points2, lines1, lines2, H);
00081   }
00082 
00083   //: homography from matched points - return h_matrix
00084   vgl_h_matrix_2d<double>
00085   compute(vcl_vector<vgl_homg_point_2d<double> > const& p1,
00086           vcl_vector<vgl_homg_point_2d<double> > const& p2)
00087   { vgl_h_matrix_2d<double> H; compute_p(p1, p2, H); return H; }
00088 
00089   //: homography from matched lines - return h_matrix
00090   vgl_h_matrix_2d<double>
00091   compute(vcl_vector<vgl_homg_line_2d<double> > const& l1,
00092           vcl_vector<vgl_homg_line_2d<double> > const& l2)
00093   { vgl_h_matrix_2d<double> H; compute_l(l1, l2, H); return H; }
00094 
00095   //: homography from matched lines with weight vector - return h_matrix
00096   vgl_h_matrix_2d<double>
00097   compute(vcl_vector<vgl_homg_line_2d<double> > const& l1,
00098           vcl_vector<vgl_homg_line_2d<double> > const& l2,
00099           vcl_vector<double> const& weights)
00100   { vgl_h_matrix_2d<double> H; compute_l(l1, l2, weights, H); return H; }
00101 
00102   //: homography from matched points and lines - return h_matrix
00103   vgl_h_matrix_2d<double>
00104   compute(vcl_vector<vgl_homg_point_2d<double> > const& p1,
00105           vcl_vector<vgl_homg_point_2d<double> > const& p2,
00106           vcl_vector<vgl_homg_line_2d<double> > const& l1,
00107           vcl_vector<vgl_homg_line_2d<double> > const& l2)
00108   { vgl_h_matrix_2d<double>  H; compute_pl(p1, p2, l1, l2, H); return H; }
00109 
00110  protected:
00111   bool verbose_;
00112   virtual bool compute_p(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00113                          vcl_vector<vgl_homg_point_2d<double> > const& points2,
00114                          vgl_h_matrix_2d<double>& H) = 0;
00115 
00116   virtual bool compute_l(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00117                          vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00118                          vgl_h_matrix_2d<double>& H) = 0;
00119 
00120   virtual bool compute_l(vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00121                          vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00122                          vcl_vector<double> const& weights,
00123                          vgl_h_matrix_2d<double>& H) = 0;
00124 
00125   virtual bool compute_pl(vcl_vector<vgl_homg_point_2d<double> > const& points1,
00126                           vcl_vector<vgl_homg_point_2d<double> > const& points2,
00127                           vcl_vector<vgl_homg_line_2d<double> > const& lines1,
00128                           vcl_vector<vgl_homg_line_2d<double> > const& lines2,
00129                           vgl_h_matrix_2d<double>& H) = 0;
00130 };
00131 
00132 #endif // vgl_h_matrix_2d_compute_h_