Go to the documentation of this file.00001 #include "mfpf_max_finder.h"
00002
00003
00004
00005
00006
00007 #include <vsl/vsl_binary_loader.h>
00008 #include <vnl/vnl_vector.h>
00009 #include <vgl/vgl_point_2d.h>
00010 #include <vgl/vgl_vector_2d.h>
00011
00012 #include <vimt/vimt_bilin_interp.h>
00013 #include <vimt/vimt_sample_profile_bilin.h>
00014
00015
00016
00017
00018
00019 mfpf_max_finder::mfpf_max_finder()
00020 {
00021 }
00022
00023
00024
00025
00026
00027 mfpf_max_finder::~mfpf_max_finder()
00028 {
00029 }
00030
00031
00032 double mfpf_max_finder::radius() const
00033 {
00034 return 1.0;
00035 }
00036
00037
00038
00039
00040 void mfpf_max_finder::get_outline(vcl_vector<vgl_point_2d<double> >& pts) const
00041 {
00042 pts.resize(2);
00043 pts[0]=vgl_point_2d<double>(-0.5,0);
00044 pts[1]=vgl_point_2d<double>( 0.5,0);
00045 }
00046
00047
00048
00049
00050 double mfpf_max_finder::evaluate(const vimt_image_2d_of<float>& image,
00051 const vgl_point_2d<double>& p,
00052 const vgl_vector_2d<double>& u)
00053 {
00054 double v2 = vimt_bilin_interp_safe(image,p);
00055 return -1.0*v2;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065 void mfpf_max_finder::evaluate_region(
00066 const vimt_image_2d_of<float>& image,
00067 const vgl_point_2d<double>& p,
00068 const vgl_vector_2d<double>& u,
00069 vimt_image_2d_of<double>& response)
00070 {
00071 int n=1+2*search_ni_;
00072 vnl_vector<double> v(n);
00073 vgl_vector_2d<double> u1=step_size_*u;
00074 const vgl_point_2d<double> p0 = p-search_ni_*u1;
00075 vimt_sample_profile_bilin(v,image,p0,u1,n);
00076 response.image().set_size(n,1);
00077 double* r = response.image().top_left_ptr();
00078 for (int i=0;i<n;++i,++r)
00079 {
00080 *r = -1*v[i];
00081 }
00082
00083
00084
00085
00086
00087 const vgl_point_2d<double> p1 = p-search_ni_*u1;
00088
00089 vimt_transform_2d i2w;
00090 i2w.set_similarity(vgl_point_2d<double>(u1.x(),u1.y()),p1);
00091 response.set_world2im(i2w.inverse());
00092 }
00093
00094
00095
00096
00097
00098 double mfpf_max_finder::search_one_pose(
00099 const vimt_image_2d_of<float>& image,
00100 const vgl_point_2d<double>& p,
00101 const vgl_vector_2d<double>& u,
00102 vgl_point_2d<double>& new_p)
00103 {
00104 int n=1+2*search_ni_;
00105 vnl_vector<double> v(n);
00106 vgl_vector_2d<double> u1=step_size_*u;
00107 const vgl_point_2d<double> p0 = p-search_ni_*u1;
00108 vimt_sample_profile_bilin(v,image,p0,u1,n);
00109 int best_i=0;
00110 double best_e = v[0];
00111 for (int i=1;i<n;++i)
00112 {
00113 double e = v[i];
00114 if (e>best_e) { best_e=e; best_i=i; }
00115 }
00116 new_p = p+(best_i-search_ni_)*u1;
00117 return -1.0 * best_e;
00118 }
00119
00120
00121
00122
00123
00124 vcl_string mfpf_max_finder::is_a() const
00125 {
00126 return vcl_string("mfpf_max_finder");
00127 }
00128
00129
00130 mfpf_point_finder* mfpf_max_finder::clone() const
00131 {
00132 return new mfpf_max_finder(*this);
00133 }
00134
00135
00136
00137
00138
00139 void mfpf_max_finder::print_summary(vcl_ostream& os) const
00140 {
00141 os<<"{ ";
00142 mfpf_point_finder::print_summary(os);
00143 os<<" }";
00144 }
00145
00146 short mfpf_max_finder::version_no() const
00147 {
00148 return 1;
00149 }
00150
00151
00152 void mfpf_max_finder::b_write(vsl_b_ostream& bfs) const
00153 {
00154 vsl_b_write(bfs,version_no());
00155 mfpf_point_finder::b_write(bfs);
00156 }
00157
00158
00159
00160
00161
00162 void mfpf_max_finder::b_read(vsl_b_istream& bfs)
00163 {
00164 if (!bfs) return;
00165 short version;
00166 vsl_b_read(bfs,version);
00167 switch (version)
00168 {
00169 case 1:
00170 mfpf_point_finder::b_read(bfs);
00171 break;
00172 default:
00173 vcl_cerr << "I/O ERROR: vsl_b_read(vsl_b_istream&)\n"
00174 << " Unknown version number "<< version << vcl_endl;
00175 bfs.is().clear(vcl_ios::badbit);
00176 return;
00177 }
00178 }