contrib/rpl/rrel/rrel_affine_est.h
Go to the documentation of this file.
00001 #ifndef rrel_affine_est_h_
00002 #define rrel_affine_est_h_
00003 
00004 //:
00005 // \file
00006 // \author Gehua yang
00007 // \date Oct 2004
00008 // Class to maintain data and optimization model for affine transformation estimation
00009 
00010 #include <rrel/rrel_estimation_problem.h>
00011 #include <rrel/rrel_linear_regression.h>
00012 #include <vgl/vgl_fwd.h>
00013 #include <vnl/vnl_fwd.h>
00014 #include <vcl_vector.h>
00015 
00016 class rrel_affine_est : public rrel_estimation_problem {
00017 public:
00018   typedef rrel_linear_regression* regression_ptr;
00019   //: Constructor that includes all information in the sample vectors.
00020   //  For each sample, the first m-1 entries are the independent
00021   //  variables, and the last entry is the dependent variable.
00022   rrel_affine_est( const vcl_vector< vgl_point_2d<double> > & from_pts,
00023                    const vcl_vector< vgl_point_2d<double> > & to_pts );
00024 
00025   //: Constructor with data pre-separated into arrays of independent and dependent variables. 
00026   rrel_affine_est( const vcl_vector< vnl_vector<double> > & from_pts,
00027                    const vcl_vector< vnl_vector<double> > & to_pts,
00028                    unsigned int dim = 2 );
00029 
00030   //: Destructor.
00031   virtual ~rrel_affine_est();
00032 
00033   //: Total number of data points.
00034   unsigned int num_samples( ) const; 
00035 
00036   //: organize into usual representation
00037   vnl_vector<double> 
00038   trans( const vnl_vector<double>& params ) const;
00039 
00040   vnl_matrix<double> 
00041   A( const vnl_vector<double>& params ) const;
00042 
00043   //: Generate a parameter estimate from a minimal sample set.
00044   bool fit_from_minimal_set( const vcl_vector<int>& point_indices,
00045                              vnl_vector<double>& params ) const;
00046 
00047   //: Compute signed fit residuals relative to the parameter estimate.
00048   void compute_residuals( const vnl_vector<double>& params,
00049                           vcl_vector<double>& residuals ) const;
00050 
00051   //: \brief Weighted least squares parameter estimate. 
00052   bool weighted_least_squares_fit( vnl_vector<double>& params,
00053                                    vnl_matrix<double>& norm_covar,
00054                                    const vcl_vector<double>* weights=0 ) const;
00055 
00056 protected:
00057   
00058   vcl_vector< vnl_vector<double> > from_pts_;
00059   vcl_vector< vnl_vector<double> > to_pts_;
00060 
00061   unsigned affine_dof_;
00062   unsigned min_num_pts_;
00063   unsigned num_samples_;
00064 };
00065   
00066 #endif