3 #include "../csm/csm_all.h" 14 void convolve(
const int*valid,
const double*original,
int n,
double*dest,
double*filter,
int filter_len);
16 int main(
int argc,
const char * argv[]) {
20 options_double(ops,
"scale_deg", &
p.scale_deg, 0.0,
"Scale factor (degrees) ");
21 options_int(ops,
"neighbours", &
p.neighbours, 1,
"How many neighbours to consider (regardless of scale).");
24 fprintf(stderr,
"A simple program for smoothing a sensor scan.\n\nUsage:\n");
35 sm_error(
"Invalid laser data (#%d in file)\n", count);
50 void convolve(
const int*valid,
const double*original,
int n,
double*dest,
double*filter,
int filter_len)
62 for(j=-(filter_len-1);j<=(filter_len-1);j++) {
64 if(i2<0) i2=0;
if(i2>=n) i2=n-1;
65 if(!valid[i2]) i2 = i;
66 dest[i] += original[i2] * filter[abs(j)];
72 int len = neighbours + 1;
78 double mahal =
square(dist_rad / scale_rad);
79 filter[j] = exp(-mahal);
82 sm_info(
"filter[%d] = %f mahal = %f dist_rad = %f scale_rad = %f \n", j, filter[j], mahal, dist_rad, scale_rad);
89 double filter_tot = filter[0];
90 for(j=1;j<len;j++) filter_tot+=filter[j];
92 for(j=0;j<len;j++) filter[j]/=filter_tot;
94 double new_readings[ld->
nrays];
void sm_set_program_name(const char *name)
void ld_write_as_json(LDP ld, FILE *stream)
void copy_d(const double *from, int n, double *to)
void convolve(const int *valid, const double *original, int n, double *dest, double *filter, int filter_len)
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
int ld_valid_fields(LDP ld)
LDP ld_read_smart(FILE *)
void ld_smooth(LDP ld, int neighbours, double scale_rad)
double *restrict readings
struct option * options_allocate(int n)
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
int main(int argc, const char *argv[])
void options_print_help(struct option *options, FILE *f)
void sm_info(const char *msg,...)
void sm_error(const char *msg,...)
int options_parse_args(struct option *ops, int argc, const char *argv[])