GRASS 8 Programmer's Manual
8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
c_reassign.c
Go to the documentation of this file.
1
/*!
2
\file cluster/c_reassign.c
3
4
\brief Cluster library - Reassign cluster
5
6
SPDX-FileCopyrightText: 2001-2009 GRASS Development Team
7
SPDX-License-Identifier: GPL-2.0-or-later
8
9
\author Original author CERL
10
*/
11
12
#include <math.h>
13
#include <
grass/cluster.h
>
14
15
/*!
16
\brief ?
17
18
\param C pointer to Cluster structure
19
\param interrupted
20
21
\return number of changes
22
*/
23
int
I_cluster_reassign
(
struct
Cluster
*C,
int
*
interrupted
)
24
{
25
double
min
, d, z;
26
double
q;
27
int
c, np;
28
int
old;
29
int
p, band,
class
;
30
int
changes
;
31
int
first;
32
33
changes
= 0;
34
for
(c = 0; c < C->
nclasses
; c++) {
35
C->
countdiff
[c] = 0;
36
for
(band = 0; band < C->
nbands
; band++)
37
C->
sumdiff
[band][c] = 0;
38
}
39
40
min
=
HUGE_VAL
;
41
class
= 0;
42
for
(p = 0; p < C->
npoints
; p++) {
43
if
(*
interrupted
)
44
return
0;
45
if
(C->
class
[p] < 0)
/* point to be ignored */
46
continue
;
47
48
/* find minimum distance to center of all classes */
49
first = 1;
50
for
(c = 0; c < C->
nclasses
; c++) {
51
d = 0;
52
np = C->
count
[c];
53
if
(np == 0)
54
continue
;
55
for
(band = 0; band < C->
nbands
; band++) {
56
z = C->
points
[band][p] * np - C->
sum
[band][c];
57
d += z * z;
58
}
59
d /= (np * np);
60
61
if
(first || (d <
min
)) {
62
class
= c;
63
min
= d;
64
first = 0;
65
}
66
}
67
68
if
(C->
class
[p] !=
class
) {
69
old = C->
class
[p];
70
C->
class
[p] =
class
;
71
changes
++;
72
73
C->
countdiff
[
class
]++;
74
C->
countdiff
[old]--;
75
76
for
(band = 0; band < C->
nbands
; band++) {
77
q = C->
points
[band][p];
78
C->
sumdiff
[band][
class
] += q;
79
C->
sumdiff
[band][old] -= q;
80
}
81
}
82
}
83
84
if
(
changes
) {
85
for
(c = 0; c < C->
nclasses
; c++) {
86
C->
count
[c] += C->
countdiff
[c];
87
for
(band = 0; band < C->
nbands
; band++)
88
C->
sum
[band][c] += C->
sumdiff
[band][c];
89
}
90
}
91
92
return
changes
;
93
}
I_cluster_reassign
int I_cluster_reassign(struct Cluster *C, int *interrupted)
?
Definition
c_reassign.c:23
AMI_STREAM
Definition
ami_stream.h:153
cluster.h
min
#define min(x, y)
Definition
draw2.c:29
HUGE_VAL
#define HUGE_VAL
Values needed for Ray-Convex Polyhedron Intersection Test below originally by Eric Haines,...
Definition
gs_query.c:25
Cluster
Definition
cluster.h:7
Cluster::count
int * count
Definition
cluster.h:18
Cluster::npoints
int npoints
Definition
cluster.h:9
Cluster::countdiff
int * countdiff
Definition
cluster.h:19
Cluster::class
int * class
Definition
cluster.h:16
Cluster::nclasses
int nclasses
Definition
cluster.h:26
Cluster::points
DCELL ** points
Definition
cluster.h:10
Cluster::sum
double ** sum
Definition
cluster.h:20
Cluster::nbands
int nbands
Definition
cluster.h:8
Cluster::sumdiff
double ** sumdiff
Definition
cluster.h:21
lib
cluster
c_reassign.c
Generated on Sun Sep 13 2026 06:57:48 for GRASS 8 Programmer's Manual by
1.9.8