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