contrib/rpl/rgrl/rgrl_trans_reduced_quad.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_reduced_quad_h_
00002 #define rgrl_trans_reduced_quad_h_
00003 //:
00004 // \file
00005 // \brief Derived class to represent a reduced quadratic transformation in 2D arbitrary dimensions.
00006 // \author Charlene Tsai
00007 // \date Sep 2003
00008 
00009 #include "rgrl_transformation.h"
00010 #include <vcl_iosfwd.h>
00011 
00012 //:
00013 // A reduced quadratic transformation, when centered, consists of a
00014 // similarity transform + 2 2nd-order radial terms. Uncentering the transform
00015 // makes it look like a quadratic transform
00016 //
00017 class rgrl_trans_reduced_quad
00018   : public rgrl_transformation
00019 {
00020  public:
00021   //: Initialize to the identity transformation.
00022   //
00023   rgrl_trans_reduced_quad( unsigned int dimension = 0);
00024 
00025   //: Construct uncentered quadratic standard transform
00026   //
00027   //  The transform is q = \a Q * hot(p) + \a A * p + \a trans, where
00028   //  hot(p)= [px^2 py^2 pxpy]^t in 2D, and
00029   //  hot(p)= [px^2 py^2 pz^2 pxpy pypz pxpz]^t in 3D.
00030   //
00031   rgrl_trans_reduced_quad( vnl_matrix<double> const& Q,
00032                            vnl_matrix<double> const& A,
00033                            vnl_vector<double> const& trans,
00034                            vnl_matrix<double> const& covar );
00035 
00036   //: Construct uncentered quadratic standard transform with unknown covar
00037   //
00038   //  The transform is q = \a Q * hot(p) + \a A * p + \a trans, where
00039   //  hot(p)= [px^2 py^2 pxpy]^t in 2D, and
00040   //  hot(p)= [px^2 py^2 pz^2 pxpy pypz pxpz]^t in 3D.
00041   //
00042   //  The covariance matrix is a zero matrix.
00043   //
00044   rgrl_trans_reduced_quad( vnl_matrix<double> const& Q,
00045                            vnl_matrix<double> const& A,
00046                            vnl_vector<double> const& trans );
00047 
00048   //: Construct a centered quadratic transform.
00049   //
00050   //  The transform is q = \a Q * hot(p) + \a A * p + \a trans, where
00051   //  hot(p)= [px^2 py^2 pxpy]^t in 2D, and
00052   //  hot(p)= [px^2 py^2 pz^2 pxpy pypz pxpz]^t in 3D.
00053   //
00054   rgrl_trans_reduced_quad( vnl_matrix<double> const& Q,
00055                            vnl_matrix<double> const& A,
00056                            vnl_vector<double> const& trans,
00057                            vnl_matrix<double> const& covar,
00058                            vnl_vector<double> const& from_centre,
00059                            vnl_vector<double> const& to_centre );
00060 
00061   void set_from_center( vnl_vector<double> const& from_center );
00062 
00063   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00064 
00065   //:  Provide the covariance matrix of the centered estimate (scale is factored in)
00066   //
00067   //   For the centered transformation A, the covar matrix is for the parameter
00068   //   vector [c d a b tx ty]^t, where c and d are for the 2nd order terms,
00069   //   and a, b, tx and ty are for the similarity transform.
00070   //
00071   // defined in base class
00072   // vnl_matrix<double> covar() const;
00073 
00074   //: The 2nd-order component of the quadratic transform
00075   vnl_matrix<double> const& Q() const;
00076 
00077   //: The 1st-order component of the quadratic transform
00078   vnl_matrix<double> const& A() const;
00079 
00080   //: The translation component of the quadratic transform
00081   vnl_vector<double> const& t() const;
00082 
00083   //:  Inverse map with an initial guess
00084   virtual void inv_map( const vnl_vector<double>& to,
00085                         bool initialize_next,
00086                         const vnl_vector<double>& to_delta,
00087                         vnl_vector<double>& from,
00088                         vnl_vector<double>& from_next_est) const;
00089 
00090   //: Compute jacobian w.r.t. location
00091   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00092 
00093   //:  transform the transformation for images of different resolution
00094   virtual rgrl_transformation_sptr scale_by( double scale ) const;
00095 
00096   // Defines type-related functions
00097   rgrl_type_macro( rgrl_trans_reduced_quad, rgrl_transformation );
00098 
00099   //: Output UNCENTERED transformation, with the origin as the center.
00100   void write(vcl_ostream& os ) const;
00101 
00102   // for input
00103   bool read(vcl_istream& is );
00104 
00105   //: make a clone copy
00106   rgrl_transformation_sptr clone() const;
00107 
00108  protected:
00109   void map_loc( vnl_vector<double> const& from,
00110                 vnl_vector<double>      & to ) const;
00111 
00112   void map_dir( vnl_vector<double> const& from_loc,
00113                 vnl_vector<double> const& from_dir,
00114                 vnl_vector<double>      & to_dir    ) const;
00115  private:
00116   //: Return the vector of 2nd order terms of p = [x y]^t
00117   vnl_vector<double> higher_order_terms(vnl_vector<double> p) const;
00118 
00119  private:
00120   vnl_matrix<double> Q_;
00121   vnl_matrix<double> A_;
00122   vnl_vector<double> trans_;
00123   vnl_vector<double> from_centre_;
00124 
00125   // TODO - pure virtual functions of rgrl_transformation
00126   virtual void inv_map(vnl_vector<double> const&, vnl_vector<double>&) const;
00127   virtual rgrl_transformation_sptr inverse_transform() const;
00128 };
00129 
00130 
00131 #endif