input2d.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*!
  2. * \file input2d.c
  3. *
  4. * \author H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 (original authors)
  5. * \author modified by McCauley in August 1995
  6. * \author modified by Mitasova in August 1995
  7. * \author modified by Brown in June 1999 - added elatt & smatt
  8. *
  9. * \copyright
  10. * (C) 1993-1999 by Helena Mitasova and the GRASS Development Team
  11. *
  12. * \copyright
  13. * This program is free software under the
  14. * GNU General Public License (>=v2).
  15. * Read the file COPYING that comes with GRASS
  16. * for details.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <math.h>
  21. #include <grass/gis.h>
  22. #include <grass/raster.h>
  23. #include <grass/bitmap.h>
  24. #include <grass/linkm.h>
  25. #include <grass/interpf.h>
  26. #include <grass/glocale.h>
  27. /*!
  28. * Creates a bitmap mask from given raster map
  29. *
  30. * Creates a bitmap mask from maskmap raster file and/or current MASK if
  31. * present and returns a pointer to the bitmask. If no mask is in force
  32. * returns NULL.
  33. */
  34. struct BM *IL_create_bitmask(struct interp_params *params)
  35. {
  36. int i, j, cfmask = -1, irev, MASKfd;
  37. const char *mapsetm;
  38. CELL *cellmask, *MASK;
  39. struct BM *bitmask;
  40. if ((MASKfd = Rast_maskfd()) >= 0)
  41. MASK = Rast_allocate_c_buf();
  42. else
  43. MASK = NULL;
  44. if (params->maskmap != NULL || MASK != NULL) {
  45. bitmask = BM_create(params->nsizc, params->nsizr);
  46. if (params->maskmap != NULL) {
  47. mapsetm = G_find_raster2(params->maskmap, "");
  48. if (!mapsetm)
  49. G_fatal_error(_("Mask raster map <%s> not found"),
  50. params->maskmap);
  51. cellmask = Rast_allocate_c_buf();
  52. cfmask = Rast_open_old(params->maskmap, mapsetm);
  53. }
  54. else
  55. cellmask = NULL;
  56. for (i = 0; i < params->nsizr; i++) {
  57. irev = params->nsizr - i - 1;
  58. if (cellmask)
  59. Rast_get_c_row(cfmask, cellmask, i);
  60. if (MASK)
  61. Rast_get_c_row(MASKfd, MASK, i);
  62. for (j = 0; j < params->nsizc; j++) {
  63. if ((cellmask && (cellmask[j] == 0 || Rast_is_c_null_value(&cellmask[j]))) ||
  64. (MASK && (MASK[j] == 0 || Rast_is_c_null_value(&MASK[j]))))
  65. BM_set(bitmask, j, irev, 0);
  66. else
  67. BM_set(bitmask, j, irev, 1);
  68. }
  69. }
  70. G_message(_("Bitmap mask created"));
  71. }
  72. else
  73. bitmask = NULL;
  74. if (cfmask >= 0)
  75. Rast_close(cfmask);
  76. return bitmask;
  77. }
  78. int translate_quad(struct multtree *tree,
  79. double numberx,
  80. double numbery, double numberz, int n_leafs)
  81. {
  82. int total = 0, i, ii;
  83. if (tree == NULL)
  84. return 0;
  85. if (tree->data == NULL)
  86. return 0;
  87. if (tree->leafs != NULL) {
  88. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  89. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  90. ((struct quaddata *)(tree->data))->xmax -= numberx;
  91. ((struct quaddata *)(tree->data))->ymax -= numbery;
  92. for (ii = 0; ii < n_leafs; ii++)
  93. total +=
  94. translate_quad(tree->leafs[ii], numberx, numbery, numberz,
  95. n_leafs);
  96. }
  97. else {
  98. ((struct quaddata *)(tree->data))->x_orig -= numberx;
  99. ((struct quaddata *)(tree->data))->y_orig -= numbery;
  100. ((struct quaddata *)(tree->data))->xmax -= numberx;
  101. ((struct quaddata *)(tree->data))->ymax -= numbery;
  102. for (i = 0; i < ((struct quaddata *)(tree->data))->n_points; i++) {
  103. ((struct quaddata *)(tree->data))->points[i].x -= numberx;
  104. ((struct quaddata *)(tree->data))->points[i].y -= numbery;
  105. ((struct quaddata *)(tree->data))->points[i].z -= numberz;
  106. }
  107. return 1;
  108. }
  109. return total;
  110. }