GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
c_assign.c
Go to the documentation of this file.
1
/*!
2
\file cluster/c_assign.c
3
4
\brief Cluster library - Assign cluster
5
6
(C) 2001-2009 by the GRASS Development Team
7
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
10
11
\author Original author CERL
12
*/
13
14
#include <math.h>
15
#include <
grass/cluster.h
>
16
17
/*!
18
\brief Assign cluster
19
20
\param C pointer to Cluster structure
21
\param interrupted ?
22
23
\return -1 on interrupted
24
\return 0 on success
25
*/
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
}
Cluster::nbands
int nbands
Definition:
cluster.h:9
Cluster::sum
double ** sum
Definition:
cluster.h:21
Cluster::mean
double ** mean
Definition:
cluster.h:24
Cluster::nclasses
int nclasses
Definition:
cluster.h:27
Cluster
Definition:
cluster.h:7
Cluster::npoints
int npoints
Definition:
cluster.h:10
Cluster::count
int * count
Definition:
cluster.h:19
Cluster::class
int * class
Definition:
cluster.h:17
I_cluster_assign
int I_cluster_assign(struct Cluster *C, int *interrupted)
Assign cluster.
Definition:
c_assign.c:26
Cluster::points
DCELL ** points
Definition:
cluster.h:11
HUGE_VAL
#define HUGE_VAL
Values needed for Ray-Convex Polyhedron Intersection Test below originally by Eric Haines...
Definition:
gs_query.c:29
cluster.h
G_debug
int G_debug(int, const char *,...) __attribute__((format(printf
lib
cluster
c_assign.c
Generated on Tue Feb 14 2023 05:55:58 for GRASS GIS 8 Programmer's Manual by
1.8.13