clustering.c
Go to the documentation of this file.
1 #include <math.h>
2 
3 #include "csm_all.h"
4 
5 
6 /*
7  A very very simple clustering algorithm.
8  Try threshold = 5*sigma
9 */
10 
11 void ld_simple_clustering(LDP ld, double threshold) {
12  int cluster = -1;
13  double last_reading = 0; /* I have to initialize it
14  explicitely or else gcc complains it might be uninitialized.
15  Stupid compiler, it cannot even solve the halting problem. */
16 
17  int i;
18  for(i=0;i<ld->nrays;i++) {
19  /* Skip if not valid */
20  if(!ld_valid_ray(ld,i)) {
21  ld->cluster[i] = -1;
22  continue;
23  }
24  /* If this is the first valid point, assign cluster #0 */
25  if(-1==cluster)
26  cluster = 0;
27  else
28  /* Else, start a new cluster if distance is above threshold */
29  if( fabs(last_reading-ld->readings[i]) > threshold)
30  cluster++;
31 
32  ld->cluster[i] = cluster;
33  last_reading = ld->readings[i];
34  }
35 
36  /* TODO: set to -1 the one-point clusters */
37 }
38 
int *restrict cluster
Definition: laser_data.h:26
INLINE int ld_valid_ray(LDP ld, int i)
double *restrict readings
Definition: laser_data.h:24
void ld_simple_clustering(LDP ld, double threshold)
Definition: clustering.c:11


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