Modified to adhere to new polygon naming convention, and also to read the
new Robin Peel aiport format.
This commit is contained in:
parent
8de225f5bf
commit
78bca880ea
3 changed files with 130 additions and 36 deletions
|
@ -33,17 +33,22 @@ genapts_SOURCES = \
|
||||||
point2d.cxx point2d.hxx
|
point2d.cxx point2d.hxx
|
||||||
|
|
||||||
genapts_LDADD = \
|
genapts_LDADD = \
|
||||||
|
$(top_builddir)/Tools/Polygon/libPolygon.a \
|
||||||
$(top_builddir)/Lib/Bucket/libBucket.a \
|
$(top_builddir)/Lib/Bucket/libBucket.a \
|
||||||
$(top_builddir)/Lib/Debug/libDebug.a \
|
$(top_builddir)/Lib/Debug/libDebug.a \
|
||||||
$(top_builddir)/Lib/Misc/libMisc.a \
|
$(top_builddir)/Lib/Misc/libMisc.a \
|
||||||
$(top_builddir)/Lib/zlib/libz.a \
|
$(top_builddir)/Lib/zlib/libz.a \
|
||||||
$(base_LIBS)
|
$(base_LIBS)
|
||||||
|
|
||||||
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib
|
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Tools
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# $Log$
|
# $Log$
|
||||||
|
# Revision 1.5 1999/02/25 21:32:47 curt
|
||||||
|
# Modified to adhere to new polygon naming convention, and also to read the
|
||||||
|
# new Robin Peel aiport format.
|
||||||
|
#
|
||||||
# Revision 1.4 1999/02/11 01:10:50 curt
|
# Revision 1.4 1999/02/11 01:10:50 curt
|
||||||
# Start of scenery revamp project.
|
# Start of scenery revamp project.
|
||||||
#
|
#
|
||||||
|
|
|
@ -178,8 +178,8 @@ list_container convex_hull( list_container input_list )
|
||||||
// double check list size ... this should never fail because a
|
// double check list size ... this should never fail because a
|
||||||
// single runway will always generate four points.
|
// single runway will always generate four points.
|
||||||
if ( radians_map.size() < 3 ) {
|
if ( radians_map.size() < 3 ) {
|
||||||
// printf("convex hull not possible with < 3 points\n");
|
cout << "convex hull not possible with < 3 points" << endl;
|
||||||
exit(0);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that we run the while loop at least once
|
// ensure that we run the while loop at least once
|
||||||
|
@ -256,6 +256,10 @@ list_container convex_hull( list_container input_list )
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.5 1999/02/25 21:32:48 curt
|
||||||
|
// Modified to adhere to new polygon naming convention, and also to read the
|
||||||
|
// new Robin Peel aiport format.
|
||||||
|
//
|
||||||
// Revision 1.4 1998/09/17 18:40:42 curt
|
// Revision 1.4 1998/09/17 18:40:42 curt
|
||||||
// Debug message tweaks.
|
// Debug message tweaks.
|
||||||
//
|
//
|
||||||
|
|
|
@ -42,24 +42,29 @@
|
||||||
#include <Debug/logstream.hxx>
|
#include <Debug/logstream.hxx>
|
||||||
#include <Include/fg_constants.h>
|
#include <Include/fg_constants.h>
|
||||||
#include <Misc/fgstream.hxx>
|
#include <Misc/fgstream.hxx>
|
||||||
|
#include <Polygon/index.hxx>
|
||||||
|
|
||||||
#include "area.hxx"
|
#include "area.hxx"
|
||||||
#include "convex_hull.hxx"
|
#include "convex_hull.hxx"
|
||||||
|
|
||||||
|
|
||||||
// write out airport data
|
// write out airport data
|
||||||
void write_airport( list_container hull_list, FGBucket b, const string& root,
|
void write_airport( int p_index, list_container hull_list, FGBucket b,
|
||||||
const bool cut_and_keep ) {
|
const string& root, const bool cut_and_keep ) {
|
||||||
char tmp[256];
|
char tile_name[256], poly_index[256];
|
||||||
|
|
||||||
long int index = b.gen_index();
|
long int b_index = b.gen_index();
|
||||||
string base = b.gen_base_path();
|
string base = b.gen_base_path();
|
||||||
string path = root + "/Scenery/" + base;
|
string path = root + "/Scenery/" + base;
|
||||||
string command = "mkdir -p " + path;
|
string command = "mkdir -p " + path;
|
||||||
system( command.c_str() );
|
system( command.c_str() );
|
||||||
|
|
||||||
sprintf(tmp, "%ld", index);
|
sprintf(tile_name, "%ld", b_index);
|
||||||
string aptfile = path + "/" + tmp + ".apt";
|
string aptfile = path + "/" + tile_name;
|
||||||
|
|
||||||
|
sprintf( poly_index, "%d", p_index );
|
||||||
|
aptfile += ".";
|
||||||
|
aptfile += poly_index;
|
||||||
cout << "apt file = " << aptfile << endl;
|
cout << "apt file = " << aptfile << endl;
|
||||||
|
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
@ -69,9 +74,9 @@ void write_airport( list_container hull_list, FGBucket b, const string& root,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cut_and_keep ) {
|
if ( cut_and_keep ) {
|
||||||
fprintf( fd, "cut_and_keep\n" );
|
fprintf( fd, "AirportKeep\n" );
|
||||||
} else {
|
} else {
|
||||||
fprintf( fd, "cut_and_ignore\n" );
|
fprintf( fd, "AirportIgnore\n" );
|
||||||
}
|
}
|
||||||
fprintf( fd, "%d\n", hull_list.size() );
|
fprintf( fd, "%d\n", hull_list.size() );
|
||||||
// write perimeter polygon
|
// write perimeter polygon
|
||||||
|
@ -86,32 +91,77 @@ void write_airport( list_container hull_list, FGBucket b, const string& root,
|
||||||
|
|
||||||
|
|
||||||
// process and airport + runway list
|
// process and airport + runway list
|
||||||
void process_airport( string last_airport, list < string > & runway_list,
|
void process_airport( string airport, list < string > & runway_list,
|
||||||
const string& root ) {
|
const string& root ) {
|
||||||
list_container rwy_list, apt_list, hull_list;
|
list_container rwy_list, apt_list, hull_list;
|
||||||
list_iterator current, last;
|
list_iterator current, last;
|
||||||
|
|
||||||
string line_str;
|
// parse main airport information
|
||||||
double lon, lat;
|
int elev;
|
||||||
// int i;
|
|
||||||
int count;
|
cout << airport << endl;
|
||||||
|
string apt_type = airport.substr(0, 1);
|
||||||
|
string apt_code = airport.substr(2, 4);
|
||||||
|
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;
|
||||||
|
*/
|
||||||
|
|
||||||
|
// parse runways and generate the vertex list
|
||||||
|
string rwy_str;
|
||||||
|
double lon, lat, hdg;
|
||||||
|
int len, width;
|
||||||
|
|
||||||
// generate the vertices of all the runways
|
|
||||||
int len, width, hdg, label_hdg, elev;
|
|
||||||
char codes[10];
|
|
||||||
char side;
|
|
||||||
cout << "(apt) " << last_airport;
|
|
||||||
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);
|
rwy_str = (*current_runway);
|
||||||
cout << line_str;
|
|
||||||
|
|
||||||
sscanf( line_str.c_str(), "%lf %lf %d %d %d %s %d %c %d\n",
|
cout << rwy_str << endl;
|
||||||
&lon, &lat, &len, &width, &hdg, codes, &label_hdg,
|
string rwy_no = rwy_str.substr(2, 4);
|
||||||
&side, &elev );
|
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, 6);
|
||||||
|
string rwy_end2 = rwy_str.substr(59, 6);
|
||||||
|
|
||||||
rwy_list = gen_runway_area( lon, lat, (double)hdg * DEG_TO_RAD,
|
/*
|
||||||
|
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)len * FEET_TO_METER,
|
||||||
(double)width * FEET_TO_METER );
|
(double)width * FEET_TO_METER );
|
||||||
|
|
||||||
|
@ -123,6 +173,11 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( apt_list.size() == 0 ) {
|
||||||
|
cout << "no runway points generated" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
|
@ -134,10 +189,13 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
// generate convex hull
|
// generate convex hull
|
||||||
hull_list = convex_hull(apt_list);
|
hull_list = convex_hull(apt_list);
|
||||||
|
|
||||||
|
// get next polygon index
|
||||||
|
int index = poly_index_next();
|
||||||
|
|
||||||
// find average center, min, and max point of convex hull
|
// find average center, min, and max point of convex hull
|
||||||
point2d average, min, max;
|
point2d average, min, max;
|
||||||
double sum_x, sum_y;
|
double sum_x, sum_y;
|
||||||
count = hull_list.size();
|
int 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;
|
||||||
|
@ -167,7 +225,7 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
cout << "Bucket max = " << b_max << endl;
|
cout << "Bucket max = " << b_max << endl;
|
||||||
|
|
||||||
if ( b_min == b_max ) {
|
if ( b_min == b_max ) {
|
||||||
write_airport( hull_list, b, root, true );
|
write_airport( index, hull_list, b, root, true );
|
||||||
} else {
|
} else {
|
||||||
FGBucket b_cur;
|
FGBucket b_cur;
|
||||||
int dx, dy, i, j;
|
int dx, dy, i, j;
|
||||||
|
@ -185,9 +243,9 @@ void process_airport( string last_airport, list < string > & runway_list,
|
||||||
for ( i = 0; i <= dx; i++ ) {
|
for ( i = 0; i <= dx; i++ ) {
|
||||||
b_cur = fgBucketOffset(min.x, min.y, i, j);
|
b_cur = fgBucketOffset(min.x, min.y, i, j);
|
||||||
if ( b_cur == b ) {
|
if ( b_cur == b ) {
|
||||||
write_airport( hull_list, b_cur, root, true );
|
write_airport( index, hull_list, b_cur, root, true );
|
||||||
} else {
|
} else {
|
||||||
write_airport( hull_list, b_cur, root, false );
|
write_airport( index, hull_list, b_cur, root, false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,16 +266,32 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
if ( argc != 3 ) {
|
if ( argc != 3 ) {
|
||||||
FG_LOG( FG_GENERAL, FG_ALERT,
|
FG_LOG( FG_GENERAL, FG_ALERT,
|
||||||
"Usage " << argv[0] << " <apt_file> <work dir>" );
|
"Usage " << argv[0] << " <apt_file> <work_dir>" );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make work directory
|
||||||
|
string work_dir = argv[2];
|
||||||
|
string command = "mkdir -p " + work_dir;
|
||||||
|
system( command.c_str() );
|
||||||
|
|
||||||
|
// initialize persistant polygon counter
|
||||||
|
string counter_file = work_dir + "/polygon.counter";
|
||||||
|
poly_index_init( counter_file );
|
||||||
|
|
||||||
fg_gzifstream in( argv[1] );
|
fg_gzifstream in( argv[1] );
|
||||||
if ( !in ) {
|
if ( !in ) {
|
||||||
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << argv[1] );
|
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << argv[1] );
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// throw away the first 3 lines
|
||||||
|
in.getline(tmp, 256);
|
||||||
|
in.getline(tmp, 256);
|
||||||
|
in.getline(tmp, 256);
|
||||||
|
|
||||||
|
last_airport = "";
|
||||||
|
|
||||||
while ( ! in.eof() ) {
|
while ( ! in.eof() ) {
|
||||||
in.getline(tmp, 256);
|
in.getline(tmp, 256);
|
||||||
line = tmp;
|
line = tmp;
|
||||||
|
@ -227,10 +301,7 @@ int main( int argc, char **argv ) {
|
||||||
// empty, skip
|
// empty, skip
|
||||||
} else if ( line[0] == '#' ) {
|
} else if ( line[0] == '#' ) {
|
||||||
// comment, skip
|
// comment, skip
|
||||||
} else if ( line[0] == '\t' ) {
|
} else if ( (line[0] == 'A') || (line[0] == 'S') ) {
|
||||||
// runway entry
|
|
||||||
runway_list.push_back(line);
|
|
||||||
} else {
|
|
||||||
// start of airport record
|
// start of airport record
|
||||||
airport = line;
|
airport = line;
|
||||||
|
|
||||||
|
@ -243,6 +314,16 @@ int main( int argc, char **argv ) {
|
||||||
runway_list.erase(runway_list.begin(), runway_list.end());
|
runway_list.erase(runway_list.begin(), runway_list.end());
|
||||||
|
|
||||||
last_airport = airport;
|
last_airport = airport;
|
||||||
|
} else if ( line[0] == 'R' ) {
|
||||||
|
// runway entry
|
||||||
|
runway_list.push_back(line);
|
||||||
|
} else if ( line == "99" ) {
|
||||||
|
// end of file
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
FG_LOG( FG_GENERAL, FG_ALERT,
|
||||||
|
"Unknown line in file" << endl << line );
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,6 +337,10 @@ int main( int argc, char **argv ) {
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.7 1999/02/25 21:32:49 curt
|
||||||
|
// Modified to adhere to new polygon naming convention, and also to read the
|
||||||
|
// new Robin Peel aiport format.
|
||||||
|
//
|
||||||
// Revision 1.6 1999/02/11 01:10:51 curt
|
// Revision 1.6 1999/02/11 01:10:51 curt
|
||||||
// Start of scenery revamp project.
|
// Start of scenery revamp project.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue