File: input2d.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (113 lines) | stat: -rw-r--r-- 3,012 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

/*-
 * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
 * University of Illinois
 * US Army Construction Engineering Research Lab  
 * Copyright 1993, H. Mitasova (University of Illinois),
 * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)   
 *
 * modified by McCauley in August 1995
 * modified by Mitasova in August 1995  
 * modified by Mitasova in November 1996 to include variable smoothing
 * modified by Brown in June 1999 - added elatt & smatt
 *
 */


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/site.h>
#include <grass/bitmap.h>
#include <grass/linkm.h>
#include <grass/interpf.h>
#include <grass/glocale.h>

struct BM *IL_create_bitmask(struct interp_params *params)

/** Creates a bitmap mask from given raster map **/
{
    int i, j, cfmask = 0, irev, MASKfd;
    char *mapsetm;
    CELL *cellmask, *MASK;
    struct BM *bitmask;

    if ((MASKfd = G_maskfd()) >= 0)
	MASK = G_allocate_cell_buf();
    else
	MASK = NULL;

    if (params->maskmap != NULL || MASK != NULL) {
	bitmask = BM_create(params->nsizc, params->nsizr);

	if (params->maskmap != NULL) {
	    mapsetm = G_find_cell2(params->maskmap, "");
	    if (!mapsetm)
		G_fatal_error(_("Mask raster map <%s> not found"),
			      params->maskmap);

	    cellmask = G_allocate_cell_buf();
	    cfmask = G_open_cell_old(params->maskmap, mapsetm);
	}
	else
	    cellmask = NULL;

	for (i = 0; i < params->nsizr; i++) {
	    irev = params->nsizr - i - 1;
	    if (cellmask)
		G_get_map_row(cfmask, cellmask, i);
	    if (MASK)
		G_get_map_row(MASKfd, MASK, i);
	    for (j = 0; j < params->nsizc; j++) {
		if ((cellmask && cellmask[j] == 0) || (MASK && MASK[j] == 0))
		    BM_set(bitmask, j, irev, 0);
		else
		    BM_set(bitmask, j, irev, 1);
	    }
	}
	G_message(_("Bitmap mask created"));
    }
    else
	bitmask = NULL;

    return bitmask;
}

int translate_quad(struct multtree *tree,
		   double numberx,
		   double numbery, double numberz, int n_leafs)
{
    int total = 0, i, ii;

    if (tree == NULL)
	return 0;
    if (tree->data == NULL)
	return 0;

    if (tree->leafs != NULL) {
	((struct quaddata *)(tree->data))->x_orig -= numberx;
	((struct quaddata *)(tree->data))->y_orig -= numbery;
	((struct quaddata *)(tree->data))->xmax -= numberx;
	((struct quaddata *)(tree->data))->ymax -= numbery;
	for (ii = 0; ii < n_leafs; ii++)
	    total +=
		translate_quad(tree->leafs[ii], numberx, numbery, numberz,
			       n_leafs);
    }
    else {
	((struct quaddata *)(tree->data))->x_orig -= numberx;
	((struct quaddata *)(tree->data))->y_orig -= numbery;
	((struct quaddata *)(tree->data))->xmax -= numberx;
	((struct quaddata *)(tree->data))->ymax -= numbery;
	for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
	    ((struct quaddata *)(tree->data))->points[i].x -= numberx;
	    ((struct quaddata *)(tree->data))->points[i].y -= numbery;
	    ((struct quaddata *)(tree->data))->points[i].z -= numberz;
	}

	return 1;
    }

    return total;
}