[GRASS-SVN] r64033 - grass/trunk/vector/v.generalize

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 9 12:04:07 PST 2015


Author: mmetz
Date: 2015-01-09 12:04:07 -0800 (Fri, 09 Jan 2015)
New Revision: 64033

Modified:
   grass/trunk/vector/v.generalize/main.c
   grass/trunk/vector/v.generalize/misc.c
Log:
v.generalize: add another test to check_topo()

Modified: grass/trunk/vector/v.generalize/main.c
===================================================================
--- grass/trunk/vector/v.generalize/main.c	2015-01-09 20:03:02 UTC (rev 64032)
+++ grass/trunk/vector/v.generalize/main.c	2015-01-09 20:04:07 UTC (rev 64033)
@@ -550,7 +550,7 @@
 	    if (Points->n_points < 2) {
 		after = APoints->n_points;
 		n_oversimplified++;
-                if(error_out->answer)
+                if (error_out->answer)
 		    Vect_write_line(&Error, type, APoints, Cats);
 	    }
 	    /* check for topology corruption */
@@ -558,7 +558,7 @@
 		if (!check_topo(&Out, i, APoints, Points, Cats)) {
 		    after = APoints->n_points;
 		    not_modified_boundaries++;
-                    if(error_out->answer)
+                    if (error_out->answer)
 		        Vect_write_line(&Error, type, APoints, Cats);
 		}
 		else
@@ -582,17 +582,17 @@
 
 	/* make sure that clean topo is built at the end */
 	Vect_build_partial(&Out, GV_BUILD_NONE);
-        if(error_out->answer)
+        if (error_out->answer)
 	    Vect_build_partial(&Error, GV_BUILD_NONE);
     }
 
     Vect_build(&Out);
-    if(error_out->answer)
+    if (error_out->answer)
         Vect_build(&Error);
 
     Vect_close(&In);
     Vect_close(&Out);
-    if(error_out->answer)
+    if (error_out->answer)
         Vect_close(&Error);
 
     G_message("-----------------------------------------------------");

