[GRASS-SVN] r72378 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 18 07:45:01 PDT 2018


Author: mmetz
Date: 2018-03-18 07:45:01 -0700 (Sun, 18 Mar 2018)
New Revision: 72378

Modified:
   grass/trunk/lib/vector/Vlib/build_nat.c
Log:
Vlib: print messages only when needed during topology building

Modified: grass/trunk/lib/vector/Vlib/build_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_nat.c	2018-03-17 15:53:56 UTC (rev 72377)
+++ grass/trunk/lib/vector/Vlib/build_nat.c	2018-03-18 14:45:01 UTC (rev 72378)
@@ -33,7 +33,7 @@
 int Vect_build_nat(struct Map_info *Map, int build)
 {
     struct Plus_head *plus;
-    int i, s, type, line;
+    int i, s, type, line, counter;
     off_t offset;
     int side, area;
     struct line_cats *Cats;
@@ -127,32 +127,35 @@
     if (plus->built < GV_BUILD_AREAS) {
 	/* Build areas */
 	/* Go through all bundaries and try to build area for both sides */
-	G_important_message(_("Building areas..."));
-	G_percent(0, plus->n_lines, 1);
-	for (line = 1; line <= plus->n_lines; line++) {
-	    G_percent(line, plus->n_lines, 1);
+	if (plus->n_blines > 0) {
+	    counter = 1;
+	    G_important_message(_("Building areas..."));
+	    G_percent(0, plus->n_blines, 1);
+	    for (line = 1; line <= plus->n_lines; line++) {
 
-	    /* build */
-	    if (plus->Line[line] == NULL) {
-		continue;
-	    }			/* dead line */
-	    Line = plus->Line[line];
-	    if (Line->type != GV_BOUNDARY) {
-		continue;
-	    }
+		/* build */
+		if (plus->Line[line] == NULL)
+		    continue;		/* dead */
 
-	    for (s = 0; s < 2; s++) {
-		if (s == 0)
-		    side = GV_LEFT;
-		else
-		    side = GV_RIGHT;
+		Line = plus->Line[line];
+		if (Line->type != GV_BOUNDARY)
+		    continue;
 
-		G_debug(3, "Build area for line = %d, side = %d", line, side);
-		Vect_build_line_area(Map, line, side);
+		G_percent(counter++, plus->n_blines, 1);
+
+		for (s = 0; s < 2; s++) {
+		    if (s == 0)
+			side = GV_LEFT;
+		    else
+			side = GV_RIGHT;
+
+		    G_debug(3, "Build area for line = %d, side = %d", line, side);
+		    Vect_build_line_area(Map, line, side);
+		}
 	    }
+	    G_verbose_message(n_("One area built", "%d areas built", plus->n_areas), plus->n_areas);
+	    G_verbose_message(n_("One isle built", "%d isles built", plus->n_isles), plus->n_isles);
 	}
-	G_verbose_message(n_("One area built", "%d areas built", plus->n_areas), plus->n_areas);
-	G_verbose_message(n_("One isle built", "%d isles built", plus->n_isles), plus->n_isles);
 	plus->built = GV_BUILD_AREAS;
     }
 
@@ -161,11 +164,14 @@
 
     /* Attach isles to areas */
     if (plus->built < GV_BUILD_ATTACH_ISLES) {
-	G_important_message(_("Attaching islands..."));
-	for (i = 1; i <= plus->n_isles; i++) {
-	    G_percent(i, plus->n_isles, 1);
-	    Vect_get_isle_box(Map, i, &box);
-	    Vect_attach_isle(Map, i, &box);
+	if (plus->n_isles > 0) {
+	    G_important_message(_("Attaching islands..."));
+	    G_percent(0, plus->n_isles, 1);
+	    for (i = 1; i <= plus->n_isles; i++) {
+		G_percent(i, plus->n_isles, 1);
+		Vect_get_isle_box(Map, i, &box);
+		Vect_attach_isle(Map, i, &box);
+	    }
 	}
 	plus->built = GV_BUILD_ATTACH_ISLES;
     }
@@ -175,38 +181,41 @@
 
     /* Attach centroids to areas */
     if (plus->built < GV_BUILD_CENTROIDS) {
-	int nlines;
 	struct P_topo_c *topo;
 
-	G_important_message(_("Attaching centroids..."));
+	if (plus->n_blines > 0) {
+	    counter = 1;
+	    G_important_message(_("Attaching centroids..."));
+	    G_percent(0, plus->n_clines, 1);
 
-	nlines = Vect_get_num_lines(Map);
-	for (line = 1; line <= nlines; line++) {
-	    G_percent(line, nlines, 1);
+	    for (line = 1; line <= plus->n_lines; line++) {
 
-	    Line = plus->Line[line];
-	    if (!Line)
-		continue;	/* Dead */
+		Line = plus->Line[line];
+		if (!Line)
+		    continue;	/* dead */
 
-	    if (Line->type != GV_CENTROID)
-		continue;
+		if (Line->type != GV_CENTROID)
+		    continue;
 
-	    Vect_read_line(Map, Points, NULL, line);
-	    area = Vect_find_area(Map, Points->x[0], Points->y[0]);
+		G_percent(counter++, plus->n_clines, 1);
 
-	    if (area > 0) {
-		G_debug(3, "Centroid (line=%d) in area %d", line, area);
+		Vect_read_line(Map, Points, NULL, line);
+		area = Vect_find_area(Map, Points->x[0], Points->y[0]);
 
-		Area = plus->Area[area];
-		topo = (struct P_topo_c *)Line->topo;
+		if (area > 0) {
+		    G_debug(3, "Centroid (line=%d) in area %d", line, area);
 
-		if (Area->centroid == 0) {	/* first */
-		    Area->centroid = line;
-		    topo->area = area;
+		    Area = plus->Area[area];
+		    topo = (struct P_topo_c *)Line->topo;
+
+		    if (Area->centroid == 0) {	/* first */
+			Area->centroid = line;
+			topo->area = area;
+		    }
+		    else {		/* duplicate */
+			topo->area = -area;
+		    }
 		}
-		else {		/* duplicate */
-		    topo->area = -area;
-		}
 	    }
 	}
 	plus->built = GV_BUILD_CENTROIDS;
@@ -213,6 +222,8 @@
     }
 
     /* Add areas to category index */
+    /* add message and G_percent() ? 
+     * it seems fast enough, no message / precent needed */
     for (i = 1; i <= plus->n_areas; i++) {
 	int c;
 



More information about the grass-commit mailing list