[GRASS-SVN] r61325 - grass-addons/grass7/raster3d/r3.flow

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 22 09:36:36 PDT 2014


Author: annakrat
Date: 2014-07-22 09:36:36 -0700 (Tue, 22 Jul 2014)
New Revision: 61325

Modified:
   grass-addons/grass7/raster3d/r3.flow/flowline.c
   grass-addons/grass7/raster3d/r3.flow/main.c
   grass-addons/grass7/raster3d/r3.flow/r3flow_structs.h
Log:
r3.flow: flowlines can be integrated in both directions

Modified: grass-addons/grass7/raster3d/r3.flow/flowline.c
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/flowline.c	2014-07-22 16:24:03 UTC (rev 61324)
+++ grass-addons/grass7/raster3d/r3.flow/flowline.c	2014-07-22 16:36:36 UTC (rev 61325)
@@ -83,7 +83,7 @@
 				 integration->cell_size);
 	max_step = get_time_step("cell", MAX_STEP, velocity_norm,
 				 integration->cell_size);
-	delta_t *= integration->direction;
+	delta_t *= (integration->actual_direction == FLOWDIR_UP ? 1 : -1);
 	if (rk45_integrate_next
 	    (region, gradient_info, point, new_point,
 	     &delta_t, min_step, max_step) < 0)

Modified: grass-addons/grass7/raster3d/r3.flow/main.c
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/main.c	2014-07-22 16:24:03 UTC (rev 61324)
+++ grass-addons/grass7/raster3d/r3.flow/main.c	2014-07-22 16:36:36 UTC (rev 61325)
@@ -101,8 +101,7 @@
 int main(int argc, char *argv[])
 {
     struct Option *vector_opt, *seed_opt, *flowlines_opt, *flowacc_opt,
-	*scalar_opt, *unit_opt, *step_opt, *limit_opt, *skip_opt;
-    struct Flag *up_flag;
+	*scalar_opt, *unit_opt, *step_opt, *limit_opt, *skip_opt, *dir_opt;
     struct GModule *module;
     RASTER3D_Region region;
     RASTER3D_Map *flowacc;
@@ -201,10 +200,15 @@
     skip_opt->description =
 	_("Number of cells between flow lines in x, y and z direction");
 
-    up_flag = G_define_flag();
-    up_flag->key = 'u';
-    up_flag->description = _("Compute upstream flowlines "
-			     "instead of default downstream flowlines");
+    dir_opt = G_define_option();
+    dir_opt->key = "direction";
+    dir_opt->type = TYPE_STRING;
+    dir_opt->required = NO;
+    dir_opt->multiple = NO;
+    dir_opt->options = "up,down,both";
+    dir_opt->answer = "down";
+    dir_opt->description = _("Compute flowlines upstream, "
+                             "downstream or in both direction.");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -231,7 +235,12 @@
 	integration.step = 0.25;
     }
     integration.limit = atof(limit_opt->answer);
-    integration.direction = up_flag->answer ? 1 : -1;
+    if (strcmp(dir_opt->answer, "up") == 0)
+        integration.direction_type = FLOWDIR_UP;
+    else if (strcmp(dir_opt->answer, "down") == 0)
+        integration.direction_type = FLOWDIR_DOWN;
+    else
+        integration.direction_type = FLOWDIR_BOTH;
 
 
     /* cell size is the diagonal */
@@ -333,8 +342,18 @@
 	    }
 	    G_percent(seed_count, n_seeds, 1);
 	    cat = seed_count + 1;
-	    compute_flowline(&region, &seed, &gradient_info, flowacc,
-			     &integration, &fl_map, fl_cats, fl_points, cat);
+	    if (integration.direction_type == FLOWDIR_UP || 
+		integration.direction_type == FLOWDIR_BOTH) {
+		integration.actual_direction = FLOWDIR_UP;
+		compute_flowline(&region, &seed, &gradient_info, flowacc,
+				 &integration, &fl_map, fl_cats, fl_points, cat);
+	    }
+	    if (integration.direction_type == FLOWDIR_DOWN || 
+		integration.direction_type == FLOWDIR_BOTH) {
+		integration.actual_direction = FLOWDIR_DOWN;
+		compute_flowline(&region, &seed, &gradient_info, flowacc,
+				 &integration, &fl_map, fl_cats, fl_points, cat);
+	    }
 	    seed_count++;
 	}
 
@@ -365,9 +384,20 @@
 		    if (seed.flowaccum || seed.flowline) {
 			G_percent(seed_count, n_seeds, 1);
 			cat = seed_count + 1;
+			if (integration.direction_type == FLOWDIR_UP || 
+			    integration.direction_type == FLOWDIR_BOTH) {
+			    integration.actual_direction = FLOWDIR_UP;
 			compute_flowline(&region, &seed, &gradient_info,
 					 flowacc, &integration, &fl_map,
 					 fl_cats, fl_points, cat);
+			}
+			if (integration.direction_type == FLOWDIR_DOWN || 
+			    integration.direction_type == FLOWDIR_BOTH) {
+			    integration.actual_direction = FLOWDIR_DOWN;
+			    compute_flowline(&region, &seed, &gradient_info,
+					     flowacc, &integration, &fl_map,
+					     fl_cats, fl_points, cat);
+			}
 			seed_count++;
 		    }
 		}

Modified: grass-addons/grass7/raster3d/r3.flow/r3flow_structs.h
===================================================================
--- grass-addons/grass7/raster3d/r3.flow/r3flow_structs.h	2014-07-22 16:24:03 UTC (rev 61324)
+++ grass-addons/grass7/raster3d/r3.flow/r3flow_structs.h	2014-07-22 16:36:36 UTC (rev 61325)
@@ -12,9 +12,12 @@
     int flowaccum;
 };
 
+enum flowdir {FLOWDIR_UP, FLOWDIR_DOWN, FLOWDIR_BOTH};
+
 struct Integration
 {
-    int direction;
+    enum flowdir direction_type;
+    enum flowdir actual_direction;
     char *unit;
     double step;
     double cell_size;



More information about the grass-commit mailing list