From f01a1daa7b28729a3be5d1297744055682cc0f57 Mon Sep 17 00:00:00 2001 From: Ralf Gerlich Date: Fri, 8 Feb 2008 22:24:42 +0100 Subject: [PATCH] Fixed criterion for removal of small degenerate polygons. --- src/Airports/GenAirports/build.cxx | 4 ++ src/Lib/Geometry/poly_support.cxx | 64 ++++++++++++++++-------------- src/Lib/Geometry/poly_support.hxx | 3 ++ 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/Airports/GenAirports/build.cxx b/src/Airports/GenAirports/build.cxx index db669301..2bbef0fb 100644 --- a/src/Airports/GenAirports/build.cxx +++ b/src/Airports/GenAirports/build.cxx @@ -802,6 +802,8 @@ void build_airport( string airport_id, float alt_m, SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_dups() = " << poly.total_size()); poly = remove_bad_contours( poly ); SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_bad() = " << poly.total_size()); + poly = remove_tiny_contours( poly ); + SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_tiny_contours() = " << poly.total_size()); rwy_polys[k].set_poly( poly ); } @@ -818,6 +820,8 @@ void build_airport( string airport_id, float alt_m, base_poly = remove_dups( base_poly ); SG_LOG(SG_GENERAL, SG_DEBUG, "remove bad contours base"); base_poly = remove_bad_contours( base_poly ); + SG_LOG(SG_GENERAL, SG_DEBUG, "remove small contours base"); + base_poly = remove_tiny_contours( base_poly ); // write_polygon( base_poly, "base-fin" ); SG_LOG(SG_GENERAL, SG_DEBUG, " after clean up: " << base_poly); diff --git a/src/Lib/Geometry/poly_support.cxx b/src/Lib/Geometry/poly_support.cxx index f343fe3d..5e56eff5 100644 --- a/src/Lib/Geometry/poly_support.cxx +++ b/src/Lib/Geometry/poly_support.cxx @@ -414,25 +414,28 @@ static void collect_contour_points( TGContourNode* node, TGPolygon &p, point_lis static void write_tree_element( TGContourNode *node, TGPolygon& p, int hole=0) { int contour_num = node->get_contour_num(); - char buf[256]; - sprintf(buf, "failed/element%ld.poly",contour_num); - FILE *treefp = fopen(buf,"w"); - fprintf(treefp,"#2D\n"); - fprintf(treefp,"Airport\n"); - - fprintf(treefp,"1\n"); - - fprintf(treefp,"%ld\n",p.contour_size(contour_num)); - fprintf(treefp,"%d\n",hole); - - for (int i=0;iget_num_kids(); ++i ) { if ( node->get_kid( i ) != NULL ) { write_tree_element( node->get_kid( i ), p, 1-hole); @@ -507,10 +510,6 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) { // cout << "calc_point_inside() maxdiff=" << maxdiff << " yline=" << yline << endl; - if (maxdiff < SG_EPSILON) { - throw sg_exception("Polygon is too small in y-direction"); - } - vector < double > xcuts; intersect_yline_with_contour( yline, node, p, xcuts ); @@ -1042,18 +1041,25 @@ TGPolygon remove_bad_contours( const TGPolygon &poly ) { continue; } - point_list allpoints = contour; - - sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY)); - - point_list::iterator point_it; - - point_it=allpoints.begin(); - Point3D lastpt=*point_it; + /* keeping the contour */ + int flag = poly.get_hole_flag( i ); + result.add_contour( contour, flag ); + } + + return result; +} + +// remove any too small contours +TGPolygon remove_tiny_contours( const TGPolygon &poly ) { + TGPolygon result; + result.erase(); + + for ( int i = 0; i < poly.contours(); ++i ) { + point_list contour = poly.get_contour( i ); double area=poly.area_contour(i); - if (-SG_EPSILON