GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_assign.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <grass/cluster.h>
3 
4 int I_cluster_assign(struct Cluster *C, int *interrupted)
5 {
6  int p, c;
7  int class, band;
8  double d, q;
9  double dmin;
10 
11  /*
12  fprintf (stderr,"I_cluster_assign(npoints=%d,nclasses=%d,nbands=%d)\n",
13  C->npoints, C->nclasses, C->nbands);
14  */
15 
16  for (p = 0; p < C->npoints; p++) {
17  if (*interrupted)
18  return -1;
19 
20  dmin = HUGE_VAL;
21  class = 0;
22  for (c = 0; c < C->nclasses; c++) {
23  d = 0.0;
24  for (band = 0; band < C->nbands; band++) {
25  q = C->points[band][p];
26  q -= C->mean[band][c];
27  d += q * q;
28  }
29  if (c == 0 || d < dmin) {
30  class = c;
31  dmin = d;
32  }
33  }
34  C->class[p] = class;
35  C->count[class]++;
36  for (band = 0; band < C->nbands; band++)
37  C->sum[band][class] += C->points[band][p];
38  }
39 
40  return 0;
41 }
tuple q
Definition: forms.py:2019
DCELL dmin
Definition: g3dcolor.c:53
#define C
Definition: intr_char.c:17
int I_cluster_assign(struct Cluster *C, int *interrupted)
Definition: c_assign.c:4
#define HUGE_VAL
Values needed for Ray-Convex Polyhedron Intersection Test below originally by Eric Haines...
Definition: gs_query.c:29