GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
input2d.c
Go to the documentation of this file.
1 
2 /*-
3  * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
4  * University of Illinois
5  * US Army Construction Engineering Research Lab
6  * Copyright 1993, H. Mitasova (University of Illinois),
7  * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)
8  *
9  * modified by McCauley in August 1995
10  * modified by Mitasova in August 1995
11  * modified by Mitasova in November 1996 to include variable smoothing
12  * modified by Brown in June 1999 - added elatt & smatt
13  *
14  */
15 
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <math.h>
20 #include <grass/gis.h>
21 #include <grass/site.h>
22 #include <grass/bitmap.h>
23 #include <grass/linkm.h>
24 #include <grass/interpf.h>
25 #include <grass/glocale.h>
26 
27 struct BM *IL_create_bitmask(struct interp_params *params)
28 
29 
30 {
31  int i, j, cfmask = 0, irev, MASKfd;
32  char *mapsetm;
33  CELL *cellmask, *MASK;
34  struct BM *bitmask;
35 
36  if ((MASKfd = G_maskfd()) >= 0)
37  MASK = G_allocate_cell_buf();
38  else
39  MASK = NULL;
40 
41  if (params->maskmap != NULL || MASK != NULL) {
42  bitmask = BM_create(params->nsizc, params->nsizr);
43 
44  if (params->maskmap != NULL) {
45  mapsetm = G_find_cell2(params->maskmap, "");
46  if (!mapsetm)
47  G_fatal_error(_("Mask raster map <%s> not found"),
48  params->maskmap);
49 
50  cellmask = G_allocate_cell_buf();
51  cfmask = G_open_cell_old(params->maskmap, mapsetm);
52  }
53  else
54  cellmask = NULL;
55 
56  for (i = 0; i < params->nsizr; i++) {
57  irev = params->nsizr - i - 1;
58  if (cellmask)
59  G_get_map_row(cfmask, cellmask, i);
60  if (MASK)
61  G_get_map_row(MASKfd, MASK, i);
62  for (j = 0; j < params->nsizc; j++) {
63  if ((cellmask && cellmask[j] == 0) || (MASK && MASK[j] == 0))
64  BM_set(bitmask, j, irev, 0);
65  else
66  BM_set(bitmask, j, irev, 1);
67  }
68  }
69  G_message(_("Bitmap mask created"));
70  }
71  else
72  bitmask = NULL;
73 
74  return bitmask;
75 }
76 
77 int translate_quad(struct multtree *tree,
78  double numberx,
79  double numbery, double numberz, int n_leafs)
80 {
81  int total = 0, i, ii;
82 
83  if (tree == NULL)
84  return 0;
85  if (tree->data == NULL)
86  return 0;
87 
88  if (tree->leafs != NULL) {
89  ((struct quaddata *)(tree->data))->x_orig -= numberx;
90  ((struct quaddata *)(tree->data))->y_orig -= numbery;
91  ((struct quaddata *)(tree->data))->xmax -= numberx;
92  ((struct quaddata *)(tree->data))->ymax -= numbery;
93  for (ii = 0; ii < n_leafs; ii++)
94  total +=
95  translate_quad(tree->leafs[ii], numberx, numbery, numberz,
96  n_leafs);
97  }
98  else {
99  ((struct quaddata *)(tree->data))->x_orig -= numberx;
100  ((struct quaddata *)(tree->data))->y_orig -= numbery;
101  ((struct quaddata *)(tree->data))->xmax -= numberx;
102  ((struct quaddata *)(tree->data))->ymax -= numbery;
103  for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
104  ((struct quaddata *)(tree->data))->points[i].x -= numberx;
105  ((struct quaddata *)(tree->data))->points[i].y -= numbery;
106  ((struct quaddata *)(tree->data))->points[i].z -= numberz;
107  }
108 
109  return 1;
110  }
111 
112  return total;
113 }
double xmax
Definition: dataquad.c:293
double y_orig
Definition: dataquad.h:33
int G_open_cell_old(const char *name, const char *mapset)
Open an existing integer raster map (cell)
Definition: opencell.c:100
struct BM * IL_create_bitmask(struct interp_params *params)
Definition: input2d.c:27
int y
Definition: plot.c:34
double x_orig
Definition: dataquad.h:32
int translate_quad(struct multtree *tree, double numberx, double numbery, double numberz, int n_leafs)
Definition: input2d.c:77
int G_get_map_row(int fd, CELL *buf, int row)
Get raster row (this routine is deprecated!)
Definition: gis/get_row.c:848
struct triple * points
Definition: dataquad.h:39
struct quaddata * data
Definition: qtree.h:40
CELL * G_allocate_cell_buf(void)
Allocate memory for a CELL type raster map.
Definition: alloc_cell.c:64
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don&#39;t touch)
Definition: find_cell.c:83
void G_message(const char *msg,...)
Print a message to stderr.
Definition: lib/gis/error.c:74
int G_maskfd(void)
Test for MASK.
Definition: maskfd.c:28
double ymax
Definition: dataquad.c:293
struct BM * BM_create(int x, int y)
Create bitmap of dimension x/y and return structure token.
Definition: bitmap.c:60
return NULL
Definition: dbfopen.c:1394
char * maskmap
Definition: interpf.h:46
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to &#39;val&#39; at location &#39;x&#39; &#39;y&#39;.
Definition: bitmap.c:187
Definition: qtree.h:38
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
struct multtree ** leafs
Definition: qtree.h:41
int n_points
Definition: dataquad.h:38