contrib/oxl/mvl/FMPlanarNonLinFun.h
Go to the documentation of this file.
00001 // This is oxl/mvl/FMPlanarNonLinFun.h
00002 #ifndef FMPlanarNonLinFun_h_
00003 #define FMPlanarNonLinFun_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief a class that contains the functions required for FMPlanarComputeLinear.
00010 //
00011 // \author
00012 //   Martin Armstrong, Oxford 21/11/96
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   22 Oct 2002 - Peter Vanroose - added vgl_homg_point_2d interface
00017 // \endverbatim
00018 //
00019 //-----------------------------------------------------------------------------
00020 
00021 #include <vcl_vector.h>
00022 #include <vnl/vnl_least_squares_function.h>
00023 #include <vnl/vnl_double_3x3.h>
00024 #include <vgl/vgl_homg_point_2d.h>
00025 #include <mvl/HomgPoint2D.h>
00026 #include <mvl/HomgMetric.h>
00027 #include <mvl/HomgNorm2D.h>
00028 
00029 class FMatrixPlanar;
00030 class ImageMetric;
00031 
00032 class FMPlanarNonLinFun : public vnl_least_squares_function
00033 {
00034   int data_size_;
00035 
00036   vcl_vector<vgl_homg_point_2d<double> > points1_;
00037   vcl_vector<vgl_homg_point_2d<double> > points2_;
00038 
00039   HomgNorm2D normalized_;
00040 
00041   vnl_double_3x3 denorm_matrix_;
00042   vnl_double_3x3 denorm_matrix_inv_;
00043 
00044 #if 0 // unused ?!
00045   double outlier_distance_squared_;
00046   int terminate_count_;
00047 #endif
00048 
00049   HomgMetric image_metric1_;
00050   HomgMetric image_metric2_;
00051 
00052  public:
00053   //: Initialize object, will fit F to points1,2 using imagemetrics.
00054   //  Rejecting points > outlier_distance_squared from epipolar lines
00055   FMPlanarNonLinFun(const ImageMetric*, const ImageMetric*,
00056                     double outlier_distance_squared,
00057                     vcl_vector<vgl_homg_point_2d<double> >& points1,
00058                     vcl_vector<vgl_homg_point_2d<double> >& points2);
00059   FMPlanarNonLinFun(const ImageMetric*, const ImageMetric*,
00060                     double outlier_distance_squared,
00061                     vcl_vector<HomgPoint2D>& points1,
00062                     vcl_vector<HomgPoint2D>& points2);
00063 
00064   bool compute(FMatrixPlanar* F);
00065 
00066   //: The virtual function from vnl_levenberg_marquardt
00067   void f(vnl_vector<double> const& x, vnl_vector<double>& fx);
00068 
00069   // Helpers-------------------------------------------------------------------
00070  private:
00071   void fmatrix_to_params(const FMatrixPlanar& F, vnl_vector<double>& params);
00072   FMatrixPlanar params_to_fmatrix(const vnl_vector<double>& params);
00073 
00074   void fmatrix_to_params_awf(const FMatrixPlanar& F, vnl_vector<double>& params);
00075   FMatrixPlanar params_to_fmatrix_awf(const vnl_vector<double>& params);
00076 
00077   void fmatrix_to_params_mna(const FMatrixPlanar& F, vnl_vector<double>& params);
00078   FMatrixPlanar params_to_fmatrix_mna(const vnl_vector<double>& params);
00079 };
00080 
00081 #endif // FMPlanarNonLinFun_h_