Add a routine to catch/remove some addition degeneracy our polygon clipper
can produce.
This commit is contained in:
parent
0dc39b1911
commit
38bb74f339
2 changed files with 49 additions and 1 deletions
|
@ -510,7 +510,7 @@ static void contour_tesselate( TGContourNode *node, const TGPolygon &p,
|
|||
cout << "contour = " << contour_num << " nodes = " << total_pts << endl;
|
||||
|
||||
#if 0
|
||||
// testing ... don't enable this otherwise
|
||||
// testing ... don't enable this if not testing
|
||||
if ( contour_num != 0 || total_pts != 28 ) {
|
||||
out_pts.push_back( Point3D(0, 0, 0) );
|
||||
out_pts.push_back( Point3D(0, 1, 0) );
|
||||
|
@ -1222,6 +1222,47 @@ TGPolygon reduce_degeneracy( const TGPolygon& poly ) {
|
|||
}
|
||||
|
||||
|
||||
static point_list remove_contour_cycles( const point_list& contour ) {
|
||||
point_list result;
|
||||
result.clear();
|
||||
|
||||
unsigned int i = 0;
|
||||
while ( i < contour.size() ) {
|
||||
result.push_back( contour[i] );
|
||||
for ( unsigned int j = i + 1; j < contour.size(); ++j ) {
|
||||
if ( contour[i] == contour[j] && i + 2 > j ) {
|
||||
cout << "detected a small cycle: i = "
|
||||
<< i << " j = " << j << endl;
|
||||
for ( int k = i; k <= j; ++k ) {
|
||||
cout << " " << contour[k] << endl;
|
||||
}
|
||||
// i = j;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Occasionally the outline of the clipped polygon can take a side
|
||||
// track, then double back on return to the start of the side track
|
||||
// branch and continue normally. Attempt to detect and clear this
|
||||
// extraneous nonsense.
|
||||
TGPolygon remove_cycles( const TGPolygon& poly ) {
|
||||
TGPolygon result;
|
||||
// cout << "remove cycles: " << poly << endl;
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
point_list contour = poly.get_contour(i);
|
||||
contour = remove_contour_cycles( contour );
|
||||
result.add_contour( contour, poly.get_hole_flag(i) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// remove any degenerate contours
|
||||
TGPolygon remove_bad_contours( const TGPolygon &poly ) {
|
||||
TGPolygon result;
|
||||
|
|
|
@ -86,6 +86,13 @@ TGPolygon remove_dups( const TGPolygon &poly );
|
|||
TGPolygon reduce_degeneracy( const TGPolygon& poly );
|
||||
|
||||
|
||||
// Occasionally the outline of the clipped polygon can take a side
|
||||
// track, then double back on return to the start of the side track
|
||||
// branch and continue normally. Attempt to detect and clear this
|
||||
// extraneous nonsense.
|
||||
TGPolygon remove_cycles( const TGPolygon& poly );
|
||||
|
||||
|
||||
// Find a point in the given node list that lies between start and
|
||||
// end, return true if something found, false if nothing found.
|
||||
bool find_intermediate_node( const Point3D& start, const Point3D& end,
|
||||
|
|
Loading…
Reference in a new issue