contrib/rpl/rgrl/rgrl_trans_rigid.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_rigid_h_
00002 #define rgrl_trans_rigid_h_
00003 //:
00004 // \file
00005 // \author Tomasz Malisiewicz
00006 // \date   March 2004
00007 
00008 #include "rgrl_transformation.h"
00009 #include <vcl_iosfwd.h>
00010 
00011 //: Represents a rigid transformation.
00012 //
00013 //  A rigid transform is q = R p + t where R
00014 //  is an n-dimensional rotation matrix, and t is an n-dimensional
00015 //  translation vector.  This is just like a similarity transformation with scale=1.
00016 //  Note that R has {9,4} parameters, but only {3,1} degrees of freedom in {3D,2D}.
00017 //  t has {3,2} degrees of freedom in {3D,2D}.
00018 //  This can be most easily seen from the fact that rotation matrices are orthonormal.
00019 //  The rigid transform has {6,3} total degrees of freedom (rotation + translation) in {3D,2D}.
00020 //  The relationship between dimensionality(d) and dof(degrees of freedom) is: dof = 3(d-1)
00021 class rgrl_trans_rigid
00022   : public rgrl_transformation
00023 {
00024  public:
00025   //: Initialize to the identity transformation.
00026   //
00027   rgrl_trans_rigid( unsigned int dimension = 0);
00028 
00029   //: Constructor based on an initial transformation and covar estimate
00030   //
00031   rgrl_trans_rigid( vnl_matrix<double> const& rot,
00032                     vnl_vector<double> const& trans,
00033                     vnl_matrix<double> const& covar );
00034 
00035   //: Constructor based on an initial transformation and unknown covar
00036   //
00037   //  The  covariance matrix is a zero matrix.
00038   rgrl_trans_rigid( vnl_matrix<double> const& rot,
00039                     vnl_vector<double> const& trans );
00040 
00041   //: Sets the translation component of this transformation
00042   //  \note This method is valid for only the 3d version
00043   void set_translation(double tx, double ty, double tz);
00044 
00045   //: Sets the translation component of this transformation
00046   //  \note This method is valid for only the 2d version
00047   void set_translation(double tx, double ty);
00048 
00049   //: Sets the rotation part of this transformation
00050   //  \note This method is valid for only the 3d version
00051   void set_rotation(double theta, double alpha, double phi);
00052 
00053   //: Sets the rotation part of this transformation
00054   //  \note This method is valid for only the 2d version
00055   void set_rotation(double theta);
00056 
00057   //: Given a rotation matrix which is the product of three independent rotations, extract the angles
00058   //  \note This method is valid for only the 3d version
00059   void determine_angles( double& phi, double& alpha, double& theta) const;
00060 
00061   //: Extract the angles
00062   //  \note This method is valid for only the 2d version
00063   void determine_angles( double& theta ) const;
00064 
00065 
00066   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p  ) const;
00067 
00068   //: The rotation component of this transform
00069   vnl_matrix<double> const& R() const;
00070 
00071   //: The translation component of the transform
00072   vnl_vector<double> t() const;
00073 
00074   //:  Inverse map with an initial guess
00075   void inv_map( const vnl_vector<double>& to,
00076                 bool initialize_next,
00077                 const vnl_vector<double>& to_delta,
00078                 vnl_vector<double>& from,
00079                 vnl_vector<double>& from_next_est) const;
00080 
00081   //:  Inverse map based on the transformation.
00082   //   The inverse mapping for R(p)+ t = q is p = A^-1(q-t)
00083   void inv_map( const vnl_vector<double>& to,
00084                 vnl_vector<double>& from ) const;
00085 
00086   //: is this an invertible transformation?
00087   virtual bool is_invertible() const { return true; }
00088 
00089   //: Return an inverse transformation
00090   //  This function only exist for certain transformations.
00091   virtual rgrl_transformation_sptr inverse_transform() const;
00092 
00093   //: Compute jacobian w.r.t. location
00094   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00095 
00096   //:  transform the transformation for images of different resolution
00097   rgrl_transformation_sptr scale_by( double scale ) const;
00098 
00099   // Defines type-related functions
00100   rgrl_type_macro( rgrl_trans_rigid, rgrl_transformation )
00101 
00102   // for output
00103   void write(vcl_ostream& os ) const;
00104 
00105   // for input
00106   bool read(vcl_istream& is );
00107 
00108   //: make a clone copy
00109   rgrl_transformation_sptr clone() const;
00110 
00111  protected:
00112   void map_loc( vnl_vector<double> const& from,
00113                 vnl_vector<double>      & to ) const;
00114 
00115   void map_dir( vnl_vector<double> const& from_loc,
00116                 vnl_vector<double> const& from_dir,
00117                 vnl_vector<double>      & to_dir    ) const;
00118 
00119  private:
00120   vnl_matrix<double> R_;
00121   vnl_vector<double> trans_;
00122 };
00123 
00124 
00125 #endif