1 #include <gsl/gsl_vector.h>
4 #include "../csm_all.h"
9 const double a = -1.0/6.0;
10 const double b = +1.0/120.0;
12 return x * (.99 + x2 * ( a + b * x2));
16 #define DEBUG_SEARCH(a) ;
20 for(i=0;i<ld->
nrays;i++) {
45 double x = a[0] - b[0];
46 double y = a[1] - b[1];
53 #define SQUARE(a) ((a)*(a))
63 double max_correspondence_dist2 =
square(
params->max_correspondence_dist);
73 const double *p_i_w = points_w[i].p;
74 double p_i_w_nrm2 = points_w[i].rho;
75 double p_i_w_phi = points_w[i].phi;
86 double best_dist = 42;
91 we_start_at = start_cell;
93 we_start_at = last_best + 1;
95 if(we_start_at > to) we_start_at = to;
96 if(we_start_at < from) we_start_at = from;
98 int up = we_start_at+1;
99 int down = we_start_at;
100 double last_dist_up = 0;
101 double last_dist_down = -1;
104 int down_stopped = 0;
106 DEBUG_SEARCH(printf(
"i=%d p_i_w = %f %f\n",i, p_i_w[0], p_i_w,[1]));
107 DEBUG_SEARCH(printf(
"i=%d [from %d down %d mid %d up %d to %d]\n",
108 i,from,down,start_cell,up,to));
110 while ( (!up_stopped) || (!down_stopped) ) {
111 int now_up = up_stopped ? 0 :
112 down_stopped ? 1 : last_dist_up < last_dist_down;
121 up_stopped = 1;
continue; }
130 if((last_dist_up < best_dist) || (j1==-1) )
131 j1 = up, best_dist = last_dist_up;
134 if (up > start_cell) {
140 double min_dist_up = p_i_w_nrm2 *
141 ((delta_theta >
M_PI*0.5) ? 1 :
mysin(delta_theta));
144 if(
SQUARE(min_dist_up) > best_dist) {
145 up_stopped = 1;
continue;
168 down_stopped = 1;
continue; }
173 if( (last_dist_down < best_dist) || (j1==-1) )
174 j1 = down, best_dist = last_dist_down;
176 if (down < start_cell) {
178 double min_dist_down = p_i_w_nrm2 *
179 ((delta_theta >
M_PI*0.5) ? 1 :
mysin(delta_theta));
180 if(
SQUARE(min_dist_down) > best_dist) {
181 down_stopped = 1;
continue;
190 DEBUG_SEARCH(printf(
"i=%d j1=%d dist=%f\n",i,j1,best_dist));
193 if( (-1==j1) || (best_dist > max_correspondence_dist2) ) {
209 if((j2up==-1)&&(j2down==-1)) {
213 if(j2up ==-1) { j2 = j2down; }
else
214 if(j2down==-1) { j2 = j2up; }
else {
217 j2 = dist_up < dist_down ? j2up : j2down;
227 params->use_point_to_line_distance ? corr_pl : corr_pp;