00001
00002 #ifndef mbl_thin_plate_spline_2d_h_
00003 #define mbl_thin_plate_spline_2d_h_
00004
00005
00006
00007
00008
00009 #include <vgl/vgl_point_2d.h>
00010 #include <vcl_vector.h>
00011 #include <vnl/vnl_vector.h>
00012 #include <vnl/vnl_matrix.h>
00013 #include <vsl/vsl_binary_io.h>
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 class mbl_thin_plate_spline_2d
00043 {
00044 vnl_vector<double> Wx_,Wy_;
00045 double Ax0_, AxX_, AxY_;
00046 double Ay0_, AyX_, AyY_;
00047 double energy_x_,energy_y_;
00048
00049 bool return_pure_affine_;
00050
00051 vcl_vector<vgl_point_2d<double> > src_pts_;
00052
00053
00054 vnl_matrix<double> L_inv_;
00055
00056
00057 void build_pure_affine(const vcl_vector<vgl_point_2d<double> >& source_pts,
00058 const vcl_vector<vgl_point_2d<double> >& dest_pts);
00059
00060
00061 void set_params(const vnl_vector<double>& W1,
00062 const vnl_vector<double>& W2);
00063
00064 void set_up_rhs(vnl_vector<double>& Bx,
00065 vnl_vector<double>& By,
00066 const vcl_vector<vgl_point_2d<double> >& dest_pts);
00067
00068
00069 void compute_energy(vnl_vector<double>& W1,
00070 vnl_vector<double>& W2,
00071 const vnl_matrix<double>& L);
00072
00073 public:
00074
00075
00076 mbl_thin_plate_spline_2d();
00077
00078
00079 virtual ~mbl_thin_plate_spline_2d();
00080
00081
00082 void build(const vcl_vector<vgl_point_2d<double> >& source_pts,
00083 const vcl_vector<vgl_point_2d<double> >& dest_pts,
00084 bool compute_the_energy=false);
00085
00086
00087
00088
00089 void set_source_pts(const vcl_vector<vgl_point_2d<double> >& source_pts);
00090
00091
00092 void build(const vcl_vector<vgl_point_2d<double> >& dest_pts);
00093
00094
00095 vgl_point_2d<double> operator()(double x, double y) const;
00096
00097
00098 vgl_point_2d<double> operator()(const vgl_point_2d<double>& p) const
00099 { return operator()(p.x(),p.y()); }
00100
00101
00102
00103 double bendingEnergyX() const { return energy_x_; }
00104
00105
00106
00107 double bendingEnergyY() const { return energy_y_; }
00108
00109
00110
00111
00112 void set_pure_affine(bool val) { return_pure_affine_ = val; }
00113
00114
00115 short version_no() const;
00116
00117
00118 void print_summary(vcl_ostream& os) const;
00119
00120
00121 void b_write(vsl_b_ostream& bfs) const;
00122
00123
00124 void b_read(vsl_b_istream& bfs);
00125
00126
00127 bool operator==(const mbl_thin_plate_spline_2d& tps) const;
00128 };
00129
00130
00131 void vsl_b_write(vsl_b_ostream& bfs, const mbl_thin_plate_spline_2d& b);
00132
00133
00134 void vsl_b_read(vsl_b_istream& bfs, mbl_thin_plate_spline_2d& b);
00135
00136
00137 vcl_ostream& operator<<(vcl_ostream& os,const mbl_thin_plate_spline_2d& b);
00138
00139 #endif
00140
00141