1 // This is oxl/mvl/FMatrixComputeNonLinear.h
2 #ifndef FMatrixComputeNonLinear_h_
3 #define FMatrixComputeNonLinear_h_
4 //:
5 // \file
6 //    FMatrixComputeNonLinear is a class that contains the functions required for
7 //  two differing Non-Linear minimisations of the F Matrix:
8 //  - Zhengyou Zhang's 36 different rank 2 parametrisations of the F Matrix
9 //  - Phil Torr's augmentation of a given 7 points basis
10 //
11 // \author
12 //     David McKinnon, U.Q. 2/1/01
13 //
14 //-----------------------------------------------------------------------------
15 
16 #include <iostream>
17 #include <vector>
18 #ifdef _MSC_VER
19 #  include <vcl_msvc_warnings.h>
20 #endif
21 #include <vnl/vnl_least_squares_function.h>
22 #include <vgl/vgl_homg_point_2d.h>
23 #include <mvl/AffineMetric.h>
24 #include <mvl/HomgNorm2D.h>
25 #include <mvl/PairMatchSetCorner.h>
26 #include <mvl/FMatrix.h> // needed since there is an FMatrix data member
27 
28 class FMatrixComputeNonLinear : public vnl_least_squares_function
29 {
30  public:
31 
32   // Constructors/Destructors--------------------------------------------------
33   FMatrixComputeNonLinear(PairMatchSetCorner* matches);
34 
35   // Computations--------------------------------------------------------------
36   // Calling this function results in the 36 parametrisations
37   bool compute(FMatrix* F);
38   // Calling this function results in the augmentation of the basis
39   bool compute_basis(FMatrix* F, std::vector<int> basis);
40 
41   // The virtual function from vnl_levenberg_marquardt
42   void f(const vnl_vector<double>& x, vnl_vector<double>& fx) override;
43 
44  private:
45   // Data Members--------------------------------------------------------------
46   int data_size_;
47   PairMatchSetCorner& matches_;
48   int p_, q_, r_;
49   FMatrix F_orig_;
50   bool one_;
51   std::vector<vgl_homg_point_2d<double> > basis1_;
52   std::vector<vgl_homg_point_2d<double> > basis2_;
53   std::vector<vgl_homg_point_2d<double> > points1_;
54   std::vector<vgl_homg_point_2d<double> > points2_;
55 
56   // Helpers-------------------------------------------------------------------
57   void fmatrix_to_params(const FMatrix& F, vnl_vector<double>& params);
58   FMatrix params_to_fmatrix(const vnl_vector<double>& params);
59   void get_plan(int &r1, int &c1, int &r2, int &c2) const;
60   vnl_vector<double> calculate_residuals(FMatrix* F);
61 };
62 
63 #endif // FMatrixComputeNonLinear_h_
64