[GRASS-SVN] r55647 - grass/trunk/raster/r.watershed/ram

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 6 13:38:52 PDT 2013


Author: mmetz
Date: 2013-04-06 13:38:52 -0700 (Sat, 06 Apr 2013)
New Revision: 55647

Modified:
   grass/trunk/raster/r.watershed/ram/close_maps.c
   grass/trunk/raster/r.watershed/ram/do_astar.c
Log:
r.watershed.ram fix diagonal flow bias, fix aspect colors

Modified: grass/trunk/raster/r.watershed/ram/close_maps.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/close_maps.c	2013-04-06 20:37:05 UTC (rev 55646)
+++ grass/trunk/raster/r.watershed/ram/close_maps.c	2013-04-06 20:38:52 UTC (rev 55647)
@@ -214,7 +214,7 @@
 	}
 	Rast_close(fd);
 	Rast_init_colors(&colors);
-	Rast_make_aspect_colors(&colors, 0, 8);
+	Rast_make_aspect_colors(&colors, -8, 8);
 	Rast_write_colors(asp_name, this_mapset, &colors);
     }
     G_free(asp);

Modified: grass/trunk/raster/r.watershed/ram/do_astar.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/do_astar.c	2013-04-06 20:37:05 UTC (rev 55646)
+++ grass/trunk/raster/r.watershed/ram/do_astar.c	2013-04-06 20:38:52 UTC (rev 55647)
@@ -3,7 +3,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-double get_slope2(CELL, CELL, double);
+static double get_slope2(CELL, CELL, double);
 
 int do_astar(void)
 {
@@ -151,24 +151,26 @@
 		    }
 		}
 
-		/* add neighbour as new point if not in the list */
-		if (is_in_list == 0 && skip_diag == 0) {
-		    add_pt(upr, upc, alt_nbr[ct_dir]);
-		    /* set flow direction */
-		    asp[index_up] = drain[upr - r + 1][upc - c + 1];
-		}
-		else if (is_in_list && is_worked == 0) {
-		    /* neighbour is edge in list, not yet worked */
-		    if (asp[index_up] < 0) {
+		if (!skip_diag) {
+		    /* add neighbour as new point if not in the list */
+		    if (is_in_list == 0) {
+			add_pt(upr, upc, alt_nbr[ct_dir]);
+			/* set flow direction */
 			asp[index_up] = drain[upr - r + 1][upc - c + 1];
+		    }
+		    else if (is_in_list && is_worked == 0) {
+			/* neighbour is edge in list, not yet worked */
+			if (asp[index_up] < 0) {
+			    asp[index_up] = drain[upr - r + 1][upc - c + 1];
 
-			if (wat[index_doer] > 0)
-			    wat[index_doer] = -1.0 * wat[index_doer];
+			    if (wat[index_doer] > 0)
+				wat[index_doer] = -1.0 * wat[index_doer];
+			}
+			/* neighbour is inside real depression, not yet worked */
+			else if (asp[index_up] == 0) {
+			    asp[index_up] = drain[upr - r + 1][upc - c + 1];
+			}
 		    }
-		    /* neighbour is inside real depression, not yet worked */
-		    else if (asp[index_up] == 0) {
-			asp[index_up] = drain[upr - r + 1][upc - c + 1];
-		    }
 		}
 	    }    /* end if in region */
 	}    /* end sides */
@@ -197,14 +199,46 @@
 
 /* compare two heap points */
 /* return 1 if a < b else 0 */
