Modifications towards doing more sensible runway surfaces and markings.
This commit is contained in:
parent
e46696de86
commit
c490afd971
3 changed files with 75 additions and 250 deletions
|
@ -49,6 +49,7 @@
|
|||
#include <Polygon/index.hxx>
|
||||
#include <Polygon/polygon.hxx>
|
||||
#include <Polygon/split.hxx>
|
||||
#include <Polygon/superpoly.hxx>
|
||||
#include <Triangulate/trieles.hxx>
|
||||
|
||||
#include "convex_hull.hxx"
|
||||
|
@ -466,8 +467,9 @@ static void my_chomp( string& str ) {
|
|||
void build_airport( string airport_raw, string_list& runways_raw,
|
||||
const string& root ) {
|
||||
|
||||
poly_list rwy_polys, rwy_tris, rwy_txs;
|
||||
FGPolygon runway, runway_a, runway_b, result, result_a, result_b;
|
||||
superpoly_list rwy_polys;
|
||||
// poly_list rwy_tris, rwy_txs;
|
||||
FGPolygon runway, runway_a, runway_b, result, clipped_a, clipped_b;
|
||||
FGPolygon base;
|
||||
point_list apt_pts;
|
||||
Point3D p;
|
||||
|
@ -563,8 +565,22 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
runways.push_back( rwy );
|
||||
}
|
||||
|
||||
FGSuperPoly sp;
|
||||
string surface_flag;
|
||||
string material;
|
||||
for ( int i = 0; i < (int)runways.size(); ++i ) {
|
||||
runway = gen_runway_w_mid( runways[i] );
|
||||
surface_flag = runways[i].surface_flags.substr(0, 1);
|
||||
cout << "surface flag = " << surface_flag << endl;
|
||||
if ( surface_flag == "A" ) {
|
||||
material = "Asphalt";
|
||||
} else if ( surface_flag == "C" ) {
|
||||
material = "Concrete";
|
||||
} else if ( surface_flag == "D" ) {
|
||||
material = "DryLake";
|
||||
} else if ( surface_flag == "T" ) {
|
||||
material = "Grass";
|
||||
}
|
||||
|
||||
// runway half "a"
|
||||
runway_a.erase();
|
||||
|
@ -591,14 +607,20 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
cout << " point = " << p << endl;
|
||||
}
|
||||
|
||||
result_a = polygon_diff( runway_a, accum );
|
||||
rwy_polys.push_back( result_a );
|
||||
cout << "result_a = " << result_a.contours() << endl;
|
||||
clipped_a = polygon_diff( runway_a, accum );
|
||||
sp.erase();
|
||||
sp.set_poly( clipped_a );
|
||||
sp.set_material( material );
|
||||
rwy_polys.push_back( sp );
|
||||
cout << "clipped_a = " << clipped_a.contours() << endl;
|
||||
accum = polygon_union( runway_a, accum );
|
||||
|
||||
result_b = polygon_diff( runway_b, accum );
|
||||
rwy_polys.push_back( result_b );
|
||||
cout << "result_b = " << result_b.contours() << endl;
|
||||
clipped_b = polygon_diff( runway_b, accum );
|
||||
sp.erase();
|
||||
sp.set_poly( clipped_b );
|
||||
sp.set_material( material );
|
||||
rwy_polys.push_back( sp );
|
||||
cout << "clipped_b = " << clipped_b.contours() << endl;
|
||||
accum = polygon_union( runway_b, accum );
|
||||
|
||||
#if 0
|
||||
|
@ -606,24 +628,24 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
char tmpa[256], tmpb[256];
|
||||
sprintf( tmpa, "a%d", i );
|
||||
sprintf( tmpb, "b%d", i );
|
||||
write_polygon( result_a, tmpa );
|
||||
write_polygon( result_b, tmpb );
|
||||
write_polygon( clipped_a, tmpa );
|
||||
write_polygon( clipped_b, tmpb );
|
||||
#endif
|
||||
|
||||
// print runway points
|
||||
cout << "clipped runway pts (a)" << endl;
|
||||
for ( int j = 0; j < result_a.contours(); ++j ) {
|
||||
for ( int k = 0; k < result_a.contour_size( j ); ++k ) {
|
||||
p = result_a.get_pt(j, k);
|
||||
for ( int j = 0; j < clipped_a.contours(); ++j ) {
|
||||
for ( int k = 0; k < clipped_a.contour_size( j ); ++k ) {
|
||||
p = clipped_a.get_pt(j, k);
|
||||
cout << " point = " << p << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// print runway points
|
||||
cout << "clipped runway pts (b)" << endl;
|
||||
for ( int j = 0; j < result_b.contours(); ++j ) {
|
||||
for ( int k = 0; k < result_b.contour_size( j ); ++k ) {
|
||||
p = result_b.get_pt(j, k);
|
||||
for ( int j = 0; j < clipped_b.contours(); ++j ) {
|
||||
for ( int k = 0; k < clipped_b.contour_size( j ); ++k ) {
|
||||
p = clipped_b.get_pt(j, k);
|
||||
cout << " point = " << p << endl;
|
||||
}
|
||||
}
|
||||
|
@ -654,9 +676,10 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
|
||||
// build temporary node list
|
||||
for ( int k = 0; k < (int)rwy_polys.size(); ++k ) {
|
||||
for ( int i = 0; i < rwy_polys[k].contours(); ++i ) {
|
||||
for ( int j = 0; j < rwy_polys[k].contour_size( i ); ++j ) {
|
||||
tmp_nodes.unique_add( rwy_polys[k].get_pt(i, j) );
|
||||
FGPolygon poly = rwy_polys[k].get_poly();
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
for ( int j = 0; j < poly.contour_size( i ); ++j ) {
|
||||
tmp_nodes.unique_add( poly.get_pt(i, j) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -698,16 +721,19 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
|
||||
for ( int k = 0; k < (int)rwy_polys.size(); ++k ) {
|
||||
cout << "add nodes/remove dups runway = " << k << endl;
|
||||
rwy_polys[k] = add_nodes_to_poly( rwy_polys[k], tmp_nodes );
|
||||
FGPolygon poly = rwy_polys[k].get_poly();
|
||||
poly = add_nodes_to_poly( poly, tmp_nodes );
|
||||
|
||||
#if 0
|
||||
char tmp[256];
|
||||
sprintf( tmp, "r%d", k );
|
||||
write_polygon( rwy_polys[k], tmp );
|
||||
write_polygon( poly, tmp );
|
||||
#endif
|
||||
|
||||
rwy_polys[k] = remove_dups( rwy_polys[k] );
|
||||
rwy_polys[k] = remove_bad_contours( rwy_polys[k] );
|
||||
poly = remove_dups( poly );
|
||||
poly = remove_bad_contours( poly );
|
||||
|
||||
rwy_polys[k].set_poly( poly );
|
||||
}
|
||||
cout << "add nodes/remove dups base " << endl;
|
||||
base_poly = add_nodes_to_poly( base_poly, tmp_nodes );
|
||||
|
@ -718,19 +744,24 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
|
||||
// tesselate the polygons and prepair them for final output
|
||||
|
||||
FGPolygon poly;
|
||||
for ( int i = 0; i < (int)runways.size(); ++i ) {
|
||||
cout << "Tesselating runway = " << i << endl;
|
||||
FGPolygon tri_a, tri_b, tc_a, tc_b;
|
||||
|
||||
tri_a = polygon_tesselate_alt( rwy_polys[2 * i] );
|
||||
poly = rwy_polys[2 * i].get_poly();
|
||||
tri_a = polygon_tesselate_alt( poly );
|
||||
tc_a = rwy_calc_tex_coords( runways[i], 0.0, tri_a );
|
||||
rwy_tris.push_back( tri_a );
|
||||
rwy_txs.push_back( tc_a );
|
||||
rwy_polys[2 * i].set_tris( tri_a );
|
||||
rwy_polys[2 * i].set_texcoords( tc_a );
|
||||
rwy_polys[2 * i].set_tri_mode( GL_TRIANGLES );
|
||||
|
||||
tri_b = polygon_tesselate_alt( rwy_polys[2 * i + 1] );
|
||||
poly = rwy_polys[2 * i + 1].get_poly();
|
||||
tri_b = polygon_tesselate_alt( poly );
|
||||
tc_b = rwy_calc_tex_coords( runways[i], 180.0, tri_b );
|
||||
rwy_tris.push_back( tri_b );
|
||||
rwy_txs.push_back( tc_b );
|
||||
rwy_polys[2 * i + 1].set_tris( tri_b );
|
||||
rwy_polys[2 * i + 1].set_texcoords( tc_b );
|
||||
rwy_polys[2 * i + 1].set_tri_mode( GL_TRIANGLES );
|
||||
}
|
||||
|
||||
cout << "Tesselating base" << endl;
|
||||
|
@ -782,9 +813,13 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
int_list tri_v;
|
||||
int_list tri_tc;
|
||||
|
||||
for ( int k = 0; k < (int)rwy_tris.size(); ++k ) {
|
||||
// for ( int k = 0; k < (int)rwy_tris.size(); ++k ) {
|
||||
for ( int k = 0; k < (int)rwy_polys.size(); ++k ) {
|
||||
cout << "tri " << k << endl;
|
||||
FGPolygon tri_poly = rwy_tris[k];
|
||||
// FGPolygon tri_poly = rwy_tris[k];
|
||||
FGPolygon tri_poly = rwy_polys[k].get_tris();
|
||||
FGPolygon tri_txs = rwy_polys[k].get_texcoords();
|
||||
string material = rwy_polys[k].get_material();
|
||||
for ( int i = 0; i < tri_poly.contours(); ++i ) {
|
||||
tri_v.clear();
|
||||
tri_tc.clear();
|
||||
|
@ -792,13 +827,13 @@ void build_airport( string airport_raw, string_list& runways_raw,
|
|||
p = tri_poly.get_pt( i, j );
|
||||
index = nodes.unique_add( p );
|
||||
tri_v.push_back( index );
|
||||
tc = rwy_txs[k].get_pt( i, j );
|
||||
tc = tri_txs.get_pt( i, j );
|
||||
index = texcoords.unique_add( tc );
|
||||
tri_tc.push_back( index );
|
||||
}
|
||||
tris_v.push_back( tri_v );
|
||||
tris_tc.push_back( tri_tc );
|
||||
tri_materials.push_back( "Concrete" );
|
||||
tri_materials.push_back( material );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,223 +48,6 @@
|
|||
#include "convex_hull.hxx"
|
||||
|
||||
|
||||
#if 0
|
||||
// write out airport data
|
||||
void write_airport( long int p_index, const FGPolygon& hull_list, FGBucket b,
|
||||
const string& root, const bool cut_and_keep ) {
|
||||
char tile_name[256], poly_index[256];
|
||||
|
||||
string base = b.gen_base_path();
|
||||
string path = root + "/" + base;
|
||||
string command = "mkdir -p " + path;
|
||||
system( command.c_str() );
|
||||
|
||||
long int b_index = b.gen_index();
|
||||
sprintf(tile_name, "%ld", b_index);
|
||||
string aptfile = path + "/" + tile_name;
|
||||
|
||||
sprintf( poly_index, "%ld", p_index );
|
||||
aptfile += ".";
|
||||
aptfile += poly_index;
|
||||
cout << "apt file = " << aptfile << endl;
|
||||
|
||||
FILE *fd;
|
||||
if ( (fd = fopen(aptfile.c_str(), "a")) == NULL ) {
|
||||
cout << "Cannot open file: " << aptfile << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// polygon type
|
||||
if ( cut_and_keep ) {
|
||||
fprintf( fd, "AirportKeep\n" );
|
||||
} else {
|
||||
fprintf( fd, "AirportIgnore\n" );
|
||||
}
|
||||
|
||||
// number of contours
|
||||
fprintf( fd, "1\n" );
|
||||
|
||||
// size of first contour
|
||||
fprintf( fd, "%d\n", hull_list.contour_size(0) );
|
||||
|
||||
// hole flag
|
||||
fprintf( fd, "%d\n", 0 ); // not a hole
|
||||
|
||||
// write contour (polygon) points
|
||||
for ( int i = 0; i < hull_list.contour_size(0); ++i ) {
|
||||
fprintf( fd, "%.7f %.7f\n",
|
||||
hull_list.get_pt(0,i).x(),
|
||||
hull_list.get_pt(0,i).y() );
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
||||
// process and airport + runway list
|
||||
void process_airport( string airport, list < string > & runways_list,
|
||||
const string& root ) {
|
||||
FGPolygon rwy_list, hull;
|
||||
point_list apt_list;
|
||||
|
||||
// parse main airport information
|
||||
int elev;
|
||||
|
||||
cout << airport << endl;
|
||||
string apt_type = airport.substr(0, 1);
|
||||
string apt_code = airport.substr(2, 4); my_chomp(apt_code);
|
||||
string apt_lat = airport.substr(7, 10);
|
||||
string apt_lon = airport.substr(18, 11);
|
||||
string apt_elev = airport.substr(30, 5);
|
||||
sscanf( apt_elev.c_str(), "%d", &elev );
|
||||
string apt_use = airport.substr(36, 1);
|
||||
string apt_twr = airport.substr(37, 1);
|
||||
string apt_bldg = airport.substr(38, 1);
|
||||
string apt_name = airport.substr(40);
|
||||
|
||||
/*
|
||||
cout << " type = " << apt_type << endl;
|
||||
cout << " code = " << apt_code << endl;
|
||||
cout << " lat = " << apt_lat << endl;
|
||||
cout << " lon = " << apt_lon << endl;
|
||||
cout << " elev = " << apt_elev << " " << elev << endl;
|
||||
cout << " use = " << apt_use << endl;
|
||||
cout << " twr = " << apt_twr << endl;
|
||||
cout << " bldg = " << apt_bldg << endl;
|
||||
cout << " name = " << apt_name << endl;
|
||||
*/
|
||||
|
||||
// Ignore any seaplane bases
|
||||
if ( apt_type == "S" ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// parse runways and generate the vertex list
|
||||
string rwy_str;
|
||||
double lon, lat, hdg;
|
||||
int len, width;
|
||||
|
||||
list < string >::iterator last_runway = runways_list.end();
|
||||
for ( list < string >::iterator current_runway = runways_list.begin();
|
||||
current_runway != last_runway ; ++current_runway ) {
|
||||
rwy_str = (*current_runway);
|
||||
|
||||
cout << rwy_str << endl;
|
||||
string rwy_no = rwy_str.substr(2, 4);
|
||||
string rwy_lat = rwy_str.substr(6, 10);
|
||||
sscanf( rwy_lat.c_str(), "%lf", &lat);
|
||||
string rwy_lon = rwy_str.substr(17, 11);
|
||||
sscanf( rwy_lon.c_str(), "%lf", &lon);
|
||||
string rwy_hdg = rwy_str.substr(29, 7);
|
||||
sscanf( rwy_hdg.c_str(), "%lf", &hdg);
|
||||
string rwy_len = rwy_str.substr(36, 7);
|
||||
sscanf( rwy_len.c_str(), "%d", &len);
|
||||
string rwy_width = rwy_str.substr(43, 4);
|
||||
sscanf( rwy_width.c_str(), "%d", &width);
|
||||
string rwy_sfc = rwy_str.substr(47, 4);
|
||||
string rwy_end1 = rwy_str.substr(52, 8);
|
||||
string rwy_end2 = rwy_str.substr(61, 8);
|
||||
|
||||
/*
|
||||
cout << " no = " << rwy_no << endl;
|
||||
cout << " lat = " << rwy_lat << " " << lat << endl;
|
||||
cout << " lon = " << rwy_lon << " " << lon << endl;
|
||||
cout << " hdg = " << rwy_hdg << " " << hdg << endl;
|
||||
cout << " len = " << rwy_len << " " << len << endl;
|
||||
cout << " width = " << rwy_width << " " << width << endl;
|
||||
cout << " sfc = " << rwy_sfc << endl;
|
||||
cout << " end1 = " << rwy_end1 << endl;
|
||||
cout << " end2 = " << rwy_end2 << endl;
|
||||
*/
|
||||
|
||||
rwy_list = gen_runway_area( lon, lat, hdg * DEG_TO_RAD,
|
||||
(double)len * FEET_TO_METER,
|
||||
(double)width * FEET_TO_METER );
|
||||
|
||||
// add rwy_list to apt_list
|
||||
for (int i = 0; i < (int)rwy_list.contour_size(0); ++i ) {
|
||||
apt_list.push_back( rwy_list.get_pt(0,i) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( apt_list.size() == 0 ) {
|
||||
cout << "no runway points generated" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// printf("Runway points in degrees\n");
|
||||
// current = apt_list.begin();
|
||||
// last = apt_list.end();
|
||||
// for ( ; current != last; ++current ) {
|
||||
// printf( "%.5f %.5f\n", current->lon, current->lat );
|
||||
// }
|
||||
// printf("\n");
|
||||
|
||||
// generate convex hull
|
||||
hull = convex_hull(apt_list);
|
||||
|
||||
// get next polygon index
|
||||
long int index = poly_index_next();
|
||||
|
||||
// find average center, min, and max point of convex hull
|
||||
Point3D min(200.0), max(-200.0);
|
||||
double sum_x, sum_y;
|
||||
int count = hull.contour_size(0);
|
||||
sum_x = sum_y = 0.0;
|
||||
for ( int i = 0; i < count; ++i ) {
|
||||
// printf("return = %.6f %.6f\n", (*current).x, (*current).y);
|
||||
Point3D p = hull.get_pt( 0, i );
|
||||
sum_x += p.x();
|
||||
sum_y += p.y();
|
||||
|
||||
if ( p.x() < min.x() ) { min.setx( p.x() ); }
|
||||
if ( p.y() < min.y() ) { min.sety( p.y() ); }
|
||||
if ( p.x() > max.x() ) { max.setx( p.x() ); }
|
||||
if ( p.y() > max.y() ) { max.sety( p.y() ); }
|
||||
}
|
||||
Point3D average( sum_x / count, sum_y / count, 0 );
|
||||
|
||||
// find buckets for center, min, and max points of convex hull.
|
||||
// note to self: self, you should think about checking for runways
|
||||
// that span the data line
|
||||
FGBucket b(average.x(), average.y());
|
||||
FGBucket b_min(min.x(), min.y());
|
||||
FGBucket b_max(max.x(), max.y());
|
||||
cout << "Bucket center = " << b << endl;
|
||||
cout << "Bucket min = " << b_min << endl;
|
||||
cout << "Bucket max = " << b_max << endl;
|
||||
|
||||
if ( b_min == b_max ) {
|
||||
write_airport( index, hull, b, root, true );
|
||||
} else {
|
||||
FGBucket b_cur;
|
||||
int dx, dy, i, j;
|
||||
|
||||
fgBucketDiff(b_min, b_max, &dx, &dy);
|
||||
cout << "airport spans tile boundaries" << endl;
|
||||
cout << " dx = " << dx << " dy = " << dy << endl;
|
||||
|
||||
if ( (dx > 2) || (dy > 2) ) {
|
||||
cout << "somethings really wrong!!!!" << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for ( j = 0; j <= dy; j++ ) {
|
||||
for ( i = 0; i <= dx; i++ ) {
|
||||
b_cur = fgBucketOffset(min.x(), min.y(), i, j);
|
||||
if ( b_cur == b ) {
|
||||
write_airport( index, hull, b_cur, root, true );
|
||||
} else {
|
||||
write_airport( index, hull, b_cur, root, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
// string answer; cin >> answer;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// reads the apt_full file and extracts and processes the individual
|
||||
// airport records
|
||||
int main( int argc, char **argv ) {
|
||||
|
|
|
@ -46,6 +46,13 @@ struct FGRunway {
|
|||
string surface_flags;
|
||||
string end1_flags;
|
||||
string end2_flags;
|
||||
|
||||
FGPolygon threshold;
|
||||
FGPolygon tens, tens_margin, ones, ones_margin;
|
||||
FGPolygon letter, letter_margin_left, letter_margin_right;
|
||||
FGPolygon pre_td_zone;
|
||||
FGPolygon td3_zone, td2_zone, td1a_zone, td1b_zone;
|
||||
FGPolygon aim_point;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue