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

View file

@ -68,11 +68,11 @@ point_list WaterRunway::GetNodes()
if (buoys){ if (buoys){
double heading, az2, length; double heading, az2, length;
// calculate runway heading and 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 // create a polygon for the outline and use it to calculate the point list
int divs = (int)(length / 100.0); 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); length, 0, 0, width, heading, false);
Point3D pt, inc; Point3D pt, inc;

View file

@ -185,14 +185,14 @@ public:
point_list GetNodes(); 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: private:

View file

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