20 #include <grass/cluster.h>
21 static int extend(
struct Cluster *,
int);
22 static int all_zero(
struct Cluster *,
int);
29 for (band = 0; band < C->nbands; band++)
42 for (band = 0; band < C->nbands; band++) {
46 z = C->points[band][C->npoints] = x[band];
47 C->band_sum[band] += z;
48 C->band_sum2[band] += z * z;
56 return extend(C, n) ? 0 : -1;
65 C->points[band][C->npoints +
n] = x;
66 C->band_sum[band] += x;
67 C->band_sum2[band] += x * x;
79 for (next = cur; next <
n; next++) {
80 if (!all_zero(C, next)) {
82 for (band = 0; band < C->nbands; band++)
83 C->points[band][cur] = C->points[band][next];
87 return C->npoints = cur;
90 static int all_zero(
struct Cluster *
C,
int i)
94 for (band = 0; band < C->nbands; band++)
95 if (C->points[band][i])
100 static int extend(
struct Cluster *C,
int n)
104 while ((C->npoints + n) > C->np) {
106 for (band = 0; band < C->nbands; band++) {
108 (DCELL *)
I_realloc(C->points[band], C->np *
sizeof(DCELL));
109 if (C->points[band] ==
NULL)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
int I_cluster_begin_point_set(struct Cluster *C, int n)
int I_cluster_point_part(struct Cluster *C, DCELL x, int band, int n)
void * I_realloc(void *b, size_t n)
int I_cluster_end_point_set(struct Cluster *C, int n)
int I_cluster_point(struct Cluster *C, DCELL *x)