Intermediate fix for calc_point_inside
This commit is contained in:
parent
fe7f626265
commit
cd90019bbf
2 changed files with 34 additions and 31 deletions
|
@ -796,6 +796,8 @@ void build_airport( string airport_id, float alt_m,
|
||||||
for ( k = 0; k < (int)rwy_polys.size(); ++k ) {
|
for ( k = 0; k < (int)rwy_polys.size(); ++k ) {
|
||||||
TGPolygon poly = rwy_polys[k].get_poly();
|
TGPolygon poly = rwy_polys[k].get_poly();
|
||||||
|
|
||||||
|
SG_LOG(SG_GENERAL, SG_DEBUG, "total size of section " << k << " before =" << poly.total_size());
|
||||||
|
|
||||||
poly = remove_dups( poly );
|
poly = remove_dups( poly );
|
||||||
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 );
|
||||||
|
@ -822,7 +824,7 @@ void build_airport( string airport_id, float alt_m,
|
||||||
// tesselate the polygons and prepair them for final output
|
// tesselate the polygons and prepair them for final output
|
||||||
|
|
||||||
for ( i = 0; i < (int)rwy_polys.size(); ++i ) {
|
for ( i = 0; i < (int)rwy_polys.size(); ++i ) {
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating section = " << i);
|
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating section = " << i << " flag = " << rwy_polys[i].get_flag());
|
||||||
|
|
||||||
TGPolygon poly = rwy_polys[i].get_poly();
|
TGPolygon poly = rwy_polys[i].get_poly();
|
||||||
SG_LOG(SG_GENERAL, SG_DEBUG, "total size before = " << poly.total_size());
|
SG_LOG(SG_GENERAL, SG_DEBUG, "total size before = " << poly.total_size());
|
||||||
|
|
|
@ -395,25 +395,11 @@ static void intersect_yline_with_contour( double yline, TGContourNode *node, TGP
|
||||||
|
|
||||||
// cout << "intersect_yline_with_contour() p0=(" << p0.x() << ", " << p0.y() << ") p1=(" << p1.x() << ", " << p1.y() << ") ymin=" << ymin << " ymax=" << ymax << " yline=" << yline << endl;
|
// cout << "intersect_yline_with_contour() p0=(" << p0.x() << ", " << p0.y() << ") p1=(" << p1.x() << ", " << p1.y() << ") ymin=" << ymin << " ymax=" << ymax << " yline=" << yline << endl;
|
||||||
|
|
||||||
if ((yline+SG_EPSILON)<ymin || ymax<(yline-SG_EPSILON)) {
|
if (yline<ymin || ymax<yline) {
|
||||||
// cout << "intersect_yline_with_contour() does not intersect" << endl;
|
// cout << "intersect_yline_with_contour() does not intersect" << endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ymax-ymin<SG_EPSILON) {
|
|
||||||
// cout << "intersect_yline_with_contour() edge is nearly x-parallel" << endl;
|
|
||||||
|
|
||||||
if (yline-ymin<SG_EPSILON) {
|
|
||||||
throw sg_exception("Edges must not coincide with x-parallel intersection line");
|
|
||||||
}
|
|
||||||
// else the edge does not intersect
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (yline-ymin<SG_EPSILON) {
|
|
||||||
throw sg_exception("Points may not lie on x-parallel intersection line");
|
|
||||||
}
|
|
||||||
|
|
||||||
double t=(yline-p0.y())/(p1.y()-p0.y());
|
double t=(yline-p0.y())/(p1.y()-p0.y());
|
||||||
double x=p0.x()+t*(p1.x()-p0.x());
|
double x=p0.x()+t*(p1.x()-p0.x());
|
||||||
|
|
||||||
|
@ -477,6 +463,8 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
||||||
|
|
||||||
sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY));
|
sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY));
|
||||||
|
|
||||||
|
// TODO: check bounding box size for whether polygon is empty
|
||||||
|
|
||||||
point_list::iterator point_it;
|
point_list::iterator point_it;
|
||||||
|
|
||||||
point_it=allpoints.begin();
|
point_it=allpoints.begin();
|
||||||
|
@ -494,11 +482,11 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
||||||
lastpt=*point_it;
|
lastpt=*point_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxdiff<SG_EPSILON) {
|
cout << "calc_point_inside() " << allpoints.size() << " points ";
|
||||||
throw sg_exception("Polygon is empty");
|
copy(allpoints.begin(), allpoints.end(), ostream_iterator<Point3D>(cout, " "));
|
||||||
}
|
cout << endl;
|
||||||
|
|
||||||
// cout << "calc_point_inside() contour_num=" << contour_num << " " << pts.size() << " points ymin=" << ymin << " ymax=" << ymax << endl;
|
cout << "calc_point_inside() maxdiff=" << maxdiff << " yline=" << yline << endl;
|
||||||
|
|
||||||
vector < double > xcuts;
|
vector < double > xcuts;
|
||||||
|
|
||||||
|
@ -512,9 +500,9 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
||||||
|
|
||||||
sort( xcuts.begin(), xcuts.end() );
|
sort( xcuts.begin(), xcuts.end() );
|
||||||
|
|
||||||
// cout << "calc_point_inside() " << xcuts.size() << " intersections ";
|
cout << "calc_point_inside() " << xcuts.size() << " intersections ";
|
||||||
// copy(xcuts.begin(), xcuts.end(), ostream_iterator<double>(cout, " "));
|
copy(xcuts.begin(), xcuts.end(), ostream_iterator<double>(cout, " "));
|
||||||
// cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
if ( xcuts.size() < 2 || (xcuts.size() % 2) != 0 ) {
|
if ( xcuts.size() < 2 || (xcuts.size() % 2) != 0 ) {
|
||||||
throw sg_exception("Geometric inconsistency in calc_point_inside()");
|
throw sg_exception("Geometric inconsistency in calc_point_inside()");
|
||||||
|
@ -1026,13 +1014,26 @@ TGPolygon remove_bad_contours( const TGPolygon &poly ) {
|
||||||
|
|
||||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||||
point_list contour = poly.get_contour( i );
|
point_list contour = poly.get_contour( i );
|
||||||
if ( contour.size() >= 3 ) {
|
if ( contour.size() < 3) {
|
||||||
// good
|
//cout << "tossing a bad contour" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double xmin,xmax,ymin,ymax;
|
||||||
|
xmin=xmax=contour[0].x();
|
||||||
|
ymin=ymax=contour[0].y();
|
||||||
|
for ( int j = 1; j < contour.size(); ++j ) {
|
||||||
|
xmin = SGMisc<double>::min(xmin,contour[j].x());
|
||||||
|
ymin = SGMisc<double>::min(ymin,contour[j].y());
|
||||||
|
xmax = SGMisc<double>::max(xmax,contour[j].x());
|
||||||
|
ymax = SGMisc<double>::max(ymax,contour[j].y());
|
||||||
|
}
|
||||||
|
if ( xmax-xmin < SG_EPSILON || ymax-ymin < SG_EPSILON ) {
|
||||||
|
//cout << "tossing a bad contour (too small)" << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* keeping the contour */
|
||||||
int flag = poly.get_hole_flag( i );
|
int flag = poly.get_hole_flag( i );
|
||||||
result.add_contour( contour, flag );
|
result.add_contour( contour, flag );
|
||||||
} else {
|
|
||||||
//cout << "tossing a bad contour" << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue