1
0
Fork 0

multithreaded genapt850

This commit is contained in:
Peter Sadrozinski 2012-11-27 20:37:25 -05:00
parent 3dfe15559e
commit 1929799b4b
30 changed files with 850 additions and 1448 deletions

View file

@ -1,35 +1,34 @@
include_directories(${PROJECT_SOURCE_DIR}/src/Lib)
add_executable(genapts850
airport.hxx airport.cxx
apt_math.hxx apt_math.cxx
apt_surface.hxx apt_surface.cxx
beznode.hxx
closedpoly.hxx closedpoly.cxx
elevations.cxx elevations.hxx
global.hxx
helipad.hxx helipad.cxx
lights.cxx
linearfeature.hxx linearfeature.cxx
linked_objects.hxx linked_objects.cxx
main.cxx
object.hxx object.cxx
parser.hxx parser.cxx
runway.cxx runway.hxx
rwy_simple.cxx
rwy_gen.cxx
scheduler.cxx scheduler.hxx
taxiway.cxx taxiway.hxx
)
airport.hxx airport.cxx
apt_math.hxx apt_math.cxx
apt_surface.hxx apt_surface.cxx
beznode.hxx
closedpoly.hxx closedpoly.cxx
debug.hxx debug.cxx
elevations.cxx elevations.hxx
global.hxx
helipad.hxx helipad.cxx
lights.cxx
linearfeature.hxx linearfeature.cxx
linked_objects.hxx linked_objects.cxx
main.cxx
object.hxx object.cxx
parser.hxx parser.cxx
runway.cxx runway.hxx
rwy_simple.cxx
rwy_gen.cxx
scheduler.cxx scheduler.hxx
taxiway.cxx taxiway.hxx
)
target_link_libraries(genapts850
Polygon Geometry
Array Output
${POCO_FOUNDATION}
${POCO_NET}
${GDAL_LIBRARY}
${SIMGEAR_CORE_LIBRARIES}
${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}
${RT_LIBRARY})
${SIMGEAR_CORE_LIBRARIES}
${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}
${RT_LIBRARY})
install(TARGETS genapts850 RUNTIME DESTINATION bin)
install(TARGETS genapts850 RUNTIME DESTINATION bin)

View file

@ -1,11 +1,4 @@
#include "beznode.hxx"
#include "runway.hxx"
#include "helipad.hxx"
#include "airport.hxx"
#include <list>
#include <map>
#include <string>
#include <ctime>
#include <stdio.h>
@ -26,18 +19,13 @@
#include <Output/output.hxx>
#include "beznode.hxx"
#include "runway.hxx"
#include "helipad.hxx"
#include "airport.hxx"
#include "global.hxx"
#include "elevations.hxx"
static std::string my_ctime(time_t& tt)
{
char buf[256];
strcpy(buf,ctime(&tt));
buf[strlen(buf)-1]='\0';
return std::string( buf );
}
#include "debug.hxx"
Airport::Airport( int c, char* def)
{
@ -88,7 +76,7 @@ Airport::Airport( int c, char* def)
altitude *= SG_FEET_TO_METER;
SG_LOG( SG_GENERAL, SG_DEBUG, "Read airport with icao " << icao << ", control tower " << ct << ", and description " << description );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Read airport with icao " << icao << ", control tower " << ct << ", and description " << description );
}
Airport::~Airport()
@ -336,7 +324,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
apt_lat = apt_lat / (double)num_samples;
SGBucket b( apt_lon, apt_lat );
SG_LOG(SG_GENERAL, SG_DEBUG, b.gen_base_path() << "/" << b.gen_index_str());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, b.gen_base_path() << "/" << b.gen_index_str());
// If we are cutting in the linear features, add them first
if (pavements.size())
@ -347,41 +335,38 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
}
SG_LOG(SG_GENERAL, SG_INFO, "Parse Complete - Runways: " << runways.size() << " Pavements: " << pavements.size() << " Features: " << features.size() << " Taxiways: " << taxiways.size() );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Parse Complete - Runways: " << runways.size() << " Pavements: " << pavements.size() << " Features: " << features.size() << " Taxiways: " << taxiways.size() );
// Starting to clip the polys (for now - only UNIX builds)
build_start.stamp();
// Add the linear features
tgPolygonInitClipperAccumulator();
if (features.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << features.size() << " Linear Feature Polys");
tgAccumulator lf_accum;
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << features.size() << " Linear Feature Polys");
for ( unsigned int i=0; i<features.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Feature Poly " << i + 1 << " of " << features.size() << " : " << features[i]->GetDescription() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Feature Poly " << i + 1 << " of " << features.size() << " : " << features[i]->GetDescription() );
features[i]->BuildBtg( line_polys, rwy_lights, make_shapefiles );
features[i]->BuildBtg( line_polys, rwy_lights, lf_accum, make_shapefiles );
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building Linear Features for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished building Linear Features for " << icao << " at " << DebugTimeToString(log_time) );
}
/* Done with the linear features accumulator */
tgPolygonFreeClipperAccumulator();
/* Initialize a new accumulator for the other objects */
tgPolygonInitClipperAccumulator();
tgAccumulator pvmt_accum;
// Build runways next
if (runways.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Runway Polys");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Runway Polys");
for ( unsigned int i=0; i<runways.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Runway " << i + 1 << " of " << runways.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Runway " << i + 1 << " of " << runways.size());
slivers.clear();
if ( isDebugRunway(i) ) {
@ -393,11 +378,11 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if (boundary.size())
{
runways[i]->BuildBtg( rwy_polys, rwy_lights, slivers, shapefile );
runways[i]->BuildBtg( rwy_polys, rwy_lights, slivers, pvmt_accum, shapefile );
}
else
{
runways[i]->BuildBtg( rwy_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys, shapefile );
runways[i]->BuildBtg( rwy_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys, pvmt_accum, shapefile );
}
// Now try to merge any slivers we found
@ -405,15 +390,15 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building runways for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished building runways for " << icao << " at " << DebugTimeToString(log_time) );
}
if (lightobjects.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << lightobjects.size() << " Light Objects ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << lightobjects.size() << " Light Objects ");
for ( unsigned int i=0; i<lightobjects.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build runway light " << i + 1 << " of " << lightobjects.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build runway light " << i + 1 << " of " << lightobjects.size());
lightobjects[i]->BuildBtg( rwy_lights );
}
}
@ -421,19 +406,19 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Build helipads (use runway poly- and texture list for this)
if (helipads.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << helipads.size() << " Helipad Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << helipads.size() << " Helipad Polys ");
for ( unsigned int i=0; i<helipads.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build helipad " << i + 1 << " of " << helipads.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build helipad " << i + 1 << " of " << helipads.size());
slivers.clear();
if (boundary.size())
{
helipads[i]->BuildBtg( rwy_polys, rwy_lights, slivers );
helipads[i]->BuildBtg( rwy_polys, rwy_lights, slivers, pvmt_accum );
}
else
{
helipads[i]->BuildBtg( rwy_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys );
helipads[i]->BuildBtg( rwy_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys, pvmt_accum );
}
// Now try to merge any slivers we found
@ -444,10 +429,10 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Build the pavements
if (pavements.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << pavements.size() << " Pavement Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << pavements.size() << " Pavement Polys ");
for ( unsigned int i=0; i<pavements.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Pavement " << i + 1 << " of " << pavements.size() << " : " << pavements[i]->GetDescription());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Pavement " << i + 1 << " of " << pavements.size() << " : " << pavements[i]->GetDescription());
slivers.clear();
if ( isDebugPavement(i) ) {
@ -459,11 +444,11 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if (boundary.size())
{
pavements[i]->BuildBtg( pvmt_polys, slivers, shapefile );
pavements[i]->BuildBtg( pvmt_polys, slivers, pvmt_accum, shapefile );
}
else
{
pavements[i]->BuildBtg( pvmt_polys, slivers, apt_base_polys, apt_clearing_polys, shapefile );
pavements[i]->BuildBtg( pvmt_polys, slivers, apt_base_polys, apt_clearing_polys, pvmt_accum, shapefile );
}
// Now try to merge any slivers we found
@ -472,16 +457,16 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished building Pavements for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished building Pavements for " << icao << " at " << DebugTimeToString(log_time) );
}
// Build the legacy taxiways
if (taxiways.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << taxiways.size() << " Taxiway Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << taxiways.size() << " Taxiway Polys ");
for ( unsigned int i=0; i<taxiways.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Taxiway " << i + 1 << " of " << taxiways.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Taxiway " << i + 1 << " of " << taxiways.size());
slivers.clear();
if ( isDebugTaxiway(i) ) {
@ -493,11 +478,11 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if (boundary.size())
{
taxiways[i]->BuildBtg( pvmt_polys, rwy_lights, slivers, shapefile );
taxiways[i]->BuildBtg( pvmt_polys, rwy_lights, slivers, pvmt_accum, shapefile );
}
else
{
taxiways[i]->BuildBtg( pvmt_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys, shapefile );
taxiways[i]->BuildBtg( pvmt_polys, rwy_lights, slivers, apt_base_polys, apt_clearing_polys, pvmt_accum, shapefile );
}
// Now try to merge any slivers we found
@ -509,15 +494,15 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Build runway shoulders here
if ( runways.size() )
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Runway Shoulder Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Runway Shoulder Polys ");
for ( unsigned int i=0; i<runways.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Runway shoulder " << i + 1 << " of " << runways.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Runway shoulder " << i + 1 << " of " << runways.size());
if ( runways[i]->GetsShoulder() )
{
slivers.clear();
runways[i]->BuildShoulder( rwy_polys, slivers );
runways[i]->BuildShoulder( rwy_polys, slivers, pvmt_accum );
// Now try to merge any slivers we found
tgPolygon::MergeSlivers( rwy_polys, slivers );
@ -529,15 +514,15 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Build helipad shoulders here
if ( helipads.size() )
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Helipad Shoulder Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << runways.size() << " Helipad Shoulder Polys ");
for ( unsigned int i=0; i<helipads.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Helipad shoulder " << i + 1 << " of " << helipads.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Helipad shoulder " << i + 1 << " of " << helipads.size());
if ( helipads[i]->GetsShoulder() )
{
slivers.clear();
helipads[i]->BuildShoulder( rwy_polys, slivers );
helipads[i]->BuildShoulder( rwy_polys, slivers, pvmt_accum );
// Now try to merge any slivers we found
tgPolygon::MergeSlivers( rwy_polys, slivers );
@ -550,12 +535,12 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
tgPolygon apt_base, apt_clearing;
if (boundary.size())
{
SG_LOG(SG_GENERAL, SG_INFO, "Build " << boundary.size() << " Boundary Polys ");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build " << boundary.size() << " Boundary Polys ");
shapefile = "";
for ( unsigned int i=0; i<boundary.size(); i++ )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Build Userdefined boundary " << i + 1 << " of " << boundary.size());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Build Userdefined boundary " << i + 1 << " of " << boundary.size());
boundary[i]->BuildBtg( apt_base, apt_clearing, shapefile );
}
} else {
@ -565,13 +550,13 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( apt_base.TotalNodes() == 0 )
{
SG_LOG(SG_GENERAL, SG_ALERT, "no airport points generated");
GENAPT_LOG(SG_GENERAL, SG_ALERT, "no airport points generated");
return;
}
tgPolygon filled_base = tgPolygon::StripHoles( apt_base );
tgPolygon divided_base = tgPolygon::SplitLongEdges( filled_base, 200.0 );
tgPolygon base_poly = tgPolygon::DiffWithAccumulator( divided_base );
tgPolygon base_poly = pvmt_accum.Diff( divided_base );
build_end.stamp();
build_time = build_end - build_start;
@ -584,7 +569,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
UniqueSGGeodSet tmp_feat_nodes;
// build temporary node list from runways...
SG_LOG(SG_GENERAL, SG_INFO, "Build Node List " );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Build Node List " );
for ( unsigned int k = 0; k < rwy_polys.size(); ++k )
{
tgPolygon poly = rwy_polys[k];
@ -643,14 +628,14 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished collecting nodes for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished collecting nodes for " << icao << " at " << DebugTimeToString(log_time) );
// second pass : runways
for ( unsigned int k = 0; k < rwy_polys.size(); ++k )
{
tgPolygon poly = rwy_polys[k];
poly = tgPolygon::AddColinearNodes( poly, tmp_pvmt_nodes.get_list() );
SG_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
rwy_polys[k] = poly;
}
@ -659,7 +644,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
{
tgPolygon poly = pvmt_polys[k];
poly = tgPolygon::AddColinearNodes( poly, tmp_pvmt_nodes.get_list() );
SG_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
pvmt_polys[k] = poly;
}
@ -668,12 +653,12 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
{
tgPolygon poly = line_polys[k];
poly = tgPolygon::AddColinearNodes( poly, tmp_feat_nodes.get_list() );
SG_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "total size after add nodes = " << poly.TotalNodes());
line_polys[k] = poly;
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished adding intermediate nodes for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished adding intermediate nodes for " << icao << " at " << DebugTimeToString(log_time) );
for ( unsigned int k = 0; k < line_polys.size(); ++k )
{
@ -693,7 +678,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished cleaning polys for " << icao << " at " << my_ctime(log_time) );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished cleaning polys for " << icao << " at " << DebugTimeToString(log_time) );
base_poly = tgPolygon::AddColinearNodes( base_poly, tmp_pvmt_nodes.get_list() );
base_poly = tgPolygon::Snap( base_poly, gSnap );
@ -730,14 +715,14 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// tesselate the polygons and prepair them for final output
if ( rwy_polys.size() )
{
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating " << rwy_polys.size() << " Runway Polys " );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Tesselating " << rwy_polys.size() << " Runway Polys " );
for ( unsigned int i = 0; i < rwy_polys.size(); ++i )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating runway poly = " << i + 1 << " of " << rwy_polys.size() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Tesselating runway poly = " << i + 1 << " of " << rwy_polys.size() );
SG_LOG(SG_GENERAL, SG_DEBUG, "contours before " << rwy_polys[i].Contours() << " total points before = " << rwy_polys[i].TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "contours before " << rwy_polys[i].Contours() << " total points before = " << rwy_polys[i].TotalNodes());
rwy_polys[i].Tesselate();
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << rwy_polys[i].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << rwy_polys[i].Triangles());
rwy_polys[i].Texture();
}
}
@ -745,14 +730,14 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( pvmt_polys.size() )
{
// tesselate the polygons and prepair them for final output
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating " << pvmt_polys.size() << " Pavement Polys " );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Tesselating " << pvmt_polys.size() << " Pavement Polys " );
for ( unsigned int i = 0; i < pvmt_polys.size(); ++i )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating pavement poly = " << i + 1 << " of " << pvmt_polys.size() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Tesselating pavement poly = " << i + 1 << " of " << pvmt_polys.size() );
SG_LOG(SG_GENERAL, SG_DEBUG, "contours before " << pvmt_polys[i].Contours() << " total points before = " << pvmt_polys[i].TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "contours before " << pvmt_polys[i].Contours() << " total points before = " << pvmt_polys[i].TotalNodes());
pvmt_polys[i].Tesselate();
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << pvmt_polys[i].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << pvmt_polys[i].Triangles());
pvmt_polys[i].Texture();
}
}
@ -760,14 +745,14 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( line_polys.size() )
{
// tesselate the polygons and prepair them for final output
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating " << line_polys.size() << " Linear Feature Polys " );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Tesselating " << line_polys.size() << " Linear Feature Polys " );
for ( unsigned int i = 0; i < line_polys.size(); ++i )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating line poly = " << i + 1 << " of " << line_polys.size() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Tesselating line poly = " << i + 1 << " of " << line_polys.size() );
SG_LOG(SG_GENERAL, SG_DEBUG, "contours before " << line_polys[i].Contours() << " total points before = " << line_polys[i].TotalNodes());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "contours before " << line_polys[i].Contours() << " total points before = " << line_polys[i].TotalNodes());
line_polys[i].Tesselate();
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << line_polys[i].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles after = " << line_polys[i].Triangles());
line_polys[i].Texture();
}
}
@ -776,12 +761,20 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
intersecting contours */
base_poly = tgPolygon::Simplify( base_poly );
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly : " << base_poly.Contours() << " contours " );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly : " << base_poly.Contours() << " contours " );
base_poly.Tesselate();
SG_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly - done : Triangles = " << base_poly.Triangles());
GENAPT_LOG(SG_GENERAL, SG_INFO, "Tesselating base poly - done : Triangles = " << base_poly.Triangles());
// should we texture base here?
triangulation_end.stamp();
// a few airports fail here
if ( base_poly.Triangles() == 0 )
{
GENAPT_LOG(SG_GENERAL, SG_ALERT, "no base poly triangles");
return;
}
triangulation_time = triangulation_end - triangulation_start;
//
@ -823,13 +816,13 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
SGVec3f vnt = SGVec3f::fromGeod( base_poly.GetNode(0, 0) );
vnt = normalize(vnt);
SG_LOG(SG_GENERAL, SG_INFO, "Adding runway nodes and normals");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Adding runway nodes and normals");
for ( unsigned int k = 0; k < rwy_polys.size(); ++k )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
std::string material = rwy_polys[k].GetMaterial();
SG_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << rwy_polys[k].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << rwy_polys[k].Triangles());
for ( unsigned int i = 0; i < rwy_polys[k].Triangles(); ++i )
{
tri_v.clear();
@ -855,13 +848,13 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
}
SG_LOG(SG_GENERAL, SG_INFO, "Adding pavement nodes and normals");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Adding pavement nodes and normals");
for ( unsigned int k = 0; k < pvmt_polys.size(); ++k )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
std::string material = pvmt_polys[k].GetMaterial();
SG_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << pvmt_polys[k].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << pvmt_polys[k].Triangles());
for ( unsigned int i = 0; i < pvmt_polys[k].Triangles(); ++i )
{
tri_v.clear();
@ -886,13 +879,13 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
}
SG_LOG(SG_GENERAL, SG_INFO, "Adding line nodes and normals");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Adding line nodes and normals");
for ( unsigned int k = 0; k < line_polys.size(); ++k )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "tri " << k);
std::string material = line_polys[k].GetMaterial();
SG_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
SG_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << line_polys[k].Triangles());
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "material = " << material);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "triangles = " << line_polys[k].Triangles());
for ( unsigned int i = 0; i < line_polys[k].Triangles(); ++i )
{
tri_v.clear();
@ -921,7 +914,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
std::vector< SGVec2f > base_txs;
int_list base_tc;
SG_LOG(SG_GENERAL, SG_INFO, "Adding base nodes and normals");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Adding base nodes and normals");
for ( unsigned int i = 0; i < base_poly.Triangles(); ++i )
{
tri_v.clear();
@ -961,7 +954,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
for ( unsigned int j = 0; j < divided_base.ContourSize( i ); ++j )
{
index = nodes.add( divided_base.GetNode(i, j) );
SG_LOG(SG_GENERAL, SG_DEBUG, "added base point " << divided_base.GetNode(i, j) << " at " << index );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "added base point " << divided_base.GetNode(i, j) << " at " << index );
}
}
@ -972,15 +965,15 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// it avoids biases introduced from the surrounding area if the
// airport is located in a bowl or on a hill.
SG_LOG(SG_GENERAL, SG_DEBUG, " calc average elevation");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " calc average elevation");
{
std::vector < SGGeod > dbg = nodes.get_list();
// dump the node list
SG_LOG(SG_GENERAL, SG_DEBUG, " node list size is " << dbg.size() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " node list size is " << dbg.size() );
for (unsigned int w = 0; w<dbg.size(); w++)
{
SG_LOG(SG_GENERAL, SG_DEBUG, " node " << w << " is " << dbg[w] );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " node " << w << " is " << dbg[w] );
}
}
@ -989,7 +982,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Now build the fitted airport surface ...
// calculation min/max coordinates of airport area
SG_LOG(SG_GENERAL, SG_DEBUG, " calculation min/max coordinates of airport area");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " calculation min/max coordinates of airport area");
SGGeod min_deg = SGGeod::fromDeg(9999.0, 9999.0);
SGGeod max_deg = SGGeod::fromDeg(-9999.0, -9999.0);
@ -998,35 +991,35 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
SGGeod p = nodes.get_list()[j];
if ( p.getLongitudeDeg() < min_deg.getLongitudeDeg() )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "new min lon from node " << j << " is " << p.getLongitudeDeg() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "new min lon from node " << j << " is " << p.getLongitudeDeg() );
min_deg.setLongitudeDeg( p.getLongitudeDeg() );
}
if ( p.getLongitudeDeg() > max_deg.getLongitudeDeg() )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "new max lon from node " << j << " is " << p.getLongitudeDeg() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "new max lon from node " << j << " is " << p.getLongitudeDeg() );
max_deg.setLongitudeDeg( p.getLongitudeDeg() );
}
if ( p.getLatitudeDeg() < min_deg.getLatitudeDeg() )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "new min lat from node " << j << " is " << p.getLatitudeDeg() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "new min lat from node " << j << " is " << p.getLatitudeDeg() );
min_deg.setLatitudeDeg( p.getLatitudeDeg() );
}
if ( p.getLatitudeDeg() > max_deg.getLatitudeDeg() )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "new max lat from node " << j << " is " << p.getLatitudeDeg() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "new max lat from node " << j << " is " << p.getLatitudeDeg() );
max_deg.setLatitudeDeg( p.getLatitudeDeg() );
}
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Before extending for lights: min = " << min_deg << " max = " << max_deg );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Before extending for lights: min = " << min_deg << " max = " << max_deg );
// extend the min/max coordinates of airport area to cover all
// lights as well
SG_LOG(SG_GENERAL, SG_DEBUG, " extend the min/max coordinates of airport area to cover all lights as well : num rwy lights is " << rwy_lights.size() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " extend the min/max coordinates of airport area to cover all lights as well : num rwy lights is " << rwy_lights.size() );
for ( unsigned int i = 0; i < rwy_lights.size(); ++i )
{
SG_LOG(SG_GENERAL, SG_DEBUG, " extend the min/max coordinates of airport area to cover all lights as well : rwy light " << i << "has " << rwy_lights[i].ContourSize() << " lights " );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " extend the min/max coordinates of airport area to cover all lights as well : rwy light " << i << "has " << rwy_lights[i].ContourSize() << " lights " );
for ( unsigned int j = 0; j < rwy_lights[i].ContourSize(); ++j )
{
@ -1057,19 +1050,19 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
max_deg.setLongitudeDeg( max_deg.getLongitudeDeg() + 0.01 * dlon );
min_deg.setLatitudeDeg( min_deg.getLatitudeDeg() - 0.01 * dlat );
max_deg.setLatitudeDeg( max_deg.getLatitudeDeg() + 0.01 * dlat );
SG_LOG(SG_GENERAL, SG_DEBUG, "min = " << min_deg << " max = " << max_deg );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "min = " << min_deg << " max = " << max_deg );
SG_LOG(SG_GENERAL, SG_DEBUG, "Create Apt surface:" );
SG_LOG(SG_GENERAL, SG_DEBUG, " root: " << root );
//SG_LOG(SG_GENERAL, SG_DEBUG, " elev: " << elev_src );
SG_LOG(SG_GENERAL, SG_DEBUG, " min: " << min_deg );
SG_LOG(SG_GENERAL, SG_DEBUG, " max: " << max_deg );
SG_LOG(SG_GENERAL, SG_DEBUG, " average: " << average );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Create Apt surface:" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " root: " << root );
//GENAPT_LOG(SG_GENERAL, SG_DEBUG, " elev: " << elev_src );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " min: " << min_deg );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " max: " << max_deg );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " average: " << average );
tg::Rectangle aptBounds(min_deg, max_deg);
TGAptSurface apt_surf( root, elev_src, aptBounds, average );
SG_LOG(SG_GENERAL, SG_DEBUG, "Airport surface created");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Airport surface created");
// add base skirt (to hide potential cracks)
// this has to happen after we've calculated the node elevations
@ -1088,7 +1081,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( uindex >= 0 )
{
Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20);
SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
lindex = nodes.simple_add( lower );
geod_nodes.push_back( lower );
strip_v.push_back( uindex );
@ -1103,7 +1096,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
else
{
string message = "Ooops missing node when building skirt (in init)";
SG_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
GENAPT_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
throw sg_exception( message );
}
@ -1115,7 +1108,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( uindex >= 0 )
{
Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20);
SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
lindex = nodes.simple_add( lower );
geod_nodes.push_back( lower );
strip_v.push_back( uindex );
@ -1128,7 +1121,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
else
{
string message = "Ooops missing node when building skirt (in loop)";
SG_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
GENAPT_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
throw sg_exception( message );
}
}
@ -1139,7 +1132,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
if ( uindex >= 0 )
{
Point3D lower = geod_nodes[uindex] - Point3D(0, 0, 20);
SG_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, geod_nodes[uindex] << " <-> " << lower);
lindex = nodes.simple_add( lower );
geod_nodes.push_back( lower );
strip_v.push_back( uindex );
@ -1152,7 +1145,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
else
{
string message = "Ooops missing node when building skirt (at end)";
SG_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
GENAPT_LOG( SG_GENERAL, SG_ALERT, message << " " << p );
throw sg_exception( message );
}
@ -1191,7 +1184,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
//string flag = rwy_lights[i].GetFlag();
//if ( flag != (string)"" )
//{
// SG_LOG(SG_GENERAL, SG_INFO, " flag " << flag);
// GENAPT_LOG(SG_GENERAL, SG_INFO, " flag " << flag);
// double max = -9999;
// const_elev_map_iterator it = elevation_map.find( flag );
// if ( it != elevation_map.end() )
@ -1206,11 +1199,11 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// }
// }
// elevation_map[flag] = max;
// SG_LOG( SG_GENERAL, SG_INFO, " " << flag << " max = " << max );
// GENAPT_LOG( SG_GENERAL, SG_INFO, " " << flag << " max = " << max );
//}
}
SG_LOG(SG_GENERAL, SG_INFO, "Done with lighting calc_elevations() num light polys is " << rwy_lights.size() );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Done with lighting calc_elevations() num light polys is " << rwy_lights.size() );
// pass two, for each light group check if we need to lift (based
// on flag) and do so, then output next structures.
@ -1233,7 +1226,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
}
// calculate node elevations
SG_LOG(SG_GENERAL, SG_DEBUG, "Computing airport node elevations");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Computing airport node elevations");
std::vector<SGGeod> geod_nodes = calc_elevations( apt_surf, nodes.get_list(), 0.0 );
divided_base = calc_elevations( apt_surf, divided_base, 0.0 );
@ -1253,9 +1246,9 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
SGVec3d gbs_center = d.getCenter();
double gbs_radius = d.getRadius();
SG_LOG(SG_GENERAL, SG_DEBUG, "gbs center = " << gbs_center);
SG_LOG(SG_GENERAL, SG_DEBUG, "Done with wgs84 node mapping");
SG_LOG(SG_GENERAL, SG_DEBUG, " center = " << gbs_center << " radius = " << gbs_radius );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "gbs center = " << gbs_center);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Done with wgs84 node mapping");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " center = " << gbs_center << " radius = " << gbs_radius );
// null structures
group_list fans_v; fans_v.clear();
@ -1310,7 +1303,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
SGGeod ref_geod;
// calc elevations and write out windsock references
SG_LOG(SG_GENERAL, SG_DEBUG, "Computing windsock node elevations");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Computing windsock node elevations");
for ( unsigned int i = 0; i < windsocks.size(); ++i )
{

View file

@ -3,6 +3,7 @@
#include <simgear/timing/timestamp.hxx>
#include <simgear/math/sg_types.hxx>
#include <simgear/threads/SGThread.hxx>
#include "runway.hxx"
#include "object.hxx"
@ -11,10 +12,7 @@
#include "closedpoly.hxx"
#include "linearfeature.hxx"
#include "linked_objects.hxx"
typedef std::map<std::string, std::vector<int>, std::less<std::string> > debug_map;
typedef debug_map::iterator debug_map_iterator;
typedef debug_map::const_iterator debug_map_const_iterator;
#include "debug.hxx"
class Airport
{

View file

@ -34,6 +34,7 @@
#include "elevations.hxx"
#include "global.hxx"
#include "apt_surface.hxx"
#include "debug.hxx"
static bool limit_slope( SimpleMatrix *Pts, int i1, int j1, int i2, int j2,
@ -54,7 +55,7 @@ static bool limit_slope( SimpleMatrix *Pts, int i1, int j1, int i2, int j2,
slope_error = true;
SG_LOG( SG_GENERAL, SG_DEBUG, " (a) detected slope of " << slope << " dist = " << dist );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, " (a) detected slope of " << slope << " dist = " << dist );
double e1 = fabs(average_elev_m - p1.getElevationM());
double e2 = fabs(average_elev_m - p2.getElevationM());
@ -109,7 +110,7 @@ TGAptSurface::TGAptSurface( const std::string& path,
double x_nm = x_rad * SG_RAD_TO_NM * xfact;
double x_m = x_nm * SG_NM_TO_METER;
SG_LOG( SG_GENERAL, SG_DEBUG,
GENAPT_LOG( SG_GENERAL, SG_DEBUG,
"Area size = " << y_m << " x " << x_m << " (m)" );
int xdivs = (int)(x_m / coarse_grid) + 1;
@ -119,7 +120,7 @@ TGAptSurface::TGAptSurface( const std::string& path,
// interesting
if ( xdivs < 8 ) { xdivs = 8; }
if ( ydivs < 8 ) { ydivs = 8; }
SG_LOG(SG_GENERAL, SG_DEBUG, " M(" << ydivs << "," << xdivs << ")");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " M(" << ydivs << "," << xdivs << ")");
double dlon = x_deg / xdivs;
double dlat = y_deg / ydivs;
@ -154,14 +155,14 @@ TGAptSurface::TGAptSurface( const std::string& path,
double ave_divider = (mult+1) * (mult+1);
for ( int j = 0; j < Pts->rows(); ++j ) {
for ( int i = 0; i < Pts->cols(); ++i ) {
SG_LOG(SG_GENERAL, SG_DEBUG, i << "," << j);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, i << "," << j);
double accum = 0.0;
double lon_accum = 0.0;
double lat_accum = 0.0;
for ( int jj = 0; jj <= mult; ++jj ) {
for ( int ii = 0; ii <= mult; ++ii ) {
double value = dPts.element(mult*i + ii, mult*j + jj).getElevationM();
SG_LOG( SG_GENERAL, SG_DEBUG, "value = " << value );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "value = " << value );
accum += value;
lon_accum += dPts.element(mult*i + ii, mult*j + jj).getLongitudeDeg();
lat_accum += dPts.element(mult*i + ii, mult*j + jj).getLatitudeDeg();
@ -169,7 +170,7 @@ TGAptSurface::TGAptSurface( const std::string& path,
}
double val_ave = accum / ave_divider;
SG_LOG( SG_GENERAL, SG_DEBUG, " val_ave = " << val_ave );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, " val_ave = " << val_ave );
Pts->set(i, j, SGGeod::fromDegM( _min_deg.getLongitudeDeg() + i * dlon,
_min_deg.getLatitudeDeg() + j * dlat,
val_ave )
@ -179,7 +180,7 @@ TGAptSurface::TGAptSurface( const std::string& path,
bool slope_error = true;
while ( slope_error ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "start of slope processing pass" );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "start of slope processing pass" );
slope_error = false;
// Add some "slope" sanity to the resulting surface grid points
for ( int j = 0; j < Pts->rows() - 1; ++j ) {
@ -201,12 +202,12 @@ TGAptSurface::TGAptSurface( const std::string& path,
double clon = (_min_deg.getLongitudeDeg() + _max_deg.getLongitudeDeg()) / 2.0;
double clat = (_min_deg.getLatitudeDeg() + _max_deg.getLatitudeDeg()) / 2.0;
area_center = SGGeod::fromDegM( clon, clat, _average_elev_m );
SG_LOG(SG_GENERAL, SG_DEBUG, "Central offset point = " << area_center);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Central offset point = " << area_center);
// Create the fitted surface
SG_LOG(SG_GENERAL, SG_DEBUG, "ready to create fitted surface");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "ready to create fitted surface");
fit();
SG_LOG(SG_GENERAL, SG_DEBUG, " fit process successful.");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " fit process successful.");
}
@ -227,7 +228,7 @@ void TGAptSurface::fit() {
int nobs = Pts->cols() * Pts->rows(); // number of observations
SG_LOG(SG_GENERAL, SG_DEBUG, "QR triangularisation" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "QR triangularisation" );
// Create an array (matrix) with 16 columns (predictor values) A[n]
TNT::Array2D<double> mat(nobs,16);
@ -278,7 +279,7 @@ double TGAptSurface::query( SGGeod query ) {
// sanity check
if ( !_aptBounds.isInside(query) )
{
SG_LOG(SG_GENERAL, SG_WARN,
GENAPT_LOG(SG_GENERAL, SG_WARN,
"Warning: query out of bounds for fitted surface!");
return -9999.0;
}

View file

@ -31,7 +31,7 @@
#include <simgear/debug/logstream.hxx>
#include <Lib/Polygon/polygon.hxx>
#include "debug.hxx"
/***
* A dirt simple matrix class for our convenience based on top of SGGeod
@ -56,10 +56,10 @@ public:
inline SGGeod element( int col, int row ) {
int index = ( row * _cols ) + col;
if ( col < 0 || col >= _cols ) {
SG_LOG(SG_GENERAL, SG_WARN, "column out of bounds on read (" << col << " >= " << _cols << ")");
GENAPT_LOG(SG_GENERAL, SG_WARN, "column out of bounds on read (" << col << " >= " << _cols << ")");
int *p = 0; *p = 1; // force crash
} else if ( row < 0 || row >= _rows ) {
SG_LOG(SG_GENERAL, SG_WARN, "row out of bounds on read (" << row << " >= " << _rows << ")");
GENAPT_LOG(SG_GENERAL, SG_WARN, "row out of bounds on read (" << row << " >= " << _rows << ")");
int *p = 0; *p = 1; // force crash
}
return m.GetNode(index);
@ -68,10 +68,10 @@ public:
inline void set( int col, int row, SGGeod p ) {
int index = ( row * _cols ) + col;
if ( col < 0 || col >= _cols ) {
SG_LOG(SG_GENERAL, SG_WARN,"column out of bounds on set (" << col << " >= " << _cols << ")");
GENAPT_LOG(SG_GENERAL, SG_WARN,"column out of bounds on set (" << col << " >= " << _cols << ")");
int *p = 0; *p = 1; // force crash
} else if ( row < 0 || row >= _rows ) {
SG_LOG(SG_GENERAL, SG_WARN,"row out of bounds on set (" << row << " >= " << _rows << ")");
GENAPT_LOG(SG_GENERAL, SG_WARN,"row out of bounds on set (" << row << " >= " << _rows << ")");
int *p = 0; *p = 1; // force crash
}
m.SetNode(index, p);

View file

@ -8,6 +8,8 @@
#include <simgear/debug/logstream.hxx>
#include <simgear/math/SGMath.hxx>
#include "debug.hxx"
inline double LinearDistance( const SGGeod& p0, const SGGeod& p1 )
{
return SGGeodesy::distanceM( p0, p1 );
@ -259,7 +261,7 @@ public:
void Print()
{
SG_LOG(SG_GENERAL, SG_DEBUG,
GENAPT_LOG(SG_GENERAL, SG_DEBUG,
"\tLoc: " << loc << "\n" <<
"\tprev_cp: " << prev_cp << "\n" <<
"\tnext_cp: " << next_cp << "\n" );

View file

@ -63,7 +63,7 @@ ClosedPoly::ClosedPoly( int st, float s, float th, char* desc )
ClosedPoly::~ClosedPoly()
{
SG_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Deleting ClosedPoly " << description );
}
void ClosedPoly::AddNode( BezNode* node )
@ -75,7 +75,7 @@ void ClosedPoly::AddNode( BezNode* node )
}
cur_contour->push_back( node );
SG_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "CLOSEDPOLY::ADDNODE : " << node->GetLoc() );
// For pavement polys, add a linear feature for each contour
if (is_pavement)
@ -92,7 +92,7 @@ void ClosedPoly::AddNode( BezNode* node )
feature_desc += "boundary";
}
SG_LOG(SG_GENERAL, SG_DEBUG, " Adding node " << node->GetLoc() << " to current linear feature " << cur_feature);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Adding node " << node->GetLoc() << " to current linear feature " << cur_feature);
cur_feature = new LinearFeature(feature_desc, 1.0f );
}
cur_feature->AddNode( node );
@ -101,13 +101,13 @@ void ClosedPoly::AddNode( BezNode* node )
void ClosedPoly::CloseCurContour()
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Close Contour");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Close Contour");
// if we are recording a pavement marking - it must be closed -
// add the first node of the poly
if (cur_feature)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "We still have an active linear feature - add the first node to close it");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "We still have an active linear feature - add the first node to close it");
cur_feature->Finish(true, features.size() );
features.push_back(cur_feature);
@ -146,7 +146,7 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
double total_dist;
int num_segs = BEZIER_DETAIL;
SG_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src->size() << " nodes");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Creating a contour with " << src->size() << " nodes");
// clear anything in this point list
dst.Erase();
@ -154,7 +154,7 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
// iterate through each bezier node in the contour
for (unsigned int i = 0; i <= src->size()-1; i++)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nHandling Node " << i << "\n\n");
curNode = src->at(i);
if (i < src->size() - 1)
@ -211,8 +211,8 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
{
// If total distance is < 4 meters, then we need to modify num Segments so that each segment >= 2 meters
num_segs = ((int)total_dist + 1);
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( < 16.0) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( < 16.0) so num_segs is " << num_segs );
}
else
{
@ -223,16 +223,16 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
{
// If total distance is > 800 meters, then we need to modify num Segments so that each segment <= 100 meters
num_segs = total_dist / 100.0f + 1;
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( > 100.0) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( > 100.0) so num_segs is " << num_segs );
}
else
{
if (curve_type != CURVE_LINEAR)
{
num_segs = 8;
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " (OK) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " (OK) so num_segs is " << num_segs );
}
else
{
@ -274,11 +274,11 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
if (p==0)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Curve Anchor node (type " << curve_type << ") at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Curve Anchor node (type " << curve_type << ") at " << curLoc );
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, " add bezier node (type " << curve_type << ") at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " add bezier node (type " << curve_type << ") at " << curLoc );
}
// now set set cur location for the next iteration
@ -299,11 +299,11 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
if (p==0)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Linear anchor node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Linear anchor node at " << curLoc );
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, " add linear node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " add linear node at " << curLoc );
}
// now set set prev and cur locations for the next iteration
@ -317,7 +317,7 @@ void ClosedPoly::ConvertContour( BezContour* src, tgContour& dst )
// just add the one vertex - dist is small
dst.AddNode( curLoc );
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Linear Anchor node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Linear Anchor node at " << curLoc );
curLoc = nextLoc;
}
@ -333,10 +333,10 @@ void ClosedPoly::Finish()
// error handling
if (boundary == NULL)
{
SG_LOG(SG_GENERAL, SG_ALERT, "no boundary");
GENAPT_LOG(SG_GENERAL, SG_ALERT, "no boundary");
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Converting a poly with " << holes.size() << " holes");
if (boundary != NULL)
{
@ -408,20 +408,20 @@ std::string ClosedPoly::GetMaterial( int surface )
break;
default:
SG_LOG(SG_GENERAL, SG_ALERT, "ClosedPoly::BuildBtg: unknown surface type " << surface_type );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "ClosedPoly::BuildBtg: unknown surface type " << surface_type );
exit(1);
}
return material;
}
int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, std::string& shapefile_name )
int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, tgAccumulator& accum, std::string& shapefile_name )
{
if (is_pavement && pre_tess.Contours() )
{
tgPolygon base, safe_base;
BuildBtg( rwy_polys, slivers, shapefile_name );
BuildBtg( rwy_polys, slivers, accum, shapefile_name );
base = tgPolygon::Expand( pre_tess, 20.0 );
safe_base = tgPolygon::Expand( pre_tess, 50.0);
@ -437,16 +437,16 @@ int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tg
return 1;
}
int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, std::string& shapefile_name )
int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgAccumulator& accum, std::string& shapefile_name )
{
if ( is_pavement && pre_tess.Contours() )
{
if( shapefile_name.size() ) {
tgPolygon::ToShapefile( pre_tess, "./airport_dbg", std::string("preclip"), shapefile_name );
tgPolygon::AccumulatorToShapefiles( "./airport_dbg", "accum" );
accum.ToShapefiles( "./airport_dbg", "accum" );
}
tgPolygon clipped = tgPolygon::DiffWithAccumulator( pre_tess );
tgPolygon clipped = accum.Diff( pre_tess );
if ( clipped.Contours() ) {
if( shapefile_name.size() ) {
@ -462,7 +462,7 @@ int ClosedPoly::BuildBtg( tgpolygon_list& rwy_polys, tgcontour_list& slivers, st
rwy_polys.push_back( clipped );
tgPolygon::AddToAccumulator( pre_tess );
accum.Add( pre_tess );
}
}

View file

@ -26,12 +26,14 @@ public:
// Build BTG for pavements for airports with no boundary
int BuildBtg( tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
int BuildBtg( tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgpolygon_list& apt_base_polys,
tgpolygon_list& apt_clearing_polys,
tgAccumulator& accum,
std::string& shapefile_name );
FeatureList* GetFeatures()

View file

@ -0,0 +1,17 @@
#include "debug.hxx"
std::map<long, std::string> thread_prefix_map;
SGMutex logMutex;
void DebugRegisterPrefix( const std::string& prefix ) {
thread_prefix_map[SGThread::current()] = prefix;
}
std::string DebugTimeToString(time_t& tt)
{
char buf[256];
strcpy(buf,ctime(&tt));
buf[strlen(buf)-1]='\0';
return std::string( buf );
}

View file

@ -0,0 +1,34 @@
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <simgear/threads/SGThread.hxx>
#ifndef __DEBUG_HXX__
#define __DEBUG_HXX__
/* a debug map maps ICAOs to a vector of indexs we want to debug */
typedef std::map<std::string, std::vector<int>, std::less<std::string> > debug_map;
typedef debug_map::iterator debug_map_iterator;
typedef debug_map::const_iterator debug_map_const_iterator;
/* We'll need a mutex to print log messages 1 at a time */
extern SGMutex logMutex;
/* This map maps thread IDs to ICAO prefixes */
extern std::map<long, std::string> thread_prefix_map;
extern void DebugRegisterPrefix( const std::string& prefix );
extern std::string DebugTimeToString(time_t& tt);
#define GENAPT_LOG(C,P,M) do { \
logstream& __tmplogstreamref(sglog()); \
if(__tmplogstreamref.would_log(C,P)) { \
logMutex.lock(); \
__tmplogstreamref << loglevel(C,P) << thread_prefix_map[SGThread::current()] << ":" << M << std::endl; \
logMutex.unlock(); \
} \
} while(0)
#endif

View file

@ -63,7 +63,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
for ( i = 0; i < points.size(); ++i ) {
if ( points[i].getElevationM() < -9000.0 && !found_one ) {
first = points[i];
SG_LOG( SG_GENERAL, SG_DEBUG, "found first = " << first );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "found first = " << first );
found_one = true;
}
@ -81,7 +81,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
if ( array.open(array_path) ) {
found_file = true;
SG_LOG( SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path );
}
i++;
}
@ -123,7 +123,7 @@ double tgAverageElevation( const std::string &root, const string_list elev_src,
count++;
}
double average = total / (double) count;
SG_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of point list = " << average);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of point list = " << average);
return average;
}
@ -178,7 +178,7 @@ void tgCalcElevations( const std::string &root, const string_list elev_src,
if ( array.open(array_path) ) {
found_file = true;
SG_LOG( SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Using array_path = " << array_path );
}
j++;
}
@ -230,7 +230,7 @@ void tgCalcElevations( const std::string &root, const string_list elev_src,
}
}
double grid_average = total / (double) count;
SG_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of matrix = " << grid_average);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Average surface height of matrix = " << grid_average);
#endif
}
@ -247,13 +247,13 @@ void tgClampElevations( SimpleMatrix &Pts,
for ( i = 0; i < Pts.cols(); ++i ) {
SGGeod p = Pts.element(i,j);
if ( p.getElevationM() < center_m - max_clamp_m ) {
SG_LOG(SG_GENERAL, SG_DEBUG, " clamping " << p.getElevationM()
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " clamping " << p.getElevationM()
<< " to " << center_m - max_clamp_m );
p.setElevationM( center_m - max_clamp_m );
Pts.set(i, j, p);
}
if ( p.getElevationM() > center_m + max_clamp_m ) {
SG_LOG(SG_GENERAL, SG_DEBUG, " clamping " << p.getElevationM()
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " clamping " << p.getElevationM()
<< " to " << center_m + max_clamp_m );
p.setElevationM( center_m + max_clamp_m );
Pts.set(i, j, p);

View file

@ -23,6 +23,7 @@
#include "apt_math.hxx"
#include "helipad.hxx"
#include "runway.hxx"
#include "debug.hxx"
#include <stdlib.h>
@ -37,7 +38,7 @@ Helipad::Helipad(char* definition)
heli.designator, &heli.lat, &heli.lon, &heli.heading, &heli.length, &heli.width, &heli.surface,
&heli.marking, &heli.shoulder, &heli.smoothness, &heli.edge_lights);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read helipad: (" << heli.lon << "," << heli.lat << ") heading: " << heli.heading << " length: " << heli.length << " width: " << heli.width );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read helipad: (" << heli.lon << "," << heli.lat << ") heading: " << heli.heading << " length: " << heli.length << " width: " << heli.width );
}
tglightcontour_list Helipad::gen_helipad_lights(double maxsize) {
@ -115,7 +116,8 @@ void Helipad::build_helipad_shoulders( const tgContour& outer_area )
void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
tglightcontour_list& rwy_lights,
tgcontour_list& slivers )
tgcontour_list& slivers,
tgAccumulator& accum )
{
//
// Generate the basic helipad outlines
@ -144,14 +146,14 @@ void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
}
// Clip the new polygon against what ever has already been created.
tgPolygon clipped = tgContour::DiffWithAccumulator( helipad );
tgPolygon clipped = accum.Diff( helipad );
tgPolygon::RemoveSlivers( clipped, slivers );
// Split long edges to create an object that can better flow with
// the surface terrain
tgPolygon heli_poly = tgPolygon::SplitLongEdges( clipped, 400.0 );
tgContour::AddToAccumulator( helipad );
accum.Add( helipad );
heli_poly.SetMaterial( heli_mat );
heli_poly.SetTexParams( helipad.GetNode(0), heli_size, heli_size, heli.heading );
@ -169,7 +171,7 @@ void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
outer_area = tgContour::Snap( outer_area, gSnap );
tgPolygon outer_poly = tgContour::Diff( outer_area, heli_poly );
clipped = tgPolygon::DiffWithAccumulator( outer_poly );
clipped = accum.Diff( outer_poly );
tgPolygon::RemoveSlivers( clipped, slivers );
// Split long edges to create an object that can better flow with
@ -183,7 +185,7 @@ void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
extra_heli.SetTexLimits( 1,1,0,0 );
extra_heli.SetTexMethod( TG_TEX_BY_TPS_NOCLIP );
rwy_polys.push_back( extra_heli );
tgPolygon::AddToAccumulator( extra_heli );
accum.Add( extra_heli );
build_helipad_shoulders( outer_area );
@ -201,9 +203,10 @@ void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
tglightcontour_list& rwy_lights,
tgcontour_list& slivers,
tgpolygon_list& apt_base_polys,
tgpolygon_list& apt_clearing_polys )
tgpolygon_list& apt_clearing_polys,
tgAccumulator& accum )
{
BuildBtg( rwy_polys, rwy_lights, slivers );
BuildBtg( rwy_polys, rwy_lights, slivers, accum );
// generate area around helipad
double length, width;
@ -237,7 +240,8 @@ void Helipad::BuildBtg( tgpolygon_list& rwy_polys,
}
void Helipad::BuildShoulder( tgpolygon_list& rwy_polys,
tgcontour_list& slivers )
tgcontour_list& slivers,
tgAccumulator& accum )
{
tgPolygon shoulder;
@ -245,7 +249,7 @@ void Helipad::BuildShoulder( tgpolygon_list& rwy_polys,
shoulder = shoulder_polys[i];
// Clip the new polygon against what ever has already been created.
tgPolygon clipped = tgPolygon::DiffWithAccumulator( shoulder );
tgPolygon clipped = accum.Diff( shoulder );
tgPolygon::RemoveSlivers( clipped, slivers );
// Split long edges to create an object that can better flow with
@ -255,6 +259,6 @@ void Helipad::BuildShoulder( tgpolygon_list& rwy_polys,
rwy_polys.push_back( shoulder_polys[i] );
tgPolygon::AddToAccumulator( shoulder );
accum.Add( shoulder );
}
}
}

View file

@ -25,13 +25,15 @@ public:
void BuildBtg( tgpolygon_list& heli_polys,
tglightcontour_list& heli_lights,
tgcontour_list& slivers );
tgcontour_list& slivers,
tgAccumulator& accum );
void BuildBtg( tgpolygon_list& heli_polys,
tglightcontour_list& heli_lights,
tgcontour_list& slivers,
tgpolygon_list& apt_base_polys,
tgpolygon_list& apt_clearing_polys );
tgpolygon_list& apt_clearing_polys,
tgAccumulator& accum );
SGGeod GetLoc()
{
@ -44,7 +46,9 @@ public:
}
void BuildShoulder( tgpolygon_list& rwy_polys,
tgcontour_list& slivers );
tgcontour_list& slivers,
tgAccumulator& accum
);
private:
struct TGRunway {

View file

@ -25,7 +25,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
Marking* cur_mark = NULL;
Lighting* cur_light = NULL;
SG_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src->size() << " nodes");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " LinearFeature::ConvertContour - Creating a contour with " << src->size() << " nodes");
// clear anything in the point list
points.Erase();
@ -53,7 +53,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if (curNode->GetMarking() != cur_mark->type)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Marking has changed from " << cur_mark->type << " to " << curNode->GetMarking() << " save mark from " << cur_mark->start_idx << " to " << points.GetSize() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Marking has changed from " << cur_mark->type << " to " << curNode->GetMarking() << " save mark from " << cur_mark->start_idx << " to " << points.GetSize() );
// marking has ended, or changed
cur_mark->end_idx = points.GetSize();
@ -62,7 +62,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Continue Marking from " << cur_mark->start_idx << " with type " << cur_mark->type );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Continue Marking from " << cur_mark->start_idx << " with type " << cur_mark->type );
}
}
@ -71,7 +71,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if (curNode->GetMarking())
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Start Marking from " << points.GetSize() << " with type " << curNode->GetMarking() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Start Marking from " << points.GetSize() << " with type " << curNode->GetMarking() );
// we aren't watching a mark, and this node has one
cur_mark = new Marking;
@ -90,7 +90,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if (curNode->GetLighting() != cur_light->type)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Lighting has changed from " << cur_light->type << " to " << curNode->GetLighting() << " save light from " << cur_light->start_idx << " to " << points.GetSize() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Lighting has changed from " << cur_light->type << " to " << curNode->GetLighting() << " save light from " << cur_light->start_idx << " to " << points.GetSize() );
// lighting has ended, or changed : add final light
cur_light->end_idx = points.GetSize();
@ -99,7 +99,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Continue Lighting from " << cur_light->start_idx << " with type " << cur_light->type );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Continue Lighting from " << cur_light->start_idx << " with type " << cur_light->type );
}
}
@ -108,7 +108,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if (curNode->GetLighting())
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Start Lighting from " << points.GetSize() << " with type " << curNode->GetLighting() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Start Lighting from " << points.GetSize() << " with type " << curNode->GetLighting() );
// we aren't watching a mark, and this node has one
cur_light = new Lighting;
@ -169,12 +169,12 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if ( (abs(theta1 - 180.0) < 5.0 ) || (abs(theta1) < 5.0 ) || (isnan(theta1)) )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Quadtratic curve with cp in line : convert to linear: " << description << ": theta is " << theta1 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Quadtratic curve with cp in line : convert to linear: " << description << ": theta is " << theta1 );
curve_type = CURVE_LINEAR;
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Quadtratic curve withOUT cp in line : keep quadtratic: " << description << ": theta is " << theta1 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Quadtratic curve withOUT cp in line : keep quadtratic: " << description << ": theta is " << theta1 );
}
}
@ -182,30 +182,30 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
if ( (abs(theta1 - 180.0) < 5.0 ) || (abs(theta1) < 5.0 ) || (isnan(theta1)) )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Cubic curve with cp1 in line : " << description << ": theta is " << theta1 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Cubic curve with cp1 in line : " << description << ": theta is " << theta1 );
if ( (abs(theta2 - 180.0) < 5.0 ) || (abs(theta2) < 5.0 ) || (isnan(theta2)) )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\n and cp2 in line : " << description << ": theta is " << theta2 << " CONVERTING TO LINEAR" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\n and cp2 in line : " << description << ": theta is " << theta2 << " CONVERTING TO LINEAR" );
curve_type = CURVE_LINEAR;
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\n BUT cp2 NOT in line : " << description << ": theta is " << theta2 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\n BUT cp2 NOT in line : " << description << ": theta is " << theta2 );
}
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Cubic curve withOUT cp1 in line : keep quadtratic: " << description << ": theta is " << theta1 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: Cubic curve withOUT cp1 in line : keep quadtratic: " << description << ": theta is " << theta1 );
if ( (abs(theta2 - 180.0) < 5.0 ) || (abs(theta2) < 5.0 ) || (isnan(theta2)) )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\n BUT cp2 IS in line : " << description << ": theta is " << theta2 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\n BUT cp2 IS in line : " << description << ": theta is " << theta2 );
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\n AND cp2 NOT in line : " << description << ": theta is " << theta2 );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\n AND cp2 NOT in line : " << description << ": theta is " << theta2 );
}
}
}
@ -216,8 +216,8 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
// If total distance is < 4 meters, then we need to modify num Segments so that each segment >= 1/2 meter
num_segs = ((int)total_dist + 1) * 2;
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( < 4.0) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( < 4.0) so num_segs is " << num_segs );
}
else
{
@ -228,16 +228,16 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
{
// If total distance is > 800 meters, then we need to modify num Segments so that each segment <= 100 meters
num_segs = total_dist / 100.0f + 1;
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( > 100.0) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " ( > 100.0) so num_segs is " << num_segs );
}
else
{
if (curve_type != CURVE_LINEAR)
{
num_segs = 8;
SG_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
SG_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " (OK) so num_segs is " << num_segs );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Segment from " << curNode->GetLoc() << " to " << nextNode->GetLoc() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " Distance is " << total_dist << " (OK) so num_segs is " << num_segs );
}
else
{
@ -272,11 +272,11 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
if (p==0)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Curve Anchor node (type " << curve_type << ") at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Curve Anchor node (type " << curve_type << ") at " << curLoc );
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, " add bezier node (type " << curve_type << ") at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " add bezier node (type " << curve_type << ") at " << curLoc );
}
// now set set prev and cur locations for the next iteration
@ -298,11 +298,11 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
if (p==0)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Linear anchor node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Linear anchor node at " << curLoc );
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, " add linear node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, " add linear node at " << curLoc );
}
// now set set prev and cur locations for the next iteration
@ -316,7 +316,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
// just add the one vertex - dist is small
points.AddNode(curLoc);
SG_LOG(SG_GENERAL, SG_DEBUG, "adding Linear Anchor node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "adding Linear Anchor node at " << curLoc );
curLoc = nextLoc;
}
@ -325,7 +325,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
if (closed)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Closed COntour : adding last node at " << curLoc );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Closed COntour : adding last node at " << curLoc );
// need to add the markings for last segment
points.AddNode(curLoc);
@ -334,7 +334,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
// check for marking that goes all the way to the end...
if (cur_mark)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Marking from " << cur_mark->start_idx << " with type " << cur_mark->type << " ends at the end of the contour: " << points.GetSize() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Marking from " << cur_mark->start_idx << " with type " << cur_mark->type << " ends at the end of the contour: " << points.GetSize() );
cur_mark->end_idx = points.GetSize()-1;
marks.push_back(cur_mark);
@ -344,7 +344,7 @@ void LinearFeature::ConvertContour( BezContour* src, bool closed )
// check for lighting that goes all the way to the end...
if (cur_light)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Lighting from " << cur_light->start_idx << " with type " << cur_light->type << " ends at the end of the contour: " << points.GetSize() );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::ConvertContour Lighting from " << cur_light->start_idx << " with type " << cur_light->type << " ends at the end of the contour: " << points.GetSize() );
cur_light->end_idx = points.GetSize()-1;
lights.push_back(cur_light);
@ -373,7 +373,7 @@ SGGeod LinearFeature::OffsetPointMiddle( const SGGeod& gPrev, const SGGeod& gCur
double courseOffset, distOffset;
SGGeod pt;
SG_LOG(SG_GENERAL, SG_DEBUG, "Find average angle for contour: prev (" << gPrev << "), "
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Find average angle for contour: prev (" << gPrev << "), "
"cur (" << gCur << "), "
"next (" << gNext << ")" );
@ -399,13 +399,13 @@ SGGeod LinearFeature::OffsetPointMiddle( const SGGeod& gPrev, const SGGeod& gCur
theta = SGMiscd::rad2deg(CalculateTheta( dirCur, dirNext, cp ) );
if ( (abs(theta - 180.0) < 0.1) || (abs(theta) < 0.1) || (isnan(theta)) ) {
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: (degenerate case) " << description << ": theta is " << theta );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: (degenerate case) " << description << ": theta is " << theta );
// straight line blows up math - offset 90 degree and dist is as given
courseOffset = SGMiscd::normalizePeriodic(0, 360, courseNext-90.0);
distOffset = offset_by;
} else {
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: (normal case) " << description << ": theta is " << theta );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature: (normal case) " << description << ": theta is " << theta );
// calculate correct distance for the offset point
if (cp.z() < 0.0f) {
@ -418,7 +418,7 @@ SGGeod LinearFeature::OffsetPointMiddle( const SGGeod& gPrev, const SGGeod& gCur
// calculate the point from cur
pt = SGGeodesy::direct(gCur, courseOffset, distOffset);
SG_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << distOffset << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << distOffset << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
return pt;
}
@ -428,7 +428,7 @@ SGGeod LinearFeature::OffsetPointFirst( const SGGeod& cur, const SGGeod& next, d
double courseOffset;
SGGeod pt;
SG_LOG(SG_GENERAL, SG_DEBUG, "Find OffsetPoint at Start : cur (" << cur << "), "
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Find OffsetPoint at Start : cur (" << cur << "), "
"next (" << next << ")" );
// find the offset angle
@ -437,7 +437,7 @@ SGGeod LinearFeature::OffsetPointFirst( const SGGeod& cur, const SGGeod& next, d
// calculate the point from cur
pt = SGGeodesy::direct( cur, courseOffset, offset_by );
SG_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << offset_by << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << offset_by << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
return pt;
}
@ -447,7 +447,7 @@ SGGeod LinearFeature::OffsetPointLast( const SGGeod& prev, const SGGeod& cur, do
double courseOffset;
SGGeod pt;
SG_LOG(SG_GENERAL, SG_DEBUG, "Find OffsetPoint at End : prev (" << prev << "), "
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Find OffsetPoint at End : prev (" << prev << "), "
"cur (" << cur << ")" );
// find the offset angle
@ -456,7 +456,7 @@ SGGeod LinearFeature::OffsetPointLast( const SGGeod& prev, const SGGeod& cur, do
// calculate the point from cur
pt = SGGeodesy::direct( cur, courseOffset, offset_by );
SG_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << offset_by << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\theading is " << courseOffset << " distance is " << offset_by << " point is (" << pt.getLatitudeDeg() << "," << pt.getLongitudeDeg() << ")" );
return pt;
}
@ -606,13 +606,13 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
break;
default:
SG_LOG(SG_GENERAL, SG_ALERT, "LinearFeature::Finish: unknown marking " << marks[i]->type );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "LinearFeature::Finish: unknown marking " << marks[i]->type );
exit(1);
}
for (unsigned int j = marks[i]->start_idx; j <= marks[i]->end_idx; j++)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::Finish: calculating offsets for mark " << i << " whose start idx is " << marks[i]->start_idx << " and end idx is " << marks[i]->end_idx << " cur idx is " << j );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::Finish: calculating offsets for mark " << i << " whose start idx is " << marks[i]->start_idx << " and end idx is " << marks[i]->end_idx << " cur idx is " << j );
// for each point on the PointsList, generate a quad from
// start to next, offset by 2 distnaces from the edge
@ -713,7 +713,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
for (unsigned int j = lights[i]->start_idx; j <= lights[i]->end_idx; j++)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::Finish: calculating offsets for light " << i << " whose start idx is " << lights[i]->start_idx << " and end idx is " << lights[i]->end_idx << " cur idx is " << j );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::Finish: calculating offsets for light " << i << " whose start idx is " << lights[i]->start_idx << " and end idx is " << lights[i]->end_idx << " cur idx is " << j );
// for each point on the PointsList, offset by 2 distnaces from the edge, and add a point to the superpoly contour
if (j == lights[i]->start_idx)
{
@ -797,7 +797,7 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
// if there were lights generated - create the superpoly
if (cur_light_contour.ContourSize())
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: Adding light contour with " << cur_light_contour.ContourSize() << " lights" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: Adding light contour with " << cur_light_contour.ContourSize() << " lights" );
cur_light_contour.SetFlag("");
lighting_polys.push_back(cur_light_contour);
}
@ -805,35 +805,35 @@ int LinearFeature::Finish( bool closed, unsigned int idx )
// create the superpoly for the alternating light color
if (alt_light_contour.ContourSize())
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: Adding light contour with " << cur_light_contour.ContourSize() << " lights" );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: Adding light contour with " << cur_light_contour.ContourSize() << " lights" );
alt_light_contour.SetFlag("");
lighting_polys.push_back(cur_light_contour);
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: No points for linear feature " << description << " light index " << i );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::Finish: No points for linear feature " << description << " light index " << i );
}
}
return 1;
}
int LinearFeature::BuildBtg(tgpolygon_list& line_polys, tglightcontour_list& lights, bool make_shapefiles )
int LinearFeature::BuildBtg(tgpolygon_list& line_polys, tglightcontour_list& lights, tgAccumulator& accum, bool make_shapefiles )
{
tgPolygon poly;
SGGeod min, max, minp, maxp;
SG_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::BuildBtg: " << description);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "\nLinearFeature::BuildBtg: " << description);
for ( unsigned int i = 0; i < marking_polys.size(); i++)
{
// Clipping and triangulation need to copy texparams, and material info...
marking_polys[i] = tgPolygon::DiffWithAccumulator( marking_polys[i] );
marking_polys[i] = accum.Diff( marking_polys[i] );
line_polys.push_back( marking_polys[i] );
tgPolygon::AddToAccumulator( marking_polys[i] );
accum.Add( marking_polys[i] );
}
SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::BuildBtg: add " << lighting_polys.size() << " light defs");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::BuildBtg: add " << lighting_polys.size() << " light defs");
for ( unsigned i = 0; i < lighting_polys.size(); i++)
{
lights.push_back( lighting_polys[i] );

View file

@ -2,6 +2,8 @@
#define _LINEARFEATURE_H_
#include <Polygon/polygon.hxx>
#include "beznode.hxx"
#define LF_NONE (0)
#define LF_SOLID_YELLOW (1)
@ -90,7 +92,7 @@ public:
}
int Finish( bool closed, unsigned int idx );
int BuildBtg( tgpolygon_list& line_polys, tglightcontour_list& lights, bool debug );
int BuildBtg( tgpolygon_list& line_polys, tglightcontour_list& lights, tgAccumulator& accum, bool debug );
private:
SGGeod OffsetPointFirst( const SGGeod& cur, const SGGeod& next, double offset_by );

