1
0
Fork 0

temporary workaround for accumulator diff failure.

- will log the failures to a file in current directory.
This commit is contained in:
Peter Sadrozinski 2015-05-27 09:53:45 -04:00
parent c5faeae357
commit 87fe67d5fc
5 changed files with 74 additions and 47 deletions

View file

@ -285,7 +285,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
// Add the linear features // Add the linear features
if (features.size()) if (features.size())
{ {
tgAccumulator lf_accum; tgAccumulator lf_accum(icao);
TG_LOG(SG_GENERAL, SG_INFO, "Build " << features.size() << " Linear Feature Polys"); TG_LOG(SG_GENERAL, SG_INFO, "Build " << features.size() << " Linear Feature Polys");
for ( unsigned int i=0; i<features.size(); i++ ) for ( unsigned int i=0; i<features.size(); i++ )
@ -302,7 +302,7 @@ void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
} }
/* Initialize a new accumulator for the other objects */ /* Initialize a new accumulator for the other objects */
tgAccumulator pvmt_accum; tgAccumulator pvmt_accum(icao);
// Build runways next // Build runways next
if (runways.size()) if (runways.size())

View file

@ -41,7 +41,7 @@ bool TGConstruct::ClipLandclassPolys( void ) {
tgcontour_list slivers; tgcontour_list slivers;
SGGeod p; SGGeod p;
bool debug_area, debug_shape; bool debug_area, debug_shape;
tgAccumulator accum; tgAccumulator accum(bucket.gen_index_str());
unsigned int accum_idx = 0; unsigned int accum_idx = 0;
// set up clipping tile : and remember to add the nodes! // set up clipping tile : and remember to add the nodes!

View file

@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <climits>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -12,6 +13,8 @@ tgPolygon tgAccumulator::Diff( const tgContour& subject )
{ {
tgPolygon result; tgPolygon result;
UniqueSGGeodSet all_nodes; UniqueSGGeodSet all_nodes;
bool done = false;
unsigned int max_hits = UINT_MAX;
/* before diff - gather all nodes */ /* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.GetSize(); ++i ) { for ( unsigned int i = 0; i < subject.GetSize(); ++i ) {
@ -28,31 +31,42 @@ tgPolygon tgAccumulator::Diff( const tgContour& subject )
ClipperLib::Path clipper_subject = tgContour::ToClipper( subject ); ClipperLib::Path clipper_subject = tgContour::ToClipper( subject );
ClipperLib::Paths clipper_result; ClipperLib::Paths clipper_result;
ClipperLib::Clipper c; while ( !done && max_hits > 0 ) {
c.Clear(); ClipperLib::Clipper c;
c.Clear();
c.AddPath(clipper_subject, ClipperLib::ptSubject, true); c.AddPath(clipper_subject, ClipperLib::ptSubject, true);
// clip result against all polygons in the accum that intersect our bb // clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < accum.size(); i++) { for (unsigned int i=0; i < accum.size(); i++) {
tgRectangle box2 = BoundingBox_FromClipper( accum[i] ); tgRectangle box2 = BoundingBox_FromClipper( accum[i] );
if ( box2.intersects(box1) ) if ( box2.intersects(box1) )
{ {
c.AddPaths(accum[i], ClipperLib::ptClip, true); if ( num_hits < max_hits ) {
num_hits++; c.AddPaths(accum[i], ClipperLib::ptClip, true);
num_hits++;
}
}
} }
}
if (num_hits) { if (num_hits) {
if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) { if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE" ); SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE - reducing accumulator" );
exit(-1); max_hits = num_hits-1;
FILE* fp = fopen( "./accumulator_fail.log", "a" );
fprintf( fp, "%s : reduce from %d to %d\n", debugstr.c_str(), num_hits, max_hits );
fclose(fp);
} else {
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
done = true;
}
} else {
result.AddContour( subject );
done = true;
} }
result = tgPolygon::FromClipper( clipper_result );
result = tgPolygon::AddColinearNodes( result, all_nodes );
} else {
result.AddContour( subject );
} }
return result; return result;
@ -62,6 +76,8 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
{ {
tgPolygon result; tgPolygon result;
UniqueSGGeodSet all_nodes; UniqueSGGeodSet all_nodes;
bool done = false;
unsigned int max_hits = UINT_MAX;
/* before diff - gather all nodes */ /* before diff - gather all nodes */
for ( unsigned int i = 0; i < subject.Contours(); ++i ) { for ( unsigned int i = 0; i < subject.Contours(); ++i ) {
@ -80,36 +96,44 @@ tgPolygon tgAccumulator::Diff( const tgPolygon& subject )
ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject ); ClipperLib::Paths clipper_subject = tgPolygon::ToClipper( subject );
ClipperLib::Paths clipper_result; ClipperLib::Paths clipper_result;
ClipperLib::Clipper c; while ( !done && max_hits > 0 ) {
c.Clear(); ClipperLib::Clipper c;
c.Clear();
c.AddPaths(clipper_subject, ClipperLib::ptSubject, true); c.AddPaths(clipper_subject, ClipperLib::ptSubject, true);
// clip result against all polygons in the accum that intersect our bb // clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < accum.size(); i++) { for (unsigned int i=0; i < accum.size(); i++) {
tgRectangle box2 = BoundingBox_FromClipper( accum[i] ); tgRectangle box2 = BoundingBox_FromClipper( accum[i] );
if ( box2.intersects(box1) ) if ( box2.intersects(box1) )
{ {
c.AddPaths(accum[i], ClipperLib::ptClip, true); c.AddPaths(accum[i], ClipperLib::ptClip, true);
num_hits++; 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 ); if (num_hits) {
result = tgPolygon::AddColinearNodes( result, all_nodes ); if ( !c.Execute(ClipperLib::ctDifference, clipper_result, ClipperLib::pftNonZero, ClipperLib::pftNonZero) ) {
SG_LOG(SG_GENERAL, SG_ALERT, "Diff With Accumulator returned FALSE - reducing accumulator" );
max_hits = num_hits-1;
// Make sure we keep texturing info FILE* fp = fopen( "./accumulator_fail.log", "a" );
result.SetMaterial( subject.GetMaterial() ); fprintf( fp, "%s : reduce from %d to %d\n", debugstr.c_str(), num_hits, max_hits );
result.SetTexParams( subject.GetTexParams() ); fclose(fp);
} else { } else {
result = subject; 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() );
done = true;
}
} else {
result = subject;
done = true;
}
} }
return result; return result;

View file

@ -8,6 +8,8 @@
class tgAccumulator class tgAccumulator
{ {
public: public:
tgAccumulator( const std::string& d ) : debugstr(d) {}
tgPolygon Diff( const tgContour& subject ); tgPolygon Diff( const tgContour& subject );
tgPolygon Diff( const tgPolygon& subject ); tgPolygon Diff( const tgPolygon& subject );
@ -22,6 +24,7 @@ private:
clipper_polygons_list accum; clipper_polygons_list accum;
UniqueSGGeodSet nodes; UniqueSGGeodSet nodes;
std::string debugstr;
}; };
#endif // _TGACCUMULATOR_HXX #endif // _TGACCUMULATOR_HXX

View file

@ -924,7 +924,7 @@ tgpolygon_list tgContour::ExpandToPolygons( const tgContour& subject, double wid
tgContour expanded; tgContour expanded;
tgPolygon segment; tgPolygon segment;
tgAccumulator accum; tgAccumulator accum("ExpandToPolygons");
tgpolygon_list result; tgpolygon_list result;
// generate poly and texparam lists for each line segment // generate poly and texparam lists for each line segment