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