View file

@ -1,18 +1,19 @@
#include <simgear/debug/logstream.hxx>
#include "linked_objects.hxx"
#include "debug.hxx"
Windsock::Windsock( char* definition )
{
sscanf(definition, "%lf %lf %d", &lat, &lon, &lit);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read Windsock: (" << lon << "," << lat << ") lit: " << lit );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read Windsock: (" << lon << "," << lat << ") lit: " << lit );
}
Beacon::Beacon( char* definition )
{
sscanf(definition, "%lf %lf %d", &lat, &lon, &code);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read Beacon: (" << lon << "," << lat << ") code: " << code );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read Beacon: (" << lon << "," << lat << ") code: " << code );
}
Sign::Sign( char* definition )
@ -26,7 +27,7 @@ Sign::Sign( char* definition )
// Flightgear wants the heading to be the heading in which the sign is read
heading = -def_heading + 360.0;
SG_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat << ") heading " << def_heading << " size " << size << " definition: " << sgdef << " calc view heading: " << heading );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read Sign: (" << lon << "," << lat << ") heading " << def_heading << " size " << size << " definition: " << sgdef << " calc view heading: " << heading );
sgn_def = sgdef;
}

View file

@ -13,14 +13,10 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#include <string.h>
#include <string>
#include <iostream>
#include <Poco/Environment.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/Socket.h>
#include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SocketStream.h>
#include <boost/thread.hpp>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
@ -30,6 +26,7 @@
#include <Geometry/util.hxx>
#include <Geometry/poly_support.hxx>
#include "scheduler.hxx"
#include "beznode.hxx"
#include "closedpoly.hxx"
#include "linearfeature.hxx"
@ -37,24 +34,10 @@
#include "scheduler.hxx"
using namespace std;
using namespace Poco;
// TODO : Modularize this function
// IDEAS
// 1) Start / Stop MarkStyle
// 2) Start / Stop LightStyle
// 3) holes
// 4) CreatePavementSS(pavement type)
// 5) CreateMarkingSS(marking type)
// 6) CalcStripeOffsets should be AddMarkingVerticies, and take the 2 distances from pavement edge...
// SCRAP ALL IDEAS - Markings are encapsulated in LinearFeature class.
// Start creates a new object
// End closes the object (and should add it to a list - either in the parser, or ClosedPoly)
// Display usage
static void usage( int argc, char **argv ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << argv[0] << "\n--input=<apt_file>"
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Usage: " << argv[0] << "\n--input=<apt_file>"
<< "\n--work=<work_dir>\n[ --start-id=abcd ] [ --restart-id=abcd ] [ --nudge=n ] "
<< "[--min-lon=<deg>] [--max-lon=<deg>] [--min-lat=<deg>] [--max-lat=<deg>] "
<< "[ --airport=abcd ] [--max-slope=<decimal>] [--tile=<tile>] [--threads] [--threads=x]"
@ -123,45 +106,35 @@ double gSnap = 0.00000001; // approx 1 mm
//TODO : new polygon chop API
extern bool tgPolygon_index_init( const std::string& path );
// For creating a buffered stream to write to the socket
Net::StreamSocket ss;
Net::SocketStreamBuf ssb( ss );
ostream os(&ssb);
int main(int argc, char **argv)
{
SGGeod min = SGGeod::fromDeg( -180, -90 );
SGGeod max = SGGeod::fromDeg( 180, 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;
elev_src.clear();
setup_default_elevation_sources(elev_src);
string debug_dir = ".";
vector<string> debug_runway_defs;
vector<string> debug_pavement_defs;
vector<string> debug_taxiway_defs;
vector<string> debug_feature_defs;
std::string debug_dir = ".";
vector<std::string> debug_runway_defs;
vector<std::string> debug_pavement_defs;
vector<std::string> debug_taxiway_defs;
vector<std::string> debug_feature_defs;
// Set Normal logging
sglog().setLogLevels( SG_GENERAL, SG_INFO );
// parse arguments
string work_dir = "";
string input_file = "";
string summary_file = "./genapt850.csv";
string start_id = "";
string restart_id = "";
string airport_id = "";
long airport_pos = -1;
string last_apt_file = "./last_apt.txt";
int num_threads = 1;
int redirect_port = -1;
std::string work_dir = "";
std::string input_file = "";
std::string summary_file = "./genapt850.csv";
std::string start_id = "";
std::string restart_id = "";
std::string airport_id = "";
std::string last_apt_file = "./last_apt.txt";
int num_threads = 1;
int arg_pos;
for (arg_pos = 1; arg_pos < argc; arg_pos++)
@ -179,10 +152,6 @@ int main(int argc, char **argv)
{
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 )
{
restart_id = arg.substr(13);
@ -242,10 +211,6 @@ int main(int argc, char **argv)
else if ( (arg.find("--verbose") == 0) || (arg.find("-v") == 0) )
{
sglog().setLogLevels( SG_GENERAL, SG_BULK );
}
else if ( arg.find("--redirect-port=") == 0 )
{
redirect_port = atoi( arg.substr(16).c_str() );
}
else if ( (arg.find("--max-slope=") == 0) )
{
@ -257,7 +222,7 @@ int main(int argc, char **argv)
}
else if ( (arg.find("--threads") == 0) )
{
num_threads = Poco::Environment::processorCount();
num_threads = boost::thread::hardware_concurrency();
}
else if (arg.find("--debug-dir=") == 0)
{
@ -273,7 +238,7 @@ int main(int argc, char **argv)
}
else if (arg.find("--debug-taxiways=") == 0)
{
SG_LOG(SG_GENERAL, SG_INFO, "add debug taxiway " << arg.substr(17) );
GENAPT_LOG(SG_GENERAL, SG_INFO, "add debug taxiway " << arg.substr(17) );
debug_taxiway_defs.push_back( arg.substr(17) );
}
else if (arg.find("--debug-features=") == 0)
@ -292,53 +257,38 @@ int main(int argc, char **argv)
}
}
string airportareadir=work_dir+"/AirportArea";
std::string airportareadir=work_dir+"/AirportArea";
// check for output redirect
if ( redirect_port >= 0 ) {
// this is the main program -
GENAPT_LOG(SG_GENERAL, SG_INFO, "Launch command was " << argv[0] );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Run genapts with " << num_threads << " threads" );
GENAPT_LOG(SG_GENERAL, SG_INFO, "Input file = " << input_file);
GENAPT_LOG(SG_GENERAL, SG_INFO, "Terrain sources = ");
for ( unsigned int i = 0; i < elev_src.size(); ++i ) {
GENAPT_LOG(SG_GENERAL, SG_INFO, " " << work_dir << "/" << elev_src[i] );
}
GENAPT_LOG(SG_GENERAL, SG_INFO, "Work directory = " << work_dir);
GENAPT_LOG(SG_GENERAL, SG_INFO, "Nudge = " << nudge);
GENAPT_LOG(SG_GENERAL, SG_INFO, "Longitude = " << min.getLongitudeDeg() << ':' << max.getLongitudeDeg());
GENAPT_LOG(SG_GENERAL, SG_INFO, "Latitude = " << min.getLatitudeDeg() << ':' << max.getLatitudeDeg());
// create a stream socket back to the main process
Net::SocketAddress sa( "localhost", redirect_port );
ss.connect(sa);
// then a buffered stream to write to the socket
os.rdbuf(&ssb);
// then hook up SG_LOG to the stream buf
sglog().set_output( os );
} else {
// this is the main program -
SG_LOG(SG_GENERAL, SG_INFO, "Launch command was " << argv[0] );
SG_LOG(SG_GENERAL, SG_INFO, "Run genapts with " << num_threads << " threads" );
SG_LOG(SG_GENERAL, SG_INFO, "Input file = " << input_file);
SG_LOG(SG_GENERAL, SG_INFO, "Terrain sources = ");
for ( unsigned int i = 0; i < elev_src.size(); ++i ) {
SG_LOG(SG_GENERAL, SG_INFO, " " << work_dir << "/" << elev_src[i] );
}
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.getLongitudeDeg() << ':' << max.getLongitudeDeg());
SG_LOG(SG_GENERAL, SG_INFO, "Latitude = " << min.getLatitudeDeg() << ':' << max.getLatitudeDeg());
if (!max.isValid() || !min.isValid())
{
SG_LOG(SG_GENERAL, SG_ALERT, "Bad longitude or latitude");
exit(1);
}
// make work directory
SG_LOG(SG_GENERAL, SG_INFO, "Creating AirportArea directory");
SGPath sgp( airportareadir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
if (!max.isValid() || !min.isValid())
{
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Bad longitude or latitude");
exit(1);
}
string command = argv[0];
string lastaptfile = work_dir+"/last_apt";
// make work directory
GENAPT_LOG(SG_GENERAL, SG_INFO, "Creating AirportArea directory");
SGPath sgp( airportareadir );
sgp.append( "dummy" );
sgp.create_dir( 0755 );
std::string lastaptfile = work_dir+"/last_apt";
// initialize persistant polygon counter
string counter_file = airportareadir+"/poly_counter";
std::string counter_file = airportareadir+"/poly_counter";
tgPolygon_index_init( counter_file );
tg::Rectangle boundingBox(min, max);
@ -346,14 +296,14 @@ int main(int argc, char **argv)
if ( work_dir == "" )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Error: no work directory specified." );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Error: no work directory specified." );
usage( argc, argv );
exit(-1);
}
if ( input_file == "" )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Error: no input file." );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Error: no input file." );
exit(-1);
}
@ -363,12 +313,12 @@ int main(int argc, char **argv)
sg_gzifstream in( input_file );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << input_file );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << input_file );
exit(-1);
}
// Create the scheduler
Scheduler* scheduler = new Scheduler(command, input_file, work_dir, elev_src);
Scheduler* scheduler = new Scheduler(input_file, work_dir, elev_src);
// Add any debug
scheduler->set_debug( debug_dir, debug_runway_defs, debug_pavement_defs, debug_taxiway_defs, debug_feature_defs );
@ -379,22 +329,15 @@ int main(int argc, char **argv)
// just find and add the one airport
scheduler->AddAirport( airport_id );
SG_LOG(SG_GENERAL, SG_INFO, "Finished Adding airport - now parse");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Finished Adding airport - now parse");
// and schedule parsers
scheduler->Schedule( num_threads, summary_file );
}
// We are given an airport position from a main scheduler - parse this
else if ( airport_pos != -1 )
{
// create and start the real parser
Parser parser(input_file, work_dir, elev_src);
parser.set_debug( debug_dir, debug_runway_defs, debug_pavement_defs, debug_taxiway_defs, debug_feature_defs );
parser.Parse( airport_pos );
}
else if ( start_id != "" )
{
SG_LOG(SG_GENERAL, SG_INFO, "move forward to " << start_id );
GENAPT_LOG(SG_GENERAL, SG_INFO, "move forward to " << start_id );
// scroll forward in datafile
position = scheduler->FindAirport( start_id );
@ -416,9 +359,8 @@ int main(int argc, char **argv)
}
}
SG_LOG(SG_GENERAL, SG_INFO, "Done");
GENAPT_LOG(SG_GENERAL, SG_INFO, "Done");
exit(0);
return 0;
}
}

