contrib/rpl/rgrl/rgrl_trans_similarity.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_similarity_h_
00002 #define rgrl_trans_similarity_h_
00003 //:
00004 // \file
00005 // \author Amitha Perera
00006 // \date   Feb 2003
00007 
00008 #include "rgrl_transformation.h"
00009 #include <vcl_iosfwd.h>
00010 
00011 //: Represents a similarity transformation.
00012 //
00013 //  A similarity transform is q = k R p + t, where k is the scale, R
00014 //  is an n-dimensional rotation matrix, and t is an n-dimensional
00015 //  translation vector.
00016 //
00017 //  It only works for 2D now.
00018 //
00019 class rgrl_trans_similarity
00020   : public rgrl_transformation
00021 {
00022  public:
00023   //: Initialize to the identity transformation.
00024   //
00025   rgrl_trans_similarity( unsigned int dimension = 0);
00026 
00027   //: Constructor based on an initial transformation and covar estimate
00028   //
00029   rgrl_trans_similarity( vnl_matrix<double> const& rot_and_scale,
00030                          vnl_vector<double> const& trans,
00031                          vnl_matrix<double> const& covar );
00032 
00033   //: Constructor based on an initial transformation and unknown covar
00034   //
00035   //  The  covariance matrix is a zero matrix.
00036   rgrl_trans_similarity( vnl_matrix<double> const& rot_and_scale,
00037                          vnl_vector<double> const& trans );
00038 
00039   //: Construct a centered affine transform.
00040   //
00041   //  The transform is q = \a A * ( p - \a from_centre ) + \a trans + \a to_centre.
00042   //
00043   //  See covar() for the ordering of the covariance matrix.
00044   //
00045   rgrl_trans_similarity( vnl_matrix<double> const& A,
00046                          vnl_vector<double> const& trans,
00047                          vnl_matrix<double> const& covar,
00048                          vnl_vector<double> const& from_centre,
00049                          vnl_vector<double> const& to_centre );
00050 
00051   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00052 
00053   //:  Provide the covariance matrix of the estimate (scale is factored in)
00054   //
00055   //   for 2D, the covar matrix is for the vector [a b tx ty], where
00056   //   [a -b tx; b a ty] = [A_ trans]
00057   //
00058   // defined in base class
00059   // vnl_matrix<double> covar() const;
00060 
00061   //: The scaling and rotation component of the transform
00062   vnl_matrix<double> const& A() const;
00063 
00064   //: The translation component of the transform
00065   vnl_vector<double> t() const;
00066 
00067   //: The scaling component of the transform
00068   double scaling() const;
00069   
00070   //:  Inverse map with an initial guess
00071   void inv_map( const vnl_vector<double>& to,
00072                 bool initialize_next,
00073                 const vnl_vector<double>& to_delta,
00074                 vnl_vector<double>& from,
00075                 vnl_vector<double>& from_next_est) const;
00076 
00077   //:  Inverse map based on the transformation.
00078   //   The inverse mapping for A(p)+ t = q is p = A^-1(q-t)
00079   void inv_map( const vnl_vector<double>& to,
00080                 vnl_vector<double>& from ) const;
00081 
00082   //: is this an invertible transformation?
00083   virtual bool is_invertible() const { return true; }
00084 
00085   //: Return an inverse transformation
00086   //  This function only exist for certain transformations.
00087   virtual rgrl_transformation_sptr inverse_transform() const;
00088 
00089   //: Compute jacobian w.r.t. location
00090   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00091 
00092   //:  transform the transformation for images of different resolution
00093   rgrl_transformation_sptr scale_by( double scale ) const;
00094 
00095   //: Accessor for from_centre_
00096   vnl_vector<double> const &  from_centre() { return from_centre_; }
00097 
00098   // Defines type-related functions
00099   rgrl_type_macro( rgrl_trans_similarity, rgrl_transformation );
00100 
00101   // for output
00102   virtual void write(vcl_ostream& os ) const;
00103 
00104   // for input
00105   virtual bool read(vcl_istream& is );
00106 
00107   //: make a clone copy
00108   rgrl_transformation_sptr clone() const;
00109 
00110 protected:
00111   void map_loc( vnl_vector<double> const& from,
00112                 vnl_vector<double>      & to ) const;
00113 
00114   void map_dir( vnl_vector<double> const& from_loc,
00115                 vnl_vector<double> const& from_dir,
00116                 vnl_vector<double>      & to_dir    ) const;
00117 
00118  private:
00119   vnl_matrix<double> A_;
00120   vnl_vector<double> trans_;
00121   vnl_vector<double> from_centre_;
00122 };
00123 
00124 
00125 #endif