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