1
0
Fork 0

Fixed criterion for removal of small degenerate polygons.

This commit is contained in:
Ralf Gerlich 2008-02-08 22:24:42 +01:00
parent e29bdcfe59
commit f01a1daa7b
3 changed files with 42 additions and 29 deletions

View file

@ -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()); SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_dups() = " << poly.total_size());
poly = remove_bad_contours( poly ); poly = remove_bad_contours( poly );
SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_bad() = " << poly.total_size()); 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 ); 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 ); base_poly = remove_dups( base_poly );
SG_LOG(SG_GENERAL, SG_DEBUG, "remove bad contours base"); SG_LOG(SG_GENERAL, SG_DEBUG, "remove bad contours base");
base_poly = remove_bad_contours( base_poly ); 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" ); // write_polygon( base_poly, "base-fin" );
SG_LOG(SG_GENERAL, SG_DEBUG, " after clean up: " << base_poly); SG_LOG(SG_GENERAL, SG_DEBUG, " after clean up: " << base_poly);

View file

@ -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) { static void write_tree_element( TGContourNode *node, TGPolygon& p, int hole=0) {
int contour_num = node->get_contour_num(); 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"); if (contour_num != -1) {
fprintf(treefp,"Airport\n"); char buf[256];
sprintf(buf, "failed/element%ld.poly",contour_num);
FILE *treefp = fopen(buf,"w");
fprintf(treefp,"1\n"); fprintf(treefp,"#2D\n");
fprintf(treefp,"Airport\n");
fprintf(treefp,"%ld\n",p.contour_size(contour_num)); fprintf(treefp,"1\n");
fprintf(treefp,"%d\n",hole);
for (int i=0;i<p.contour_size(contour_num);i++) { fprintf(treefp,"%ld\n",p.contour_size(contour_num));
Point3D pt=p.get_pt(contour_num,i); fprintf(treefp,"%d\n",hole);
fprintf(treefp,"%.15f %.15f\n",pt.x(),pt.y());
for (int i=0;i<p.contour_size(contour_num);i++) {
Point3D pt=p.get_pt(contour_num,i);
fprintf(treefp,"%.15f %.15f\n",pt.x(),pt.y());
}
fclose(treefp);
} }
fclose(treefp);
for ( int i = 0; i < node->get_num_kids(); ++i ) { for ( int i = 0; i < node->get_num_kids(); ++i ) {
if ( node->get_kid( i ) != NULL ) { if ( node->get_kid( i ) != NULL ) {
write_tree_element( node->get_kid( i ), p, 1-hole); 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; // 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; vector < double > xcuts;
intersect_yline_with_contour( yline, node, p, xcuts ); intersect_yline_with_contour( yline, node, p, xcuts );
@ -1042,18 +1041,25 @@ TGPolygon remove_bad_contours( const TGPolygon &poly ) {
continue; continue;
} }
point_list allpoints = contour; /* keeping the contour */
int flag = poly.get_hole_flag( i );
result.add_contour( contour, flag );
}
sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY)); return result;
}
point_list::iterator point_it; // remove any too small contours
TGPolygon remove_tiny_contours( const TGPolygon &poly ) {
TGPolygon result;
result.erase();
point_it=allpoints.begin(); for ( int i = 0; i < poly.contours(); ++i ) {
Point3D lastpt=*point_it; point_list contour = poly.get_contour( i );
double area=poly.area_contour(i); double area=poly.area_contour(i);
if (-SG_EPSILON<area && area<SG_EPSILON) { if (-SG_EPSILON*SG_EPSILON<area && area<SG_EPSILON*SG_EPSILON) {
// cout << "tossing a bad contour " << i << " (too small)" << endl; // cout << "tossing a bad contour " << i << " (too small)" << endl;
continue; continue;
} }

View file

@ -95,6 +95,9 @@ bool find_intermediate_node( const Point3D& start, const Point3D& end,
// remove any degenerate contours // remove any degenerate contours
TGPolygon remove_bad_contours( const TGPolygon &poly ); TGPolygon remove_bad_contours( const TGPolygon &poly );
// remove any too small contours
TGPolygon remove_tiny_contours( const TGPolygon &poly );
#endif // _POLY_SUPPORT_HXX #endif // _POLY_SUPPORT_HXX