core/vgl/algo/vgl_h_matrix_1d_compute.h
Go to the documentation of this file.
00001 #ifndef vgl_h_matrix_1d_compute_h_
00002 #define vgl_h_matrix_1d_compute_h_
00003 //:
00004 // \file
00005 // \brief Virtual base class of classes to generate a line-to-line projectivity from a set of matched points
00006 //
00007 // \author
00008 //  Frederik Schaffalitzky , Robotic Research Group
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   23 Mar 2003 - J.L. Mundy - preparing for upgrade to vgl
00013 //                 computations restricted to vgl_homg_point_1d<double>
00014 //                 Seems somewhat overdoing it to template the transform
00015 //                 solvers since double is needed for robust computation
00016 //   23 Jun 2003 - Peter Vanroose - made compute_cool_homg pure virtual
00017 //   24 Jun 2003 - Peter Vanroose - implemented the second compute() method
00018 //   13 Jun 2004 - Peter Vanroose - added compute() overload, similar to 2d interface
00019 // \endverbatim
00020 
00021 #include <vgl/vgl_homg_point_1d.h>
00022 #include <vgl/algo/vgl_h_matrix_1d.h>
00023 #include <vcl_vector.h>
00024 
00025 class vgl_h_matrix_1d_compute
00026 {
00027  public:
00028   //
00029   vgl_h_matrix_1d_compute() : verbose_(false) {}
00030   virtual ~vgl_h_matrix_1d_compute() {}
00031 
00032   //: set this to true for verbose run-time information; default is false
00033   void verbose(bool v) { verbose_=v; }
00034 
00035   //
00036   // Compute methods :
00037   //
00038 
00039   //: principal interface: given point correspondences in p1,p2, returns H
00040   bool compute(const vcl_vector<vgl_homg_point_1d<double> >& p1,
00041                const vcl_vector<vgl_homg_point_1d<double> >& p2,
00042                vgl_h_matrix_1d<double>& H)
00043   { return compute_cool_homg(p1,p2,H); } // calls pure virtual function
00044 
00045   //: nonhomogeneous interface: given point correspondences in p1,p2, returns H
00046   bool compute(const double p1[],
00047                const double p2[],
00048                unsigned int length, // length of both p1 and p2
00049                vgl_h_matrix_1d<double>& H)
00050   { return compute_array_dbl(p1,p2,length,H); }
00051 
00052   //: homography from matched points - return h_matrix
00053   vgl_h_matrix_1d<double>
00054   compute(vcl_vector<vgl_homg_point_1d<double> > const& p1,
00055           vcl_vector<vgl_homg_point_1d<double> > const& p2)
00056   { vgl_h_matrix_1d<double> H; compute(p1, p2, H); return H; }
00057 
00058  protected:
00059   bool verbose_;
00060 
00061   virtual bool compute_cool_homg(const vcl_vector<vgl_homg_point_1d<double> > &,
00062                                  const vcl_vector<vgl_homg_point_1d<double> > &,
00063                                  vgl_h_matrix_1d<double>& H) = 0;
00064 
00065   bool compute_array_dbl(const double p1[], const double p2[], unsigned int length,
00066                          vgl_h_matrix_1d<double>& H)
00067   {
00068     vcl_vector<vgl_homg_point_1d<double> > pt1; pt1.reserve(length);
00069     vcl_vector<vgl_homg_point_1d<double> > pt2; pt2.reserve(length);
00070     for (unsigned int i=0;i<length; ++i) {
00071       pt1.push_back(vgl_homg_point_1d<double>(p1[i],1.0));
00072       pt2.push_back(vgl_homg_point_1d<double>(p2[i],1.0));
00073     }
00074     return compute_cool_homg(pt1,pt2,H); // pure virtual function
00075   }
00076 };
00077 
00078 #endif // vgl_h_matrix_1d_compute_h_