GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
input2d.c
Go to the documentation of this file.
1
/*!
2
* \file input2d.c
3
*
4
* \author H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 (original authors)
5
* \author modified by McCauley in August 1995
6
* \author modified by Mitasova in August 1995
7
* \author modified by Brown in June 1999 - added elatt & smatt
8
*
9
* \copyright
10
* (C) 1993-1999 by Helena Mitasova and the GRASS Development Team
11
*
12
* \copyright
13
* This program is free software under the
14
* GNU General Public License (>=v2).
15
* Read the file COPYING that comes with GRASS
16
* for details.
17
*/
18
19
#include <stdio.h>
20
#include <stdlib.h>
21
#include <math.h>
22
23
#include <grass/gis.h>
24
#include <grass/raster.h>
25
#include <grass/bitmap.h>
26
#include <grass/linkm.h>
27
#include <grass/interpf.h>
28
#include <grass/glocale.h>
29
30
/*!
31
* Creates a bitmap mask from given raster map
32
*
33
* Creates a bitmap mask from maskmap raster file and/or current MASK if
34
* present and returns a pointer to the bitmask. If no mask is in force
35
* returns NULL.
36
*/
37
struct
BM *
IL_create_bitmask
(
struct
interp_params
*params)
38
{
39
int
i, j, cfmask = -1, irev, MASKfd;
40
const
char
*mapsetm;
41
CELL *cellmask, *MASK;
42
struct
BM *bitmask;
43
44
if
((MASKfd = Rast_maskfd()) >= 0)
45
MASK = Rast_allocate_c_buf();
46
else
47
MASK =
NULL
;
48
49
if
(params->
maskmap
!=
NULL
|| MASK !=
NULL
) {
50
bitmask =
BM_create
(params->
nsizc
, params->
nsizr
);
51
52
if
(params->
maskmap
!=
NULL
) {
53
mapsetm =
G_find_raster2
(params->
maskmap
,
""
);
54
if
(!mapsetm)
55
G_fatal_error
(_(
"Mask raster map <%s> not found"
),
56
params->
maskmap
);
57
58
cellmask = Rast_allocate_c_buf();
59
cfmask = Rast_open_old(params->
maskmap
, mapsetm);
60
}
61
else
62
cellmask =
NULL
;
63
64
for
(i = 0; i < params->
nsizr
; i++) {
65
irev = params->
nsizr
- i - 1;
66
if
(cellmask)
67
Rast_get_c_row(cfmask, cellmask, i);
68
if
(MASK)
69
Rast_get_c_row(MASKfd, MASK, i);
70
for
(j = 0; j < params->
nsizc
; j++) {
71
if
((cellmask && (cellmask[j] == 0 ||
72
Rast_is_c_null_value(&cellmask[j]))) ||
73
(MASK && (MASK[j] == 0 || Rast_is_c_null_value(&MASK[j]))))
74
BM_set
(bitmask, j, irev, 0);
75
else
76
BM_set
(bitmask, j, irev, 1);
77
}
78
}
79
G_message
(_(
"Bitmap mask created"
));
80
}
81
else
82
bitmask =
NULL
;
83
84
if
(cfmask >= 0)
85
Rast_close(cfmask);
86
87
return
bitmask;
88
}
89
90
int
translate_quad
(
struct
multtree
*tree,
double
numberx,
double
numbery,
91
double
numberz,
int
n_leafs)
92
{
93
int
total = 0, i, ii;
94
95
if
(tree ==
NULL
)
96
return
0;
97
if
(tree->
data
==
NULL
)
98
return
0;
99
100
if
(tree->
leafs
!=
NULL
) {
101
((
struct
quaddata
*)(tree->
data
))->
x_orig
-= numberx;
102
((
struct
quaddata
*)(tree->
data
))->
y_orig
-= numbery;
103
((
struct
quaddata
*)(tree->
data
))->
xmax
-= numberx;
104
((
struct
quaddata
*)(tree->
data
))->
ymax
-= numbery;
105
for
(ii = 0; ii < n_leafs; ii++)
106
total +=
translate_quad
(tree->
leafs
[ii], numberx, numbery, numberz,
107
n_leafs);
108
}
109
else
{
110
((
struct
quaddata
*)(tree->
data
))->
x_orig
-= numberx;
111
((
struct
quaddata
*)(tree->
data
))->
y_orig
-= numbery;
112
((
struct
quaddata
*)(tree->
data
))->
xmax
-= numberx;
113
((
struct
quaddata
*)(tree->
data
))->
ymax
-= numbery;
114
for
(i = 0; i < ((
struct
quaddata
*)(tree->
data
))->n_points; i++) {
115
((
struct
quaddata
*)(tree->
data
))->
points
[i].
x
-= numberx;
116
((
struct
quaddata
*)(tree->
data
))->
points
[i].y -= numbery;
117
((
struct
quaddata
*)(tree->
data
))->
points
[i].z -= numberz;
118
}
119
120
return
1;
121
}
122
123
return
total;
124
}
BM_create
struct BM * BM_create(int x, int y)
Create bitmap of dimension x/y and return structure token.
Definition
bitmap.c:57
BM_set
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to 'val' at location 'x' 'y'.
Definition
bitmap.c:182
NULL
#define NULL
Definition
ccmath.h:32
G_find_raster2
const char * G_find_raster2(const char *name, const char *mapset)
Find a raster map (look but don't touch).
Definition
find_rast.c:76
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition
gis/error.c:159
G_message
void G_message(const char *msg,...)
Print a message to stderr.
Definition
gis/error.c:89
IL_create_bitmask
struct BM * IL_create_bitmask(struct interp_params *params)
Definition
input2d.c:37
translate_quad
int translate_quad(struct multtree *tree, double numberx, double numbery, double numberz, int n_leafs)
Definition
input2d.c:90
interp_params
Definition
interpf.h:70
interp_params::maskmap
char * maskmap
Definition
interpf.h:90
interp_params::nsizr
int nsizr
Definition
interpf.h:92
interp_params::nsizc
int nsizc
Definition
interpf.h:92
multtree
Definition
qtree.h:52
multtree::leafs
struct multtree ** leafs
Definition
qtree.h:54
multtree::data
struct quaddata * data
Definition
qtree.h:53
quaddata
Definition
dataquad.h:45
quaddata::ymax
double ymax
Definition
dataquad.h:49
quaddata::y_orig
double y_orig
Definition
dataquad.h:47
quaddata::x_orig
double x_orig
Definition
dataquad.h:46
quaddata::points
struct triple * points
Definition
dataquad.h:53
quaddata::xmax
double xmax
Definition
dataquad.h:48
x
#define x
rst
interp_float
input2d.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0