View file

@ -1,12 +1,13 @@
#include <simgear/math/SGMathFwd.hxx>
#include <simgear/debug/logstream.hxx>
#include "object.hxx"
#include "debug.hxx"
LightingObj::LightingObj( char* definition )
{
sscanf(definition, "%lf %lf %d %lf %lf %s", &lat, &lon, &type, &heading, &glideslope, &assoc_rw);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read lighting object: (" << lon << "," << lat << ") heading: " << heading << " type: " << type );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read lighting object: (" << lon << "," << lat << ") heading: " << heading << " type: " << type );
}
void LightingObj::BuildBtg( tglightcontour_list& lights )
@ -29,7 +30,7 @@ void LightingObj::BuildBtg( tglightcontour_list& lights )
if (type == 1)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Generating VASI = " << assoc_rw);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Generating VASI = " << assoc_rw);
// VASI coordinates describe the center between the two bars.
// Space between the bars is 200m
@ -64,7 +65,7 @@ void LightingObj::BuildBtg( tglightcontour_list& lights )
}
else if (type == 2)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Generating PAPI 4L = " << assoc_rw);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Generating PAPI 4L = " << assoc_rw);
// unit1
pt1 = SGGeodesy::direct( ref, left_hdg, -12 );
@ -79,7 +80,7 @@ void LightingObj::BuildBtg( tglightcontour_list& lights )
}
else if (type == 3)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Generating PAPI 4R = " << assoc_rw);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Generating PAPI 4R = " << assoc_rw);
// unit1
pt1 = SGGeodesy::direct( ref, left_hdg, 12 );
@ -94,19 +95,19 @@ void LightingObj::BuildBtg( tglightcontour_list& lights )
}
else if (type == 4)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Space Shuttle PAPI is deprecated. Use the normal PAPI and set the glideslope accordingly");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Space Shuttle PAPI is deprecated. Use the normal PAPI and set the glideslope accordingly");
return;
}
else if (type == 5)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Generating tri-colour VASI = " << assoc_rw);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Generating tri-colour VASI = " << assoc_rw);
// only one light here
light_contour.AddLight( ref, normal );
}
else if (type == 6)
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Generating runway guard light = " << assoc_rw);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Generating runway guard light = " << assoc_rw);
light_contour.SetType( "RWY_GUARD_LIGHTS" );
@ -118,7 +119,7 @@ void LightingObj::BuildBtg( tglightcontour_list& lights )
}
else
{
SG_LOG(SG_GENERAL, SG_ALERT, "Unknown lighting object (PAPI/VASI...) code: " << type);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Unknown lighting object (PAPI/VASI...) code: " << type);
return;
}

