Преглед изворни кода

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, https://trac.osgeo.org/grass/changeset/60839 + https://trac.osgeo.org/grass/changeset/60842

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@60930 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler пре 11 година
родитељ
комит
f7c103d2d9
3 измењених фајлова са 24 додато и 8 уклоњено
  1. 2 2
      raster/r.patch/do_patch.c
  2. 21 5
      raster/r.patch/main.c
  3. 1 1
      raster/r.patch/r.patch.html

+ 2 - 2
raster/r.patch/do_patch.c

@@ -21,13 +21,13 @@ int G_is_zero_value(void *rast, RASTER_MAP_TYPE data_type)
 
 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 */

+ 21 - 5
raster/r.patch/main.c

@@ -37,10 +37,12 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
 
     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 @@ int main(int argc, char *argv[])
 	    out_type = DCELL_TYPE;
 
 	Rast_init_cell_stats(&statf[i]);
+
+	Rast_get_cellhd(name, "", &cellhd[i]);
     }
 
     rname = opt2->answer;
@@ -113,20 +116,33 @@ int main(int argc, char *argv[])
     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);

+ 1 - 1
raster/r.patch/r.patch.html

@@ -106,6 +106,6 @@ r.patch in=$MAPS out=mosaic
 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>