[GRASS-SVN] r55652 - grass-addons/grass7/raster/r.hydrodem
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Apr 7 06:26:48 PDT 2013
Author: mmetz
Date: 2013-04-07 06:26:48 -0700 (Sun, 07 Apr 2013)
New Revision: 55652
Modified:
grass-addons/grass7/raster/r.hydrodem/do_astar.c
grass-addons/grass7/raster/r.hydrodem/hydro_con.c
grass-addons/grass7/raster/r.hydrodem/init_search.c
grass-addons/grass7/raster/r.hydrodem/load.c
grass-addons/grass7/raster/r.hydrodem/local_proto.h
grass-addons/grass7/raster/r.hydrodem/main.c
Log:
r.hydrodem: sync to r.stream.extract
Modified: grass-addons/grass7/raster/r.hydrodem/do_astar.c
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/do_astar.c 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/do_astar.c 2013-04-07 13:26:48 UTC (rev 55652)
@@ -26,8 +26,8 @@
int asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
CELL ele_val, ele_down, ele_nbr[8];
char is_bottom;
- char asp_val, asp_val_this;
- char flag_value, is_in_list, is_worked;
+ char is_in_list, is_worked;
+ struct dir_flag df;
struct heap_point heap_p;
/* sides
* |7|1|4|
@@ -85,16 +85,16 @@
c = heap_p.c;
first_cum--;
- bseg_get(&bitflags, &flag_value, r, c);
- FLAG_SET(flag_value, WORKEDFLAG);
- bseg_put(&bitflags, &flag_value, r, c);
+ seg_get(&dirflag, (char *)&df, r, c);
+ FLAG_SET(df.flag, WORKEDFLAG);
+ seg_put(&dirflag, (char *)&df, r, c);
ele_val = ele_down = heap_p.ele;
is_bottom = 0;
- bseg_get(&draindir, &asp_val_this, r, c);
- if (asp_val_this > 0 && !FLAG_GET(flag_value, EDGEFLAG)) {
- r_nbr = r + asp_r[(int)asp_val_this];
- c_nbr = c + asp_c[(int)asp_val_this];
+
+ if (df.dir > 0 && !FLAG_GET(df.flag, EDGEFLAG)) {
+ r_nbr = r + asp_r[(int)df.dir];
+ c_nbr = c + asp_c[(int)df.dir];
cseg_get(&ele, &ele_down, r_nbr, c_nbr);
if (ele_down > ele_val)
is_bottom = 1;
@@ -110,9 +110,9 @@
if (r_nbr < 0 || r_nbr >= nrows || c_nbr < 0 || c_nbr >= ncols)
continue;
- bseg_get(&bitflags, &flag_value, r_nbr, c_nbr);
- is_in_list = FLAG_GET(flag_value, INLISTFLAG);
- is_worked = FLAG_GET(flag_value, WORKEDFLAG);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
+ is_in_list = FLAG_GET(df.flag, INLISTFLAG);
+ is_worked = FLAG_GET(df.flag, WORKEDFLAG);
skip_diag = 0;
/* avoid diagonal flow direction bias */
@@ -139,41 +139,41 @@
}
}
- if (is_in_list == 0 && skip_diag == 0) {
- asp_val = drain[r_nbr - r + 1][c_nbr - c + 1];
- heap_add(r_nbr, c_nbr, ele_nbr[ct_dir], asp_val, flag_value);
+ if (!skip_diag) {
+ if (is_in_list == 0) {
+ df.dir = drain[r_nbr - r + 1][c_nbr - c + 1];
+ FLAG_SET(df.flag, INLISTFLAG);
+ seg_put(&dirflag, (char *)&df, r_nbr, c_nbr);
+ heap_add(r_nbr, c_nbr, ele_nbr[ct_dir]);
- if (ele_nbr[ct_dir] < ele_val)
- is_bottom = 0;
- }
- else if (is_in_list && is_worked == 0) {
- if (FLAG_GET(flag_value, EDGEFLAG)) {
- bseg_get(&draindir, &asp_val, r_nbr, c_nbr);
- if (asp_val < 0) {
- /* update edge cell ? no */
- /* asp_val = drain[r_nbr - r + 1][c_nbr - c + 1]; */
- /* check if this causes trouble */
- bseg_put(&draindir, &asp_val, r_nbr, c_nbr);
+ if (ele_nbr[ct_dir] < ele_val)
+ is_bottom = 0;
+ }
+ else if (is_in_list && is_worked == 0) {
+ if (FLAG_GET(df.flag, EDGEFLAG)) {
+ if (df.dir < 0) {
+ /* update edge cell ? no */
+ /* df.dir = drain[r_nbr - r + 1][c_nbr - c + 1]; */
+ /* check if this causes trouble */
+ /* seg_put(&dirflag, (char *)&df, r_nbr, c_nbr); */
- if (ele_nbr[ct_dir] < ele_val)
- is_bottom = 0;
+ if (ele_nbr[ct_dir] < ele_val)
+ is_bottom = 0;
+ }
}
- }
- else if (FLAG_GET(flag_value, DEPRFLAG)) {
- G_debug(3, "real depression");
- /* neighbour is inside real depression, not yet worked */
- bseg_get(&draindir, &asp_val, r_nbr, c_nbr);
- if (asp_val == 0 && ele_val <= ele_nbr[ct_dir]) {
- asp_val = drain[r_nbr - r + 1][c_nbr - c + 1];
- bseg_put(&draindir, &asp_val, r_nbr, c_nbr);
- FLAG_UNSET(flag_value, DEPRFLAG);
- bseg_put(&bitflags, &flag_value, r_nbr, c_nbr);
+ else if (FLAG_GET(df.flag, DEPRFLAG)) {
+ G_debug(3, "real depression");
+ /* neighbour is inside real depression, not yet worked */
+ if (df.dir == 0 && ele_val <= ele_nbr[ct_dir]) {
+ df.dir = drain[r_nbr - r + 1][c_nbr - c + 1];
+ FLAG_UNSET(df.flag, DEPRFLAG);
+ seg_put(&dirflag, (char *)&df, r_nbr, c_nbr);
+ }
}
}
}
} /* end neighbours */
-
if (is_bottom) {
/* add sink bottom */
/* process upstream */
@@ -263,7 +263,7 @@
* add item to heap
* returns heap_size
*/
-unsigned int heap_add(int r, int c, CELL ele, char asp, char flag_value)
+unsigned int heap_add(int r, int c, CELL ele)
{
struct heap_point heap_p;
@@ -279,10 +279,6 @@
heap_p.ele = ele;
heap_p.added = nxt_avail_pt;
- bseg_put(&draindir, &asp, r, c);
- FLAG_SET(flag_value, INLISTFLAG);
- bseg_put(&bitflags, &flag_value, r, c);
-
nxt_avail_pt++;
/* sift up: move new point towards top of heap */
Modified: grass-addons/grass7/raster/r.hydrodem/hydro_con.c
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/hydro_con.c 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/hydro_con.c 2013-04-07 13:26:48 UTC (rev 55652)
@@ -30,7 +30,7 @@
CELL ele_val, ele_nbr;
int n_to_fill;
int top, done;
- char drain_val;
+ struct dir_flag df;
/* go upstream from spill point */
r = peak_r;
@@ -57,11 +57,11 @@
c_nbr < ncols) {
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
- if (drain_val > 0) {
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
+ if (df.dir > 0) {
/* contributing cell */
- if (r_nbr + asp_r[(int)drain_val] == r &&
- c_nbr + asp_c[(int)drain_val] == c) {
+ if (r_nbr + asp_r[(int)df.dir] == r &&
+ c_nbr + asp_c[(int)df.dir] == c) {
/* contributing neighbour is lower than
* spill point, add to stack */
@@ -92,7 +92,7 @@
}
}
} /* end contributing */
- else if (drain_val == 0 && peak_ele > ele_nbr)
+ else if (df.dir == 0 && peak_ele > ele_nbr)
/* found bottom of real depression, don't fill */
return -1;
} /* end in region */
@@ -115,12 +115,12 @@
{
int r_nbr, c_nbr, ct_dir;
CELL ele_nbr;
- char drain_val, drain_val_nbr;
+ struct dir_flag df, df_nbr;
int counter = 0;
- bseg_get(&draindir, &drain_val, r, c);
+ seg_get(&dirflag, (char *)&df, r, c);
- if (drain_val < 1)
+ if (df.dir < 1)
return 0;
for (ct_dir = 0; ct_dir < sides; ct_dir++) {
@@ -130,14 +130,14 @@
if (r_nbr >= 0 && r_nbr < nrows && c_nbr >= 0 && c_nbr < ncols) {
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
- bseg_get(&draindir, &drain_val_nbr, r_nbr, c_nbr);
- if (drain_val_nbr > 0) {
+ seg_get(&dirflag, (char *)&df_nbr, r_nbr, c_nbr);
+ if (df_nbr.dir > 0) {
/* not a contributing cell */
- if (r_nbr + asp_r[(int)drain_val_nbr] != r ||
- c_nbr + asp_c[(int)drain_val_nbr] != c) {
+ if (r_nbr + asp_r[(int)df_nbr.dir] != r ||
+ c_nbr + asp_c[(int)df_nbr.dir] != c) {
/* does not contribute to this cell */
- if (r + asp_r[(int)drain_val] != r_nbr ||
- c + asp_c[(int)drain_val] != c_nbr) {
+ if (r + asp_r[(int)df.dir] != r_nbr ||
+ c + asp_c[(int)df.dir] != c_nbr) {
if (ele_nbr == this_ele)
counter++;
}
@@ -155,7 +155,7 @@
CELL ele_nbr;
int n_to_fill = 0;
int top, done;
- char drain_val;
+ struct dir_flag df;
/* post-order traversal */
/* add spill point as root to stack */
@@ -176,11 +176,11 @@
c_nbr < ncols) {
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
- if (drain_val > 0) {
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
+ if (df.dir > 0) {
/* contributing cell */
- if (r_nbr + asp_r[(int)drain_val] == r &&
- c_nbr + asp_c[(int)drain_val] == c) {
+ if (r_nbr + asp_r[(int)df.dir] == r &&
+ c_nbr + asp_c[(int)df.dir] == c) {
/* contributing neighbour is lower than
* spill point, add to stack */
@@ -224,7 +224,7 @@
int peak_r, int peak_c)
{
int r, c, r_nbr, c_nbr, carved = 0;
- char drain_val;
+ struct dir_flag df;
int ct_dir;
CELL ele_val, ele_nbr;
int top, done;
@@ -250,11 +250,11 @@
c_nbr < ncols) {
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
- if (drain_val > 0) {
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
+ if (df.dir > 0) {
/* contributing cell */
- if (r_nbr + asp_r[(int) drain_val] == r &&
- c_nbr + asp_c[(int) drain_val] == c) {
+ if (r_nbr + asp_r[(int)df.dir] == r &&
+ c_nbr + asp_c[(int)df.dir] == c) {
/* contributing neighbour is lower than
* current point, add to stack */
@@ -294,27 +294,27 @@
/* <-- carve upstream from spill point */
/* carve downstream from sink bottom */
- bseg_get(&draindir, &drain_val, bottom_r, bottom_c);
- if (drain_val < 1) {
+ seg_get(&dirflag, (char *)&df, bottom_r, bottom_c);
+ if (df.dir < 1) {
G_warning(_("Can't carve downstream from r %d, c %d"), bottom_r,
bottom_c);
return 0;
}
- r_nbr = bottom_r + asp_r[(int) drain_val];
- c_nbr = bottom_c + asp_c[(int) drain_val];
+ r_nbr = bottom_r + asp_r[(int)df.dir];
+ c_nbr = bottom_c + asp_c[(int)df.dir];
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
/* go downstream up to peak and down to bottom again */
while (ele_nbr >= bottom_ele) {
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
cseg_put(&ele, &bottom_ele, r_nbr, c_nbr);
carved++;
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
}
else {
@@ -334,7 +334,8 @@
CELL ele_val, ele_nbr, ele_last, peak_ele, bottom_ele;
int down_uphill, down_downhill, n_cells;
struct sink_list *last_sink;
- char drain_val, flag_value;
+ struct dir_flag df;
+
int n_splits, n_to_fill;
int n_filled, n_carved, n_just_a_bit, n_processed;
int carve_to_edge, skipme;
@@ -363,10 +364,10 @@
/* go downstream, get spill point */
peak_r = r;
peak_c = c;
- bseg_get(&draindir, &drain_val, r, c);
+ seg_get(&dirflag, (char *)&df, r, c);
- r_nbr = r + asp_r[(int) drain_val];
- c_nbr = c + asp_c[(int) drain_val];
+ r_nbr = r + asp_r[(int)df.dir];
+ c_nbr = c + asp_c[(int)df.dir];
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
@@ -381,11 +382,11 @@
peak_r = r_nbr;
peak_c = c_nbr;
}
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
ele_last = ele_nbr;
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
@@ -397,8 +398,8 @@
cseg_get(&ele, &peak_ele, peak_r, peak_c);
- bseg_get(&bitflags, &flag_value, peak_r, peak_c);
- noedge = (FLAG_GET(flag_value, EDGEFLAG) == 0);
+ seg_get(&dirflag, (char *)&df, peak_r, peak_c);
+ noedge = (FLAG_GET(df.flag, EDGEFLAG) == 0);
r_nbr = peak_r;
c_nbr = peak_c;
ele_nbr = peak_ele;
@@ -422,13 +423,13 @@
while (ele_nbr >= bottom_ele) {
if (ele_nbr > bottom_ele)
down_downhill++;
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
/* detect flat area ? */
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
}
@@ -561,11 +562,11 @@
if (next_bottom_ele > ele_nbr)
next_bottom_ele = ele_nbr;
}
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
last_ele = ele_nbr;
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
@@ -589,11 +590,11 @@
if (ele_nbr > bottom_ele) {
down_uphill = n_cells;
}
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
ele_last = ele_nbr;
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
@@ -659,18 +660,18 @@
r_nbr = next_r;
c_nbr = next_c;
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
- if (drain_val > 0) {
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
+ if (df.dir > 0) {
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
/* go to next higher cell downstream */
while (ele_nbr == bottom_ele ||
ele_nbr < min_bottom_ele) {
- bseg_get(&draindir, &drain_val, r_nbr, c_nbr);
+ seg_get(&dirflag, (char *)&df, r_nbr, c_nbr);
- if (drain_val > 0) {
- r_nbr = r_nbr + asp_r[(int) drain_val];
- c_nbr = c_nbr + asp_c[(int) drain_val];
+ if (df.dir > 0) {
+ r_nbr = r_nbr + asp_r[(int)df.dir];
+ c_nbr = c_nbr + asp_c[(int)df.dir];
cseg_get(&ele, &ele_nbr, r_nbr, c_nbr);
}
Modified: grass-addons/grass7/raster/r.hydrodem/init_search.c
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/init_search.c 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/init_search.c 2013-04-07 13:26:48 UTC (rev 55652)
@@ -9,8 +9,8 @@
CELL ele_value;
int nextdr[8] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int nextdc[8] = { 0, 0, -1, 1, 1, -1, 1, -1 };
- char flag_value, flag_value_nbr, is_null;
- char asp_value;
+ char asp_value, is_null;
+ struct dir_flag df, df_nbr;
unsigned int n_depr_cells = 0;
unsigned int n_null_cells = nrows * ncols - n_points;
int depr_map_type, depr_size;
@@ -42,8 +42,8 @@
for (c = 0; c < ncols; c++) {
- bseg_get(&bitflags, &flag_value, r, c);
- is_null = FLAG_GET(flag_value, NULLFLAG);
+ seg_get(&dirflag, (char *)&df, r, c);
+ is_null = FLAG_GET(df.flag, NULLFLAG);
if (is_null) {
if (depr_fd > -1)
@@ -74,8 +74,11 @@
asp_value = -8;
cseg_get(&ele, &ele_value, r, c);
- FLAG_SET(flag_value, EDGEFLAG);
- heap_add(r, c, ele_value, asp_value, flag_value);
+ FLAG_SET(df.flag, EDGEFLAG);
+ FLAG_SET(df.flag, INLISTFLAG);
+ df.dir = asp_value;
+ seg_put(&dirflag, (char *)&df, r, c);
+ heap_add(r, c, ele_value);
if (depr_fd > -1)
depr_ptr = G_incr_void_ptr(depr_ptr, depr_size);
@@ -90,14 +93,17 @@
r_nbr = r + nextdr[ct_dir];
c_nbr = c + nextdc[ct_dir];
- bseg_get(&bitflags, &flag_value_nbr, r_nbr, c_nbr);
- is_null = FLAG_GET(flag_value_nbr, NULLFLAG);
+ seg_get(&dirflag, (char *)&df_nbr, r_nbr, c_nbr);
+ is_null = FLAG_GET(df_nbr.flag, NULLFLAG);
if (is_null) {
asp_value = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
cseg_get(&ele, &ele_value, r, c);
- FLAG_SET(flag_value, EDGEFLAG);
- heap_add(r, c, ele_value, asp_value, flag_value);
+ FLAG_SET(df.flag, EDGEFLAG);
+ FLAG_SET(df.flag, INLISTFLAG);
+ df.dir = asp_value;
+ seg_put(&dirflag, (char *)&df, r, c);
+ heap_add(r, c, ele_value);
break;
}
@@ -118,8 +124,11 @@
if (!Rast_is_null_value(depr_ptr, depr_map_type) && depr_val != 0) {
cseg_get(&ele, &ele_value, r, c);
- FLAG_SET(flag_value, DEPRFLAG);
- heap_add(r, c, ele_value, asp_value, flag_value);
+ FLAG_SET(df.flag, INLISTFLAG);
+ FLAG_SET(df.flag, DEPRFLAG);
+ df.dir = asp_value;
+ seg_put(&dirflag, (char *)&df, r, c);
+ heap_add(r, c, ele_value);
n_depr_cells++;
}
depr_ptr = G_incr_void_ptr(depr_ptr, depr_size);
Modified: grass-addons/grass7/raster/r.hydrodem/load.c
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/load.c 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/load.c 2013-04-07 13:26:48 UTC (rev 55652)
@@ -15,7 +15,7 @@
int load_map(int ele_fd)
{
int r, c;
- char flag_value, asp_value = 0;
+ struct dir_flag df;
void *ele_buf, *ptr;
CELL ele_value;
DCELL dvalue;
@@ -24,6 +24,8 @@
G_message(_("Load elevation map"));
+ df.dir = 0;
+
n_search_points = n_points = 0;
ele_map_type = Rast_get_map_type(ele_fd);
@@ -49,14 +51,14 @@
for (c = 0; c < ncols; c++) {
- flag_value = 0;
+ df.flag = 0;
/* check for masked and NULL cells */
if (Rast_is_null_value(ptr, ele_map_type)) {
- FLAG_SET(flag_value, NULLFLAG);
- FLAG_SET(flag_value, INLISTFLAG);
- FLAG_SET(flag_value, WORKEDFLAG);
- FLAG_SET(flag_value, WORKED2FLAG);
+ FLAG_SET(df.flag, NULLFLAG);
+ FLAG_SET(df.flag, INLISTFLAG);
+ FLAG_SET(df.flag, WORKEDFLAG);
+ FLAG_SET(df.flag, WORKED2FLAG);
Rast_set_c_null_value(&ele_value, 1);
}
else {
@@ -80,8 +82,7 @@
}
cseg_put(&ele, &ele_value, r, c);
- bseg_put(&draindir, &asp_value, r, c);
- bseg_put(&bitflags, &flag_value, r, c);
+ seg_put(&dirflag, (char *)&df, r, c);
ptr = G_incr_void_ptr(ptr, ele_size);
}
Modified: grass-addons/grass7/raster/r.hydrodem/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/local_proto.h 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/local_proto.h 2013-04-07 13:26:48 UTC (rev 55652)
@@ -44,6 +44,13 @@
double *acc;
};
+struct dir_flag
+{
+ char dir;
+ char flag;
+};
+
+
extern struct snode *stream_node;
extern int nrows, ncols;
extern unsigned int n_search_points, n_points, nxt_avail_pt;
@@ -64,9 +71,12 @@
extern SSEG search_heap;
extern SSEG astar_pts;
+extern SSEG dirflag;
+/*
extern BSEG bitflags;
+extern BSEG draindir;
+*/
extern CSEG ele;
-extern BSEG draindir;
extern CSEG stream;
/* load.c */
@@ -77,7 +87,7 @@
/* do_astar.c */
int do_astar(void);
-unsigned int heap_add(int, int, CELL, char, char);
+unsigned int heap_add(int, int, CELL);
/* hydro_con.c */
int hydro_con(void);
Modified: grass-addons/grass7/raster/r.hydrodem/main.c
===================================================================
--- grass-addons/grass7/raster/r.hydrodem/main.c 2013-04-07 09:23:04 UTC (rev 55651)
+++ grass-addons/grass7/raster/r.hydrodem/main.c 2013-04-07 13:26:48 UTC (rev 55652)
@@ -41,9 +41,12 @@
struct RB_TREE *draintree;
SSEG search_heap;
+SSEG dirflag;
+/*
BSEG bitflags;
-CSEG ele;
BSEG draindir;
+*/
+CSEG ele;
CSEG stream;
@@ -205,10 +208,8 @@
/* balance segment files */
/* elevation: * 2 */
memory_divisor = seg2kb * sizeof(CELL) * 2;
- /* drainage direction: as is */
- memory_divisor += seg2kb * sizeof(char);
- /* flags: * 4 */
- memory_divisor += seg2kb * sizeof(char) * 4;
+ /* flags + directions: * 2 */
+ memory_divisor += seg2kb * sizeof(struct dir_flag) * 2;
/* heap points: / 4 */
memory_divisor += seg2kb * sizeof(struct heap_point) / 4.;
@@ -231,7 +232,7 @@
heap_mem = num_open_segs * seg2kb * sizeof(struct heap_point) /
(4. * 1024.);
}
- disk_space = (1. * sizeof(CELL) + 2 * sizeof(char) +
+ disk_space = (1. * sizeof(CELL) + sizeof(struct dir_flag) +
sizeof(struct heap_point));
disk_space *= (num_seg_total * seg2kb / 1024.); /* KB -> MB */
@@ -244,23 +245,23 @@
cseg_open(&ele, seg_rows, seg_cols, num_open_segs * 2);
if (num_open_segs * 2 > num_seg_total)
heap_mem += (num_open_segs * 2 - num_seg_total) * seg2kb * sizeof(CELL) / 1024.;
- bseg_open(&draindir, seg_rows, seg_cols, num_open_segs);
- bseg_open(&bitflags, seg_rows, seg_cols, num_open_segs * 4);
+
+ seg_open(&dirflag, nrows, ncols, seg_rows, seg_cols, num_open_segs * 2,
+ sizeof(struct dir_flag), 1);
+
if (num_open_segs * 4 > num_seg_total)
heap_mem += (num_open_segs * 4 - num_seg_total) * seg2kb / 1024.;
/* load map */
if (load_map(ele_fd) < 0) {
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("Could not load input map"));
}
if (n_points == 0) {
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("No non-NULL cells loaded from input map"));
}
@@ -302,8 +303,7 @@
if (init_search(depr_fd) < 0) {
seg_close(&search_heap);
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("Could not initialize search"));
}
@@ -315,8 +315,7 @@
if (do_astar() < 0) {
seg_close(&search_heap);
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("Could not sort elevation map"));
}
seg_close(&search_heap);
@@ -324,22 +323,19 @@
/* hydrological corrections */
if (hydro_con() < 0) {
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("Could not apply hydrological conditioning"));
}
/* write output maps */
if (close_map(output.ele_hydro->answer, ele_map_type) < 0) {
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
G_fatal_error(_("Could not write output map"));
}
cseg_close(&ele);
- bseg_close(&draindir);
- bseg_close(&bitflags);
+ seg_close(&dirflag);
Rast_read_colors(input.ele->answer, mapset, &colors);
Rast_write_colors(output.ele_hydro->answer, G_mapset(), &colors);
More information about the grass-commit
mailing list