1 // This is core/vpgl/algo/vpgl_rational_adjust.h
2 #ifndef vpgl_rational_adjust_h_
3 #define vpgl_rational_adjust_h_
4 //:
5 // \file
6 // \brief Adjust 3-d offset and scale to align rational cameras to geolocations
7 // \author J. L. Mundy
8 // \date August 06, 2007
9 
10 #include <vector>
11 #ifdef _MSC_VER
12 #  include <vcl_msvc_warnings.h>
13 #endif
14 #include <vnl/vnl_vector.h>
15 #include <vnl/vnl_least_squares_function.h>
16 #include <vpgl/vpgl_rational_camera.h>
17 #include <vgl/vgl_point_2d.h>
18 #include <vgl/vgl_point_3d.h>
19 
20 //:
21 // The 3-d offset and scale parameters of rational cameras typically
22 // must be adjusted to compensate for errors in geographic alignment.
23 // This algorithm adjusts these parameters to give the smallest
24 // projection error. That is, the error between the true image location
25 // and the projected 3-d world point corresponding to that location.
26 
27 class vpgl_adjust_lsqr : public vnl_least_squares_function
28 {
29  public:
30   //: Constructor
31   // \note image points are not homogeneous because require finite points to measure projection error
32   vpgl_adjust_lsqr(vpgl_rational_camera<double>  const& rcam,
33                    std::vector<vgl_point_2d<double> > const& img_pts,
34                    std::vector<vgl_point_3d<double> >  geo_pts,
35                    unsigned num_unknowns, unsigned num_residuals);
36 
37   //: Destructor
38   ~vpgl_adjust_lsqr() override = default;
39 
40   //: The main function.
41   //  Given the parameter vector x, compute the vector of residuals fx.
42   //  fx has been sized appropriately before the call.
43   void f(vnl_vector<double> const& x, vnl_vector<double>& fx) override;
44 
45 #if 0
46   //: Called after each LM iteration to print debugging etc.
47   virtual void trace(int iteration, vnl_vector<double> const& x, vnl_vector<double> const& fx);
48 #endif
49 
50  protected:
51   unsigned num_corrs_;
52   vpgl_rational_camera<double> rcam_;
53   std::vector<vgl_point_2d<double> > img_pts_;
54   std::vector<vgl_point_3d<double> > geo_pts_;
55 };
56 
57 class vpgl_rational_adjust
58 {
59  public:
60   ~vpgl_rational_adjust()= default;
61 
62   static bool adjust(vpgl_rational_camera<double> const& initial_rcam,
63                      std::vector<vgl_point_2d<double> > img_pts,
64                      std::vector<vgl_point_3d<double> > geo_pts,
65                      vpgl_rational_camera<double> & adj_rcam);
66  protected:
67   vpgl_rational_adjust();
68 };
69 
70 
71 #endif // vpgl_rational_adjust_h_
72