00001 //: 00002 // \file 00003 // \author Tim Cootes 00004 // \brief Error term for calculation of correction to projective matrix 00005 00006 #ifndef m2d3_correction_matrix_error_h_ 00007 #define m2d3_correction_matrix_error_h_ 00008 00009 #include <vnl/vnl_matrix.h> 00010 #include <vnl/vnl_least_squares_function.h> 00011 00012 //: Computes error on constraints when computing correction matrix 00013 // Given g, returns error vector (Aq-rhs), where vector q are the 00014 // unique elements of the symmetric matrix Q=GG', G being the 00015 // 3(m+1) x 3 matrix formed from the elements of the supplied 00016 // vector g. 00017 class m23d_correction_matrix_error : public vnl_least_squares_function 00018 { 00019 //: Workspace for unique elements of symmetric matrix GG' 00020 vnl_vector<double> q_; 00021 00022 //: Constraints on q 00023 vnl_matrix<double> A_; 00024 00025 //: RHS for constraints on q (Aq=rhs) 00026 vnl_vector<double> rhs_; 00027 00028 //: Workspace for residual vector 00029 vnl_vector<double> r_; 00030 00031 //: Number of model modes 00032 unsigned n_modes_; 00033 00034 //: Current basis of interest 00035 unsigned k_; 00036 00037 //: Compute q from supplied g 00038 // g1==g2 for full q, g2 = (0 0 ..1 ...0) when computing derivatives 00039 void compute_q(const vnl_vector<double>& g1, 00040 const vnl_vector<double>& g2, 00041 vnl_vector<double>& q); 00042 00043 public: 00044 m23d_correction_matrix_error(const vnl_matrix<double>& A, 00045 const vnl_vector<double>& rhs, 00046 unsigned n_modes, 00047 unsigned k); 00048 00049 //: The main function. 00050 // Given g, returns error vector fx=(Aq-rhs), where vector q are the 00051 // unique elements of the symmetric matrix Q=GG', G being the 00052 // 3(m+1) x 3 matrix formed from the elements of the supplied 00053 // vector g. 00054 virtual void f(vnl_vector<double> const& g, 00055 vnl_vector<double>& fx); 00056 00057 //: Calculate the Jacobian, given the parameter vector g. 00058 virtual void gradf(vnl_vector<double> const& g, 00059 vnl_matrix<double>& jacobian); 00060 00061 }; 00062 00063 00064 #endif // m2d3_correction_matrix_error_h_