From e18c939f664702d24b5b91464c261f41920a679d Mon Sep 17 00:00:00 2001 From: Christian Schmitt Date: Sat, 29 Sep 2012 11:00:59 +0200 Subject: [PATCH] Speed up linear feature clipping. This makes the creation of airports much faster. --- src/Airports/GenAirports850/airport.cxx | 6 ++-- src/Airports/GenAirports850/linearfeature.cxx | 36 ++++++++++++------- src/Airports/GenAirports850/linearfeature.hxx | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/Airports/GenAirports850/airport.cxx b/src/Airports/GenAirports850/airport.cxx index 462228a2..8e17dc42 100644 --- a/src/Airports/GenAirports850/airport.cxx +++ b/src/Airports/GenAirports850/airport.cxx @@ -517,11 +517,11 @@ void Airport::merge_slivers( superpoly_list& polys, poly_list& slivers_list ) { void Airport::BuildBtg(const string& root, const string_list& elev_src ) { - ClipPolyType accum; + ClipPolyType accum; poly_list slivers; // try to keep line accumulator in clipper format for speed... - ClipPolyType line_accum; + ClipPolyType lines; poly_list line_slivers; TGPolygon apt_base; @@ -608,7 +608,7 @@ void Airport::BuildBtg(const string& root, const string_list& elev_src ) make_shapefiles = false; } - features[i]->BuildBtg( altitude, &line_polys, &line_tps, &line_accum, &rwy_lights, make_shapefiles ); + features[i]->BuildBtg( &line_polys, &line_tps, &lines, &rwy_lights, make_shapefiles ); } } else diff --git a/src/Airports/GenAirports850/linearfeature.cxx b/src/Airports/GenAirports850/linearfeature.cxx index ddf2656f..075f8fb2 100644 --- a/src/Airports/GenAirports850/linearfeature.cxx +++ b/src/Airports/GenAirports850/linearfeature.cxx @@ -3,6 +3,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -929,12 +933,12 @@ int LinearFeature::Finish( bool closed, unsigned int idx ) return 1; } -int LinearFeature::BuildBtg(float alt_m, superpoly_list* line_polys, texparams_list* line_tps, ClipPolyType* line_accum, superpoly_list* lights, bool make_shapefiles ) +int LinearFeature::BuildBtg(superpoly_list* line_polys, texparams_list* line_tps, ClipPolyType* lines, superpoly_list* lights, bool make_shapefiles ) { - TGPolygon poly; - TGPolygon clipped; + TGPolygon poly, tmp; void* ds_id = NULL; // If we are going to build shapefiles void* l_id = NULL; // datasource and layer IDs + SGVec3d min, max, minp, maxp; if ( make_shapefiles ) { char ds_name[128]; @@ -946,16 +950,23 @@ int LinearFeature::BuildBtg(float alt_m, superpoly_list* line_polys, texparams_l for ( unsigned int i = 0; i < marking_polys.size(); i++) { poly = marking_polys[i].get_poly(); - //poly = tgPolygonSimplify( poly ); - //poly = remove_tiny_contours( poly ); + poly.get_bounding_box(minp, maxp); + SGBoxd box1(minp, maxp); - SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::BuildBtg: clipping poly " << i << " of " << marking_polys.size() << " with CLIPPER "); - clipped = tgPolygonDiffClipper( poly, *line_accum ); + for (int j= 0; j < lines->contours(); ++j) + { + tmp.erase(); + tmp.add_contour(lines->get_contour(j), 0); + tmp.get_bounding_box(min, max); + SGBoxd box2(min, max); - // clean the poly before union with accum - clipped = reduce_degeneracy( clipped ); + if ( intersects(box2, box1 ) ) + { + poly = tgPolygonDiffClipper( poly, tmp ); + } + } - marking_polys[i].set_poly( clipped ); + marking_polys[i].set_poly( poly ); line_polys->push_back( marking_polys[i] ); /* If debugging this lf, write the poly, and the accum buffer at each step into their own layers */ @@ -972,11 +983,10 @@ int LinearFeature::BuildBtg(float alt_m, superpoly_list* line_polys, texparams_l l_id = tgShapefileOpenLayer( ds_id, layer_name ); sprintf( feature_name, "accum_%d", i ); - tgShapefileCreateFeature( ds_id, l_id, *line_accum, feature_name ); + tgShapefileCreateFeature( ds_id, l_id, *lines, feature_name ); } - SG_LOG(SG_GENERAL, SG_DEBUG, "LinearFeature::BuildBtg: union poly " << i << " of " << marking_polys.size() << " with CLIPPER " ); - *line_accum = tgPolygonUnionClipper( poly, *line_accum ); + lines->add_contour(poly.get_contour(0), 0); line_tps->push_back( marking_tps[i] ); } diff --git a/src/Airports/GenAirports850/linearfeature.hxx b/src/Airports/GenAirports850/linearfeature.hxx index 8799280c..f450b92d 100644 --- a/src/Airports/GenAirports850/linearfeature.hxx +++ b/src/Airports/GenAirports850/linearfeature.hxx @@ -97,7 +97,7 @@ public: } int Finish( bool closed, unsigned int idx ); - int BuildBtg( float alt_m, superpoly_list* line_polys, texparams_list* line_tps, ClipPolyType* line_accum, superpoly_list* lights, bool debug ); + int BuildBtg( superpoly_list* line_polys, texparams_list* line_tps, ClipPolyType* lines, superpoly_list* lights, bool debug ); // int BuildBtg( float alt_m, superpoly_list* line_polys, texparams_list* line_tps, ClipPolyType* line_accum, superpoly_list* lights ); private: