GRASS Programmer's Manual
6.4.2(2012)
|
00001 00002 /*- 00003 * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 00004 * University of Illinois 00005 * US Army Construction Engineering Research Lab 00006 * Copyright 1993, H. Mitasova (University of Illinois), 00007 * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL) 00008 * 00009 * modified by McCauley in August 1995 00010 * modified by Mitasova in August 1995 00011 * modified by Mitasova in November 1996 to include variable smoothing 00012 * modified by Brown in June 1999 - added elatt & smatt 00013 * 00014 */ 00015 00016 00017 #include <stdio.h> 00018 #include <stdlib.h> 00019 #include <math.h> 00020 #include <grass/gis.h> 00021 #include <grass/site.h> 00022 #include <grass/bitmap.h> 00023 #include <grass/linkm.h> 00024 #include <grass/interpf.h> 00025 #include <grass/glocale.h> 00026 00027 struct BM *IL_create_bitmask(struct interp_params *params) 00028 00029 00030 { 00031 int i, j, cfmask = 0, irev, MASKfd; 00032 char *mapsetm; 00033 CELL *cellmask, *MASK; 00034 struct BM *bitmask; 00035 00036 if ((MASKfd = G_maskfd()) >= 0) 00037 MASK = G_allocate_cell_buf(); 00038 else 00039 MASK = NULL; 00040 00041 if (params->maskmap != NULL || MASK != NULL) { 00042 bitmask = BM_create(params->nsizc, params->nsizr); 00043 00044 if (params->maskmap != NULL) { 00045 mapsetm = G_find_cell2(params->maskmap, ""); 00046 if (!mapsetm) 00047 G_fatal_error(_("Mask raster map <%s> not found"), 00048 params->maskmap); 00049 00050 cellmask = G_allocate_cell_buf(); 00051 cfmask = G_open_cell_old(params->maskmap, mapsetm); 00052 } 00053 else 00054 cellmask = NULL; 00055 00056 for (i = 0; i < params->nsizr; i++) { 00057 irev = params->nsizr - i - 1; 00058 if (cellmask) 00059 G_get_map_row(cfmask, cellmask, i); 00060 if (MASK) 00061 G_get_map_row(MASKfd, MASK, i); 00062 for (j = 0; j < params->nsizc; j++) { 00063 if ((cellmask && cellmask[j] == 0) || (MASK && MASK[j] == 0)) 00064 BM_set(bitmask, j, irev, 0); 00065 else 00066 BM_set(bitmask, j, irev, 1); 00067 } 00068 } 00069 G_message(_("Bitmap mask created")); 00070 } 00071 else 00072 bitmask = NULL; 00073 00074 return bitmask; 00075 } 00076 00077 int translate_quad(struct multtree *tree, 00078 double numberx, 00079 double numbery, double numberz, int n_leafs) 00080 { 00081 int total = 0, i, ii; 00082 00083 if (tree == NULL) 00084 return 0; 00085 if (tree->data == NULL) 00086 return 0; 00087 00088 if (tree->leafs != NULL) { 00089 ((struct quaddata *)(tree->data))->x_orig -= numberx; 00090 ((struct quaddata *)(tree->data))->y_orig -= numbery; 00091 ((struct quaddata *)(tree->data))->xmax -= numberx; 00092 ((struct quaddata *)(tree->data))->ymax -= numbery; 00093 for (ii = 0; ii < n_leafs; ii++) 00094 total += 00095 translate_quad(tree->leafs[ii], numberx, numbery, numberz, 00096 n_leafs); 00097 } 00098 else { 00099 ((struct quaddata *)(tree->data))->x_orig -= numberx; 00100 ((struct quaddata *)(tree->data))->y_orig -= numbery; 00101 ((struct quaddata *)(tree->data))->xmax -= numberx; 00102 ((struct quaddata *)(tree->data))->ymax -= numbery; 00103 for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) { 00104 ((struct quaddata *)(tree->data))->points[i].x -= numberx; 00105 ((struct quaddata *)(tree->data))->points[i].y -= numbery; 00106 ((struct quaddata *)(tree->data))->points[i].z -= numberz; 00107 } 00108 00109 return 1; 00110 } 00111 00112 return total; 00113 }