[GRASS-SVN] r60930 - in grass/branches/releasebranch_7_0: . raster/r.patch

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 23 15:02:01 PDT 2014


Author: neteler
Date: 2014-06-23 15:02:01 -0700 (Mon, 23 Jun 2014)
New Revision: 60930

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/raster/r.patch/do_patch.c
   grass/branches/releasebranch_7_0/raster/r.patch/main.c
   grass/branches/releasebranch_7_0/raster/r.patch/r.patch.html
Log:
r.patch: Don't read rows if an individual raster doesn't overlap with the current row (speed improvement for multiple input) backport from trunk, r60839 + r60842


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:59907,60031,60443,60448,60880
   + /grass/trunk:59907,60031,60443,60448,60839,60842,60880

Modified: grass/branches/releasebranch_7_0/raster/r.patch/do_patch.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.patch/do_patch.c	2014-06-23 21:00:25 UTC (rev 60929)
+++ grass/branches/releasebranch_7_0/raster/r.patch/do_patch.c	2014-06-23 22:02:01 UTC (rev 60930)
@@ -21,13 +21,13 @@
 
 int do_patch(void *result, void *patch,
 	     struct Cell_stats *statf, int ncols,
-	     RASTER_MAP_TYPE out_type, int ZEROFLAG)
+	     RASTER_MAP_TYPE out_type, int use_zero)
 {
     int more;
 
     more = 0;
     while (ncols-- > 0) {
-	if (ZEROFLAG) {		/* use 0 for transparency instead of NULL */
+	if (use_zero) {		/* use 0 for transparency instead of NULL */
 	    if (G_is_zero_value(result, out_type) ||
 		Rast_is_null_value(result, out_type)) {
 		/* Don't patch hole with a null, just mark as more */

Modified: grass/branches/releasebranch_7_0/raster/r.patch/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.patch/main.c	2014-06-23 21:00:25 UTC (rev 60929)
+++ grass/branches/releasebranch_7_0/raster/r.patch/main.c	2014-06-23 22:02:01 UTC (rev 60930)
@@ -37,10 +37,12 @@
     char *rname;
     int i;
     int row, nrows, ncols;
-    int ZEROFLAG;
+    int use_zero;
     char *new_name;
     char **names;
     char **ptr;
+    struct Cell_head window;
+    struct Cell_head *cellhd;
 
     struct GModule *module;
     struct Flag *zeroflag;
@@ -71,12 +73,10 @@
     zeroflag->description =
 	_("Use zero (0) for transparency instead of NULL");
 
-    ZEROFLAG = 0;		/* default: use NULL for transparency */
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    ZEROFLAG = (zeroflag->answer);
+    use_zero = (zeroflag->answer);
 
     names = opt1->answers;
 
@@ -89,6 +89,7 @@
 
     infd = G_malloc(nfiles * sizeof(int));
     statf = G_malloc(nfiles * sizeof(struct Cell_stats));
+    cellhd = G_malloc(nfiles * sizeof(struct Cell_head));
 
     for (i = 0; i < nfiles; i++) {
 	const char *name = names[i];
@@ -105,6 +106,8 @@
 	    out_type = DCELL_TYPE;
 
 	Rast_init_cell_stats(&statf[i]);
+
+	Rast_get_cellhd(name, "", &cellhd[i]);
     }
 
     rname = opt2->answer;
@@ -113,20 +116,33 @@
     presult = Rast_allocate_buf(out_type);
     patch = Rast_allocate_buf(out_type);
 
+    Rast_get_window(&window);
     nrows = Rast_window_rows();
     ncols = Rast_window_cols();
 
     G_verbose_message(_("Percent complete..."));
     for (row = 0; row < nrows; row++) {
+	double north_edge, south_edge;
+
 	G_percent(row, nrows, 2);
 	Rast_get_row(infd[0], presult, row, out_type);
 
+	north_edge = Rast_row_to_northing(row, &window);
+	south_edge = north_edge - window.ns_res;
+
 	if (out_type == CELL_TYPE)
 	    Rast_update_cell_stats((CELL *) presult, ncols, &statf[0]);
 	for (i = 1; i < nfiles; i++) {
+	    /* check if raster i overlaps with the current row */
+	    if (south_edge >= cellhd[i].north ||
+		north_edge <= cellhd[i].south ||
+		window.west >= cellhd[i].east ||
+		window.east <= cellhd[i].west)
+		continue;
+
 	    Rast_get_row(infd[i], patch, row, out_type);
 	    if (!do_patch
-		(presult, patch, &statf[i], ncols, out_type, ZEROFLAG))
+		(presult, patch, &statf[i], ncols, out_type, use_zero))
 		break;
 	}
 	Rast_put_row(outfd, presult, out_type);

Modified: grass/branches/releasebranch_7_0/raster/r.patch/r.patch.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.patch/r.patch.html	2014-06-23 21:00:25 UTC (rev 60929)
+++ grass/branches/releasebranch_7_0/raster/r.patch/r.patch.html	2014-06-23 22:02:01 UTC (rev 60930)
@@ -106,6 +106,6 @@
 Michael Shapiro, 
 U.S. Army Construction Engineering Research Laboratory
 <br>
--z flag by Huidae Cho
+-z flag and performance improvement by Huidae Cho
 
 <p><i>Last changed: $Date$</i>



More information about the grass-commit mailing list