contrib/rpl/rgrl/rgrl_trans_couple.cxx
Go to the documentation of this file.
00001 #include "rgrl_trans_couple.h"
00002 //:
00003 // \file
00004 // \brief a class that encapsulates a pair of transformations: forward & backward
00005 // \author Gehua Yang
00006 // \date Feb 2005
00007 
00008 #include <vcl_iostream.h>
00009 #include <vcl_cassert.h>
00010 
00011 #include <rgrl/rgrl_trans_reader.h>
00012 #include <rgrl/rgrl_util.h>
00013 
00014 rgrl_trans_couple::
00015   rgrl_trans_couple( rgrl_transformation_sptr const& forward, rgrl_transformation_sptr const& backward )
00016   : rgrl_transformation( *forward ),
00017     forward_xform_( forward ),
00018     backward_xform_( backward )
00019 {
00020 }
00021 
00022 rgrl_trans_couple::
00023 ~rgrl_trans_couple()
00024 {
00025 }
00026 
00027 void
00028 rgrl_trans_couple::
00029 map_loc( vnl_vector<double> const& from,
00030          vnl_vector<double>      & to    ) const
00031 {
00032   assert( forward_xform_ );
00033   forward_xform_ -> map_location( from, to );
00034 }
00035 
00036 void
00037 rgrl_trans_couple::
00038 map_dir( vnl_vector<double> const& from_loc,
00039          vnl_vector<double> const& from_dir,
00040          vnl_vector<double>      & to_dir    ) const
00041 {
00042   assert( forward_xform_ );
00043   forward_xform_ -> map_direction( from_loc, from_dir, to_dir );
00044 }
00045 
00046 void
00047 rgrl_trans_couple::
00048 map_tangent( vnl_vector<double> const& from_loc,
00049              vnl_vector<double> const& from_dir,
00050              vnl_vector<double>      & to_dir    ) const
00051 {
00052   assert( forward_xform_ );
00053   forward_xform_ -> map_tangent( from_loc, from_dir, to_dir );
00054 }
00055 
00056 void
00057 rgrl_trans_couple::
00058 map_normal( vnl_vector<double> const & from_loc,
00059             vnl_vector<double> const & from_dir,
00060             vnl_vector<double>       & to_dir    ) const
00061 {
00062   assert( forward_xform_ );
00063   forward_xform_ -> map_normal( from_loc, from_dir, to_dir );
00064 }
00065 
00066 void
00067 rgrl_trans_couple::
00068 map_normal( vnl_vector<double> const  & from_loc,
00069             vnl_vector<double> const  & from_dir,
00070             vnl_matrix< double > const& tangent_subspace,
00071             vnl_vector<double>        & to_dir    ) const
00072 {
00073   assert( forward_xform_ );
00074   forward_xform_ -> map_normal( from_loc, from_dir, tangent_subspace, to_dir );
00075 }
00076 
00077 vnl_matrix<double>
00078 rgrl_trans_couple::
00079 transfer_error_covar( vnl_vector<double> const& p ) const
00080 {
00081   assert( forward_xform_ );
00082   return forward_xform_ -> transfer_error_covar( p );
00083 }
00084 
00085 void
00086 rgrl_trans_couple::
00087 jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const
00088 {
00089   assert( forward_xform_ );
00090   forward_xform_ -> jacobian_wrt_loc( jac, from_loc );
00091 }
00092 
00093 rgrl_transformation_sptr
00094 rgrl_trans_couple::
00095 scale_by( double scale ) const
00096 {
00097   assert( forward_xform_ );
00098   return forward_xform_ -> scale_by( scale );
00099 }
00100 
00101 //: output transformation
00102 void
00103 rgrl_trans_couple::
00104 write( vcl_ostream& os ) const
00105 {
00106   os << "COUPLE_TRANS" << vcl_endl;
00107 
00108   assert( forward_xform_ && backward_xform_ );
00109 
00110   forward_xform_ -> write( os );
00111   backward_xform_ -> write( os );
00112 }
00113 
00114 //: input transformation
00115 bool
00116 rgrl_trans_couple::
00117 read( vcl_istream& is )
00118 {
00119   // skip empty lines
00120   rgrl_util_skip_empty_lines( is );
00121 
00122   vcl_string str;
00123   vcl_getline( is, str );
00124 
00125   if ( str.find("COUPLE_TRANS") != 0 ) {
00126     WarningMacro( "The tag is not COUPLE_TRANS. reading is aborted.\n" );
00127     return false;
00128   }
00129 
00130   // Read forward and backward
00131   forward_xform_ = rgrl_trans_reader::read( is );
00132   backward_xform_ = rgrl_trans_reader::read( is );
00133 
00134   // parent
00135   return forward_xform_
00136     && backward_xform_
00137     && is.good()
00138     && rgrl_transformation::read( is );
00139 }
00140 
00141 
00142 //:  Inverse map with an initial guess
00143 void
00144 rgrl_trans_couple::
00145 inv_map( const vnl_vector<double>& to,
00146          bool initialize_next,
00147          const vnl_vector<double>& to_delta,
00148          vnl_vector<double>& from,
00149          vnl_vector<double>& from_next_est) const
00150 {
00151   assert( forward_xform_ );
00152   forward_xform_ -> inv_map( to, initialize_next, to_delta, from, from_next_est );
00153 }
00154 
00155 void
00156 rgrl_trans_couple::
00157 inv_map( const vnl_vector<double>& to,
00158                vnl_vector<double>& from ) const
00159 {
00160   assert( forward_xform_ );
00161   forward_xform_ -> inv_map( to, from );
00162 }
00163 
00164 bool
00165 rgrl_trans_couple::
00166 is_invertible() const
00167 {
00168   return backward_xform_;
00169 }
00170 
00171 rgrl_transformation_sptr
00172 rgrl_trans_couple::
00173 inverse_transform() const
00174 {
00175   if ( backward_xform_ )
00176     return new rgrl_trans_couple( backward_xform_, forward_xform_ );
00177   else
00178     return 0;
00179 }
00180 
00181 //: make a clone copy
00182 rgrl_transformation_sptr
00183 rgrl_trans_couple::
00184 clone() const
00185 {
00186   return new rgrl_trans_couple( *this );
00187 }