input2d.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/site.h>
  20. #include <grass/bitmap.h>
  21. #include <grass/linkm.h>
  22. #include <grass/interpf.h>
  23. #include <grass/glocale.h>
  24. struct BM *IL_create_bitmask(struct interp_params *params)
  25. /** Creates a bitmap mask from given raster map **/
  26. {
  27. int i, j, cfmask = 0, irev, MASKfd;
  28. const char *mapsetm;
  29. CELL *cellmask, *MASK;
  30. struct BM *bitmask;
  31. if ((MASKfd = Rast_maskfd()) >= 0)
  32. MASK = Rast_allocate_c_buf();
  33. else
  34. MASK = NULL;
  35. if (params->maskmap != NULL || MASK != NULL) {
  36. bitmask = BM_create(params->nsizc, params->nsizr);
  37. if (params->maskmap != NULL) {
  38. mapsetm = G_find_raster2(params->maskmap, "");
  39. if (!mapsetm)
  40. G_fatal_error(_("Mask raster map <%s> not found"),
  41. params->maskmap);
  42. cellmask = Rast_allocate_c_buf();
  43. cfmask = Rast_open_old(params->maskmap, mapsetm);
  44. }
  45. else
  46. cellmask = NULL;
  47. for (i = 0; i < params->nsizr; i++) {
  48. irev = params->nsizr - i - 1;
  49. if (cellmask)
  50. Rast_get_c_row(cfmask, cellmask, i);
  51. if (MASK)
  52. Rast_get_c_row(MASKfd, MASK, i);
  53. for (j = 0; j < params->nsizc; j++) {
  54. if ((cellmask && cellmask[j] == 0) || (MASK && MASK[j] == 0))
  55. BM_set(bitmask, j, irev, 0);
  56. else
  57. BM_set(bitmask, j, irev, 1);
  58. }
  59. }
  60. G_message(_("Bitmap mask created"));
  61. }
  62. else
  63. bitmask = NULL;
  64. return bitmask;
  65. }
  66. int translate_quad(struct multtree *tree,
  67. double numberx,
  68. double numbery, double numberz, int n_leafs)
  69. {
  70. int total = 0, i, ii;
  71. if (tree == NULL)
  72. return 0;
  73. if (tree->data == NULL)
  74. return 0;
  75. if (tree->leafs != NULL) {
  76. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  77. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  78. ((struct quaddata *)(tree->data))->xmax -= numberx;
  79. ((struct quaddata *)(tree->data))->ymax -= numbery;
  80. for (ii = 0; ii < n_leafs; ii++)
  81. total +=
  82. translate_quad(tree->leafs[ii], numberx, numbery, numberz,
  83. n_leafs);
  84. }
  85. else {
  86. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  87. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  88. ((struct quaddata *)(tree->data))->xmax -= numberx;
  89. ((struct quaddata *)(tree->data))->ymax -= numbery;
  90. for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
  91. ((struct quaddata *)(tree->data))->points[i].x -= numberx;
  92. ((struct quaddata *)(tree->data))->points[i].y -= numbery;
  93. ((struct quaddata *)(tree->data))->points[i].z -= numberz;
  94. }
  95. return 1;
  96. }
  97. return total;
  98. }