[GRASS-SVN] r72887 - grass-addons/grass7/raster/r.accumulate

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 23 07:43:04 PDT 2018


Author: hcho
Date: 2018-06-23 07:43:04 -0700 (Sat, 23 Jun 2018)
New Revision: 72887

Modified:
   grass-addons/grass7/raster/r.accumulate/accumulate.c
   grass-addons/grass7/raster/r.accumulate/main.c
Log:
r.accumulate: Use an array for direction checks

Modified: grass-addons/grass7/raster/r.accumulate/accumulate.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-23 08:55:37 UTC (rev 72886)
+++ grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-23 14:43:04 UTC (rev 72887)
@@ -5,8 +5,13 @@
 accumulate(CELL ** dir_buf, RASTER_MAP weight_buf, RASTER_MAP acc_buf,
 	   char **done, int row, int col)
 {
+    static int dir_checks[3][3][2] = {
+	{{SE, NW}, {S, N}, {SW, NE}},
+	{{E, W}, {0, 0}, {W, E}},
+	{{NE, SW}, {N, S}, {NW, SE}}
+    };
     int rows = weight_buf.rows, cols = weight_buf.cols;
-    int i, j, neighbor_dir, loop_dir;
+    int i, j;
     double acc;
 
     if (done[row][col])
@@ -23,55 +28,8 @@
 	for (j = -1; j <= 1; j++) {
 	    if (col + j < 0 || col + j >= cols || (i == 0 && j == 0))
 		continue;
-	    neighbor_dir = dir_buf[row + i][col + j];
-	    loop_dir = 0;
-	    switch (i) {
-	    case -1:
-		switch (j) {
-		case -1:
-		    if (neighbor_dir == SE)
-			loop_dir = NW;
-		    break;
-		case 0:
-		    if (neighbor_dir == S)
-			loop_dir = N;
-		    break;
-		case 1:
-		    if (neighbor_dir == SW)
-			loop_dir = NE;
-		    break;
-		}
-		break;
-	    case 0:
-		switch (j) {
-		case -1:
-		    if (neighbor_dir == E)
-			loop_dir = W;
-		    break;
-		case 1:
-		    if (neighbor_dir == W)
-			loop_dir = E;
-		    break;
-		}
-		break;
-	    case 1:
-		switch (j) {
-		case -1:
-		    if (neighbor_dir == NE)
-			loop_dir = SW;
-		    break;
-		case 0:
-		    if (neighbor_dir == N)
-			loop_dir = S;
-		    break;
-		case 1:
-		    if (neighbor_dir == NW)
-			loop_dir = SE;
-		    break;
-		}
-		break;
-	    }
-	    if (loop_dir && dir_buf[row][col] != loop_dir)
+	    if (dir_buf[row + i][col + j] == dir_checks[i + 1][j + 1][0] &&
+		dir_buf[row][col] != dir_checks[i + 1][j + 1][1])
 		acc +=
 		    accumulate(dir_buf, weight_buf, acc_buf, done, row + i,
 			       col + j);

Modified: grass-addons/grass7/raster/r.accumulate/main.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/main.c	2018-06-23 08:55:37 UTC (rev 72886)
+++ grass-addons/grass7/raster/r.accumulate/main.c	2018-06-23 14:43:04 UTC (rev 72887)
@@ -74,7 +74,8 @@
 
     opt.acc = G_define_standard_option(G_OPT_R_OUTPUT);
     opt.acc->type = TYPE_STRING;
-    opt.acc->description = _("Name for output weighted flow accumulation map");
+    opt.acc->description =
+	_("Name for output weighted flow accumulation map");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);



More information about the grass-commit mailing list