core/vpgl/algo/vpgl_rational_adjust_multipt.h
Go to the documentation of this file.
00001 // This is core/vpgl/algo/vpgl_rational_adjust_multipt.h
00002 #ifndef vpgl_rational_adjust_multipt_h_
00003 #define vpgl_rational_adjust_multipt_h_
00004 //:
00005 // \file
00006 // \brief Adjust image offsets to register a set of rational cameras using multiple correspondence points
00007 // \author Ozge C. Ozcanli
00008 // \date Nov 17, 2011
00009 //
00010 
00011 #include <vcl_vector.h>
00012 #include <vnl/vnl_vector.h>
00013 #include <vnl/vnl_least_squares_function.h>
00014 #include <vpgl/vpgl_rational_camera.h>
00015 #include <vgl/vgl_vector_2d.h>
00016 #include <vgl/vgl_point_2d.h>
00017 #include <vgl/vgl_point_3d.h>
00018 
00019 
00020 //:
00021 // This algorithm finds a set of minimum translations that registers the input set of images using multiple correspondences
00022 // e.g. multiple 3D points projecting to a set of 2D correspondences in each image
00023 // After registration, the images have geographically corresponding rational
00024 // cameras. That is, a visible 3-d point will project into its corresponding
00025 // image location in all the images.
00026 
00027 class vpgl_cam_trans_search_lsqr : public vnl_least_squares_function
00028 {
00029  public:
00030   //: Constructor
00031   vpgl_cam_trans_search_lsqr(vcl_vector<vpgl_rational_camera<double> > const& cams,
00032                              vcl_vector< vcl_vector<vgl_point_2d<double> > > const& image_pts,  // for each 3D corr, an array of 2D corrs for each camera
00033                              vcl_vector< vgl_point_3d<double> > const& initial_pts);
00034   //: Destructor
00035   virtual ~vpgl_cam_trans_search_lsqr() {}
00036 
00037   //: The main function.
00038   //  Given the parameter vector x, compute the vector of residuals fx.
00039   //  fx has been sized appropriately before the call.
00040   virtual void f(vnl_vector<double> const& translation,   // size is 2*cams.size()
00041                  vnl_vector<double>& projection_errors);  // size is cams.size()*image_pts.size() --> compute a residual for each 3D corr point in each image
00042 
00043   void get_finals(vcl_vector<vgl_point_3d<double> >& finals);
00044 
00045  protected:
00046   vpgl_cam_trans_search_lsqr();//not valid
00047   vcl_vector<vgl_point_3d<double> > initial_pts_;
00048   vcl_vector<vpgl_rational_camera<double> > cameras_; //cameras
00049   vcl_vector<vcl_vector<vgl_point_2d<double> > > corrs_;
00050   vcl_vector<vgl_point_3d<double> > finals_;
00051 };
00052 
00053 class vpgl_rational_adjust_multiple_pts
00054 {
00055  public:
00056   ~vpgl_rational_adjust_multiple_pts() {}
00057 
00058   //: exhaustively searches the parameter space to find the best parameter setting
00059   static bool adjust(vcl_vector<vpgl_rational_camera<double> > const& cams,
00060                      vcl_vector<vcl_vector< vgl_point_2d<double> > > const& corrs,  // a vector of correspondences for each cam
00061                      double radius, int n,       // divide radius into n intervals to generate camera translation space
00062                      vcl_vector<vgl_vector_2d<double> >& cam_translations,          // output translations for each cam
00063                      vcl_vector<vgl_point_3d<double> >& intersections);             // output 3d locations for each correspondence
00064 
00065   //: run Lev-Marq optimization to search the param space to find the best parameter setting
00066   static bool adjust_lev_marq(vcl_vector<vpgl_rational_camera<double> > const& cams,
00067                               vcl_vector<vcl_vector< vgl_point_2d<double> > > const& corrs, // a vector of correspondences for each cam
00068                               vcl_vector<vgl_vector_2d<double> >& cam_translations, // output translations for each cam
00069                               vcl_vector<vgl_point_3d<double> >& intersections);    // output 3d locations for each correspondence
00070 
00071  protected:
00072   vpgl_rational_adjust_multiple_pts();
00073 };
00074 
00075 
00076 #endif // vpgl_rational_adjust_multipt_h_