Loop construct tweaks for STL usage.
Output airport file to be used to generate airport scenery on the fly by the run time sim.
This commit is contained in:
parent
a113722755
commit
2e30b5bdb6
3 changed files with 87 additions and 124 deletions
|
@ -80,10 +80,9 @@ batch_cart_to_polar_2d( list < point2d > in_list)
|
|||
|
||||
current = in_list.begin();
|
||||
last = in_list.end();
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
p = cart_to_polar_2d( *current );
|
||||
out_list.push_back(p);
|
||||
++current;
|
||||
}
|
||||
|
||||
return out_list;
|
||||
|
@ -125,13 +124,12 @@ gen_area(point2d origin, double angle, list < point2d > cart_list)
|
|||
// printf("Rotating points by %.2f\n", angle);
|
||||
current = rad_list.begin();
|
||||
last = rad_list.end();
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
current->theta -= angle;
|
||||
while ( current->theta > FG_2PI ) {
|
||||
current->theta -= FG_2PI;
|
||||
}
|
||||
// printf("(%.2f, %.2f)\n", current->theta, current->dist);
|
||||
++current;
|
||||
}
|
||||
// printf("\n");
|
||||
|
||||
|
@ -140,14 +138,13 @@ gen_area(point2d origin, double angle, list < point2d > cart_list)
|
|||
// origin.lon, origin.lat);
|
||||
current = rad_list.begin();
|
||||
last = rad_list.end();
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
p = calc_lon_lat(origin_rad, *current);
|
||||
// convert from radians to degress
|
||||
p.lon *= RAD_TO_DEG;
|
||||
p.lat *= RAD_TO_DEG;
|
||||
// printf("(%.8f, %.8f)\n", p.lon, p.lat);
|
||||
result_list.push_back(p);
|
||||
++current;
|
||||
}
|
||||
// printf("\n");
|
||||
|
||||
|
@ -218,6 +215,11 @@ gen_runway_area( double lon, double lat, double heading,
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.4 1998/09/09 20:59:53 curt
|
||||
// Loop construct tweaks for STL usage.
|
||||
// Output airport file to be used to generate airport scenery on the fly
|
||||
// by the run time sim.
|
||||
//
|
||||
// Revision 1.3 1998/09/09 16:26:31 curt
|
||||
// Continued progress in implementing the convex hull algorithm.
|
||||
//
|
||||
|
|
|
@ -94,7 +94,7 @@ bool test_point(point2d Pa, point2d Pb, point2d Pc) {
|
|||
a1 = calc_angle(a, b, origin);
|
||||
a2 = calc_angle(origin, b, c);
|
||||
|
||||
printf("a1 = %.2f a2 = %.2f\n", a1 * RAD_TO_DEG, a2 * RAD_TO_DEG);
|
||||
// printf("a1 = %.2f a2 = %.2f\n", a1 * RAD_TO_DEG, a2 * RAD_TO_DEG);
|
||||
|
||||
return ( (a1 + a2) < FG_PI );
|
||||
}
|
||||
|
@ -127,29 +127,26 @@ list_container convex_hull( list_container input_list )
|
|||
in_count = input_list.size();
|
||||
sum_x = sum_y = 0.0;
|
||||
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
sum_x += (*current).x;
|
||||
sum_y += (*current).y;
|
||||
|
||||
++current;
|
||||
}
|
||||
|
||||
average.x = sum_x / in_count;
|
||||
average.y = sum_y / in_count;
|
||||
|
||||
printf("Average center point is %.4f %.4f\n", average.x, average.y);
|
||||
// printf("Average center point is %.4f %.4f\n", average.x, average.y);
|
||||
|
||||
// STEP TWO: Translate input points so average is at origin
|
||||
current = input_list.begin();
|
||||
last = input_list.end();
|
||||
trans_list.erase( trans_list.begin(), trans_list.end() );
|
||||
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
p.x = (*current).x - average.x;
|
||||
p.y = (*current).y - average.y;
|
||||
printf("%.6f %.6f\n", p.x, p.y);
|
||||
// printf("%.6f %.6f\n", p.x, p.y);
|
||||
trans_list.push_back(p);
|
||||
++current;
|
||||
}
|
||||
|
||||
// STEP THREE: convert to radians and sort by theta
|
||||
|
@ -157,34 +154,31 @@ list_container convex_hull( list_container input_list )
|
|||
last = trans_list.end();
|
||||
radians_map.erase( radians_map.begin(), radians_map.end() );
|
||||
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current) {
|
||||
p = cart_to_polar_2d(*current);
|
||||
if ( p.dist > radians_map[p.theta] ) {
|
||||
radians_map[p.theta] = p.dist;
|
||||
}
|
||||
++current;
|
||||
}
|
||||
|
||||
printf("Sorted list\n");
|
||||
// printf("Sorted list\n");
|
||||
map_current = radians_map.begin();
|
||||
map_last = radians_map.end();
|
||||
while ( map_current != map_last ) {
|
||||
for ( ; map_current != map_last ; ++map_current ) {
|
||||
p.x = (*map_current).first;
|
||||
p.y = (*map_current).second;
|
||||
|
||||
printf("p is %.6f %.6f\n", p.x, p.y);
|
||||
|
||||
++map_current;
|
||||
// printf("p is %.6f %.6f\n", p.x, p.y);
|
||||
}
|
||||
|
||||
// STEP FOUR: traverse the sorted list and eliminate everything
|
||||
// not on the perimeter.
|
||||
printf("Traversing list\n");
|
||||
// printf("Traversing list\n");
|
||||
|
||||
// double check list size ... this should never fail because a
|
||||
// single runway will always generate four points.
|
||||
if ( radians_map.size() < 3 ) {
|
||||
printf("convex hull not possible with < 3 points\n");
|
||||
// printf("convex hull not possible with < 3 points\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -192,7 +186,7 @@ list_container convex_hull( list_container input_list )
|
|||
last_size = radians_map.size() + 1;
|
||||
|
||||
while ( last_size > radians_map.size() ) {
|
||||
printf("Running an iteration of the graham scan algorithm\n");
|
||||
// printf("Running an iteration of the graham scan algorithm\n");
|
||||
last_size = radians_map.size();
|
||||
|
||||
map_current = radians_map.begin();
|
||||
|
@ -224,11 +218,11 @@ list_container convex_hull( list_container input_list )
|
|||
// printf("Pc is %.6f %.6f\n", Pc.theta, Pc.dist);
|
||||
|
||||
if ( test_point(Pa, Pb, Pc) ) {
|
||||
printf("Accepted a point\n");
|
||||
// printf("Accepted a point\n");
|
||||
// accept point, advance Pa, Pb, and Pc.
|
||||
++map_current;
|
||||
} else {
|
||||
printf("REJECTED A POINT\n");
|
||||
// printf("REJECTED A POINT\n");
|
||||
// reject point, delete it and advance only Pb and Pc
|
||||
map_next = map_current;
|
||||
++map_next;
|
||||
|
@ -245,18 +239,16 @@ list_container convex_hull( list_container input_list )
|
|||
con_hull.erase( con_hull.begin(), con_hull.end() );
|
||||
map_current = radians_map.begin();
|
||||
map_last = radians_map.end();
|
||||
while ( map_current != map_last ) {
|
||||
for ( ; map_current != map_last ; ++map_current ) {
|
||||
p.theta = (*map_current).first;
|
||||
p.dist = (*map_current).second;
|
||||
|
||||
result.x = cos(p.theta) * p.dist + average.x;
|
||||
result.y = sin(p.theta) * p.dist + average.x;
|
||||
result.y = sin(p.theta) * p.dist + average.y;
|
||||
|
||||
printf("%.6f %.6f\n", result.x, result.y);
|
||||
|
||||
con_hull.push_back(result);
|
||||
|
||||
++map_current;
|
||||
}
|
||||
|
||||
return con_hull;
|
||||
|
@ -264,6 +256,11 @@ list_container convex_hull( list_container input_list )
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.3 1998/09/09 20:59:55 curt
|
||||
// Loop construct tweaks for STL usage.
|
||||
// Output airport file to be used to generate airport scenery on the fly
|
||||
// by the run time sim.
|
||||
//
|
||||
// Revision 1.2 1998/09/09 16:26:32 curt
|
||||
// Continued progress in implementing the convex hull algorithm.
|
||||
//
|
||||
|
|
|
@ -62,14 +62,15 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
fgBUCKET b;
|
||||
long int index;
|
||||
char base[256], tmp[256];
|
||||
string path, command, exfile, file;
|
||||
string path, command, exfile, file, aptfile;
|
||||
int i, count;
|
||||
|
||||
printf( "(apt) %s", last_airport.c_str() );
|
||||
|
||||
while ( runway_list.size() ) {
|
||||
line_str = runway_list.front();
|
||||
runway_list.pop_front();
|
||||
list < string >::iterator last_runway = runway_list.end();
|
||||
for ( list < string >::iterator current_runway = runway_list.begin();
|
||||
current_runway != last_runway ; ++current_runway ) {
|
||||
line_str = (*current_runway);
|
||||
printf( "%s", line_str.c_str() );
|
||||
|
||||
sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
|
||||
|
@ -83,19 +84,17 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
// add rwy_list to apt_list
|
||||
current = rwy_list.begin();
|
||||
last = rwy_list.end();
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
apt_list.push_back(*current);
|
||||
++current;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Runway points in degrees\n");
|
||||
current = apt_list.begin();
|
||||
last = apt_list.end();
|
||||
while ( current != last ) {
|
||||
for ( ; current != last; ++current ) {
|
||||
// printf( "(%.4f, %.4f)\n",
|
||||
printf( "%.5f %.5f\n", current->lon, current->lat );
|
||||
++current;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
@ -108,20 +107,19 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
current = hull_list.begin();
|
||||
last = hull_list.end();
|
||||
sum_x = sum_y = 0.0;
|
||||
while ( current != last ) {
|
||||
for ( ; current != last; ++current ) {
|
||||
// printf("return = %.6f %.6f\n", (*current).x, (*current).y);
|
||||
sum_x += (*current).x;
|
||||
sum_y += (*current).y;
|
||||
|
||||
++current;
|
||||
}
|
||||
|
||||
average.x = sum_x / count;
|
||||
average.y = sum_y / count;
|
||||
|
||||
// find bucket based on first point in hull list. Eventually
|
||||
// we'll need to handle cases where the area crosses bucket
|
||||
// boundaries.
|
||||
fgBucketFind( (*current).lon, (*current).lat, &b);
|
||||
// find bucket based on average center point of hull list.
|
||||
// Eventually we'll need to handle cases where the area crosses
|
||||
// bucket boundaries.
|
||||
fgBucketFind( average.lon, average.lat, &b);
|
||||
printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
|
||||
b.lon, b.lat, b.x, b.y);
|
||||
|
||||
|
@ -132,10 +130,12 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
system( command.c_str() );
|
||||
|
||||
sprintf(tmp, "%ld", index);
|
||||
exfile = path + "/" + tmp + ".node.ex";
|
||||
file = path + "/" + tmp + ".poly";
|
||||
exfile = path + "/" + tmp + ".node.ex";
|
||||
file = path + "/" + tmp + ".poly";
|
||||
aptfile = path + "/" + tmp + ".apt";
|
||||
printf( "extra node file = %s\n", exfile.c_str() );
|
||||
printf( "poly file = %s\n", file.c_str() );
|
||||
printf( "apt file = %s\n", aptfile.c_str() );
|
||||
|
||||
// output exclude nodes
|
||||
printf("Output exclude nodes\n");
|
||||
|
@ -149,16 +149,17 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
current = hull_list.begin();
|
||||
last = hull_list.end();
|
||||
i = 1;
|
||||
while ( current != last ) {
|
||||
for ( ; current != last ; ++current ) {
|
||||
// printf( "(%.4f, %.4f)\n",
|
||||
fprintf( fd, "%d %.2f %.2f %.2f\n", i,
|
||||
(*current).lon * 3600.0, (*current).lat * 3600.0, elev);
|
||||
++current;
|
||||
(*current).lon * 3600.0, (*current).lat * 3600.0,
|
||||
(double)elev * FEET_TO_METER );
|
||||
++i;
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
// output poly
|
||||
printf("Output poly\n");
|
||||
if ( (fd = fopen(file.c_str(), "w")) == NULL ) {
|
||||
printf("Cannot open file: %s\n", file.c_str());
|
||||
exit(-1);
|
||||
|
@ -179,6 +180,34 @@ void process_airport( string last_airport, list < string > & runway_list,
|
|||
fprintf( fd, "1 %.2f %.2f\n", average.x * 3600.0, average.y * 3600);
|
||||
|
||||
fclose(fd);
|
||||
|
||||
// output "apt" file
|
||||
printf("Output airport\n");
|
||||
if ( (fd = fopen(aptfile.c_str(), "w")) == NULL ) {
|
||||
printf("Cannot open file: %s\n", aptfile.c_str());
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// write main airport identifier
|
||||
fprintf(fd, "a %s", last_airport.c_str() );
|
||||
|
||||
// write perimeter polygon
|
||||
current = hull_list.begin();
|
||||
last = hull_list.end();
|
||||
for ( ; current != last ; ++current ) {
|
||||
fprintf( fd, "p %.7f %.7f %.2f\n", (*current).lon, (*current).lat,
|
||||
(double)elev * FEET_TO_METER );
|
||||
}
|
||||
|
||||
// write runway info
|
||||
for ( list < string >::iterator current_runway = runway_list.begin();
|
||||
current_runway != last_runway ; ++current_runway ) {
|
||||
line_str = (*current_runway);
|
||||
line_str = line_str.substr(1, line_str.size());
|
||||
fprintf(fd, "r %s", line_str.c_str() );
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,6 +262,9 @@ int main( int argc, char **argv ) {
|
|||
process_airport(last_airport, runway_list, argv[2]);
|
||||
}
|
||||
|
||||
// clear runway list for start of next airport
|
||||
runway_list.erase(runway_list.begin(), runway_list.end());
|
||||
|
||||
last_airport = airport;
|
||||
}
|
||||
}
|
||||
|
@ -248,78 +280,10 @@ int main( int argc, char **argv ) {
|
|||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// P13 (Globe, AZ)
|
||||
// lon = -110.6642442;
|
||||
// lat = 33.3528903;
|
||||
// heading = 102.0 * DEG_TO_RAD;
|
||||
// length = 1769;
|
||||
// width = 23;
|
||||
|
||||
// KANE
|
||||
lon = -93.2113889;
|
||||
lat = 45.145;
|
||||
elevation = 912 * FEET_TO_METER;
|
||||
heading = 270.0 * DEG_TO_RAD;
|
||||
length = 1220;
|
||||
width = 23;
|
||||
|
||||
gen_runway_area( lon * DEG_TO_RAD, lat * DEG_TO_RAD,
|
||||
heading, length, width, nodes, &count );
|
||||
|
||||
fgBucketFind(lon, lat, &b);
|
||||
printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
|
||||
b.lon, b.lat, b.x, b.y);
|
||||
|
||||
index = fgBucketGenIndex(&b);
|
||||
fgBucketGenBasePath(&b, base);
|
||||
sprintf(path, "%s/Scenery/%s", argv[1], base);
|
||||
sprintf(command, "mkdir -p %s\n", path);
|
||||
system(command);
|
||||
|
||||
sprintf(exfile, "%s/%ld.node.ex", path, index);
|
||||
sprintf(file, "%s/%ld.poly", path, index);
|
||||
printf( "extra node file = %s\n", exfile);
|
||||
printf( "poly file = %s\n", file);
|
||||
|
||||
// output extra nodes
|
||||
if ( (fd = fopen(exfile, "w")) == NULL ) {
|
||||
printf("Cannot open file: %s\n", exfile);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
fprintf(fd, "%d 2 0 0\n", count);
|
||||
for ( i = 0; i < count; i++ ) {
|
||||
fprintf( fd, "%d %.2f %.2f %.2f\n", i + 1,
|
||||
nodes[i].lon * RAD_TO_ARCSEC, nodes[i].lat * RAD_TO_ARCSEC,
|
||||
elevation);
|
||||
}
|
||||
fclose(fd);
|
||||
|
||||
// output poly
|
||||
if ( (fd = fopen(file, "w")) == NULL ) {
|
||||
printf("Cannot open file: %s\n", file);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// output empty node list
|
||||
fprintf(fd, "0 2 0 0\n");
|
||||
|
||||
// output segments
|
||||
fprintf(fd, "%d 0\n", count);
|
||||
for ( i = 0; i < count - 1; i++ ) {
|
||||
fprintf( fd, "%d %d %d\n", i + 1, i + 1, i + 2 );
|
||||
}
|
||||
fprintf( fd, "%d %d %d\n", count, count, 1 );
|
||||
|
||||
// output hole center
|
||||
fprintf( fd, "1\n");
|
||||
fprintf( fd, "1 %.2f %.2f\n", lon * 3600.0, lat * 3600);
|
||||
|
||||
fclose(fd);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// $Log: main.c,v
|
||||
// $Log$
|
||||
// Revision 1.4 1998/09/09 20:59:56 curt
|
||||
// Loop construct tweaks for STL usage.
|
||||
// Output airport file to be used to generate airport scenery on the fly
|
||||
// by the run time sim.
|
||||
//
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue