icp_corr_dumb.c
Go to the documentation of this file.
1 #include <gsl/gsl_vector.h>
2 
3 #include "icp.h"
4 #include "../csm_all.h"
5 
6 int compatible(struct sm_params*params, int i, int j);
7 
8 int compatible(struct sm_params*params, int i, int j) {
9  if(!params->do_alpha_test) return 1;
10 
11  double theta0 = 0; /* FIXME */
12  if((params->laser_sens->alpha_valid[i]==0) ||
13  (params->laser_ref->alpha_valid[j]==0))
14  return 1;
15 
16  double alpha_i = params->laser_sens->alpha[i];
17  double alpha_j = params->laser_ref->alpha[j];
18  double tolerance = deg2rad(params->do_alpha_test_thresholdDeg);
19 
21  double theta = angleDiff(alpha_j, alpha_i);
22  if(fabs(angleDiff(theta,theta0))>
23  tolerance+deg2rad(params->max_angular_correction_deg)) {
24  return 0;
25  } else {
26  return 1;
27  }
28 }
29 
31  const LDP laser_ref = params->laser_ref;
32  const LDP laser_sens = params->laser_sens;
33 
34  int i;
35  for(i=0;i<laser_sens->nrays;i++) {
36  if(!ld_valid_ray(laser_sens,i)) {
37 /* sm_debug("dumb: i %d is invalid \n", i);*/
38  ld_set_null_correspondence(laser_sens, i);
39  continue;
40  }
41 
42  double *p_i_w = laser_sens->points_w[i].p;
43 
44  int j1 = -1;
45  double best_dist = 10000;
46 
47  int from; int to; int start_cell;
48  possible_interval(p_i_w, laser_ref, params->max_angular_correction_deg,
49  params->max_linear_correction, &from, &to, &start_cell);
50 
51 /* sm_debug("dumb: i %d from %d to %d \n", i, from, to); */
52  int j;
53  for(j=from;j<=to;j++) {
54  if(!ld_valid_ray(laser_ref,j)) {
55 /* sm_debug("dumb: i %d j %d invalid\n", i, j);*/
56  continue;
57  }
58  double dist = distance_squared_d(p_i_w, laser_ref->points[j].p);
59 /* sm_debug("dumb: i %d j1 %d j %d d %f\n", i,j1,j,dist);*/
60  if(dist>square(params->max_correspondence_dist)) continue;
61 
62  if( (-1 == j1) || (dist < best_dist) ) {
63  if(compatible(params, i, j)) {
64  j1 = j;
65  best_dist = dist;
66  }
67  }
68  }
69 
70  if(j1==-1) {/* no match */
71  ld_set_null_correspondence(laser_sens, i);
72  continue;
73  }
74  /* Do not match with extrema*/
75  if(j1==0 || (j1 == (laser_ref->nrays-1))) {/* no match */
76  ld_set_null_correspondence(laser_sens, i);
77  continue;
78  }
79 
80  int j2;
81  int j2up = ld_next_valid_up (laser_ref, j1);
82  int j2down = ld_next_valid_down (laser_ref, j1);
83  if((j2up==-1)&&(j2down==-1)) {
84  ld_set_null_correspondence(laser_sens, i);
85  continue;
86  }
87  if(j2up ==-1) { j2 = j2down; } else
88  if(j2down==-1) { j2 = j2up; } else {
89  double dist_up = distance_squared_d(p_i_w, laser_ref->points[j2up ].p);
90  double dist_down = distance_squared_d(p_i_w, laser_ref->points[j2down].p);
91  j2 = dist_up < dist_down ? j2up : j2down;
92  }
93 
94  ld_set_correspondence(laser_sens, i, j1, j2);
95  laser_sens->corr[i].dist2_j1 = best_dist;
96  laser_sens->corr[i].type =
97  params->use_point_to_line_distance ? corr_pl : corr_pp;
98 
99  }
100 
101 }
102 
double dist2_j1
Definition: laser_data.h:71
int do_alpha_test
Definition: algos.h:79
INLINE int ld_next_valid_up(LDP ld, int i)
#define deg2rad(x)
Definition: gpc_test.c:22
double distance_squared_d(const double a[2], const double b[2])
Definition: math_utils.c:48
point2d *restrict points
Definition: laser_data.h:44
double angleDiff(double a, double b)
Definition: math_utils.c:128
double max_angular_correction_deg
Definition: algos.h:22
INLINE void ld_set_correspondence(LDP ld, int i, int j1, int j2)
INLINE int ld_valid_ray(LDP ld, int i)
double max_linear_correction
Definition: algos.h:24
enum correspondence::@5 type
void possible_interval(const double *p_i_w, LDP laser_sens, double max_angular_correction_deg, double max_linear_correction, int *from, int *to, int *start_cell)
Definition: math_utils.c:10
double max_correspondence_dist
Definition: algos.h:34
int *restrict alpha_valid
Definition: laser_data.h:30
LDP laser_ref
Definition: algos.h:14
double do_alpha_test_thresholdDeg
Definition: algos.h:80
point2d *restrict points_w
Definition: laser_data.h:47
LDP laser_sens
Definition: algos.h:16
void find_correspondences(struct sm_params *params)
Definition: icp_corr_dumb.c:30
struct correspondence *restrict corr
Definition: laser_data.h:36
INLINE void ld_set_null_correspondence(LDP ld, int i)
INLINE int ld_next_valid_down(LDP ld, int i)
int compatible(struct sm_params *params, int i, int j)
Definition: icp_corr_dumb.c:8
double square(double x)
Definition: math_utils.c:124
double *restrict alpha
Definition: laser_data.h:28
int use_point_to_line_distance
Definition: algos.h:99
double p[2]
Definition: laser_data.h:12


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23