input2d.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*-
  2. * Written by H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993
  3. * University of Illinois
  4. * US Army Construction Engineering Research Lab
  5. * Copyright 1993, H. Mitasova (University of Illinois),
  6. * I. Kosinovsky, (USA-CERL), and D.Gerdes (USA-CERL)
  7. *
  8. * modified by McCauley in August 1995
  9. * modified by Mitasova in August 1995
  10. * modified by Mitasova in November 1996 to include variable smoothing
  11. * modified by Brown in June 1999 - added elatt & smatt
  12. *
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <math.h>
  17. #include <grass/gis.h>
  18. #include <grass/raster.h>
  19. #include <grass/bitmap.h>
  20. #include <grass/linkm.h>
  21. #include <grass/interpf.h>
  22. #include <grass/glocale.h>
  23. struct BM *IL_create_bitmask(struct interp_params *params)
  24. /** Creates a bitmap mask from given raster map **/
  25. {
  26. int i, j, cfmask = 0, irev, MASKfd;
  27. const char *mapsetm;
  28. CELL *cellmask, *MASK;
  29. struct BM *bitmask;
  30. if ((MASKfd = Rast_maskfd()) >= 0)
  31. MASK = Rast_allocate_c_buf();
  32. else
  33. MASK = NULL;
  34. if (params->maskmap != NULL || MASK != NULL) {
  35. bitmask = BM_create(params->nsizc, params->nsizr);
  36. if (params->maskmap != NULL) {
  37. mapsetm = G_find_raster2(params->maskmap, "");
  38. if (!mapsetm)
  39. G_fatal_error(_("Mask raster map <%s> not found"),
  40. params->maskmap);
  41. cellmask = Rast_allocate_c_buf();
  42. cfmask = Rast_open_old(params->maskmap, mapsetm);
  43. }
  44. else
  45. cellmask = NULL;
  46. for (i = 0; i < params->nsizr; i++) {
  47. irev = params->nsizr - i - 1;
  48. if (cellmask)
  49. Rast_get_c_row(cfmask, cellmask, i);
  50. if (MASK)
  51. Rast_get_c_row(MASKfd, MASK, i);
  52. for (j = 0; j < params->nsizc; j++) {
  53. if ((cellmask && cellmask[j] == 0) || (MASK && MASK[j] == 0))
  54. BM_set(bitmask, j, irev, 0);
  55. else
  56. BM_set(bitmask, j, irev, 1);
  57. }
  58. }
  59. G_message(_("Bitmap mask created"));
  60. }
  61. else
  62. bitmask = NULL;
  63. return bitmask;
  64. }
  65. int translate_quad(struct multtree *tree,
  66. double numberx,
  67. double numbery, double numberz, int n_leafs)
  68. {
  69. int total = 0, i, ii;
  70. if (tree == NULL)
  71. return 0;
  72. if (tree->data == NULL)
  73. return 0;
  74. if (tree->leafs != NULL) {
  75. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  76. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  77. ((struct quaddata *)(tree->data))->xmax -= numberx;
  78. ((struct quaddata *)(tree->data))->ymax -= numbery;
  79. for (ii = 0; ii < n_leafs; ii++)
  80. total +=
  81. translate_quad(tree->leafs[ii], numberx, numbery, numberz,
  82. n_leafs);
  83. }
  84. else {
  85. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  86. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  87. ((struct quaddata *)(tree->data))->xmax -= numberx;
  88. ((struct quaddata *)(tree->data))->ymax -= numbery;
  89. for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
  90. ((struct quaddata *)(tree->data))->points[i].x -= numberx;
  91. ((struct quaddata *)(tree->data))->points[i].y -= numbery;
  92. ((struct quaddata *)(tree->data))->points[i].z -= numberz;
  93. }
  94. return 1;
  95. }
  96. return total;
  97. }