forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmask.c
72 lines (57 loc) · 1.39 KB
/
mask.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <grass/gis.h>
#include <grass/raster.h>
#include "mask.h"
#include "local_proto.h"
int init_d_mask_rules(d_Mask * d_mask)
{
d_mask->list = NULL;
return 0;
}
int add_d_mask_rule(d_Mask * d_mask, double a, double b, int inf)
{
d_Interval *I;
I = (d_Interval *) G_malloc(sizeof(d_Interval));
I->low = a <= b ? a : b;
I->high = a >= b ? a : b;
I->inf = inf;
I->next = d_mask->list;
d_mask->list = I;
return 0;
}
int mask_raster_array(void *rast, int ncols,
int change_null, RASTER_MAP_TYPE data_type)
{
DCELL x;
while (ncols-- > 0) {
x = Rast_get_d_value(rast, data_type);
if (change_null && Rast_is_null_value(rast, data_type))
Rast_set_d_value(rast, new_null, data_type);
if (mask_d_select(&x, &d_mask))
Rast_set_null_value(rast, 1, data_type);
rast = G_incr_void_ptr(rast, Rast_cell_size(data_type));
}
return 0;
}
int mask_d_select(DCELL * x, d_Mask * mask)
{
d_Interval *I;
if (mask->list == NULL)
return 0;
for (I = mask->list; I; I = I->next) {
if (mask_match_d_interval(*x, I))
return 1;
}
return 0;
}
int mask_match_d_interval(DCELL x, d_Interval * I)
{
if (Rast_is_d_null_value(&x))
return 0;
if (I->inf < 0)
return x <= I->low;
if (I->inf > 0)
return x >= I->high;
if (I->low != I->low && I->high != I->high)
return x != x;
return x >= I->low && x <= I->high;
}