Start of scenery revamp project.
This commit is contained in:
parent
d6b38f2eea
commit
b1eb65cd5d
2 changed files with 124 additions and 140 deletions
GenAirports
|
@ -34,6 +34,8 @@ genapts_SOURCES = \
|
||||||
|
|
||||||
genapts_LDADD = \
|
genapts_LDADD = \
|
||||||
$(top_builddir)/Lib/Bucket/libBucket.a \
|
$(top_builddir)/Lib/Bucket/libBucket.a \
|
||||||
|
$(top_builddir)/Lib/Debug/libDebug.a \
|
||||||
|
$(top_builddir)/Lib/Misc/libMisc.a \
|
||||||
$(top_builddir)/Lib/zlib/libz.a \
|
$(top_builddir)/Lib/zlib/libz.a \
|
||||||
$(base_LIBS)
|
$(base_LIBS)
|
||||||
|
|
||||||
|
@ -42,6 +44,9 @@ INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.4 1999/02/11 01:10:50 curt
|
||||||
|
# Start of scenery revamp project.
|
||||||
|
#
|
||||||
# Revision 1.3 1998/11/04 23:01:54 curt
|
# Revision 1.3 1998/11/04 23:01:54 curt
|
||||||
# Changes to the automake/autoconf system to reduce the number of libraries
|
# Changes to the automake/autoconf system to reduce the number of libraries
|
||||||
# that are unnecessarily linked into the various executables.
|
# that are unnecessarily linked into the various executables.
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Include/compiler.h>
|
||||||
|
|
||||||
#ifdef HAVE_STDLIB_H
|
#ifdef HAVE_STDLIB_H
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -34,16 +36,55 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include STL_STRING
|
||||||
|
|
||||||
#include <Bucket/bucketutils.h>
|
#include <Bucket/newbucket.hxx>
|
||||||
|
#include <Debug/logstream.hxx>
|
||||||
#include <Include/fg_constants.h>
|
#include <Include/fg_constants.h>
|
||||||
#include <Include/fg_zlib.h>
|
#include <Misc/fgstream.hxx>
|
||||||
|
|
||||||
#include "area.hxx"
|
#include "area.hxx"
|
||||||
#include "convex_hull.hxx"
|
#include "convex_hull.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
// write out airport data
|
||||||
|
void write_airport( list_container hull_list, FGBucket b, const string& root,
|
||||||
|
const bool cut_and_keep ) {
|
||||||
|
char tmp[256];
|
||||||
|
|
||||||
|
long int index = b.gen_index();
|
||||||
|
string base = b.gen_base_path();
|
||||||
|
string path = root + "/Scenery/" + base;
|
||||||
|
string command = "mkdir -p " + path;
|
||||||
|
system( command.c_str() );
|
||||||
|
|
||||||
|
sprintf(tmp, "%ld", index);
|
||||||
|
string aptfile = path + "/" + tmp + ".apt";
|
||||||
|
cout << "apt file = " << aptfile << endl;
|
||||||
|
|
||||||
|
FILE *fd;
|
||||||
|
if ( (fd = fopen(aptfile.c_str(), "a")) == NULL ) {
|
||||||
|
cout << "Cannot open file: " << aptfile << endl;
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( cut_and_keep ) {
|
||||||
|
fprintf( fd, "cut_and_keep\n" );
|
||||||
|
} else {
|
||||||
|
fprintf( fd, "cut_and_ignore\n" );
|
||||||
|
}
|
||||||
|
fprintf( fd, "%d\n", hull_list.size() );
|
||||||
|
// write perimeter polygon
|
||||||
|
list_iterator current = hull_list.begin();
|
||||||
|
list_iterator last = hull_list.end();
|
||||||
|
for ( ; current != last ; ++current ) {
|
||||||
|
fprintf( fd, "%.7f %.7f\n", (*current).lon, (*current).lat );
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// process and airport + runway list
|
// process and airport + runway list
|
||||||
void process_airport( string last_airport, list < string > & runway_list,
|
void process_airport( string last_airport, list < string > & runway_list,
|
||||||
const string& root ) {
|
const string& root ) {
|
||||||
|
@ -52,26 +93,19 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
|
|
||||||
string line_str;
|
string line_str;
|
||||||
double lon, lat;
|
double lon, lat;
|
||||||
|
// int i;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
// generate the vertices of all the runways
|
||||||
int len, width, hdg, label_hdg, elev;
|
int len, width, hdg, label_hdg, elev;
|
||||||
char codes[10];
|
char codes[10];
|
||||||
char side;
|
char side;
|
||||||
point2d average;
|
cout << "(apt) " << last_airport;
|
||||||
double sum_x, sum_y;
|
|
||||||
|
|
||||||
FILE *fd;
|
|
||||||
fgBUCKET b;
|
|
||||||
long int index;
|
|
||||||
char base[256], tmp[256];
|
|
||||||
string path, command, exfile, file, aptfile;
|
|
||||||
int i, count;
|
|
||||||
|
|
||||||
printf( "(apt) %s", last_airport.c_str() );
|
|
||||||
|
|
||||||
list < string >::iterator last_runway = runway_list.end();
|
list < string >::iterator last_runway = runway_list.end();
|
||||||
for ( list < string >::iterator current_runway = runway_list.begin();
|
for ( list < string >::iterator current_runway = runway_list.begin();
|
||||||
current_runway != last_runway ; ++current_runway ) {
|
current_runway != last_runway ; ++current_runway ) {
|
||||||
line_str = (*current_runway);
|
line_str = (*current_runway);
|
||||||
printf( "%s", line_str.c_str() );
|
cout << line_str;
|
||||||
|
|
||||||
sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
|
sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
|
||||||
&lon, &lat, &len, &width, &hdg, codes, &label_hdg,
|
&lon, &lat, &len, &width, &hdg, codes, &label_hdg,
|
||||||
|
@ -90,123 +124,75 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf("Runway points in degrees\n");
|
// printf("Runway points in degrees\n");
|
||||||
current = apt_list.begin();
|
// current = apt_list.begin();
|
||||||
last = apt_list.end();
|
// last = apt_list.end();
|
||||||
for ( ; current != last; ++current ) {
|
// for ( ; current != last; ++current ) {
|
||||||
// printf( "%.5f %.5f\n", current->lon, current->lat );
|
// printf( "%.5f %.5f\n", current->lon, current->lat );
|
||||||
}
|
// }
|
||||||
// printf("\n");
|
// printf("\n");
|
||||||
|
|
||||||
// generate convex hull
|
// generate convex hull
|
||||||
hull_list = convex_hull(apt_list);
|
hull_list = convex_hull(apt_list);
|
||||||
|
|
||||||
// find average center point of convex hull
|
// find average center, min, and max point of convex hull
|
||||||
|
point2d average, min, max;
|
||||||
|
double sum_x, sum_y;
|
||||||
count = hull_list.size();
|
count = hull_list.size();
|
||||||
|
|
||||||
current = hull_list.begin();
|
current = hull_list.begin();
|
||||||
last = hull_list.end();
|
last = hull_list.end();
|
||||||
sum_x = sum_y = 0.0;
|
sum_x = sum_y = 0.0;
|
||||||
|
min.x = min.y = 200.0;
|
||||||
|
max.x = max.y = -200.0;
|
||||||
for ( ; current != last; ++current ) {
|
for ( ; current != last; ++current ) {
|
||||||
// printf("return = %.6f %.6f\n", (*current).x, (*current).y);
|
// printf("return = %.6f %.6f\n", (*current).x, (*current).y);
|
||||||
sum_x += (*current).x;
|
sum_x += (*current).x;
|
||||||
sum_y += (*current).y;
|
sum_y += (*current).y;
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( (*current).x < min.x ) { min.x = (*current).x; }
|
||||||
|
if ( (*current).y < min.y ) { min.y = (*current).y; }
|
||||||
|
if ( (*current).x > max.x ) { max.x = (*current).x; }
|
||||||
|
if ( (*current).y > max.y ) { max.y = (*current).y; }
|
||||||
|
}
|
||||||
average.x = sum_x / count;
|
average.x = sum_x / count;
|
||||||
average.y = sum_y / count;
|
average.y = sum_y / count;
|
||||||
|
|
||||||
// find bucket based on average center point of hull list.
|
// find buckets for center, min, and max points of convex hull.
|
||||||
// Eventually we'll need to handle cases where the area crosses
|
// note to self: self, you should think about checking for runways
|
||||||
// bucket boundaries.
|
// that span the data line
|
||||||
fgBucketFind( average.lon, average.lat, &b);
|
FGBucket b(average.lon, average.lat);
|
||||||
printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
|
FGBucket b_min(min.x, min.y);
|
||||||
b.lon, b.lat, b.x, b.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;
|
||||||
|
|
||||||
index = fgBucketGenIndex(&b);
|
if ( b_min == b_max ) {
|
||||||
fgBucketGenBasePath(&b, base);
|
write_airport( hull_list, b, root, true );
|
||||||
path = root + "/Scenery/" + base;
|
} else {
|
||||||
command = "mkdir -p " + path;
|
FGBucket b_cur;
|
||||||
system( command.c_str() );
|
int dx, dy, i, j;
|
||||||
|
|
||||||
sprintf(tmp, "%ld", index);
|
fgBucketDiff(b_min, b_max, &dx, &dy);
|
||||||
exfile = path + "/" + tmp + ".node.ex";
|
cout << "airport spans tile boundaries" << endl;
|
||||||
file = path + "/" + tmp + ".poly";
|
cout << " dx = " << dx << " dy = " << dy << endl;
|
||||||
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
|
if ( (dx > 1) || (dy > 1) ) {
|
||||||
printf("Output exclude nodes\n");
|
cout << "somethings really wrong!!!!" << endl;
|
||||||
if ( (fd = fopen(exfile.c_str(), "w")) == NULL ) {
|
exit(-1);
|
||||||
printf("Cannot open file: %s\n", exfile.c_str());
|
}
|
||||||
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( hull_list, b_cur, root, true );
|
||||||
|
} else {
|
||||||
|
write_airport( hull_list, b_cur, root, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// string answer; cin >> answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf( fd, "%d 2 0 0\n", count );
|
|
||||||
|
|
||||||
current = hull_list.begin();
|
|
||||||
last = hull_list.end();
|
|
||||||
i = 1;
|
|
||||||
for ( ; current != last ; ++current ) {
|
|
||||||
// printf( "(%.4f, %.4f)\n",
|
|
||||||
fprintf( fd, "%d %.2f %.2f %.2f\n", i,
|
|
||||||
(*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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// output empty node list
|
|
||||||
fprintf(fd, "0 2 0 0\n");
|
|
||||||
|
|
||||||
// output segments
|
|
||||||
fprintf( fd, "%d 0\n", count );
|
|
||||||
for ( i = 1; i < count; i++ ) {
|
|
||||||
fprintf( fd, "%d %d %d\n", i, i, i + 1 );
|
|
||||||
}
|
|
||||||
fprintf( fd, "%d %d %d\n", count, count, 1 );
|
|
||||||
|
|
||||||
// output hole center
|
|
||||||
fprintf( fd, "1\n");
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -214,38 +200,30 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
// airport records
|
// airport records
|
||||||
int main( int argc, char **argv ) {
|
int main( int argc, char **argv ) {
|
||||||
list < string > runway_list;
|
list < string > runway_list;
|
||||||
string apt_path, gz_apt_path;
|
|
||||||
string airport, last_airport;
|
string airport, last_airport;
|
||||||
fgFile f;
|
string line;
|
||||||
char line[256];
|
char tmp[256];
|
||||||
/*
|
|
||||||
fgBUCKET b;
|
fglog().setLogLevels( FG_ALL, FG_DEBUG );
|
||||||
point2d nodes[4];
|
|
||||||
char base[256], path[256], command[256], file[256], exfile[256];
|
|
||||||
double lon, lat, elevation, heading;
|
|
||||||
double length, width;
|
|
||||||
long int index;
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( argc != 3 ) {
|
if ( argc != 3 ) {
|
||||||
printf("Usage %s <apt_file> <work dir>\n", argv[0]);
|
FG_LOG( FG_GENERAL, FG_ALERT,
|
||||||
exit(0);
|
"Usage " << argv[0] << " <apt_file> <work dir>" );
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
apt_path = argv[1];
|
fg_gzifstream in( argv[1] );
|
||||||
gz_apt_path = apt_path + ".gz";
|
if ( !in ) {
|
||||||
|
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << argv[1] );
|
||||||
// first try "path.gz"
|
exit(-1);
|
||||||
if ( (f = fgopen(gz_apt_path.c_str(), "rb")) == NULL ) {
|
|
||||||
// next try "path"
|
|
||||||
if ( (f = fgopen(apt_path.c_str(), "rb")) == NULL ) {
|
|
||||||
printf( "Cannot open file: %s\n", apt_path.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( fggets(f, line, 250) != NULL ) {
|
while ( ! in.eof() ) {
|
||||||
// printf("%s", line);
|
in.getline(tmp, 256);
|
||||||
if ( strlen(line) == 0 ) {
|
line = tmp;
|
||||||
|
// cout << line << endl;
|
||||||
|
|
||||||
|
if ( line.length() == 0 ) {
|
||||||
// empty, skip
|
// empty, skip
|
||||||
} else if ( line[0] == '#' ) {
|
} else if ( line[0] == '#' ) {
|
||||||
// comment, skip
|
// comment, skip
|
||||||
|
@ -273,13 +251,14 @@ int main( int argc, char **argv ) {
|
||||||
process_airport(last_airport, runway_list, argv[2]);
|
process_airport(last_airport, runway_list, argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fgclose(f);
|
return 0;
|
||||||
|
|
||||||
return(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.6 1999/02/11 01:10:51 curt
|
||||||
|
// Start of scenery revamp project.
|
||||||
|
//
|
||||||
// Revision 1.5 1998/09/17 18:40:43 curt
|
// Revision 1.5 1998/09/17 18:40:43 curt
|
||||||
// Debug message tweaks.
|
// Debug message tweaks.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue