From 7e5aa9c98c270271b2a27e4ae166604f7a352951 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 29 Apr 1999 21:39:27 +0000 Subject: [PATCH] Fixing slight bugs with calculating point inside multi-contoured polygons. --- Tools/Construct/Makefile.am | 3 +- Tools/Construct/Triangulate/polygon.cxx | 8 ++--- Tools/Construct/Triangulate/polygon.hxx | 2 +- Tools/Construct/Triangulate/triangle.cxx | 37 +++++++++++++++++++----- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Tools/Construct/Makefile.am b/Tools/Construct/Makefile.am index 79fc6b321..2f07b7be0 100644 --- a/Tools/Construct/Makefile.am +++ b/Tools/Construct/Makefile.am @@ -3,6 +3,7 @@ SUBDIRS = \ Clipper \ Combine \ GenOutput \ - Match \ Triangulate \ Main + +# Match diff --git a/Tools/Construct/Triangulate/polygon.cxx b/Tools/Construct/Triangulate/polygon.cxx index 6020d9595..e305aa846 100644 --- a/Tools/Construct/Triangulate/polygon.cxx +++ b/Tools/Construct/Triangulate/polygon.cxx @@ -82,13 +82,13 @@ static bool intersects( const Point3D& p0, const Point3D& p1, double x, } -// calculate an "arbitrary" point inside the specified contour for +// calculate some "arbitrary" point inside the specified contour for // assigning attribute areas void FGPolygon::calc_point_inside( const int contour, const FGTriNodes& trinodes ) { Point3D tmp, min, ln, p1, p2, p3, m, result; - // 1. find point, min, with smallest y + // 1. find a point on the specified contour, min, with smallest y // min.y() starts greater than the biggest possible lat (degrees) min.sety( 100.0 ); @@ -161,7 +161,7 @@ void FGPolygon::calc_point_inside( const int contour, if ( intersects(p1, p2, m.x(), &result) ) { // cout << "intersection = " << result << endl; if ( ( result.y() < p3.y() ) && - ( fabs(result.y() - m.y()) > FG_EPSILON ) ) { + ( result.y() > m.y() + FG_EPSILON ) ) { p3 = result; } } @@ -173,7 +173,7 @@ void FGPolygon::calc_point_inside( const int contour, if ( intersects(p1, p2, m.x(), &result) ) { // cout << "intersection = " << result << endl; if ( ( result.y() < p3.y() ) && - ( fabs(result.y() - m.y()) > FG_EPSILON ) ) { + ( result.y() > m.y() + FG_EPSILON ) ) { p3 = result; } } diff --git a/Tools/Construct/Triangulate/polygon.hxx b/Tools/Construct/Triangulate/polygon.hxx index ac21e0967..1959bb3c1 100644 --- a/Tools/Construct/Triangulate/polygon.hxx +++ b/Tools/Construct/Triangulate/polygon.hxx @@ -86,7 +86,7 @@ public: return poly[contour][i]; } - // calculate an "arbitrary" point inside the specified contour for + // calculate some "arbitrary" point inside the specified contour for // assigning attribute areas void calc_point_inside( const int contour, const FGTriNodes& trinodes ); inline Point3D get_point_inside( const int contour ) const { diff --git a/Tools/Construct/Triangulate/triangle.cxx b/Tools/Construct/Triangulate/triangle.cxx index 80a8d5d38..969899a5d 100644 --- a/Tools/Construct/Triangulate/triangle.cxx +++ b/Tools/Construct/Triangulate/triangle.cxx @@ -40,6 +40,7 @@ FGTriangle::build( const point_list& corner_list, const point_list& fit_list, const FGgpcPolyList& gpc_polys ) { + int debug_counter = 0; FGPolygon poly; int index; @@ -75,6 +76,7 @@ FGTriangle::build( const point_list& corner_list, polylist[i].clear(); // cout << "area type = " << i << endl; + debug_counter = 0; current = gpc_polys.polys[i].begin(); last = gpc_polys.polys[i].end(); for ( ; current != last; ++current ) { @@ -87,12 +89,6 @@ FGTriangle::build( const point_list& corner_list, exit(-1); } - if (gpc_poly->num_contours > 1 ) { - cout << "FATAL ERROR! no multi-contour support" << endl; - sleep(2); - // exit(-1); - } - poly.erase(); int j; @@ -123,11 +119,38 @@ FGTriangle::build( const point_list& corner_list, poly.set_hole_flag( j, gpc_poly->hole[j] ); } - for ( j = 0; j < gpc_poly->num_contours; j++ ) { + for ( j = 0; j < gpc_poly->num_contours; ++j ) { poly.calc_point_inside( j, in_nodes ); } + // temporary ... write out/hole polygon info for debugging + for ( j = 0; j < (int)poly.contours(); ++j ) { + char pname[256]; + sprintf(pname, "poly%02d-%02d-%02d", i, debug_counter, j); + FILE *fp = fopen( pname, "w" ); + int index; + Point3D point; + for ( int k = 0; k < poly.contour_size( j ); ++k ) { + index = poly.get_pt_index( j, k ); + point = in_nodes.get_node( index ); + fprintf( fp, "%.6f %.6f\n", point.x(), point.y() ); + } + index = poly.get_pt_index( j, 0 ); + point = in_nodes.get_node( index ); + fprintf( fp, "%.6f %.6f\n", point.x(), point.y() ); + fclose(fp); + + char hname[256]; + sprintf(hname, "hole%02d-%02d-%02d", i, debug_counter, j); + FILE *fh = fopen( hname, "w" ); + point = poly.get_point_inside( j ); + fprintf( fh, "%.6f %.6f\n", point.x(), point.y() ); + fclose(fh); + } + polylist[i].push_back( poly ); + + ++debug_counter; } }