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