GRASS GIS 7 Programmer's Manual  7.0.5(2016)-r00000
c_assign.c
Go to the documentation of this file.
1 
14 #include <math.h>
15 #include <grass/cluster.h>
16 
26 int I_cluster_assign(struct Cluster *C, int *interrupted)
27 {
28  int p, c;
29  int class, band;
30  double d, q;
31  double dmin;
32 
33  G_debug(3, "I_cluster_assign(npoints=%d,nclasses=%d,nbands=%d)",
34  C->npoints, C->nclasses, C->nbands);
35 
36  for (p = 0; p < C->npoints; p++) {
37  if (*interrupted)
38  return -1;
39 
40  dmin = HUGE_VAL;
41  class = 0;
42  for (c = 0; c < C->nclasses; c++) {
43  d = 0.0;
44  for (band = 0; band < C->nbands; band++) {
45  q = C->points[band][p];
46  q -= C->mean[band][c];
47  d += q * q;
48  }
49  if (c == 0 || d < dmin) {
50  class = c;
51  dmin = d;
52  }
53  }
54  C->class[p] = class;
55  C->count[class]++;
56  for (band = 0; band < C->nbands; band++)
57  C->sum[band][class] += C->points[band][p];
58  }
59 
60  return 0;
61 }
int I_cluster_assign(struct Cluster *C, int *interrupted)
Assign cluster.
Definition: c_assign.c:26
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
#define HUGE_VAL
Values needed for Ray-Convex Polyhedron Intersection Test below originally by Eric Haines...
Definition: gs_query.c:29