-int cmp_pnt(CELL elea, CELL eleb, int addeda, int addedb)
+static int cmp_pnt(CELL elea, CELL eleb, int addeda, int addedb)
 {
-    if (elea < eleb)
-	return 1;
-    else if (elea == eleb) {
-	if (addeda < addedb)
-	    return 1;
+    if (elea == eleb) {
+	return (addeda < addedb);
     }
+    return (elea < eleb);
+}
+
+/* standard sift-up routine for d-ary min heap */
+static int sift_up(int start, CELL ele)
+{
+    register int parent, child, child_idx, child_added;
+    CELL elep;
+
+    child = start;
+    child_added = heap_index[child];
+    child_idx = astar_pts[child];
+
+    while (child > 1) {
+	GET_PARENT(parent, child);
+
+	elep = alt[astar_pts[parent]];
+	/* child smaller */
+	if (cmp_pnt(ele, elep, child_added, heap_index[parent])) {
+	    /* push parent point down */
+	    heap_index[child] = heap_index[parent];
+	    astar_pts[child] = astar_pts[parent];
+	    child = parent;
+	}
+	else
+	    /* no more sifting up, found new slot for child */
+	    break;
+    }
+
+    /* put point in new slot */
+    if (child < start) {
+	heap_index[child] = child_added;
+	astar_pts[child] = child_idx;
+    }
+
     return 0;
 }
 
@@ -250,25 +284,19 @@
 	/* select child with lower ele, if both are equal, older child
 	 * older child is older startpoint for flow path, important */
 	ele = alt[astar_pts[child]];
-	if (child < heap_size) {
-	    childr = child + 1;
-	    i = child + 3;
-	    while (childr <= heap_size && childr < i) {
-		eler = alt[astar_pts[childr]];
-		if (cmp_pnt(eler, ele, heap_index[childr], heap_index[child])) {
-		    child = childr;
-		    ele = eler;
-		}
-		childr++;
+	i = child + 3;
+	for (childr = child + 1; childr <= heap_size && childr < i; childr++) {
+	    eler = alt[astar_pts[childr]];
+	    if (cmp_pnt(eler, ele, heap_index[childr], heap_index[child])) {
+		child = childr;
+		ele = eler;
 	    }
 	}
 
 	/* move hole down */
-
 	heap_index[parent] = heap_index[child];
 	astar_pts[parent] = astar_pts[child];
 	parent = child;
-
     }
 
     /* hole is in lowest layer, move to heap end */
@@ -287,42 +315,6 @@
     return 0;
 }
 
-/* standard sift-up routine for d-ary min heap */
-int sift_up(int start, CELL ele)
-{
-    register int parent, child, child_idx, child_added;
-    CELL elep;
-
-    child = start;
-    child_added = heap_index[child];
-    child_idx = astar_pts[child];
-
-    while (child > 1) {
-	GET_PARENT(parent, child);
-
-	elep = alt[astar_pts[parent]];
-	/* child smaller */
-	if (cmp_pnt(ele, elep, child_added, heap_index[parent])) {
-	    /* push parent point down */
-	    heap_index[child] = heap_index[parent];
-	    astar_pts[child] = astar_pts[parent];
-	    child = parent;
-	}
-	else
-	    /* no more sifting up, found new slot for child */
-	    break;
-    }
-
-    /* put point in new slot */
-    if (child < start) {
-	heap_index[child] = child_added;
-	astar_pts[child] = child_idx;
-    }
-
-    return 0;
-
-}
-
 double
 get_slope(int r, int c, int downr, int downc, CELL ele, CELL downe)
 {
@@ -341,37 +333,10 @@
     return (slope);
 }
 
-double get_slope2(CELL ele, CELL up_ele, double dist)
+static double get_slope2(CELL ele, CELL up_ele, double dist)
 {
     if (ele >= up_ele)
 	return 0.0;
     else
 	return (double)(up_ele - ele) / dist;
 }
-
-/* replace is unused */
-int replace(			/* ele was in there */
-	       int upr, int upc, int r, int c)
-/* CELL ele;  */
-{
-    int now, heap_run;
-    int r2, c2;
-
-    /* find the current neighbour point and 
-     * set flow direction to focus point */
-
-    heap_run = 0;
-
-    while (heap_run <= heap_size) {
-	now = heap_index[heap_run];
-	/* if (astar_pts[now].r == upr && astar_pts[now].c == upc) { */
-	seg_index_rc(alt_seg, astar_pts[now], &r2, &c2);
-	if (r2 == upr && c2 == upc) {
-	    /* astar_pts[now].downr = r;
-	    astar_pts[now].downc = c; */
-	    return 0;
-	}
-	heap_run++;
-    }
-    return 0;
-}



More information about the grass-commit mailing list