contrib/rpl/rgrl/rgrl_trans_spline.h
Go to the documentation of this file.
00001 #ifndef rgrl_trans_spline_h_
00002 #define rgrl_trans_spline_h_
00003 //:
00004 // \file
00005 // \brief Here I only implement it as a cubic B-spline.
00006 // \author Ying-Lin Bess Lee
00007 // \date   Sept 2003
00008 
00009 #include "rgrl_transformation.h"
00010 #include "rgrl_spline.h"
00011 #include "rgrl_spline_sptr.h"
00012 #include <vnl/vnl_vector.h>
00013 #include <vnl/vnl_matrix.h>
00014 #include <vcl_vector.h>
00015 #include <vcl_iosfwd.h>
00016 
00017 class rgrl_trans_spline
00018   : public rgrl_transformation
00019 {
00020  public:
00021   //: Constructor
00022   //  should not be used by anything other than reader
00023   //  use the following two constructors instead.
00024   rgrl_trans_spline(unsigned int dim = 0);
00025 
00026   //: Constructor
00027   rgrl_trans_spline( vcl_vector<rgrl_spline_sptr> const& splines,
00028                      vnl_vector< double > const& x0, vnl_vector< double > const& delta,
00029                      rgrl_transformation_sptr xform = 0 );
00030   //: Constructor
00031   rgrl_trans_spline( vcl_vector<rgrl_spline_sptr> const& splines,
00032                      vnl_vector< double > const& x0, vnl_vector< double > const& delta,
00033                      vnl_matrix< double > const& covar,
00034                      rgrl_transformation_sptr xform = 0 );
00035 
00036   ~rgrl_trans_spline() {}
00037 
00038   vnl_vector< double > const& get_delta() const { return delta_; }
00039   void set_covar( vnl_matrix<double> const& cov ) { covar_ = cov; }
00040 
00041   vnl_matrix<double> transfer_error_covar( vnl_vector<double> const& p ) const;
00042 
00043   rgrl_transformation_sptr get_global_xform( ) const { return xform_; }
00044   rgrl_spline_sptr get_spline( unsigned i ) const { return splines_[i]; }
00045 
00046   //: Compute jacobian w.r.t. location
00047   virtual void jacobian_wrt_loc( vnl_matrix<double>& jac, vnl_vector<double> const& from_loc ) const;
00048 
00049   // for tester to access the private members
00050   friend class test_rgrl_trans_spline;
00051 
00052   //: for output
00053   void write( vcl_ostream& os ) const;
00054 
00055   //: for input
00056   bool read( vcl_istream& is );
00057 
00058   //: make a clone copy
00059   rgrl_transformation_sptr clone() const;
00060 
00061   // Defines type-related functions
00062   rgrl_type_macro( rgrl_trans_spline, rgrl_transformation);
00063 
00064  protected:
00065   void map_loc( vnl_vector<double> const& from,
00066                 vnl_vector<double> & to ) const;
00067 
00068   void map_dir( vnl_vector<double> const& from_loc,
00069                 vnl_vector<double> const& from_dir,
00070                 vnl_vector<double> & to_dir) const;
00071 
00072  private:
00073   void point_in_knots( vnl_vector< double > const& point, vnl_vector< double > & spline_pt ) const;
00074 
00075   // This is used for transform the data first and then spline is used
00076   // for estimate the displacement.
00077   rgrl_transformation_sptr xform_;
00078 
00079   // The displacement function has this form(in 3D): [x y z]^T = D( [x y z]^T )
00080   // This variable contains [ D_x D_y D_z ], each of which is an independent spline
00081   vcl_vector<rgrl_spline_sptr> splines_;
00082 
00083   // The covariance of control points of splines. The displacement in
00084   // x, y, z are independent to each other, the covariance between
00085   // each other's variables are 0.  So I don't save the covariance
00086   // between them.  However, the covariance between the parameters is
00087   // the same for each spline. So here, only one covariance is saved.
00088   vnl_vector<double> x0_;
00089   vnl_vector<double> delta_;
00090 
00091   // TODO - pure virtual functions of rgrl_transformation
00092   virtual void inv_map(vnl_vector<double> const&, bool,
00093                        vnl_vector<double> const&, vnl_vector<double>&, vnl_vector<double>&) const;
00094   virtual void inv_map(vnl_vector<double> const&, vnl_vector<double>&) const;
00095   virtual rgrl_transformation_sptr inverse_transform() const;
00096   virtual rgrl_transformation_sptr scale_by(double) const;
00097 };
00098 
00099 #endif