[GRASS-SVN] r60839 - grass/trunk/raster/r.patch

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 16 06:04:12 PDT 2014


Author: hcho
Date: 2014-06-16 06:04:12 -0700 (Mon, 16 Jun 2014)
New Revision: 60839

Modified:
   grass/trunk/raster/r.patch/do_patch.c
   grass/trunk/raster/r.patch/main.c
   grass/trunk/raster/r.patch/r.patch.html
Log:
r.patch: Don't read rows if an individual raster doesn't overlap with the
current row. In my test with 171 raster maps, it took 202 minutes and 29
minutes before and after this change, respectively.


Modified: grass/trunk/raster/r.patch/do_patch.c
===================================================================
--- grass/trunk/raster/r.patch/do_patch.c	2014-06-16 12:26:49 UTC (rev 60838)
+++ grass/trunk/raster/r.patch/do_patch.c	2014-06-16 13:04:12 UTC (rev 60839)
@@ -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 (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/trunk/raster/r.patch/main.c
===================================================================
--- grass/trunk/raster/r.patch/main.c	2014-06-16 12:26:49 UTC (rev 60838)
+++ grass/trunk/raster/r.patch/main.c	2014-06-16 13:04:12 UTC (rev 60839)
@@ -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,30 @@
     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)
+		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/trunk/raster/r.patch/r.patch.html
===================================================================
--- grass/trunk/raster/r.patch/r.patch.html	2014-06-16 12:26:49 UTC (rev 60838)
+++ grass/trunk/raster/r.patch/r.patch.html	2014-06-16 13:04:12 UTC (rev 60839)
@@ -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