contrib/rpl/rgrl/rgrl_trans_couple.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_couple_h_
00002 #define rgrl_trans_couple_h_
00003 //:
00004 // \file
00005 // \brief class to encapsulate a pair of transformations: forward & backward
00006 // \author Gehua Yang
00007 // \date Feb 2005
00008 
00009 #include <rgrl/rgrl_transformation_sptr.h>
00010 #include <rgrl/rgrl_transformation.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: A base class that represents a pair of transformation: forward & backward
00014 //
00015 class rgrl_trans_couple
00016   : public rgrl_transformation
00017 {
00018  public:
00019   virtual ~rgrl_trans_couple();
00020 
00021   //: default constructor
00022   rgrl_trans_couple() {  }
00023 
00024   //: initialize with covariance matrix
00025   rgrl_trans_couple( rgrl_transformation_sptr const& forward, rgrl_transformation_sptr const& backward );
00026 
00027 
00028   //: Map a tangent direction
00029   //
00030   // The resulting direction \a to_dir is a unit vector.
00031   //
00032   virtual void map_tangent( vnl_vector<double> const& from_loc,
00033                             vnl_vector<double> const& from_dir,
00034                             vnl_vector<double>      & to_dir    ) const;
00035 
00036   //: Map a normal direction
00037   //
00038   // The resulting direction \a to_dir is a unit vector.
00039   //
00040   virtual void map_normal( vnl_vector<double> const & from_loc,
00041                            vnl_vector<double> const & from_dir,
00042                            vnl_vector<double>       & to_dir    ) const;
00043 
00044   //: Map a normal direction, given the tangent subspace
00045   //
00046   // The resulting direction \a to_dir is a unit vector.
00047   //
00048   virtual void map_normal( vnl_vector<double> const  & from_loc,
00049                            vnl_vector<double> const  & from_dir,
00050                            vnl_matrix< double > const& tangent_subspace,
00051                            vnl_vector<double>        & to_dir    ) const;
00052 
00053   //:  Compute covariance of the transfer error based on transformation covariance
00054   //
00055   // This gives the additional uncertainty of the transferred point
00056   // location due to the uncertainty of the transform estimate.
00057   //
00058   virtual
00059   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p ) const;
00060 
00061 
00062   //:  Inverse map with an initial guess
00063   virtual void inv_map( const vnl_vector<double>& to,
00064                         bool initialize_next,
00065                         const vnl_vector<double>& to_delta,
00066                         vnl_vector<double>& from,
00067                         vnl_vector<double>& from_next_est) const;
00068 
00069   //:  Inverse map based on the transformation.
00070   //   This function only exist for certain transformations.
00071   virtual void inv_map( const vnl_vector<double>& to,
00072                         vnl_vector<double>& from ) const;
00073 
00074   //: is this an invertible transformation?
00075   virtual bool is_invertible() const;
00076 
00077   //: Return an inverse transformation
00078   //  This function only exist for certain transformations.
00079   virtual rgrl_transformation_sptr inverse_transform() const;
00080 
00081   //: Compute jacobian w.r.t. location
00082   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00083 
00084   //:  transform the transformation for images of different resolution
00085   rgrl_transformation_sptr scale_by( double scale ) const;
00086 
00087   //: output transformation
00088   void write( vcl_ostream& os ) const;
00089 
00090   //: input transformation
00091   bool read( vcl_istream& is );
00092 
00093   //: make a clone copy
00094   rgrl_transformation_sptr clone() const;
00095 
00096   // Defines type-related functions
00097   rgrl_type_macro( rgrl_trans_couple, rgrl_transformation );
00098 
00099  protected:
00100 
00101   //:  Apply the transformation to create a new (mapped) location
00102   //
00103   virtual
00104   void map_loc( vnl_vector<double> const& from,
00105                 vnl_vector<double>      & to    ) const;
00106 
00107   //:  Apply the transformation to create a new direction at the (mapped) location
00108   //
00109   // The resulting direction \a to_dir is a unit vector.
00110   //
00111   virtual
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 
00116  protected:
00117 
00118   rgrl_transformation_sptr forward_xform_, backward_xform_;
00119 };
00120 
00121 #endif