[GRASS-SVN] r55646 - grass/trunk/raster/r.watershed/seg

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 6 13:37:05 PDT 2013


Author: mmetz
Date: 2013-04-06 13:37:05 -0700 (Sat, 06 Apr 2013)
New Revision: 55646

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

Modified: grass/trunk/raster/r.watershed/seg/close_maps.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/close_maps.c	2013-04-06 13:38:18 UTC (rev 55645)
+++ grass/trunk/raster/r.watershed/seg/close_maps.c	2013-04-06 20:37:05 UTC (rev 55646)
@@ -233,7 +233,7 @@
 	Rast_close(fd);
 
 	Rast_init_colors(&colors);
-	Rast_make_grey_scale_colors(&colors, 1, 8);
+	Rast_make_aspect_colors(&colors, -8, 8);
 	Rast_write_colors(asp_name, this_mapset, &colors);
     }
     seg_close(&aspflag);

Modified: grass/trunk/raster/r.watershed/seg/do_astar.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_astar.c	2013-04-06 13:38:18 UTC (rev 55645)
+++ grass/trunk/raster/r.watershed/seg/do_astar.c	2013-04-06 20:37:05 UTC (rev 55646)
@@ -4,9 +4,7 @@
 #include "do_astar.h"
 
 HEAP_PNT drop_pt(void);
-int sift_up(GW_LARGE_INT, HEAP_PNT);
-int cmp_pnt(HEAP_PNT *a, HEAP_PNT *b);
-double get_slope2(CELL, CELL, double);
+static double get_slope2(CELL, CELL, double);
 
 int do_astar(void)
 {
@@ -106,32 +104,34 @@
 		    }
 		}
 
-		/* add neighbour as new point if not in the list */
-		if (is_in_list == 0 && skip_diag == 0) {
-		    /* set flow direction */
-		    af.asp = drain[upr - r + 1][upc - c + 1];
-		    add_pt(upr, upc, alt_nbr[ct_dir]);
-		    FLAG_SET(af.flag, INLISTFLAG);
-		    seg_put(&aspflag, (char *)&af, upr, upc);
-		}
-		else if (is_in_list && is_worked == 0 &&
-			 FLAG_GET(af.flag, EDGEFLAG)) {
-		    /* neighbour is edge in list, not yet worked */
-		    if (af.asp < 0) {
-			/* adjust flow direction for edge cell */
+		if (!skip_diag) {
+		    /* add neighbour as new point if not in the list */
+		    if (is_in_list == 0) {
+			/* set flow direction */
 			af.asp = drain[upr - r + 1][upc - c + 1];
+			add_pt(upr, upc, alt_nbr[ct_dir]);
+			FLAG_SET(af.flag, INLISTFLAG);
 			seg_put(&aspflag, (char *)&af, upr, upc);
-			seg_get(&watalt, (char *)&wa, r, c);
-			if (wa.wat > 0) {
-			    wa.wat = -wa.wat;
-			    seg_put(&watalt, (char *)&wa, r, c);
+		    }
+		    else if (is_in_list && is_worked == 0 &&
+			     FLAG_GET(af.flag, EDGEFLAG)) {
+			/* neighbour is edge in list, not yet worked */
+			if (af.asp < 0) {
+			    /* adjust flow direction for edge cell */
+			    af.asp = drain[upr - r + 1][upc - c + 1];
+			    seg_put(&aspflag, (char *)&af, upr, upc);
+			    seg_get(&watalt, (char *)&wa, r, c);
+			    if (wa.wat > 0) {
+				wa.wat = -wa.wat;
+				seg_put(&watalt, (char *)&wa, r, c);
+			    }
 			}
+			/* neighbour is inside real depression, not yet worked */
+			else if (af.asp == 0) {
+			    af.asp = drain[upr - r + 1][upc - c + 1];
+			    seg_put(&aspflag, (char *)&af, upr, upc);
+			}
 		    }
-		    /* neighbour is inside real depression, not yet worked */
-		    else if (af.asp == 0) {
-			af.asp = drain[upr - r + 1][upc - c + 1];
-			seg_put(&aspflag, (char *)&af, upr, upc);
-		    }
 		}
 	    }
 	}
@@ -155,17 +155,45 @@
 
 /* compare two heap points */
 /* return 1 if a < b else 0 */
-int cmp_pnt(HEAP_PNT * a, HEAP_PNT * b)
+static int cmp_pnt(HEAP_PNT * a, HEAP_PNT * b)
 {
     if (a->ele < b->ele)
 	return 1;
     else if (a->ele == b->ele) {
-	if (a->added < b->added)
-	    return 1;
+	return (a->added < b->added);
     }
+
     return 0;
 }
 
+/* standard sift-up routine for d-ary min heap */
+static int sift_up(GW_LARGE_INT start, HEAP_PNT child_p)
+{
+    GW_LARGE_INT parent, child;
+    HEAP_PNT heap_p;
+
+    child = start;
+
+    while (child > 1) {
+	parent = GET_PARENT(child);
+	seg_get(&search_heap, (char *)&heap_p, 0, parent);
+
+	/* push parent point down if child is smaller */
+	if (cmp_pnt(&child_p, &heap_p)) {
+	    seg_put(&search_heap, (char *)&heap_p, 0, child);
+	    child = parent;
+	}
+	/* no more sifting up, found slot for child */
+	else
+	    break;
+    }
+
+    /* add child to heap */
+    seg_put(&search_heap, (char *)&child_p, 0, child);
+
+    return 0;
+}
+
 /* add point routine for min heap */
 int add_pt(int r, int c, CELL ele)
 {
@@ -235,37 +263,9 @@
     return root_p;
 }
 
-/* standard sift-up routine for d-ary min heap */
-int sift_up(GW_LARGE_INT start, HEAP_PNT child_p)
+double get_slope(int r, int c, int downr, int downc, CELL ele,
+                        CELL downe)
 {
-    GW_LARGE_INT parent, child;
-    HEAP_PNT heap_p;
-
-    child = start;
-
-    while (child > 1) {
-	parent = GET_PARENT(child);
-	seg_get(&search_heap, (char *)&heap_p, 0, parent);
-
-	/* push parent point down if child is smaller */
-	if (cmp_pnt(&child_p, &heap_p)) {
-	    seg_put(&search_heap, (char *)&heap_p, 0, child);
-	    child = parent;
-	}
-	/* no more sifting up, found slot for child */
-	else
-	    break;
-    }
-
-    /* add child to heap */
-    seg_put(&search_heap, (char *)&child_p, 0, child);
-
-    return 0;
-}
-
-double
-get_slope(int r, int c, int downr, int downc, CELL ele, CELL downe)
-{
     double slope;
 
     if (r == downr)
@@ -279,7 +279,7 @@
     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;



More information about the grass-commit mailing list