GRASS 8 Programmer's Manual
8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
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
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 Assign cluster
17
18
\param C pointer to Cluster structure
19
\param interrupted ?
20
21
\return -1 on interrupted
22
\return 0 on success
23
*/
24
int
I_cluster_assign
(
struct
Cluster
*C,
int
*
interrupted
)
25
{
26
int
p, c;
27
int
class
, band;
28
double
d, q;
29
double
dmin;
30
31
G_debug
(3,
"I_cluster_assign(npoints=%d,nclasses=%d,nbands=%d)"
, C->
npoints
,
32
C->
nclasses
, C->
nbands
);
33
34
for
(p = 0; p < C->
npoints
; p++) {
35
if
(*
interrupted
)
36
return
-1;
37
38
dmin =
HUGE_VAL
;
39
class
= 0;
40
for
(c = 0; c < C->
nclasses
; c++) {
41
d = 0.0;
42
for
(band = 0; band < C->
nbands
; band++) {
43
q = C->
points
[band][p];
44
q -= C->
mean
[band][c];
45
d += q * q;
46
}
47
if
(c == 0 || d < dmin) {
48
class
= c;
49
dmin = d;
50
}
51
}
52
C->
class
[p] =
class
;
53
C->
count
[
class
]++;
54
for
(band = 0; band < C->
nbands
; band++)
55
C->
sum
[band][
class
] += C->
points
[band][p];
56
}
57
58
return
0;
59
}
I_cluster_assign
int I_cluster_assign(struct Cluster *C, int *interrupted)
Assign cluster.
Definition
c_assign.c:24
AMI_STREAM
Definition
ami_stream.h:153
cluster.h
G_debug
int G_debug(int, const char *,...) __attribute__((format(printf
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::class
int * class
Definition
cluster.h:16
Cluster::nclasses
int nclasses
Definition
cluster.h:26
Cluster::mean
double ** mean
Definition
cluster.h:23
Cluster::points
DCELL ** points
Definition
cluster.h:10
Cluster::sum
double ** sum
Definition
cluster.h:20
Cluster::nbands
int nbands
Definition
cluster.h:8
lib
cluster
c_assign.c
Generated on Thu Sep 10 2026 06:57:36 for GRASS 8 Programmer's Manual by
1.9.8