1
0
Fork 0

Use a SGGeod bounding box for the scheduler

This commit is contained in:
Christian Schmitt 2012-10-08 21:24:21 +02:00
parent 8a12f010f5
commit 306b125044
5 changed files with 185 additions and 206 deletions

View file

@ -127,11 +127,12 @@ ostream os(&ssb);
int main(int argc, char **argv)
{
float min_lon = -180;
float max_lon = 180;
float min_lat = -90;
float max_lat = 90;
long position = 0;
SGGeod max, min;
max.setLongitudeDeg(180);
max.setLatitudeDeg(90);
min.setLongitudeDeg(-180);
min.setLatitudeDeg(-90);
// Setup elevation directories
string_list elev_src;
@ -159,73 +160,69 @@ int main(int argc, char **argv)
int redirect_port = -1;
int arg_pos;
for (arg_pos = 1; arg_pos < argc; arg_pos++)
for (arg_pos = 1; arg_pos < argc; arg_pos++)
{
string arg = argv[arg_pos];
if ( arg.find("--work=") == 0 )
if ( arg.find("--work=") == 0 )
{
work_dir = arg.substr(7);
}
else if ( arg.find("--input=") == 0 )
{
input_file = arg.substr(8);
}
else if ( arg.find("--start-id=") == 0 )
else if ( arg.find("--input=") == 0 )
{
start_id = arg.substr(11);
}
input_file = arg.substr(8);
}
else if ( arg.find("--start-id=") == 0 )
{
start_id = arg.substr(11);
}
else if ( arg.find("--airport-pos=") == 0 )
{
airport_pos = atol( arg.substr(14).c_str() );
}
else if ( arg.find("--restart-id=") == 0 )
else if ( arg.find("--restart-id=") == 0 )
{
restart_id = arg.substr(13);
}
else if ( arg.find("--nudge=") == 0 )
restart_id = arg.substr(13);
}
else if ( arg.find("--nudge=") == 0 )
{
nudge = atoi( arg.substr(8).c_str() );
}
else if ( arg.find("--snap=") == 0 )
nudge = atoi( arg.substr(8).c_str() );
}
else if ( arg.find("--snap=") == 0 )
{
gSnap = atof( arg.substr(7).c_str() );
}
else if ( arg.find("--last_apt_file=") == 0 )
gSnap = atof( arg.substr(7).c_str() );
}
else if ( arg.find("--last_apt_file=") == 0 )
{
last_apt_file = arg.substr(16);
}
else if ( arg.find("--min-lon=") == 0 )
last_apt_file = arg.substr(16);
}
else if ( arg.find("--min-lon=") == 0 )
{
min_lon = atof( arg.substr(10).c_str() );
}
else if ( arg.find("--max-lon=") == 0 )
min.setLongitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--max-lon=") == 0 )
{
max_lon = atof( arg.substr(10).c_str() );
}
else if ( arg.find("--min-lat=") == 0 )
max.setLongitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--min-lat=") == 0 )
{
min_lat = atof( arg.substr(10).c_str() );
}
else if ( arg.find("--max-lat=") == 0 )
min.setLatitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--max-lat=") == 0 )
{
max_lat = atof( arg.substr(10).c_str() );
}
else if ( arg.find("--chunk=") == 0 )
max.setLatitudeDeg(atof( arg.substr(10).c_str() ));
}
else if ( arg.find("--chunk=") == 0 )
{
tg::Rectangle rectangle = tg::parseChunk(arg.substr(8).c_str(), 10.0);
min_lon = rectangle.getMin().getLongitudeDeg();
min_lat = rectangle.getMin().getLatitudeDeg();
max_lon = rectangle.getMax().getLongitudeDeg();
max_lat = rectangle.getMax().getLatitudeDeg();
}
else if ( arg.find("--tile=") == 0 )
min = rectangle.getMin();
max = rectangle.getMax();
}
else if ( arg.find("--tile=") == 0 )
{
tg::Rectangle rectangle = tg::parseTile(arg.substr(7).c_str());
min_lon = rectangle.getMin().getLongitudeDeg();
min_lat = rectangle.getMin().getLatitudeDeg();
max_lon = rectangle.getMax().getLongitudeDeg();
max_lat = rectangle.getMax().getLatitudeDeg();
}
min = rectangle.getMin();
max = rectangle.getMax();
}
else if ( arg.find("--airport=") == 0 )
{
airport_id = arg.substr(10).c_str();
@ -299,17 +296,18 @@ int main(int argc, char **argv)
}
SG_LOG(SG_GENERAL, SG_INFO, "Work directory = " << work_dir);
SG_LOG(SG_GENERAL, SG_INFO, "Nudge = " << nudge);
SG_LOG(SG_GENERAL, SG_INFO, "Longitude = " << min_lon << ':' << max_lon);
SG_LOG(SG_GENERAL, SG_INFO, "Latitude = " << min_lat << ':' << max_lat);
SG_LOG(SG_GENERAL, SG_INFO, "Longitude = " << min.getLongitudeDeg() << ':' << max.getLongitudeDeg());
SG_LOG(SG_GENERAL, SG_INFO, "Latitude = " << min.getLatitudeDeg() << ':' << max.getLatitudeDeg());
if (max_lon < min_lon || max_lat < min_lat ||
min_lat < -90 || max_lat > 90 ||
min_lon < -180 || max_lon > 180)
if (!max.isValid() || !min.isValid())
{
SG_LOG(SG_GENERAL, SG_ALERT, "Bad longitude or latitude");
exit(1);
}
tg::Rectangle boundingBox(min, max);
boundingBox.sanify();
if ( work_dir == "" )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Error: no work directory specified." );
@ -397,7 +395,7 @@ int main(int argc, char **argv)
position = scheduler->FindAirport( start_id );
// add remaining airports within boundary
if ( scheduler->AddAirports( position, min_lat, min_lon, max_lat, max_lon ) )
if ( scheduler->AddAirports( position, &boundingBox ) )
{
// parse all the airports that were found
scheduler->Schedule( num_threads, summary_file );
@ -406,7 +404,7 @@ int main(int argc, char **argv)
else
{
// find all airports within given boundary
if ( scheduler->AddAirports( 0, min_lat, min_lon, max_lat, max_lon ) )
if ( scheduler->AddAirports( 0, &boundingBox ) )
{
// and parse them
scheduler->Schedule( num_threads, summary_file );

View file

@ -68,11 +68,11 @@ point_list WaterRunway::GetNodes()
if (buoys){
double heading, az2, length;
// calculate runway heading and length
SGGeodesy::inverse(GetStart().toSGGeod(), GetEnd().toSGGeod(), heading, az2, length);
SGGeodesy::inverse(GetStart(), GetEnd(), heading, az2, length);
// create a polygon for the outline and use it to calculate the point list
int divs = (int)(length / 100.0);
TGPolygon area = gen_wgs84_area(GetStart().toSGGeod(), GetEnd().toSGGeod(),
TGPolygon area = gen_wgs84_area(GetStart(), GetEnd(),
length, 0, 0, width, heading, false);
Point3D pt, inc;

View file

@ -185,14 +185,14 @@ public:
point_list GetNodes();
Point3D GetStart(void)
SGGeod GetStart(void)
{
return ( Point3D( lon[0], lat[0], 0.0f ));
return SGGeod::fromDeg( lon[0], lat[0] );
}
Point3D GetEnd(void)
SGGeod GetEnd(void)
{
return ( Point3D( lon[1], lat[1], 0.0f ));
return SGGeod::fromDeg( lon[1], lat[1] );
}
private:

View file

@ -590,7 +590,7 @@ void Scheduler::RetryAirport( AirportInfo* pai )
retryList.push_back( *pai );
}
bool Scheduler::AddAirports( long start_pos, float min_lat, float min_lon, float max_lat, float max_lon )
bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
{
char line[2048];
char* def;
@ -605,170 +605,150 @@ bool Scheduler::AddAirports( long start_pos, float min_lat, float min_lon, float
done = false;
match = false;
// start from current position, and push all airports where a runway start or end
// lies within the given min/max coordinates
// start from current position, and push all airports where a runway start or end
// lies within the given min/max coordinates
ifstream in( filename.c_str() );
if ( !in.is_open() )
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
if (start_pos)
{
if (start_pos)
{
in.seekg(start_pos, ios::beg);
}
}
while (!done)
{
// remember the position of this line
cur_pos = in.tellg();
while (!done)
{
// remember the position of this line
cur_pos = in.tellg();
// get a line
in.getline(line, 2048);
def = &line[0];
// get a line
in.getline(line, 2048);
def = &line[0];
// Get the number code
tok = strtok(def, " \t\r\n");
// Get the number code
tok = strtok(def, " \t\r\n");
if (tok)
{
def += strlen(tok)+1;
code = atoi(tok);
if (tok)
{
def += strlen(tok)+1;
code = atoi(tok);
switch(code)
{
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE:
{
Airport* airport = new Airport( code, def );
if (match)
{
// Start off with given snap value
AirportInfo* pInfo = new AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
originalList.push_back( *pInfo );
delete pInfo;
}
// remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos;
cur_apt_name = airport->GetIcao();
delete airport;
match = false;
}
break;
case END_OF_FILE:
if (match)
{
switch(code)
{
case LAND_AIRPORT_CODE:
case SEA_AIRPORT_CODE:
case HELIPORT_CODE:
{
Airport* airport = new Airport( code, def );
if (match)
{
// Start off with given snap value
AirportInfo* pInfo = new AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
AirportInfo* pInfo = new AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
originalList.push_back( *pInfo );
delete pInfo;
}
done = true;
break;
}
// remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos;
cur_apt_name = airport->GetIcao();
delete airport;
case LAND_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
Runway* runway = new Runway(def);
Point3D start = Point3D::fromSGGeod(runway->GetStart());
Point3D end = Point3D::fromSGGeod(runway->GetEnd());
if ( (start.x() >= min_lon ) &&
(start.y() >= min_lat ) &&
(start.x() <= max_lon ) &&
(start.y() <= max_lat ) ) {
match = true;
}
else if ( (end.x() >= min_lon ) &&
(end.y() >= min_lat ) &&
(end.x() <= max_lon ) &&
(end.y() <= max_lat ) ) {
match = true;
}
delete runway;
}
break;
match = false;
}
break;
case WATER_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
WaterRunway* runway = new WaterRunway(def);
Point3D start = runway->GetStart();
Point3D end = runway->GetEnd();
if ( (start.x() >= min_lon ) &&
(start.y() >= min_lat ) &&
(start.x() <= max_lon ) &&
(start.y() <= max_lat ) ) {
match = true;
}
else if ( (end.x() >= min_lon ) &&
(end.y() >= min_lat ) &&
(end.x() <= max_lon ) &&
(end.y() <= max_lat ) ) {
match = true;
}
delete runway;
}
break;
case END_OF_FILE:
if (match)
{
// Start off with given snap value
AirportInfo* pInfo = new AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
originalList.push_back( *pInfo );
delete pInfo;
}
done = true;
break;
case HELIPAD_CODE:
// if the heliport coords are within the rect, we have
// a winner
{
Helipad* helipad = new Helipad(def);
Point3D loc = Point3D::fromSGGeod(helipad->GetLoc()) ;
if ( (loc.x() >= min_lon ) &&
(loc.y() >= min_lat ) &&
(loc.x() <= max_lon ) &&
(loc.y() <= max_lat ) ) {
match = true;
}
delete helipad;
}
break;
case LAND_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
Runway* runway = new Runway(def);
if ( boundingBox->isInside(runway->GetStart()) ) {
match = true;
}
else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true;
}
delete runway;
}
break;
case WATER_RUNWAY_CODE:
// if the the runway start / end coords are within the rect,
// we have a winner
{
WaterRunway* runway = new WaterRunway(def);
if ( boundingBox->isInside(runway->GetStart()) ) {
match = true;
}
else if ( boundingBox->isInside(runway->GetEnd()) ) {
match = true;
}
delete runway;
}
break;
case HELIPAD_CODE:
// if the heliport coords are within the rect, we have
// a winner
{
Helipad* helipad = new Helipad(def);
if ( boundingBox->isInside(helipad->GetLoc()) ) {
match = true;
}
delete helipad;
}
break;
case TAXIWAY_CODE:
case PAVEMENT_CODE:
case LINEAR_FEATURE_CODE:
case BOUNDRY_CODE:
case NODE_CODE:
case BEZIER_NODE_CODE:
case CLOSE_NODE_CODE:
case CLOSE_BEZIER_NODE_CODE:
case TERM_NODE_CODE:
case TERM_BEZIER_NODE_CODE:
case AIRPORT_VIEWPOINT_CODE:
case AIRPLANE_STARTUP_LOCATION_CODE:
case LIGHT_BEACON_CODE:
case WINDSOCK_CODE:
case TAXIWAY_SIGN:
case LIGHTING_OBJECT:
case COMM_FREQ1_CODE:
case COMM_FREQ2_CODE:
case COMM_FREQ3_CODE:
case COMM_FREQ4_CODE:
case COMM_FREQ5_CODE:
case COMM_FREQ6_CODE:
case COMM_FREQ7_CODE:
break;
}
}
}
// did we add airports to the parse list?
if ( originalList.size() )
{
return true;
} else
{
return false;
case PAVEMENT_CODE:
case LINEAR_FEATURE_CODE:
case BOUNDRY_CODE:
case NODE_CODE:
case BEZIER_NODE_CODE:
case CLOSE_NODE_CODE:
case CLOSE_BEZIER_NODE_CODE:
case TERM_NODE_CODE:
case TERM_BEZIER_NODE_CODE:
case AIRPORT_VIEWPOINT_CODE:
case AIRPLANE_STARTUP_LOCATION_CODE:
case LIGHT_BEACON_CODE:
case WINDSOCK_CODE:
case TAXIWAY_SIGN:
case LIGHTING_OBJECT:
case COMM_FREQ1_CODE:
case COMM_FREQ2_CODE:
case COMM_FREQ3_CODE:
case COMM_FREQ4_CODE:
case COMM_FREQ5_CODE:
case COMM_FREQ6_CODE:
case COMM_FREQ7_CODE:
break;
}
}
}
// did we add airports to the parse list?
if ( originalList.size() )
{
return true;
} else
{
return false;
}
}
Scheduler::Scheduler(string& cmd, string& datafile, const string& root, const string_list& elev_src)

View file

@ -19,6 +19,7 @@
#include <simgear/compiler.h>
#include <simgear/math/sg_types.hxx>
#include <simgear/timing/timestamp.hxx>
#include <Geometry/rectangle.hxx>
#define P_STATE_INIT (0)
#define P_STATE_PARSE (1)
@ -176,7 +177,7 @@ public:
long FindAirport( string icao );
void AddAirport( string icao );
bool AddAirports( long start_pos, float min_lat, float min_lon, float max_lat, float max_lon );
bool AddAirports( long start_pos, tg::Rectangle* boundingBox );
void RetryAirport( AirportInfo* pInfo );
void Schedule( int num_threads, string& summaryfile );