collect_ori.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*********************************************************************
  2. *
  3. * collect_ori.c in ~/r.spread2
  4. *
  5. * functin to collect the spread origins from the source map and
  6. * put them into a min-heap; also marks the origin locations and
  7. * the other locations to avoid redundant computation and to be
  8. * able to terminate.
  9. *********************************************************************/
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <grass/gis.h>
  13. #include <grass/raster.h>
  14. #include "cmd_line.h"
  15. #include "costHa.h"
  16. #include "local_proto.h"
  17. #define DATA(map, r, c) (map)[(r) * ncols + (c)]
  18. /*#define DEBUG */
  19. /* Globals from cmd_line */
  20. char *backdrop_layer;
  21. char *base_layer;
  22. char *dir_layer;
  23. char *max_layer;
  24. char *spotdist_layer;
  25. char *mois_layer;
  26. char *out_layer;
  27. char *start_layer;
  28. char *velocity_layer;
  29. char *x_out_layer;
  30. char *y_out_layer;
  31. float comp_dens;
  32. int display;
  33. int init_time;
  34. int least;
  35. int spotting;
  36. int time_lag;
  37. int x_out;
  38. int y_out;
  39. void collect_ori(int start_fd)
  40. {
  41. extern CELL *cell;
  42. extern CELL *map_base, *map_x_out, *map_y_out, *map_visit;
  43. extern float *map_out;
  44. extern char buf[];
  45. extern float neg, zero;
  46. extern int BARRIER;
  47. extern int nrows, ncols;
  48. extern long heap_len;
  49. extern struct costHa *heap;
  50. int row, col;
  51. for (row = 0; row < nrows; row++) {
  52. G_percent(row, nrows, 2);
  53. Rast_get_c_row(start_fd, cell, row);
  54. for (col = 0; col < ncols; col++) {
  55. if (*(cell + col) > 0) {
  56. /*Check if starting sources legally ? */
  57. if (DATA(map_base, row, col) <= 0) {
  58. G_warning("Can't start from a BARRIER at cell (%d,%d), request ignored",
  59. col, row);
  60. continue;
  61. }
  62. DATA(map_out, row, col) = (float)init_time;
  63. insertHa((float)init_time, zero, row, col, heap, &heap_len);
  64. /*mark it to avoid redundant computing */
  65. DATA(map_visit, row, col) = 1;
  66. if (x_out)
  67. DATA(map_x_out, row, col) = col;
  68. if (y_out)
  69. DATA(map_y_out, row, col) = row;
  70. G_debug(4, "origin: row=%d col=%d", row, col);
  71. #if 0
  72. if (display)
  73. draw_a_burning_cell(row, col);
  74. #endif
  75. }
  76. else {
  77. DATA(map_out, row, col) = neg;
  78. DATA(map_visit, row, col) = BARRIER;
  79. }
  80. }
  81. }
  82. G_percent(row, nrows, 2);
  83. #ifdef DEBUG
  84. {
  85. int i;
  86. printf("\nheap_len=%d ", heap_len);
  87. for (i = 1; i <= heap_len; i++)
  88. printf("(%d,%d) ", heap[i].row, heap[i].col);
  89. }
  90. #endif
  91. }