GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
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 * SPDX-FileCopyrightText: 1993-1999 Helena Mitasova
10 * SPDX-FileCopyrightText: GRASS Development Team
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14#include <stdio.h>
15#include <stdlib.h>
16#include <math.h>
17
18#include <grass/gis.h>
19#include <grass/raster.h>
20#include <grass/bitmap.h>
21#include <grass/linkm.h>
22#include <grass/interpf.h>
23#include <grass/glocale.h>
24
25/*!
26 * Creates a bitmap mask from given raster map
27 *
28 * Creates a bitmap mask from maskmap raster file and/or current MASK if
29 * present and returns a pointer to the bitmask. If no mask is in force
30 * returns NULL.
31 */
32struct BM *IL_create_bitmask(struct interp_params *params)
33{
34 int i, j, cfmask = -1, irev, MASKfd;
35 const char *mapsetm;
37 struct BM *bitmask;
38
39 if ((MASKfd = Rast_maskfd()) >= 0)
41 else
42 MASK = NULL;
43
44 if (params->maskmap != NULL || MASK != NULL) {
45 bitmask = BM_create(params->nsizc, params->nsizr);
46
47 if (params->maskmap != NULL) {
48 mapsetm = G_find_raster2(params->maskmap, "");
49 if (!mapsetm)
50 G_fatal_error(_("Mask raster map <%s> not found"),
51 params->maskmap);
52
55 }
56 else
57 cellmask = NULL;
58
59 for (i = 0; i < params->nsizr; i++) {
60 irev = params->nsizr - i - 1;
61 if (cellmask)
63 if (MASK)
65 for (j = 0; j < params->nsizc; j++) {
66 if ((cellmask && (cellmask[j] == 0 ||
68 (MASK && (MASK[j] == 0 || Rast_is_c_null_value(&MASK[j]))))
69 BM_set(bitmask, j, irev, 0);
70 else
71 BM_set(bitmask, j, irev, 1);
72 }
73 }
74 G_message(_("Bitmap mask created"));
75 }
76 else
77 bitmask = NULL;
78
79 if (cfmask >= 0)
81
82 return bitmask;
83}
84
85int translate_quad(struct multtree *tree, double numberx, double numbery,
86 double numberz, int n_leafs)
87{
88 int total = 0, i, ii;
89
90 if (tree == NULL)
91 return 0;
92 if (tree->data == NULL)
93 return 0;
94
95 if (tree->leafs != NULL) {
96 ((struct quaddata *)(tree->data))->x_orig -= numberx;
97 ((struct quaddata *)(tree->data))->y_orig -= numbery;
98 ((struct quaddata *)(tree->data))->xmax -= numberx;
99 ((struct quaddata *)(tree->data))->ymax -= numbery;
100 for (ii = 0; ii < n_leafs; ii++)
101 total += translate_quad(tree->leafs[ii], numberx, numbery, numberz,
102 n_leafs);
103 }
104 else {
105 ((struct quaddata *)(tree->data))->x_orig -= numberx;
106 ((struct quaddata *)(tree->data))->y_orig -= numbery;
107 ((struct quaddata *)(tree->data))->xmax -= numberx;
108 ((struct quaddata *)(tree->data))->ymax -= numbery;
109 for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
110 ((struct quaddata *)(tree->data))->points[i].x -= numberx;
111 ((struct quaddata *)(tree->data))->points[i].y -= numbery;
112 ((struct quaddata *)(tree->data))->points[i].z -= numberz;
113 }
114
115 return 1;
116 }
117
118 return total;
119}
#define NULL
Definition ccmath.h:32
int BM_set(struct BM *, int, int, int)
Sets bitmap value to 'val' at location 'x' 'y'.
Definition bitmap.c:182
struct BM * BM_create(int, int)
Create bitmap of dimension x/y and return structure token.
Definition bitmap.c:57
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_message(const char *,...) __attribute__((format(printf
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
Definition find_rast.c:73
CELL * Rast_allocate_c_buf(void)
Allocate memory for a CELL type raster map.
Definition alloc_cell.c:78
void Rast_close(int)
Close a raster map.
int Rast_open_old(const char *, const char *)
Open an existing integer raster map (cell)
void Rast_get_c_row(int, CELL *, int)
Get raster row (CELL type)
#define Rast_is_c_null_value(cellVal)
int Rast_maskfd(void)
Test for raster mask presence and get file descriptor if present.
Definition maskfd.c:28
int CELL
Definition gis.h:631
#define _(str)
Definition glocale.h:10
struct BM * IL_create_bitmask(struct interp_params *params)
Definition input2d.c:32
int translate_quad(struct multtree *tree, double numberx, double numbery, double numberz, int n_leafs)
Definition input2d.c:85
Definition bitmap.h:17
char * maskmap
Definition interpf.h:90
struct multtree ** leafs
Definition qtree.h:50
struct quaddata * data
Definition qtree.h:49
double ymax
Definition dataquad.h:45
double y_orig
Definition dataquad.h:43
double x_orig
Definition dataquad.h:42
struct triple * points
Definition dataquad.h:49
int n_points
Definition dataquad.h:48
double xmax
Definition dataquad.h:44
#define x