[GRASS-SVN] r39996 -
grass/branches/develbranch_6/raster/r.watershed/seg
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Dec 14 05:05:15 EST 2009
Author: mmetz
Date: 2009-12-14 05:05:15 -0500 (Mon, 14 Dec 2009)
New Revision: 39996
Modified:
grass/branches/develbranch_6/raster/r.watershed/seg/do_astar.c
grass/branches/develbranch_6/raster/r.watershed/seg/no_stream.c
Log:
backporting fixes for flow direction and basin delineation from trunk, seg mode
Modified: grass/branches/develbranch_6/raster/r.watershed/seg/do_astar.c
===================================================================
--- grass/branches/develbranch_6/raster/r.watershed/seg/do_astar.c 2009-12-14 10:03:46 UTC (rev 39995)
+++ grass/branches/develbranch_6/raster/r.watershed/seg/do_astar.c 2009-12-14 10:05:15 UTC (rev 39996)
@@ -24,8 +24,8 @@
int nbr_ew[8] = { 0, 1, 2, 3, 1, 0, 0, 1 };
int nbr_ns[8] = { 0, 1, 2, 3, 3, 2, 3, 2 };
double dx, dy, dist_to_nbr[8], ew_res, ns_res;
-
double slope[8];
+ int skip_diag;
G_message(_("SECTION 2: A * Search."));
@@ -82,54 +82,53 @@
slope[ct_dir] = alt_nbr[ct_dir] = 0;
/* check that upr, upc are within region */
if (upr >= 0 && upr < nrows && upc >= 0 && upc < ncols) {
- /* slope */
+ /* avoid diagonal flow direction bias */
bseg_get(&in_list, &in_val, upr, upc);
bseg_get(&worked, &work_val, upr, upc);
+ skip_diag = 0;
if (!work_val) {
cseg_get(&alt, &alt_up, upr, upc);
alt_nbr[ct_dir] = alt_up;
slope[ct_dir] =
get_slope2(alt_val, alt_nbr[ct_dir],
dist_to_nbr[ct_dir]);
- /* avoid diagonal flow direction bias */
- if (ct_dir > 3) {
- if (slope[nbr_ew[ct_dir]]) {
+ }
+ if (!in_val) {
+ if (ct_dir > 3 && slope[ct_dir] > 0) {
+ if (slope[nbr_ew[ct_dir]] > 0) {
/* slope to ew nbr > slope to center */
if (slope[ct_dir] <=
get_slope2(alt_nbr[nbr_ew[ct_dir]],
alt_nbr[ct_dir], ew_res))
- in_val = 1;
+ skip_diag = 1;
}
- if (!in_val && slope[nbr_ns[ct_dir]]) {
+ if (!skip_diag && slope[nbr_ns[ct_dir]] > 0) {
/* slope to ns nbr > slope to center */
if (slope[ct_dir] <=
get_slope2(alt_nbr[nbr_ns[ct_dir]],
alt_nbr[ct_dir], ns_res))
- in_val = 1;
+ skip_diag = 1;
}
}
}
/* put neighbour in search list if not yet in */
- if (in_val == 0) {
+ if (in_val == 0 && skip_diag == 0) {
cseg_get(&alt, &alt_up, upr, upc);
add_pt(upr, upc, alt_up, alt_val);
/* flow direction is set here */
drain_val = drain[upr - r + 1][upc - c + 1];
cseg_put(&asp, &drain_val, upr, upc);
}
- else {
- /* check if neighbour has not been worked on,
- * update values for asp and wat */
- if (!work_val) {
- cseg_get(&asp, &asp_up, upr, upc);
- if (asp_up < 0) {
- drain_val = drain[upr - r + 1][upc - c + 1];
- cseg_put(&asp, &drain_val, upr, upc);
- dseg_get(&wat, &wat_val, r, c);
- if (wat_val > 0) {
- wat_val = -wat_val;
- dseg_put(&wat, &wat_val, r, c);
- }
+ /* check if neighbour has not been worked on */
+ else if (in_val && !work_val) {
+ cseg_get(&asp, &asp_up, upr, upc);
+ if (asp_up < 0) {
+ drain_val = drain[upr - r + 1][upc - c + 1];
+ cseg_put(&asp, &drain_val, upr, upc);
+ dseg_get(&wat, &wat_val, r, c);
+ if (wat_val > 0) {
+ wat_val = -wat_val;
+ dseg_put(&wat, &wat_val, r, c);
}
}
}
Modified: grass/branches/develbranch_6/raster/r.watershed/seg/no_stream.c
===================================================================
--- grass/branches/develbranch_6/raster/r.watershed/seg/no_stream.c 2009-12-14 10:03:46 UTC (rev 39995)
+++ grass/branches/develbranch_6/raster/r.watershed/seg/no_stream.c 2009-12-14 10:05:15 UTC (rev 39996)
@@ -11,6 +11,7 @@
SHORT updir, riteflag, leftflag, thisdir;
while (1) {
+ cseg_put(&bas, &basin_num, row, col);
max_drain = -1;
for (r = row - 1, rr = 0; r <= row + 1; r++, rr++) {
for (c = col - 1, cc = 0; c <= col + 1; c++, cc++) {
@@ -67,14 +68,15 @@
cseg_get(&asp, &aspect, r, c);
if (aspect == drain[rr][cc]) {
thisdir = updrain[rr][cc];
- if (haf_basin_side(updir,
+ switch (haf_basin_side(updir,
(SHORT) downdir,
- thisdir) == RITE) {
+ thisdir)) {
+ case RITE:
overland_cells(r, c, basin_num, basin_num,
&new_ele);
riteflag++;
- }
- else {
+ break;
+ case LEFT:
overland_cells(r, c, basin_num, basin_num - 1,
&new_ele);
leftflag++;
@@ -83,7 +85,7 @@
}
}
}
- if (leftflag >= riteflag) {
+ if (leftflag > riteflag) {
value = basin_num - 1;
cseg_put(&haf, &value, row, col);
}
@@ -100,6 +102,7 @@
slope = MIN_SLOPE;
fprintf(fp, " %f %f\n", slope, stream_length);
}
+ cseg_put(&haf, &basin_num, row, col);
return 0;
}
}
More information about the grass-commit
mailing list