Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #include <msm/msm_points.h>
00007 #include <mbl/mbl_thin_plate_spline_2d.h>
00008
00009 #include <vul/vul_arg.h>
00010
00011 void print_usage()
00012 {
00013 vcl_cout << "Usage: msm_apply_tps_warp -sc src_control.pts -dc"
00014 << " dest_control.pts -sp src.pts -dp new_dest.pts"
00015 << vcl_endl;
00016 vcl_cout<<"Uses a Thin Plate Spline, constructed from src_control"
00017 <<" points and dest_control points to warp src points.\n"
00018 <<"Results saved to new_dest.pts"<<vcl_endl;
00019
00020 vul_arg_display_usage_and_exit();
00021
00022 }
00023
00024 int main(int argc, char** argv)
00025 {
00026 vul_arg<vcl_string> src_con_pts_path("-sc","Source control points");
00027 vul_arg<vcl_string> dest_con_pts_path("-dc","Destination control points");
00028 vul_arg<vcl_string> src_pts_path("-sp","Source points");
00029 vul_arg<vcl_string> dest_pts_path("-dp","Destination points","output.pts");
00030
00031 vul_arg_parse(argc,argv);
00032
00033 if (src_con_pts_path()=="" ||
00034 dest_con_pts_path()=="" ||
00035 src_pts_path()=="")
00036 {
00037 print_usage();
00038 return 0;
00039 }
00040
00041 msm_points src_con_points,dest_con_points;
00042 msm_points src_points,dest_points;
00043
00044 vcl_vector<vgl_point_2d<double> > src_con_pts,dest_con_pts;
00045 vcl_vector<vgl_point_2d<double> > src_pts,dest_pts;
00046
00047
00048 if (!src_con_points.read_text_file(src_con_pts_path()))
00049 {
00050 vcl_cerr<<"Failed to load points from "
00051 <<src_con_pts_path()<<vcl_endl;
00052 return 1;
00053 }
00054 src_con_points.get_points(src_con_pts);
00055
00056 if (!dest_con_points.read_text_file(dest_con_pts_path()))
00057 {
00058 vcl_cerr<<"Failed to load points from "
00059 <<dest_con_pts_path()<<vcl_endl;
00060 return 1;
00061 }
00062 dest_con_points.get_points(dest_con_pts);
00063
00064 if (!src_points.read_text_file(src_pts_path()))
00065 {
00066 vcl_cerr<<"Failed to load points from "
00067 <<src_pts_path()<<vcl_endl;
00068 return 1;
00069 }
00070 src_points.get_points(src_pts);
00071
00072 mbl_thin_plate_spline_2d tps;
00073 tps.build(src_con_pts,dest_con_pts);
00074
00075 dest_pts.resize(src_pts.size());
00076 for (unsigned i=0;i<src_pts.size();++i)
00077 dest_pts[i]=tps(src_pts[i]);
00078
00079 dest_points.set_points(dest_pts);
00080 if (!dest_points.write_text_file(dest_pts_path()))
00081 {
00082 vcl_cerr<<"Failed to write points to "
00083 <<dest_pts_path()<<vcl_endl;
00084 return 2;
00085 }
00086 vcl_cout<<"Warped points saved to "<<dest_pts_path()<<vcl_endl;
00087
00088 return 0;
00089 }
00090