Fixing slight bugs with calculating point inside multi-contoured polygons.
This commit is contained in:
parent
1f077556ba
commit
7e5aa9c98c
4 changed files with 37 additions and 13 deletions
|
@ -3,6 +3,7 @@ SUBDIRS = \
|
||||||
Clipper \
|
Clipper \
|
||||||
Combine \
|
Combine \
|
||||||
GenOutput \
|
GenOutput \
|
||||||
Match \
|
|
||||||
Triangulate \
|
Triangulate \
|
||||||
Main
|
Main
|
||||||
|
|
||||||
|
# Match
|
||||||
|
|
|
@ -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
|
// assigning attribute areas
|
||||||
void FGPolygon::calc_point_inside( const int contour,
|
void FGPolygon::calc_point_inside( const int contour,
|
||||||
const FGTriNodes& trinodes ) {
|
const FGTriNodes& trinodes ) {
|
||||||
Point3D tmp, min, ln, p1, p2, p3, m, result;
|
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.y() starts greater than the biggest possible lat (degrees)
|
||||||
min.sety( 100.0 );
|
min.sety( 100.0 );
|
||||||
|
@ -161,7 +161,7 @@ void FGPolygon::calc_point_inside( const int contour,
|
||||||
if ( intersects(p1, p2, m.x(), &result) ) {
|
if ( intersects(p1, p2, m.x(), &result) ) {
|
||||||
// cout << "intersection = " << result << endl;
|
// cout << "intersection = " << result << endl;
|
||||||
if ( ( result.y() < p3.y() ) &&
|
if ( ( result.y() < p3.y() ) &&
|
||||||
( fabs(result.y() - m.y()) > FG_EPSILON ) ) {
|
( result.y() > m.y() + FG_EPSILON ) ) {
|
||||||
p3 = result;
|
p3 = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ void FGPolygon::calc_point_inside( const int contour,
|
||||||
if ( intersects(p1, p2, m.x(), &result) ) {
|
if ( intersects(p1, p2, m.x(), &result) ) {
|
||||||
// cout << "intersection = " << result << endl;
|
// cout << "intersection = " << result << endl;
|
||||||
if ( ( result.y() < p3.y() ) &&
|
if ( ( result.y() < p3.y() ) &&
|
||||||
( fabs(result.y() - m.y()) > FG_EPSILON ) ) {
|
( result.y() > m.y() + FG_EPSILON ) ) {
|
||||||
p3 = result;
|
p3 = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public:
|
||||||
return poly[contour][i];
|
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
|
// assigning attribute areas
|
||||||
void calc_point_inside( const int contour, const FGTriNodes& trinodes );
|
void calc_point_inside( const int contour, const FGTriNodes& trinodes );
|
||||||
inline Point3D get_point_inside( const int contour ) const {
|
inline Point3D get_point_inside( const int contour ) const {
|
||||||
|
|
|
@ -40,6 +40,7 @@ FGTriangle::build( const point_list& corner_list,
|
||||||
const point_list& fit_list,
|
const point_list& fit_list,
|
||||||
const FGgpcPolyList& gpc_polys )
|
const FGgpcPolyList& gpc_polys )
|
||||||
{
|
{
|
||||||
|
int debug_counter = 0;
|
||||||
FGPolygon poly;
|
FGPolygon poly;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
|
@ -75,6 +76,7 @@ FGTriangle::build( const point_list& corner_list,
|
||||||
polylist[i].clear();
|
polylist[i].clear();
|
||||||
|
|
||||||
// cout << "area type = " << i << endl;
|
// cout << "area type = " << i << endl;
|
||||||
|
debug_counter = 0;
|
||||||
current = gpc_polys.polys[i].begin();
|
current = gpc_polys.polys[i].begin();
|
||||||
last = gpc_polys.polys[i].end();
|
last = gpc_polys.polys[i].end();
|
||||||
for ( ; current != last; ++current ) {
|
for ( ; current != last; ++current ) {
|
||||||
|
@ -87,12 +89,6 @@ FGTriangle::build( const point_list& corner_list,
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpc_poly->num_contours > 1 ) {
|
|
||||||
cout << "FATAL ERROR! no multi-contour support" << endl;
|
|
||||||
sleep(2);
|
|
||||||
// exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
poly.erase();
|
poly.erase();
|
||||||
|
|
||||||
int j;
|
int j;
|
||||||
|
@ -123,11 +119,38 @@ FGTriangle::build( const point_list& corner_list,
|
||||||
poly.set_hole_flag( j, gpc_poly->hole[j] );
|
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 );
|
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 );
|
polylist[i].push_back( poly );
|
||||||
|
|
||||||
|
++debug_counter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue