GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-57a646b4a4
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 }
#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:185
struct BM * BM_create(int, int)
Create bitmap of dimension x/y and return structure token.
Definition: bitmap.c:58
void void void void G_fatal_error(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:76
void G_message(const char *,...) __attribute__((format(printf
void Rast_close(int)
Close a raster map.
Definition: raster/close.c:99
int Rast_open_old(const char *, const char *)
Open an existing integer raster map (cell)
Definition: raster/open.c:112
void Rast_get_c_row(int, CELL *, int)
Get raster row (CELL type)
CELL * Rast_allocate_c_buf(void)
Allocate memory for a CELL type raster map.
Definition: alloc_cell.c:81
#define Rast_is_c_null_value(cellVal)
Definition: defs/raster.h:404
int Rast_maskfd(void)
Test for MASK.
Definition: maskfd.c:26
int CELL
Definition: gis.h:628
#define _(str)
Definition: glocale.h:10
struct BM * IL_create_bitmask(struct interp_params *params)
Definition: input2d.c:37
int translate_quad(struct multtree *tree, double numberx, double numbery, double numberz, int n_leafs)
Definition: input2d.c:90
Definition: bitmap.h:17
char * maskmap
Definition: interpf.h:85
Definition: qtree.h:52
struct multtree ** leafs
Definition: qtree.h:54
struct quaddata * data
Definition: qtree.h:53
double ymax
Definition: dataquad.h:49
double y_orig
Definition: dataquad.h:47
double x_orig
Definition: dataquad.h:46
struct triple * points
Definition: dataquad.h:53
int n_points
Definition: dataquad.h:52
double xmax
Definition: dataquad.h:48
#define x