View file

@ -1,32 +1,18 @@
#include <ctime>
#include <Poco/Mutex.h>
#include <Poco/Pipe.h>
#include <Poco/PipeStream.h>
#include <Poco/Process.h>
#include <Poco/Runnable.h>
#include <Poco/Semaphore.h>
#include <Poco/Thread.h>
#include <Poco/Timespan.h>
#include <Poco/Net/ServerSocket.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/SocketStream.h>
#include <Poco/Net/Socket.h>
#include <Poco/Net/StreamSocket.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx>
#include <simgear/timing/timestamp.hxx>
#include "parser.hxx"
bool Parser::GetAirportDefinition( char* line, string& icao )
bool Parser::GetAirportDefinition( char* line, std::string& icao )
{
char* tok;
int code;
Airport* airport = NULL;
bool match = false;
// Get the number code
tok = strtok(line, " \t\r\n");
@ -53,21 +39,21 @@ bool Parser::GetAirportDefinition( char* line, string& icao )
return match;
}
void Parser::set_debug( std::string path, std::vector<string> runway_defs,
std::vector<string> pavement_defs,
std::vector<string> taxiway_defs,
std::vector<string> feature_defs )
void Parser::set_debug( std::string path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs )
{
SG_LOG(SG_GENERAL, SG_ALERT, "Set debug Path " << path);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Set debug Path " << path);
debug_path = path;
/* Find any ids for our tile */
for (unsigned int i=0; i< runway_defs.size(); i++) {
string dsd = runway_defs[i];
std::string dsd = runway_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -81,7 +67,7 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i);
shapes.push_back(i);
@ -93,10 +79,10 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< pavement_defs.size(); i++) {
string dsd = pavement_defs[i];
std::string dsd = pavement_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -110,7 +96,7 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i);
shapes.push_back(i);
@ -122,10 +108,10 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< taxiway_defs.size(); i++) {
string dsd = taxiway_defs[i];
std::string dsd = taxiway_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -139,7 +125,7 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i);
shapes.push_back(i);
@ -151,10 +137,10 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< feature_defs.size(); i++) {
string dsd = feature_defs[i];
std::string dsd = feature_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -168,7 +154,7 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i);
shapes.push_back(i);
@ -180,10 +166,10 @@ void Parser::set_debug( std::string path, std::vector<string> runway_defs,
}
}
void Parser::Parse( long pos )
void Parser::run()
{
char line[2048];
string icao;
std::string icao;
SGTimeStamp parse_start;
SGTimeStamp parse_end;
@ -192,63 +178,74 @@ void Parser::Parse( long pos )
SGTimeStamp clean_time;
SGTimeStamp triangulation_time;
time_t log_time;
long pos;
ifstream in( filename.c_str() );
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
in.seekg(pos, ios::beg);
// get a line
in.getline(line, 2048);
// as long as we have airports to parse, do so
while (!global_workQueue.empty()) {
AirportInfo ai = global_workQueue.pop();
// Verify this is and airport definition and get the icao
if( GetAirportDefinition( line, icao ) ) {
SG_LOG( SG_GENERAL, SG_INFO, "Found airport " << icao << " at " << pos );
// Start parse at pos
SetState(STATE_NONE);
in.clear();
parse_start.stamp();
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "\n*******************************************************************" );
SG_LOG( SG_GENERAL, SG_ALERT, "Start airport " << icao << " at " << pos << ": start time " << ctime(&log_time) );
in.seekg(pos, ios::beg);
while ( !in.eof() && (cur_state != STATE_DONE ) )
{
in.getline(line, 2048);
// Parse the line
ParseLine(line);
if ( ai.GetIcao() == "NZSP" ) {
continue;
}
parse_end.stamp();
parse_time = parse_end - parse_start;
DebugRegisterPrefix( ai.GetIcao() );
pos = ai.GetPos();
in.seekg(pos, std::ios::beg);
// write the airport BTG
if (cur_airport)
{
cur_airport->set_debug( debug_path, debug_runways, debug_pavements, debug_taxiways, debug_features );
cur_airport->BuildBtg( work_dir, elevation );
// get a line
in.getline(line, 2048);
cur_airport->GetBuildTime( build_time );
cur_airport->GetCleanupTime( clean_time );
cur_airport->GetTriangulationTime( triangulation_time );
// Verify this is and airport definition and get the icao
if( GetAirportDefinition( line, icao ) ) {
GENAPT_LOG( SG_GENERAL, SG_INFO, "Found airport " << icao << " at " << pos );
delete cur_airport;
cur_airport = NULL;
// Start parse at pos
SetState(STATE_NONE);
in.clear();
parse_start.stamp();
log_time = time(0);
GENAPT_LOG( SG_GENERAL, SG_ALERT, "\n*******************************************************************" );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Start airport " << icao << " at " << pos << ": start time " << ctime(&log_time) );
in.seekg(pos, std::ios::beg);
while ( !in.eof() && (cur_state != STATE_DONE ) ) {
in.getline(line, 2048);
// Parse the line
ParseLine(line);
}
parse_end.stamp();
parse_time = parse_end - parse_start;
// write the airport BTG
if (cur_airport) {
cur_airport->set_debug( debug_path, debug_runways, debug_pavements, debug_taxiways, debug_features );
cur_airport->BuildBtg( work_dir, elevation );
cur_airport->GetBuildTime( build_time );
cur_airport->GetCleanupTime( clean_time );
cur_airport->GetTriangulationTime( triangulation_time );
delete cur_airport;
cur_airport = NULL;
}
log_time = time(0);
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Finished airport " << icao <<
" : parse " << parse_time << " : build " << build_time <<
" : clean " << clean_time << " : tesselate " << triangulation_time );
} else {
GENAPT_LOG( SG_GENERAL, SG_INFO, "Not an airport at pos " << pos << " line is: " << line );
}
log_time = time(0);
SG_LOG( SG_GENERAL, SG_ALERT, "Finished airport " << icao <<
" : parse " << parse_time << " : build " << build_time <<
" : clean " << clean_time << " : tesselate " << triangulation_time );
} else {
SG_LOG( SG_GENERAL, SG_INFO, "Not an airport at pos " << pos << " line is: " << line );
}
}
@ -403,8 +400,8 @@ LinearFeature* Parser::ParseFeature( char* line )
{
feature = new LinearFeature(NULL, 0.0f);
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Creating Linear Feature with desription \"" << line << "\"");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Creating Linear Feature with desription \"" << line << "\"");
return feature;
}
@ -424,11 +421,11 @@ ClosedPoly* Parser::ParsePavement( char* line )
if (numParams == 4)
{
d = strstr(line,desc);
SG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " thexture heading " << th << " and description " << d);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " thexture heading " << th << " and description " << d);
}
else
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " thexture heading " << th );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly with st " << st << " smoothness " << s << " thexture heading " << th );
}
poly = new ClosedPoly(st, s, th, d);
@ -454,7 +451,7 @@ ClosedPoly* Parser::ParseBoundary( char* line )
d = (char *)"none";
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly for airport boundary : " << d);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Creating Closed Poly for airport boundary : " << d);
poly = new ClosedPoly(d);
return poly;
@ -466,7 +463,7 @@ int Parser::SetState( int state )
// is when we get a non-node line to parse
if ( cur_airport && cur_state == STATE_PARSE_PAVEMENT )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding pavement");
cur_pavement->Finish();
cur_airport->AddPavement( cur_pavement );
cur_pavement = NULL;
@ -474,7 +471,7 @@ int Parser::SetState( int state )
if ( cur_airport && cur_state == STATE_PARSE_BOUNDARY )
{
SG_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding boundary");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Closing and Adding boundary");
cur_boundary->Finish();
cur_airport->AddBoundary( cur_boundary );
cur_boundary = NULL;
@ -510,7 +507,7 @@ int Parser::ParseLine(char* line)
if (cur_state == STATE_NONE)
{
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing land airport: " << line);
cur_airport = new Airport( code, line );
}
else
@ -522,7 +519,7 @@ int Parser::ParseLine(char* line)
if (cur_state == STATE_NONE)
{
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing heliport: " << line);
cur_airport = new Airport( code, line );
}
else
@ -533,7 +530,7 @@ int Parser::ParseLine(char* line)
case LAND_RUNWAY_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing runway: " << line);
cur_runway = new Runway(line);
if (cur_airport)
{
@ -543,7 +540,7 @@ int Parser::ParseLine(char* line)
case WATER_RUNWAY_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing water runway: " << line);
cur_waterrunway = new WaterRunway(line);
if (cur_airport)
{
@ -552,7 +549,7 @@ int Parser::ParseLine(char* line)
break;
case HELIPAD_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing helipad: " << line);
cur_helipad = new Helipad(line);
if (cur_airport)
{
@ -562,7 +559,7 @@ int Parser::ParseLine(char* line)
case TAXIWAY_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway: " << line);
cur_taxiway = new Taxiway(line);
if (cur_airport)
{
@ -572,25 +569,25 @@ int Parser::ParseLine(char* line)
case PAVEMENT_CODE:
SetState( STATE_PARSE_PAVEMENT );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing pavement: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing pavement: " << line);
cur_pavement = ParsePavement( line );
break;
case LINEAR_FEATURE_CODE:
SetState( STATE_PARSE_FEATURE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Linear Feature: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Linear Feature: " << line);
cur_feat = ParseFeature( line );
break;
case BOUNDRY_CODE:
SetState( STATE_PARSE_BOUNDARY );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing Boundary: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing Boundary: " << line);
cur_boundary = ParseBoundary( line );
break;
case NODE_CODE:
case BEZIER_NODE_CODE:
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing node: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing node: " << line);
cur_node = ParseNode( code, line, prev_node );
if ( prev_node && (cur_node != prev_node) )
@ -615,7 +612,7 @@ int Parser::ParseLine(char* line)
case CLOSE_NODE_CODE:
case CLOSE_BEZIER_NODE_CODE:
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing close loop node: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing close loop node: " << line);
cur_node = ParseNode( code, line, prev_node );
if ( cur_state == STATE_PARSE_PAVEMENT )
@ -669,7 +666,7 @@ int Parser::ParseLine(char* line)
case TERM_NODE_CODE:
case TERM_BEZIER_NODE_CODE:
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing termination node: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing termination node: " << line);
if ( cur_state == STATE_PARSE_FEATURE )
{
@ -697,7 +694,7 @@ int Parser::ParseLine(char* line)
}
else
{
SG_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Parsing termination node with no previous nodes!!!" );
// this feature is bogus...
delete cur_feat;
@ -711,66 +708,66 @@ int Parser::ParseLine(char* line)
case AIRPORT_VIEWPOINT_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing viewpoint: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing viewpoint: " << line);
break;
case AIRPLANE_STARTUP_LOCATION_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing airplane startup location: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing airplane startup location: " << line);
break;
case LIGHT_BEACON_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing light beacon: " << line);
cur_beacon = new Beacon(line);
cur_airport->AddBeacon( cur_beacon );
break;
case WINDSOCK_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing windsock: " << line);
cur_windsock = new Windsock(line);
cur_airport->AddWindsock( cur_windsock );
break;
case TAXIWAY_SIGN:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing taxiway sign: " << line);
cur_sign = new Sign(line);
cur_airport->AddSign( cur_sign );
break;
case LIGHTING_OBJECT:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing lighting object: " << line);
cur_object = new LightingObj(line);
cur_airport->AddObj( cur_object );
break;
case COMM_FREQ1_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 1: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 1: " << line);
break;
case COMM_FREQ2_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 2: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 2: " << line);
break;
case COMM_FREQ3_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 3: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 3: " << line);
break;
case COMM_FREQ4_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 4: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 4: " << line);
break;
case COMM_FREQ5_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 5: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 5: " << line);
break;
case COMM_FREQ6_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 6: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 6: " << line);
break;
case COMM_FREQ7_CODE:
SetState( STATE_PARSE_SIMPLE );
SG_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 7: " << line);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Parsing commfreq 7: " << line);
break;
case END_OF_FILE :
SG_LOG(SG_GENERAL, SG_DEBUG, "Reached end of file");
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Reached end of file");
SetState( STATE_DONE );
break;
}
@ -778,4 +775,4 @@ int Parser::ParseLine(char* line)
}
return cur_state;
}
}

View file

@ -4,17 +4,21 @@
#include <iostream>
#include <fstream>
#include <simgear/threads/SGThread.hxx>
#include "scheduler.hxx"
#include "beznode.hxx"
#include "closedpoly.hxx"
#include "linearfeature.hxx"
#include "runway.hxx"
#include "airport.hxx"
#define STATE_NONE (0)
#define STATE_PARSE_SIMPLE (1)
#define STATE_PARSE_BOUNDARY (2)
#define STATE_PARSE_PAVEMENT (3)
#define STATE_PARSE_FEATURE (4)
#define STATE_INIT (0)
#define STATE_NONE (1)
#define STATE_PARSE_SIMPLE (2)
#define STATE_PARSE_BOUNDARY (3)
#define STATE_PARSE_PAVEMENT (4)
#define STATE_PARSE_FEATURE (5)
#define STATE_DONE (10)
#define MAXLINE (256)
@ -56,12 +60,10 @@
#define END_OF_FILE (99)
using namespace std;
class Parser
class Parser : public SGThread
{
public:
Parser(string& datafile, const string& root, const string_list& elev_src)
Parser(const std::string& datafile, const std::string& root, const string_list& elev_src )
{
filename = datafile;
work_dir = root;
@ -82,8 +84,6 @@ public:
prev_node = NULL;
cur_state = STATE_NONE;
}
void Parse( long pos );
// Debug
void set_debug( std::string path, std::vector<std::string> runway_defs,
@ -92,8 +92,10 @@ public:
std::vector<std::string> feature_defs );
private:
bool IsAirportDefinition( char* line, string icao );
bool GetAirportDefinition( char* line, string& icao );
virtual void run();
bool IsAirportDefinition( char* line, std::string icao );
bool GetAirportDefinition( char* line, std::string& icao );
int SetState( int state );
@ -106,9 +108,9 @@ private:
BezNode* prev_node;
int cur_state;
string filename;
std::string filename;
string_list elevation;
string work_dir;
std::string work_dir;
// a polygon conists of an array of contours
// (first is outside boundry, remaining are holes)
@ -126,12 +128,11 @@ private:
Sign* cur_sign;
// debug
string debug_path;
std::string debug_path;
debug_map debug_runways;
debug_map debug_pavements;
debug_map debug_taxiways;
debug_map debug_features;
};
#endif
#endif

View file

@ -48,7 +48,7 @@ Runway::Runway(char* definition)
// calculate runway heading and length (used a lot)
SGGeodesy::inverse( GetStart(), GetEnd(), rwy.heading, az2, rwy.length );
SG_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] << ") to (" << rwy.lon[1] << "," << rwy.lat[1] << ") heading: " << rwy.heading << " length: " << rwy.length << " width: " << rwy.width );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read runway: (" << rwy.lon[0] << "," << rwy.lat[0] << ") to (" << rwy.lon[1] << "," << rwy.lat[1] << ") heading: " << rwy.heading << " length: " << rwy.length << " width: " << rwy.width );
}
@ -57,7 +57,7 @@ WaterRunway::WaterRunway(char* definition)
{
sscanf(definition, "%lf %d %s %lf %lf %s %lf %lf", &width, &buoys, rwnum[0], &lat[0], &lon[0], rwnum[1], &lat[1], &lon[1]);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read water runway: (" << lon[0] << "," << lat[0] << ") to (" << lon[1] << "," << lat[1] << ") width: " << width << " buoys = " << buoys );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read water runway: (" << lon[0] << "," << lat[0] << ") to (" << lon[1] << "," << lat[1] << ") width: " << width << " buoys = " << buoys );
}
tgContour WaterRunway::GetBuoys()
@ -87,7 +87,7 @@ tgContour WaterRunway::GetBuoys()
return buoys_nodes;
}
int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, std::string& shapefile_name )
int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgAccumulator& accum, std::string& shapefile_name )
{
if ( rwy.surface == 1 /* Asphalt */ )
{
@ -123,7 +123,7 @@ int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights
}
else
{
SG_LOG(SG_GENERAL, SG_WARN, "surface_code = " << rwy.surface);
GENAPT_LOG(SG_GENERAL, SG_WARN, "surface_code = " << rwy.surface);
throw sg_exception("unknown runway type!");
}
@ -132,8 +132,8 @@ int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights
{
case 1: // asphalt:
case 2: // concrete
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: asphalt or concrete " << rwy.surface);
gen_rwy( rwy_polys, slivers, shapefile_name );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: asphalt or concrete " << rwy.surface);
gen_rwy( rwy_polys, slivers, accum, shapefile_name );
gen_runway_lights( rwy_lights );
break;
@ -141,38 +141,38 @@ int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights
case 4: // Dirt
case 5: // Gravel
case 12: // dry lakebed
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Grass, Dirt, Gravel or Dry Lakebed " << rwy.surface );
gen_simple_rwy( rwy_polys, slivers );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Grass, Dirt, Gravel or Dry Lakebed " << rwy.surface );
gen_simple_rwy( rwy_polys, slivers, accum );
gen_runway_lights( rwy_lights );
break;
case 13: // water
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Water");
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Water");
break;
case 14: // snow
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Snow");
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: Snow");
break;
case 15: // transparent
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: transparent");
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: transparent");
break;
default: // unknown
SG_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: unknown: " << rwy.surface);
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Build Runway: unknown: " << rwy.surface);
break;
}
return 0;
}
int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, std::string& shapefile_name )
int Runway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, tgAccumulator& accum, std::string& shapefile_name )
{
tgContour base_contour, safe_base_contour;
tgPolygon base, safe_base;
double shoulder_width = 0.0;
BuildBtg( rwy_polys, rwy_lights, slivers, shapefile_name );
BuildBtg( rwy_polys, rwy_lights, slivers, accum, shapefile_name );
// generate area around runways
if ( (rwy.shoulder > 0) && (rwy.surface < 3) ) {

View file

@ -34,6 +34,7 @@ public:
int BuildBtg( tgpolygon_list& rwy_polys,
tglightcontour_list& rwy_lights,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
int BuildBtg( tgpolygon_list& rwy_polys,
@ -41,10 +42,12 @@ public:
tgcontour_list& slivers,
tgpolygon_list& apt_base_polys,
tgpolygon_list& apt_clearing_polys,
tgAccumulator& accum,
std::string& shapefile_name );
void BuildShoulder( tgpolygon_list& rwy_polys,
tgcontour_list& slivers );
tgcontour_list& slivers,
tgAccumulator& accum );
private:
struct TGRunway {
@ -98,6 +101,7 @@ private:
double &start_pct, double &end_pct,
tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
// generate a section of runway with shoulders
@ -110,6 +114,7 @@ private:
tgpolygon_list& rwy_polys,
tgpolygon_list& shoulder_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
// generate a section of runway without shoulders
@ -121,6 +126,7 @@ private:
const std::string& material,
tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
// generate a section of shoulder
@ -131,10 +137,11 @@ private:
double width,
std::string surface );
void gen_simple_rwy( tgpolygon_list& rwy_polys, tgcontour_list& slivers );
void gen_simple_rwy( tgpolygon_list& rwy_polys, tgcontour_list& slivers, tgAccumulator& accum );
void gen_rwy( tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
void gen_runway_lights( tglightcontour_list& lights );

View file

@ -144,6 +144,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
tgpolygon_list& rwy_polys,
tgpolygon_list& shoulder_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name )
{
double width = rwy.width;
@ -219,7 +220,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
}
}
SG_LOG(SG_GENERAL, SG_DEBUG, "start len % = " << startl_pct << " end len % = " << endl_pct);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "start len % = " << startl_pct << " end len % = " << endl_pct);
double dlx, dly;
@ -240,7 +241,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
SGVec2d t3 = SGVec2d( a2.x() + dlx * endl_pct,
a2.y() + dly * endl_pct );
SG_LOG(SG_GENERAL, SG_DEBUG, "start wid % = " << startw_pct << " end wid % = " << endw_pct);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "start wid % = " << startw_pct << " end wid % = " << endw_pct);
double dwx, dwy;
@ -298,15 +299,15 @@ void Runway::gen_runway_section( const tgPolygon& runway,
section = tgPolygon::Snap( section, gSnap );
// print runway points
SG_LOG(SG_GENERAL, SG_DEBUG, "pre clipped runway pts " << material_prefix << material);
SG_LOG(SG_GENERAL, SG_DEBUG, section );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "pre clipped runway pts " << material_prefix << material);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, section );
if( shapefile_name.size() ) {
tgPolygon::ToShapefile( section, "./airport_dbg", std::string("preclip"), shapefile_name );
}
// Clip the new polygon against what ever has already been created.
tgPolygon clipped = tgPolygon::DiffWithAccumulator( section );
tgPolygon clipped = accum.Diff( section );
if( shapefile_name.size() ) {
tgPolygon::ToShapefile( clipped, "./airport_dbg", std::string("postclip"), shapefile_name );
@ -318,7 +319,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
// the surface terrain
tgPolygon split = tgPolygon::SplitLongEdges( clipped, 400.0 );
tgPolygon::AddToAccumulator( section );
accum.Add( section );
// Store away what we need to know for texture coordinate
// calculation. (CLO 10/20/02: why can't we calculate texture
@ -350,6 +351,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
const string& material,
tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name )
{
double width = rwy.width;
@ -384,7 +386,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
}
}
SG_LOG(SG_GENERAL, SG_DEBUG, "start len % = " << startl_pct << " end len % = " << endl_pct);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "start len % = " << startl_pct << " end len % = " << endl_pct);
double dlx, dly;
@ -405,7 +407,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
SGVec2d t3 = SGVec2d( a2.x() + dlx * endl_pct,
a2.y() + dly * endl_pct );
SG_LOG(SG_GENERAL, SG_DEBUG, "start wid % = " << startw_pct << " end wid % = " << endw_pct);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "start wid % = " << startw_pct << " end wid % = " << endw_pct);
double dwx, dwy;
@ -443,11 +445,11 @@ void Runway::gen_runway_section( const tgPolygon& runway,
section = tgPolygon::Snap( section, gSnap );
// print runway points
SG_LOG(SG_GENERAL, SG_DEBUG, "pre clipped runway pts " << material_prefix << material);
SG_LOG(SG_GENERAL, SG_DEBUG, section );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "pre clipped runway pts " << material_prefix << material);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, section );
// Clip the new polygon against what ever has already been created.
tgPolygon clipped = tgPolygon::DiffWithAccumulator( section );
tgPolygon clipped = accum.Diff( section );
tgPolygon::RemoveSlivers( clipped, slivers );
@ -455,7 +457,7 @@ void Runway::gen_runway_section( const tgPolygon& runway,
// the surface terrain
tgPolygon split = tgPolygon::SplitLongEdges( clipped, 400.0 );
tgPolygon::AddToAccumulator( section );
accum.Add( section );
// Store away what we need to know for texture coordinate
// calculation. (CLO 10/20/02: why can't we calculate texture
@ -482,6 +484,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
double &start_pct, double &end_pct,
tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name )
{
if (rwname != "XX") { /* Do not create a designation block if the runway name is set to none */
@ -494,7 +497,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
letter = tmp;
}
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Runway designation letter = " << letter);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Runway designation letter = " << letter);
// create runway designation letter
if ( !letter.empty() ) {
@ -509,6 +512,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
rwy_polys,
shoulder_polys,
slivers,
accum,
shapefile_name );
}
@ -518,7 +522,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
rwname = "36";
}
SG_LOG(SG_GENERAL, SG_DEBUG, "Runway designation = " << rwname);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Runway designation = " << rwname);
char tex1[32]; tex1[0] = '\0';
char tex2[32]; tex2[0] = '\0';
@ -539,6 +543,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
rwy_polys,
shoulder_polys,
slivers,
accum,
shapefile_name );
gen_runway_section( poly,
start_pct, end_pct,
@ -549,6 +554,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
rwy_polys,
shoulder_polys,
slivers,
accum,
shapefile_name );
} else if (rwname.length() == 1) {
@ -563,6 +569,7 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
rwy_polys,
shoulder_polys,
slivers,
accum,
shapefile_name );
}
}
@ -574,9 +581,10 @@ void Runway::gen_rw_designation( tgPolygon poly, double heading, string rwname,
// document AC 150/5340-1H
void Runway::gen_rwy( tgpolygon_list& rwy_polys,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name )
{
SG_LOG( SG_GENERAL, SG_DEBUG, "Building runway = " << rwy.rwnum[0] << " / " << rwy.rwnum[1]);
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Building runway = " << rwy.rwnum[0] << " / " << rwy.rwnum[1]);
std::string section_name = "";
bool debug = shapefile_name.size() != 0;
@ -617,25 +625,25 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
// Make sure our runway is long enough for the desired marking variant
if ( (rwy.marking[rwhalf]==2 || rwy.marking[rwhalf]==4) && length < 1150 * SG_FEET_TO_METER ) {
SG_LOG( SG_GENERAL, SG_ALERT,
GENAPT_LOG( SG_GENERAL, SG_ALERT,
"Runway " << rwy.rwnum[rwhalf] << " is not long enough ("
<< rwy.length << "m) for non-precision markings! Setting runway markings to visual!");
rwy.marking[rwhalf]=1;
}
if ( (rwy.marking[rwhalf]==3 || rwy.marking[rwhalf]==5) && length < 3075 * SG_FEET_TO_METER ) {
SG_LOG( SG_GENERAL, SG_ALERT,
GENAPT_LOG( SG_GENERAL, SG_ALERT,
"Runway " << rwy.rwnum[rwhalf] << " is not long enough ("
<< rwy.length << "m) for precision markings! Setting runway markings to visual!");
rwy.marking[rwhalf]=1;
}
SG_LOG( SG_GENERAL, SG_DEBUG, "runway marking = " << rwy.marking[rwhalf] );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "runway marking = " << rwy.marking[rwhalf] );
//
// Displaced threshold if it exists
//
if ( rwy.threshold[rwhalf] > 0.0 ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] );
double final_arrow = rwy.threshold[rwhalf];
@ -667,6 +675,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
// main chunks
@ -683,6 +692,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
}
}
@ -700,6 +710,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
}
@ -717,6 +728,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
} else {
// Thresholds for all others
@ -732,6 +744,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
shapefile_name );
}
@ -739,6 +752,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
gen_rw_designation( runway_half, heading,
rwy.rwnum[rwhalf], start1_pct, end1_pct,
rwy_polys, slivers,
accum,
shapefile_name );
// Generate remaining markings depending on type of runway
@ -766,7 +780,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
// Now create the marking sections of the runway type
for ( unsigned int i=0; i < rw_marking_list.size(); ++i) {
SG_LOG(SG_GENERAL, SG_DEBUG, "Runway section texture = " << rw_marking_list[i].tex << " start_pct: " << start1_pct << " end_pct: " << end1_pct << " length: " << rw_marking_list[i].size);
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Runway section texture = " << rw_marking_list[i].tex << " start_pct: " << start1_pct << " end_pct: " << end1_pct << " length: " << rw_marking_list[i].size);
if ( end1_pct < 1.0 ) {
start1_pct = end1_pct;
@ -781,6 +795,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
}
}
@ -810,6 +825,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
}
@ -840,6 +856,7 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
rwy_polys,
shoulder_polys,
slivers,
accum,
section_name );
}
}
@ -847,7 +864,8 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
}
void Runway::BuildShoulder( tgpolygon_list& rwy_polys,
tgcontour_list& slivers )
tgcontour_list& slivers,
tgAccumulator& accum )
{
tgPolygon base, safe_base;
tgPolygon shoulder;
@ -856,7 +874,7 @@ void Runway::BuildShoulder( tgpolygon_list& rwy_polys,
shoulder = shoulder_polys[i];
// Clip the new polygon against what ever has already been created.
tgPolygon clipped = tgPolygon::DiffWithAccumulator( shoulder );
tgPolygon clipped = accum.Diff( shoulder );
tgPolygon::RemoveSlivers( clipped, slivers );
// Split long edges to create an object that can better flow with
@ -865,6 +883,6 @@ void Runway::BuildShoulder( tgpolygon_list& rwy_polys,
shoulder_polys[i] = split;
rwy_polys.push_back( shoulder_polys[i] );
tgPolygon::AddToAccumulator( shoulder );
accum.Add( shoulder );
}
}

View file

@ -23,12 +23,14 @@
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
#include "runway.hxx"
#include "debug.hxx"
using std::string;
// generate a simple runway
void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
tgcontour_list& slivers )
tgcontour_list& slivers,
tgAccumulator& accum )
{
tgContour runway = gen_runway_w_mid( 0.0, 0.0 );
tgPolygon runway_half;
@ -63,11 +65,11 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
runway_half.AddNode( 0, runway.GetNode(5) );
}
SG_LOG( SG_GENERAL, SG_DEBUG, "runway marking = " << rwy.marking[rwhalf] );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "runway marking = " << rwy.marking[rwhalf] );
// Displaced threshold if it exists
if ( rwy.threshold[rwhalf] > 0.0 ) {
SG_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Displaced threshold for RW side " << rwhalf << " is " << rwy.threshold[rwhalf] );
start_pct = end_pct;
end_pct = start_pct + ( rwy.threshold[rwhalf] / length );
@ -79,6 +81,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
"",
rwy_polys,
slivers,
accum,
empty );
}
@ -91,6 +94,7 @@ void Runway::gen_simple_rwy( tgpolygon_list& rwy_polys,
"",
rwy_polys,
slivers,
accum,
empty );
}
}