Modified: grass/trunk/vector/v.generalize/misc.c
===================================================================
--- grass/trunk/vector/v.generalize/misc.c	2015-01-09 20:03:02 UTC (rev 64032)
+++ grass/trunk/vector/v.generalize/misc.c	2015-01-09 20:04:07 UTC (rev 64033)
@@ -194,16 +194,21 @@
 {
     int i, j, intersect, newline, left_old, right_old,
 	left_new, right_new;
-    struct bound_box box;
+    struct bound_box box, abox;
     struct line_pnts **AXLines, **BXLines;
     int naxlines, nbxlines;
     static struct line_pnts *BPoints = NULL;
     static struct boxlist *List = NULL;
+    static struct line_pnts *BPoints2 = NULL;
+    static struct ilist *BList = NULL;
+    int area, isle, centr;
 
-    if (!BPoints)
+    if (!BPoints) {
 	BPoints = Vect_new_line_struct();
-    if (!List)
+	BPoints2 = Vect_new_line_struct();
 	List = Vect_new_boxlist(1);
+	BList = Vect_new_list();
+    }
 
     Vect_line_box(Points, &box);
 
@@ -273,17 +278,131 @@
     if (intersect)
 	return 0;
 
-    /* Get centroids on the left and right side */
     Vect_get_line_areas(Out, line, &left_old, &right_old);
-    if (left_old < 0)
-	left_old = Vect_get_isle_area(Out, abs(left_old));
-    if (left_old > 0)
-	left_old = Vect_get_area_centroid(Out, left_old);
-    if (right_old < 0)
-	right_old = Vect_get_isle_area(Out, abs(right_old));
-    if (right_old > 0)
-	right_old = Vect_get_area_centroid(Out, right_old);
 
+    Vect_line_box(APoints, &abox);
+
+    /* centroid on the left side */
+    isle = centr = 0;
+    area = left_old;
+    if (area < 0) {
+	isle = -area;
+	area = Vect_get_isle_area(Out, isle);
+    }
+    if (area > 0)
+	centr = Vect_get_area_centroid(Out, area);
+    if (1) {
+
+    if (centr > 0) {
+	int ret;
+	double cx, cy, cz;
+
+	Vect_read_line(Out, BPoints, NULL, centr);
+	cx = BPoints->x[0];
+	cy = BPoints->y[0];
+	cz = BPoints->z[0];
+	
+	if (Vect_point_in_box(cx, cy, cz, &box) ||
+	    Vect_point_in_box(cx, cy, cz, &abox)) {
+
+	    if (isle)
+		Vect_get_isle_boundaries(Out, isle, BList);
+	    else
+		Vect_get_area_boundaries(Out, area, BList);
+
+	    Vect_reset_line(BPoints2);
+	    for (i = 0; i < BList->n_values; i++) {
+		int bline = BList->value[i];
+		int dir = bline > 0 ? GV_FORWARD : GV_BACKWARD;
+
+		if (abs(bline) != line) {
+		    Vect_read_line(Out, BPoints, NULL, abs(bline));
+		    Vect_append_points(BPoints2, BPoints, dir);
+		}
+		else
+		    Vect_append_points(BPoints2, Points, dir);
+
+		BPoints2->n_points--;    /* skip last point, avoids duplicates */
+	    }
+	    BPoints2->n_points++;        /* close polygon */
+
+	    ret = Vect_point_in_poly(cx, cy, BPoints2);
+	    /* see Vect_point_in_area() */
+	    if (!isle) {
+		/* area: centroid must be inside */
+		if (ret == 0)
+		    return 0;
+	    }
+	    else {
+		/* isle: centroid must be outside */
+		if (ret > 0)
+		    return 0;
+	    }
+	}
+    }
+    }
+    left_old = centr;
+
+    /* centroid on the right side */
+    isle = centr = 0;
+    area = right_old;
+    if (area < 0) {
+	isle = -area;
+	area = Vect_get_isle_area(Out, isle);
+    }
+    if (area > 0)
+	centr = Vect_get_area_centroid(Out, area);
+    if (1) {
+    if (centr > 0) {
+	int ret;
+	double cx, cy, cz;
+
+	Vect_read_line(Out, BPoints, NULL, centr);
+	cx = BPoints->x[0];
+	cy = BPoints->y[0];
+	cz = BPoints->z[0];
+	
+	if (Vect_point_in_box(cx, cy, cz, &box) ||
+	    Vect_point_in_box(cx, cy, cz, &abox)) {
+
+	    if (isle)
+		Vect_get_isle_boundaries(Out, isle, BList);
+	    else
+		Vect_get_area_boundaries(Out, area, BList);
+
+	    Vect_reset_line(BPoints2);
+	    for (i = 0; i < BList->n_values; i++) {
+		int bline = BList->value[i];
+		int dir = bline > 0 ? GV_FORWARD : GV_BACKWARD;
+
+		if (abs(bline) != line) {
+		    Vect_read_line(Out, BPoints, NULL, abs(bline));
+		    Vect_append_points(BPoints2, BPoints, dir);
+		}
+		else
+		    Vect_append_points(BPoints2, Points, dir);
+
+		BPoints2->n_points--;    /* skip last point, avoids duplicates */
+	    }
+	    BPoints2->n_points++;        /* close polygon */
+
+	    ret = Vect_point_in_poly(cx, cy, BPoints2);
+	    /* see Vect_point_in_area() */
+	    if (!isle) {
+		/* area: centroid must be inside */
+		if (ret == 0)
+		    return 0;
+	    }
+	    else {
+		/* isle: centroid must be outside */
+		if (ret > 0)
+		    return 0;
+	    }
+	}
+    }
+    }
+    right_old = centr;
+
     /* OK, rewrite modified boundary */
     newline = Vect_rewrite_line(Out, line, GV_BOUNDARY, Points, Cats);
 



More information about the grass-commit mailing list