View file

@ -1,7 +1,5 @@
#include <cstring>
#include <Poco/Environment.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx>
@ -11,135 +9,7 @@
extern double gSnap;
/*** PROCESS INFO ***/
ProcessInfo::ProcessInfo( AirportInfo* pai, const ProcessHandle ph, Net::StreamSocket s ) : procHandle(ph)
{
pInfo = pai;
sock = s;
pssb = new Net::SocketStreamBuf( s );
pin = new istream( pssb );
state = P_STATE_INIT;
SetTimeout();
}
void ProcessInfo::SetTimeout( void )
{
SGTimeStamp now;
SGTimeStamp to;
now.stamp();
switch( state ) {
case P_STATE_INIT:
to.setTime(P_STATE_INIT_TIME, 0);
break;
case P_STATE_PARSE:
to.setTime(P_STATE_PARSE_TIME, 0);
break;
case P_STATE_BUILD:
to.setTime(P_STATE_BUILD_TIME, 0);
break;
case P_STATE_TRIANGULATE:
to.setTime(P_STATE_TRIANGULATE_TIME, 0);
break;
case P_STATE_OUTPUT:
to.setTime(P_STATE_OUTPUT_TIME, 0);
break;
}
timeout = (now + to);
}
void ProcessInfo::Kill( void )
{
SGTimeStamp now;
now.stamp();
// kill the process
Process::kill( procHandle.id() );
// wait for the zombie
procHandle.wait();
// mark process info - so we can reclaim it
state = P_STATE_KILLED;
}
int ProcessInfo::HandleLine( void )
{
char line[256];
pin->getline( line, 256 );
if ( pin->rdstate() != ifstream::goodbit ) {
SG_LOG( SG_GENERAL, SG_INFO, pInfo->GetIcao() << ": ProcessInfo::HandleLine read from socket error " << pin->rdstate() );
state = P_STATE_KILLED;
} else {
pInfo->SetErrorString( line );
// Print the line
SG_LOG( SG_GENERAL, SG_INFO, pInfo->GetIcao() << ": " << line);
// Update state
if ( strstr( line, "Parse Complete " ) != NULL ) {
// Grab the stats
int rwys, pvmnts, feats, twys;
sscanf(line, "Parse Complete - Runways: %d Pavements: %d Features: %d Taxiways: %d", &rwys, &pvmnts, &feats, &twys);
pInfo->SetRunways( rwys );
pInfo->SetPavements( pvmnts );
pInfo->SetFeats( feats );
pInfo->SetTaxiways( twys );
} else if ( strstr( line, "Finished airport " ) != NULL ) {
// Grab the stats
int parse_sec, parse_nsec;
int build_sec, build_nsec;
int clean_sec, clean_nsec;
int tess_sec, tess_nsec;
SGTimeStamp parse_ts;
SGTimeStamp build_ts;
SGTimeStamp clean_ts;
SGTimeStamp tess_ts;
state = P_STATE_DONE;
sscanf(line, "Finished airport %*s : parse %d.%d : build %d.%d : clean %d.%d : tesselate %d.%d",
&parse_sec, &parse_nsec, &build_sec, &build_nsec, &clean_sec, &clean_nsec, &tess_sec, &tess_nsec );
parse_ts.setTime( parse_sec, parse_nsec );
build_ts.setTime( build_sec, build_nsec );
clean_ts.setTime( clean_sec, clean_nsec );
tess_ts.setTime( tess_sec, tess_nsec );
pInfo->SetParseTime( parse_ts );
pInfo->SetBuildTime( build_ts );
pInfo->SetCleanTime( clean_ts );
pInfo->SetTessTime( tess_ts );
procHandle.wait();
} else if ( strstr( line, "Build Feature Poly " ) != NULL ) {
state = P_STATE_BUILD;
} else if ( strstr( line, "Build Pavement " ) != NULL ) {
state = P_STATE_BUILD;
} else if ( strstr( line, "Build Runway " ) != NULL ) {
state = P_STATE_BUILD;
} else if ( strstr( line, "Tesselating " ) != NULL ) {
state = P_STATE_TRIANGULATE;
} else if ( strstr( line, "Adding runway nodes and normals " ) != NULL ) {
state = P_STATE_OUTPUT;
}
}
SetTimeout();
return state;
}
SGLockedQueue<AirportInfo> global_workQueue;
ostream& operator<< (ostream &out, const AirportInfo &ai)
{
@ -173,392 +43,21 @@ ostream& operator<< (ostream &out, const AirportInfo &ai)
return out; // MSVC
}
/*** PROCESS LIST CLASS ***/
ProcessList::ProcessList( int n, string& summaryfile, Scheduler* pScheduler ) : available(n), ready(1), state( PL_STATE_WAIT_FOR_LAUNCH )
void Scheduler::set_debug( std::string path, std::vector<std::string> runway_defs,
std::vector<std::string> pavement_defs,
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs )
{
// The process List is responsible for creating new processes (Launch)
// and monitoring the status of the launched parsers (Monitor) These
// functions are called from different threads.
pss = pScheduler->GetServerSocket();
// remember the output file
csvfile.open( summaryfile.c_str(), ios_base::out | ios_base::app );
// remember the scheduler so we can add retries
scheduler = pScheduler;
// remember the number of available helper procs so we know when we're full
threads = n;
}
// When a slot is available, the main thread calls launch to instantiate a
// new pareser process
void ProcessList::Launch( string command, string work_dir, string file, AirportInfo* pai, bool last, string debug_path,
const debug_map& debug_runways, const debug_map& debug_pavements, const debug_map& debug_taxiways, const debug_map& debug_features )
{
Process::Args args;
char arg[512];
Pipe outPipe;
// generate correct command line arguments
sprintf( arg, "--work=%s", work_dir.c_str() );
args.push_back(arg);
sprintf( arg, "--input=%s", file.c_str() );
args.push_back(arg);
sprintf( arg, "--airport-pos=%ld", pai->GetPos() );
args.push_back(arg);
sprintf( arg, "--snap=%1.8lf", pai->GetSnap() );
args.push_back(arg);
sprintf( arg, "--redirect-port=%d", GENAPT_PORT );
args.push_back(arg);
// check if we have any debug defs
debug_map_const_iterator it = debug_runways.find( pai->GetIcao() );
std::string runway_def;
if ( it != debug_runways.end() ) {
runway_def = "--debug-runways=";
runway_def.append( pai->GetIcao() );
runway_def.append( ":" );
for ( unsigned int i=0; i < it->second.size(); i++ ) {
char int_str[16];
sprintf( int_str, "%d", it->second[i] );
runway_def.append( int_str );
if ( i < it->second.size()-1 ) {
runway_def.append( "," );
}
}
}
it = debug_pavements.find( pai->GetIcao() );
std::string pavement_def;
if ( it != debug_pavements.end() ) {
pavement_def = "--debug-pavements=";
pavement_def.append( pai->GetIcao() );
pavement_def.append( ":" );
for ( unsigned int i=0; i < it->second.size(); i++ ) {
char int_str[16];
sprintf( int_str, "%d", it->second[i] );
pavement_def.append( int_str );
if ( i < it->second.size()-1 ) {
pavement_def.append( "," );
}
}
}
it = debug_taxiways.find( pai->GetIcao() );
std::string taxiway_def;
if ( it != debug_taxiways.end() ) {
taxiway_def = "--debug-taxiways=";
taxiway_def.append( pai->GetIcao() );
taxiway_def.append( ":" );
for ( unsigned int i=0; i < it->second.size(); i++ ) {
char int_str[16];
sprintf( int_str, "%d", it->second[i] );
taxiway_def.append( int_str );
if ( i < it->second.size()-1 ) {
taxiway_def.append( "," );
}
}
}
it = debug_features.find( pai->GetIcao() );
std::string feature_def;
if ( it != debug_features.end() ) {
feature_def = "--debug-features=";
feature_def.append( pai->GetIcao() );
feature_def.append( ":" );
for ( unsigned int i=0; i < it->second.size(); i++ ) {
char int_str[16];
sprintf( int_str, "%d", it->second[i] );
pavement_def.append( int_str );
if ( i < it->second.size()-1 ) {
feature_def.append( "," );
}
}
}
if ( runway_def.size() || pavement_def.size() || taxiway_def.size() || feature_def.size() ) {
// sprintf( arg, "--debug-path=%s", debug_path.c_str() );
// SG_LOG( SG_GENERAL, SG_INFO, "Created debug path arg " << arg );
// args.push_back(arg);
if ( runway_def.size() ) {
SG_LOG( SG_GENERAL, SG_INFO, "Created runway arg " << runway_def );
args.push_back( runway_def.c_str() );
}
if ( pavement_def.size() ) {
SG_LOG( SG_GENERAL, SG_INFO, "Created pavement arg " << pavement_def );
args.push_back( pavement_def.c_str() );
}
if ( taxiway_def.size() ) {
SG_LOG( SG_GENERAL, SG_INFO, "Created taxiway arg " << runway_def );
args.push_back( taxiway_def.c_str() );
}
if ( feature_def.size() ) {
SG_LOG( SG_GENERAL, SG_INFO, "Created feature arg " << feature_def );
args.push_back( feature_def.c_str() );
}
}
// Launch the child process
ProcessHandle ph = Process::launch(command, args, 0, &outPipe, &outPipe);
// Wait 10 seconds for connection
Timespan timeout( 10, 0 );
bool retVal = pss->poll( timeout, Net::Socket::SELECT_READ );
// If we connected - create a new entry
if ( retVal ) {
Net::SocketAddress sockaddr;
Net::StreamSocket sock = pss->acceptConnection( sockaddr );
// Make sure the list can't be modified while adding a member
lock.lock();
ProcessInfo pi( pai, ph, sock );
plist.push_back( pi );
lock.unlock();
// If we have all of the airports in our list, we are done
// when the list is empty - set the transition state
if ( last ) {
// The launch list is empty - we're ready to monitor
state = PL_STATE_ALL_LAUNCHED;
ready.set();
} else if ( plist.size() == threads ) {
// The resource list is full - we're ready to monitor
state = PL_STATE_LIST_FULL;
ready.set();
} else {
// resource list has space, and launch list is not empty - hold off monitoring
state = PL_STATE_WAIT_FOR_LAUNCH;
}
}
}
Timespan ProcessList::GetNextTimeout()
{
SGTimeStamp now, min, timeout;
min.setTime( UINT_MAX, 0 );
timeout.setTime( 0, 0 );
for ( unsigned int i=0; i< plist.size(); i++ ) {
if ( plist[i].GetTimeout() < min ) {
min = plist[i].GetTimeout();
}
}
now.stamp();
if ( min > now ) {
timeout = min - now;
}
return Timespan( timeout.get_seconds(), timeout.get_usec() );
}
void ProcessList::HandleReceivedMessages( Net::Socket::SocketList& slr )
{
// for each socket that has data - find the corresponding icao
for (unsigned int i=0; i<slr.size(); i++) {
Net::StreamSocket ss = (Net::StreamSocket)slr[i];
// find the index handling this socket, and let it deal with the line
for ( unsigned int j=0; j < plist.size(); j++ ) {
if ( plist[j].GetSocket() == ss ) {
plist[j].HandleLine( );
break;
}
}
}
}
void ProcessList::HandleFinished( void )
{
AirportInfo* pInfo = NULL;
int num_deleted = 0;
bool done = false;
while (!done) {
done = true;
lock.lock();
for ( unsigned int i=0; i< plist.size(); i++ ) {
switch ( plist[i].GetState() ) {
case P_STATE_DONE:
plist[i].SetErrorString( (char *)"success" );
// holding the list lock - only one thread can write to the csvfile at a time
csvfile << plist[i].GetInfo() << "\n";
csvfile.flush();
// remove this airport from the list - it's complete
plist[i].CloseSock();
plist.erase( plist.begin()+i );
// keep track of the number of deleted entries
num_deleted++;
// let's iterate again to look for more timeouts...
done = false;
break;
case P_STATE_KILLED:
// holding the list lock - only one thread can write to the csvfile at a time
csvfile << plist[i].GetInfo() << "\n";
csvfile.flush();
// Schedule a retry
pInfo = plist[i].GetInfoPtr();
pInfo->IncreaseSnap();
scheduler->RetryAirport( pInfo );
// remove the airport from the monitor list - it's complete
plist[i].CloseSock();
plist.erase( plist.begin()+i );
// keep track of the number of deleted entries
num_deleted++;
// let's iterate again to look for more timeouts...
done = false;
break;
default:
break;
}
}
lock.unlock();
}
// Let launcher thread know we have opening(s)
while ( num_deleted-- ) {
// make sure we don't start waiting on output before a new apt is launched...
if (state != PL_STATE_ALL_LAUNCHED) {
state = PL_STATE_WAIT_FOR_LAUNCH;
}
// free each resource that is no longer used
available.set();
}
}
void ProcessList::WaitForSlot( void )
{
available.wait();
}
// list lock is held
void ProcessList::HandleTimeouts()
{
SGTimeStamp now;
now.stamp();
for ( unsigned int i=0; i< plist.size(); i++ ) {
if ( plist[i].GetTimeout() < now ) {
plist[i].Kill();
}
}
}
void ProcessList::Monitor()
{
// Wait until process list has a connection, then continue until we are done
while( state != PL_STATE_DONE ) {
Net::Socket::SocketList slr, slw, sle;
Timespan timeout;
int retVal;
// if we aren't ready to start - wait on ready
if ( state == PL_STATE_WAIT_FOR_LAUNCH ) {
ready.wait();
}
// then lock the list when calculating the timeouts
lock.lock();
// calculate the shortest timeout
timeout = GetNextTimeout();
// Add currently connected sockets
for ( unsigned int i=0; i< plist.size(); i++ ) {
slr.push_back( plist[i].GetSocket() );
}
// unlock before waiting on i/o
lock.unlock();
// this needs to be interrupted when new airports are added to the list
retVal = Net::Socket::select( slr, slw, sle, timeout );
if ( retVal > 0 ) {
HandleReceivedMessages( slr );
} else {
HandleTimeouts();
}
// remove finished or dead processes, and notify launcher
//
HandleFinished();
slr.clear();
slw.clear();
sle.clear();
// if we have launched all airports, we are done
if ( ( state == PL_STATE_ALL_LAUNCHED ) && ( plist.size() == 0 ) ) {
state = PL_STATE_DONE;
}
}
csvfile.close();
}
/*** PROCESS MONITOR ***/
ProcessMonitor::ProcessMonitor(ProcessList* pl) : Runnable()
{
plist = pl;
}
void ProcessMonitor::run()
{
SG_LOG( SG_GENERAL, SG_INFO, "ProcessMonitor Started " );
// Run the monitoring function in this thread
plist->Monitor();
SG_LOG( SG_GENERAL, SG_INFO, "ProcessMonitor Exited " );
}
/*** SCEDULER ***/
void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
std::vector<string> pavement_defs,
std::vector<string> taxiway_defs,
std::vector<string> feature_defs )
{
SG_LOG(SG_GENERAL, SG_ALERT, "Set debug Path " << path);
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Set debug Path " << path);
debug_path = path;
/* Find any ids for our tile */
for (unsigned int i=0; i< runway_defs.size(); i++) {
string dsd = runway_defs[i];
std::string dsd = runway_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -572,7 +71,7 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i << " for " << icao );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug runway " << i << " for " << icao );
shapes.push_back(i);
@ -584,10 +83,10 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< pavement_defs.size(); i++) {
string dsd = pavement_defs[i];
std::string dsd = pavement_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -601,7 +100,7 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i << " for " << icao );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug pavement " << i << " for " << icao );
shapes.push_back(i);
@ -613,10 +112,10 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< taxiway_defs.size(); i++) {
string dsd = taxiway_defs[i];
std::string dsd = taxiway_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -630,7 +129,7 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i << " for " << icao );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug taxiway " << i << " for " << icao );
shapes.push_back(i);
@ -642,10 +141,10 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
}
for (unsigned int i=0; i< feature_defs.size(); i++) {
string dsd = feature_defs[i];
std::string dsd = feature_defs[i];
size_t d_pos = dsd.find(":");
string icao = dsd.substr(0, d_pos);
std::string icao = dsd.substr(0, d_pos);
std::vector<int> shapes;
shapes.clear();
@ -659,7 +158,7 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
while (ss >> i)
{
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i << " for " << icao );
GENAPT_LOG(SG_GENERAL, SG_ALERT, "Adding debug feature " << i << " for " << icao );
shapes.push_back(i);
@ -671,7 +170,7 @@ void Scheduler::set_debug( std::string path, std::vector<string> runway_defs,
}
}
bool Scheduler::IsAirportDefinition( char* line, string icao )
bool Scheduler::IsAirportDefinition( char* line, std::string icao )
{
char* tok;
int code;
@ -731,21 +230,21 @@ bool Scheduler::IsAirportDefinition( char* line, string icao )
return match;
}
void Scheduler::AddAirport( string icao )
void Scheduler::AddAirport( std::string icao )
{
char line[2048];
long cur_pos;
bool found = false;
AirportInfo* pInfo;
AirportInfo ai;
ifstream in( filename.c_str() );
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
SG_LOG( SG_GENERAL, SG_INFO, "Adding airport " << icao << " to parse list");
GENAPT_LOG( SG_GENERAL, SG_INFO, "Adding airport " << icao << " to parse list");
while ( !in.eof() && !found )
{
// remember the position of this line
@ -757,31 +256,30 @@ void Scheduler::AddAirport( string icao )
// this is and airport definition - remember it
if ( IsAirportDefinition( line, icao ) )
{
SG_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << icao << " at " << cur_pos );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << icao << " at " << cur_pos );
pInfo = new AirportInfo( icao, cur_pos, gSnap );
originalList.push_back( *pInfo );
delete pInfo;
ai = AirportInfo( icao, cur_pos, gSnap );
global_workQueue.push( ai );
found = true;
}
}
}
long Scheduler::FindAirport( string icao )
long Scheduler::FindAirport( std::string icao )
{
char line[2048];
long cur_pos = 0;
bool found = false;
ifstream in( filename.c_str() );
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
SG_LOG( SG_GENERAL, SG_DEBUG, "Finding airport " << icao );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Finding airport " << icao );
while ( !in.eof() && !found )
{
// remember the position of this line
@ -793,7 +291,7 @@ long Scheduler::FindAirport( string icao )
// this is and airport definition - remember it
if ( IsAirportDefinition( line, icao ) )
{
SG_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << line << " at " << cur_pos );
GENAPT_LOG( SG_GENERAL, SG_DEBUG, "Found airport " << line << " at " << cur_pos );
found = true;
}
}
@ -819,7 +317,7 @@ bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
char* def;
long cur_pos;
long cur_apt_pos = 0;
string cur_apt_name;
std::string cur_apt_name;
char* tok;
int code;
bool match;
@ -831,16 +329,16 @@ bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
// 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() );
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
if (start_pos)
{
in.seekg(start_pos, ios::beg);
in.seekg(start_pos, std::ios::beg);
}
while (!done)
@ -870,9 +368,8 @@ bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
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;
AirportInfo ai = AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
global_workQueue.push( ai );
}
// remember this new apt pos and name, and clear match
cur_apt_pos = cur_pos;
@ -887,9 +384,8 @@ bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
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;
AirportInfo ai = AirportInfo( cur_apt_name, cur_apt_pos, gSnap );
global_workQueue.push( ai );
}
done = true;
break;
@ -965,103 +461,49 @@ bool Scheduler::AddAirports( long start_pos, tg::Rectangle* boundingBox )
}
// did we add airports to the parse list?
if ( originalList.size() )
{
if ( global_workQueue.size() ) {
return true;
} else
{
} else {
return false;
}
}
Scheduler::Scheduler(string& cmd, string& datafile, const string& root, const string_list& elev_src)
Scheduler::Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src)
{
command = cmd;
filename = datafile;
work_dir = root;
elevation = elev_src;
ifstream in( filename.c_str() );
std::ifstream in( filename.c_str() );
if ( !in.is_open() )
{
SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
GENAPT_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << filename );
exit(-1);
}
}
void Scheduler::Schedule( int num_threads, string& summaryfile )
void Scheduler::Schedule( int num_threads, std::string& summaryfile )
{
ProcessList *procList = NULL;
Thread *monThread = NULL;
ProcessMonitor *procMon = NULL;
bool done = false;
bool last = false;
ofstream csvfile;
// std::ofstream csvfile;
// open and truncate the summary file : monitor only appends
csvfile.open( summaryfile.c_str(), ios_base::out | ios_base::trunc );
csvfile.close();
// csvfile.open( summaryfile.c_str(), std::ios_base::out | std::ios_base::trunc );
// csvfile.close();
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler: Bind to socket" );
std::vector<Parser *> parsers;
for (int i=0; i<num_threads; i++) {
Parser* parser = new Parser( filename, work_dir, elevation );
// parser->set_debug();
parser->start();
parsers.push_back( parser );
}
// Bind the parent listener socket for children to connect to
ss.bind(GENAPT_PORT);
ss.listen();
while (!global_workQueue.empty()) {
sleep(1);
}
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler: Bound" );
while (!done) {
procList = new ProcessList(num_threads, summaryfile, this);
monThread = new Thread;
procMon = new ProcessMonitor(procList);
// Launch monitor thread
monThread->start(*procMon);
// now try to launch child processes to parse individual airports
for ( unsigned int i=0; i<originalList.size(); i++ ) {
// Wait for an available process slot
procList->WaitForSlot();
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler: Processing layout " << i+1 << " of " << originalList.size() << "." );
// let the process list know if more airports are coming
if ( i == originalList.size()-1 ) {
last = true;
}
// Launch a new parser
procList->Launch( command, work_dir, filename, &originalList[i], last, debug_path, debug_runways, debug_pavements, debug_taxiways, debug_features );
}
// Sync up before relaunching
monThread->join();
// Delete the old monitor
delete procMon;
delete monThread;
delete procList;
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler: originalList has " << originalList.size() << ", retry list has " << retryList.size() << " entries" );
// delete original, and copy retry to it
if ( retryList.size() ) {
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler: clear original list " );
originalList.clear();
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler - cleared original: originalList has " << originalList.size() << ", retry list has " << retryList.size() << " entries" );
for ( unsigned int i=0; i<retryList.size(); i++ ) {
originalList.push_back( retryList[i] );
}
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler - copied retryList: originalList has " << originalList.size() << ", retry list has " << retryList.size() << " entries" );
retryList.clear();
SG_LOG( SG_GENERAL, SG_INFO, "Scheduler - cleared retry: originalList has " << originalList.size() << ", retry list has " << retryList.size() << " entries" );
} else {
done = true;
}
// Then wait until they are finished
for (unsigned int i=0; i<parsers.size(); i++) {
parsers[i]->join();
}
}

View file

@ -1,26 +1,17 @@
#ifndef __SCHEDULER_HXX__
#define __SCHEDULER_HXX__
#include <string>
#include <iostream>
#include <fstream>
#include <Poco/Mutex.h>
#include <Poco/Pipe.h>
#include <Poco/PipeStream.h>
#include <Poco/Process.h>
#include <Poco/Runnable.h>
#include <Poco/Semaphore.h>
#include <Poco/Thread.h>
#include <Poco/Timespan.h>
#include <Poco/Net/ServerSocket.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/SocketStream.h>
#include <Poco/Net/Socket.h>
#include <Poco/Net/StreamSocket.h>
#include <simgear/compiler.h>
#include <simgear/math/sg_types.hxx>
#include <simgear/timing/timestamp.hxx>
#include <CGAL/Plane_3.h>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGQueue.hxx>
#include <Geometry/rectangle.hxx>
#include "airport.hxx"
#define P_STATE_INIT (0)
#define P_STATE_PARSE (1)
@ -43,27 +34,29 @@
#define PL_STATE_ALL_LAUNCHED (3)
#define PL_STATE_DONE (10)
using namespace Poco;
// Forward declaration
class Scheduler;
class AirportInfo
{
public:
AirportInfo( string id, long p, double s )
AirportInfo()
{
}
AirportInfo( std::string id, long p, double s )
{
icao = id;
pos = p;
snap = s;
numRunways = -1;
numPavements = -1;
numFeats = -1;
numTaxiways = -1;
}
string GetIcao( void ) { return icao; }
std::string GetIcao( void ) { return icao; }
long GetPos( void ) { return pos; }
double GetSnap( void ) { return snap; }
@ -82,106 +75,36 @@ public:
friend ostream& operator<<(ostream& output, const AirportInfo& ai);
private:
string icao;
std::string icao;
long pos;
int numRunways;
int numPavements;
int numFeats;
int numTaxiways;
SGTimeStamp parseTime;
SGTimeStamp buildTime;
SGTimeStamp cleanTime;
SGTimeStamp tessTime;
double snap;
string errString;
};
typedef std::vector <AirportInfo> parseList;
class ProcessInfo
{
public:
ProcessInfo( AirportInfo* pai, const ProcessHandle ph, Net::StreamSocket s );
void SetTimeout( void );
SGTimeStamp GetTimeout( void ) { return timeout; }
string GetIcao( void ) { return pInfo->GetIcao(); }
Net::StreamSocket GetSocket( void ) { return sock; }
int GetState( void ) { return state; }
AirportInfo GetInfo( void ) { return *pInfo; }
AirportInfo* GetInfoPtr( void ) { return pInfo; }
void SetErrorString( char *e ) { pInfo->SetErrorString( e ); }
int HandleLine( void );
void Kill( void );
void CloseSock( void ) { sock.close(); }
private:
AirportInfo* pInfo;
ProcessHandle procHandle;
Net::StreamSocket sock;
Net::SocketStreamBuf *pssb;
istream *pin;
int state;
SGTimeStamp timeout;
};
typedef std::vector <ProcessInfo> ProcessInfoList;
class ProcessList
{
public:
ProcessList( int n, string& summaryfile, Scheduler* pScheduler );
// The main thread needs to wait until a slot is ready for creating a new
// Parser child process
inline void WaitForSlot(void);
// When a slot is available, the main thread calls launch to instantiate a
// new pareser process
void Launch( string command, string work_dir, string file, AirportInfo* pai, bool last, string debug_path,
const debug_map& debug_runways, const debug_map& debug_pavements, const debug_map& debug_taxiways, const debug_map& debug_features );
Timespan GetNextTimeout();
void HandleReceivedMessages( Net::Socket::SocketList& slr );
void HandleTimeouts();
void HandleFinished( void );
void Monitor();
private:
Semaphore available;
Semaphore ready;
Mutex lock;
ProcessInfoList plist;
Net::ServerSocket* pss;
int state;
unsigned int threads;
ofstream csvfile;
Scheduler* scheduler;
std::string errString;
};
class ProcessMonitor : public Runnable
{
public:
ProcessMonitor(ProcessList* pl);
virtual void run();
private:
ProcessList* plist;
};
extern SGLockedQueue<AirportInfo> global_workQueue;
class Scheduler
{
public:
Scheduler(string& cmd, string& datafile, const string& root, const string_list& elev_src);
Scheduler(std::string& datafile, const std::string& root, const string_list& elev_src);
long FindAirport( string icao );
void AddAirport( string icao );
long FindAirport( std::string icao );
void AddAirport( std::string icao );
bool AddAirports( long start_pos, tg::Rectangle* boundingBox );
void RetryAirport( AirportInfo* pInfo );
void Schedule( int num_threads, string& summaryfile );
void Schedule( int num_threads, std::string& summaryfile );
// Debug
void set_debug( std::string path, std::vector<std::string> runway_defs,
@ -189,27 +112,19 @@ public:
std::vector<std::string> taxiway_defs,
std::vector<std::string> feature_defs );
Net::ServerSocket* GetServerSocket( void ) { return &ss; }
private:
bool IsAirportDefinition( char* line, string icao );
bool IsAirportDefinition( char* line, std::string icao );
string command;
string filename;
std::string filename;
string_list elevation;
string work_dir;
Net::ServerSocket ss;
// List of positions in database file to parse
parseList originalList;
parseList retryList;
std::string work_dir;
// debug
string debug_path;
std::string debug_path;
debug_map debug_runways;
debug_map debug_pavements;
debug_map debug_taxiways;
debug_map debug_features;
};
#endif

View file

@ -40,7 +40,7 @@ Taxiway::Taxiway(char* definition)
&lat, &lon, designation, &heading, &length, &threshold, &overrun,
&width, lighting, &surface, &shoulder, &markings, &smoothness, &signs);
SG_LOG(SG_GENERAL, SG_DEBUG, "Read taxiway: (" << lon << "," << lat << ") heading: " << heading << " length: " << length << " width: " << width );
GENAPT_LOG(SG_GENERAL, SG_DEBUG, "Read taxiway: (" << lon << "," << lat << ") heading: " << heading << " length: " << length << " width: " << width );
// adjust length and width from feet to meters
length *= SG_FEET_TO_METER;
@ -79,7 +79,7 @@ void Taxiway::GenLights(tglightcontour_list& rwy_lights)
}
int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, std::string& shapefile_name )
int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgAccumulator& accum, std::string& shapefile_name )
{
std::string material;
@ -127,7 +127,7 @@ int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_light
}
else
{
SG_LOG(SG_GENERAL, SG_WARN, "surface_code = " << surface);
GENAPT_LOG(SG_GENERAL, SG_WARN, "surface_code = " << surface);
throw sg_exception("unknown runway type!");
}
@ -136,10 +136,10 @@ int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_light
taxi_poly.AddContour( taxi_contour );
tgPolygon::ToShapefile( taxi_poly, "./airport_dbg", std::string("preclip"), shapefile_name );
tgPolygon::AccumulatorToShapefiles( "./airport_dbg", "accum" );
accum.ToShapefiles( "./airport_dbg", "accum" );
}
tgPolygon clipped = tgContour::DiffWithAccumulator( taxi_contour );
tgPolygon clipped = accum.Diff( taxi_contour );
tgPolygon split = tgPolygon::SplitLongEdges( clipped, 100 );
tgPolygon::RemoveSlivers( split, slivers );
@ -154,17 +154,17 @@ int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_light
tgPolygon::ToShapefile( split, "./airport_dbg", std::string("postclip"), shapefile_name );
}
tgContour::AddToAccumulator( taxi_contour );
accum.Add( taxi_contour );
return 0;
}
int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, std::string& shapefile_name )
int Taxiway::BuildBtg( tgpolygon_list& rwy_polys, tglightcontour_list& rwy_lights, tgcontour_list& slivers, tgpolygon_list& apt_base_polys, tgpolygon_list& apt_clearing_polys, tgAccumulator& accum, std::string& shapefile_name )
{
tgContour base_contour, safe_base_contour;
tgPolygon base, safe_base;
BuildBtg( rwy_polys, rwy_lights, slivers, shapefile_name );
BuildBtg( rwy_polys, rwy_lights, slivers, accum, shapefile_name );
base_contour = tgContour::Expand( taxi_contour, 20.0);
base.AddContour( base_contour );

View file

@ -14,6 +14,7 @@ public:
int BuildBtg( tgpolygon_list& taxi_polys,
tglightcontour_list& taxi_lights,
tgcontour_list& slivers,
tgAccumulator& accum,
std::string& shapefile_name );
int BuildBtg( tgpolygon_list& taxi_polys,
@ -21,6 +22,7 @@ public:
tgcontour_list& slivers,
tgpolygon_list& apt_base_polys,
tgpolygon_list& apt_clearing_polys,
tgAccumulator& accum,
std::string& shapefile_name );
private:

View file

@ -23,6 +23,8 @@
#include <fstream>
#include <limits.h>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <Geometry/point3d.hxx>
@ -1834,61 +1836,6 @@ tgPolygon tgContour::Diff( const tgContour& subject, tgPolygon& clip )
return result;
}
tgPolygon tgContour::DiffWithAccumulator( const tgContour& subject )
{
tgPolygon result;
TGTriNodes all_nodes;
/* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.GetSize(); ++i ) {
all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i) ));
}
unsigned int num_hits = 0;
tg::Rectangle box1 = subject.GetBoundingBox();
ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
c.AddPolygon(clipper_subject, ClipperLib::ptSubject);
// clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < clipper_accumulator.size(); i++) {
tg::Rectangle box2 = BoundingBox_FromClipper( clipper_accumulator[i] );
if ( box2.intersects(box1) )
{
c.AddPolygons(clipper_accumulator[i], ClipperLib::ptClip);
num_hits++;
}
}
if (num_hits) {
if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE" );
exit(-1);
}
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
} else {
result.AddContour( subject );
}
return result;
}
void tgContour::AddToAccumulator( const tgContour& subject )
{
tgPolygon poly;
poly.AddContour( subject );
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( poly );
clipper_accumulator.push_back( clipper_subject );
}
tgPolygon tgPolygon::Union( const tgContour& subject, tgPolygon& clip )
{
tgPolygon result;
@ -2424,77 +2371,6 @@ void clipperToShapefile( ClipperLib::Polygons polys, const std::string& path, co
tgPolygon::ToShapefile( poly, path, layer, name);
}
void tgPolygon::AccumulatorToShapefiles( const std::string& path, const std::string& layer_prefix )
{
char shapefile[16];
char layer[16];
for (unsigned int i=0; i < clipper_accumulator.size(); i++) {
sprintf( layer, "%s_%d", layer_prefix.c_str(), i );
sprintf( shapefile, "accum_%d", i );
clipperToShapefile( clipper_accumulator[i], path, layer, std::string(shapefile) );
}
}
tgPolygon tgPolygon::DiffWithAccumulator( const tgPolygon& subject )
{
tgPolygon result;
TGTriNodes all_nodes;
/* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.Contours(); ++i ) {
for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) {
all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) );
}
}
unsigned int num_hits = 0;
tg::Rectangle box1 = subject.GetBoundingBox();
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
c.AddPolygons(clipper_subject, ClipperLib::ptSubject);
// clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < clipper_accumulator.size(); i++) {
tg::Rectangle box2 = BoundingBox_FromClipper( clipper_accumulator[i] );
if ( box2.intersects(box1) )
{
c.AddPolygons(clipper_accumulator[i], ClipperLib::ptClip);
num_hits++;
}
}
if (num_hits) {
if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE" );
exit(-1);
}
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
// Make sure we keep texturing info
result.SetMaterial( subject.GetMaterial() );
result.SetTexParams( subject.GetTexParams() );
} else {
result = subject;
}
return result;
}
void tgPolygon::AddToAccumulator( const tgPolygon& subject )
{
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
clipper_accumulator.push_back( clipper_subject );
}
// Move slivers from in polygon to out polygon.
void tgPolygon::RemoveSlivers( tgPolygon& subject, tgcontour_list& slivers )
{
@ -2841,8 +2717,11 @@ bool tgPolygon_index_init( const std::string& path )
return true;
}
SGMutex index_next_mutex;
static long int tgPolygon_index_next()
{
SGGuard<SGMutex> g(index_next_mutex);
++poly_index;
FILE *fp = fopen( poly_path.c_str(), "w" );
@ -3350,3 +3229,129 @@ std::ostream& operator<< ( std::ostream& output, const tgTexParams& subject )
return output;
}
tgPolygon tgAccumulator::Diff( const tgContour& subject )
{
tgPolygon result;
TGTriNodes all_nodes;
/* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.GetSize(); ++i ) {
all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i) ));
}
unsigned int num_hits = 0;
tg::Rectangle box1 = subject.GetBoundingBox();
ClipperLib::Polygon clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
c.AddPolygon(clipper_subject, ClipperLib::ptSubject);
// clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < accum.size(); i++) {
tg::Rectangle box2 = BoundingBox_FromClipper( accum[i] );
if ( box2.intersects(box1) )
{
c.AddPolygons(accum[i], ClipperLib::ptClip);
num_hits++;
}
}
if (num_hits) {
if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE" );
exit(-1);
}
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
} else {
result.AddContour( subject );
}
return result;
}
void tgAccumulator::Add( const tgContour& subject )
{
tgPolygon poly;
poly.AddContour( subject );
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( poly );
accum.push_back( clipper_subject );
}
void tgAccumulator::ToShapefiles( const std::string& path, const std::string& layer_prefix )
{
char shapefile[16];
char layer[16];
for (unsigned int i=0; i < accum.size(); i++) {
sprintf( layer, "%s_%d", layer_prefix.c_str(), i );
sprintf( shapefile, "accum_%d", i );
clipperToShapefile( accum[i], path, layer, std::string(shapefile) );
}
}
tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
{
tgPolygon result;
TGTriNodes all_nodes;
/* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.Contours(); ++i ) {
for ( unsigned int j = 0; j < subject.ContourSize( i ); ++j ) {
all_nodes.unique_add( Point3D::fromSGGeod( subject.GetNode(i, j) ) );
}
}
unsigned int num_hits = 0;
tg::Rectangle box1 = subject.GetBoundingBox();
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Polygons clipper_result;
ClipperLib::Clipper c;
c.Clear();
c.AddPolygons(clipper_subject, ClipperLib::ptSubject);
// clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < accum.size(); i++) {
tg::Rectangle box2 = BoundingBox_FromClipper( accum[i] );
if ( box2.intersects(box1) )
{
c.AddPolygons(accum[i], ClipperLib::ptClip);
num_hits++;
}
}
if (num_hits) {
if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE" );
exit(-1);
}
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
// Make sure we keep texturing info
result.SetMaterial( subject.GetMaterial() );
result.SetTexParams( subject.GetTexParams() );
} else {
result = subject;
}
return result;
}
void tgAccumulator::Add( const tgPolygon& subject )
{
ClipperLib::Polygons clipper_subject = tgPolygon::ToClipper( subject );
accum.push_back( clipper_subject );
}

View file

@ -317,14 +317,13 @@ std::ostream &operator<<(std::ostream &output, const TGPolygon &poly);
// forward declaration
class tgPolygon;
class tgContour
{
public:
tgContour() {
hole = false;
}
void Erase() {
node_list.clear();
}
@ -376,8 +375,6 @@ public:
static tgContour RemoveSpikes( const tgContour& subject );
static tgPolygon Diff( const tgContour& subject, tgPolygon& clip );
static tgPolygon DiffWithAccumulator( const tgContour& subject );
static void AddToAccumulator( const tgContour& subject );
static tgContour AddColinearNodes( const tgContour& subject, TGTriNodes nodes );
static tgContour AddColinearNodes( const tgContour& subject, std::vector<SGGeod>& nodes );
@ -598,10 +595,6 @@ public:
static tgPolygon Diff( const tgPolygon& subject, tgPolygon& clip );
static tgPolygon Intersect( const tgPolygon& subject, const tgPolygon& clip );
static tgPolygon DiffWithAccumulator( const tgPolygon& subject );
static void AddToAccumulator( const tgPolygon& subject );
static void AccumulatorToShapefiles( const std::string& path, const std::string& layer );
// Conversions
static ClipperLib::Polygons ToClipper( const tgPolygon& subject );
static tgPolygon FromClipper( const ClipperLib::Polygons& subject );
@ -757,6 +750,24 @@ typedef std::vector <tgLightContour> tglightcontour_list;
typedef tglightcontour_list::iterator tglightcontour_list_iterator;
typedef tglightcontour_list::const_iterator const_tglightcontour_list_iterator;
typedef std::vector < ClipperLib::Polygons > clipper_polygons_list;
class tgAccumulator
{
public:
tgPolygon Diff( const tgContour& subject );
tgPolygon Diff( const tgPolygon& subject );
void Add( const tgContour& subject );
void Add( const tgPolygon& subject );
void ToShapefiles( const std::string& path, const std::string& layer );
private:
clipper_polygons_list accum;
};
#endif // _POLYGON_HXX