]> git.mxchange.org Git - flightgear.git/commitdiff
Fixed several problems with "hole" support, but it appears that things
authorcurt <curt>
Thu, 29 Apr 1999 04:30:24 +0000 (04:30 +0000)
committercurt <curt>
Thu, 29 Apr 1999 04:30:24 +0000 (04:30 +0000)
are working much better.  Crater lake now has an island which is always
a good thing. :-)

Tools/Construct/Clipper/clipper.cxx
Tools/Construct/Makefile.am
Tools/Construct/Triangulate/polygon.cxx
Tools/Construct/Triangulate/triangle.cxx

index 501abcdf181ba870b9467a9049efa2293de1e960..27b54bddddae8e27a1c7a1d7a89e423855e202dc 100644 (file)
@@ -56,6 +56,7 @@ bool FGClipper::load_polys(const string& path) {
     string poly_name;
     AreaType poly_type = DefaultArea;
     int contours, count, i, j;
+    int hole_flag;
     double startx, starty, x, y, lastx, lasty;
 
     FG_LOG( FG_CLIPPER, FG_INFO, "Loading " << path << " ..." );
@@ -89,6 +90,8 @@ bool FGClipper::load_polys(const string& path) {
                exit(-1);
            }
 
+           in >> hole_flag;
+
            in >> startx;
            in >> starty;
            v_list.vertex[0].x = startx;
@@ -119,8 +122,7 @@ bool FGClipper::load_polys(const string& path) {
                        << lastx << ", " << lasty );
            }
 
-           gpc_add_contour( poly, &v_list, 0 );
-
+           gpc_add_contour( poly, &v_list, hole_flag );
        }
 
        in >> skipcomment;
index f19226325bb1aac24f05d36d36f737ef8be5b32d..79fc6b321979b0f01fab35f0b59843ca308b40a0 100644 (file)
@@ -3,5 +3,6 @@ SUBDIRS = \
        Clipper \
        Combine \
        GenOutput \
+       Match \
        Triangulate \
        Main
index 5e8d6a6b84f143d590d3b0a734813bfa47f3dd6d..6020d9595bbe644546808932d11a6bf95cfe83a9 100644 (file)
@@ -124,10 +124,10 @@ void FGPolygon::calc_point_inside( const int contour,
 
     if ( min_node_index == 0 ) {
        p1 = trinodes.get_node( poly[contour][1] );
-       p2 = trinodes.get_node( poly[contour][poly.size() - 1] );
+       p2 = trinodes.get_node( poly[contour][poly[contour].size() - 1] );
     } else if ( min_node_index == (int)(poly[contour].size()) - 1 ) {
        p1 = trinodes.get_node( poly[contour][0] );
-       p2 = trinodes.get_node( poly[contour][poly.size() - 1] );
+       p2 = trinodes.get_node( poly[contour][poly[contour].size() - 2] );
     } else {
        p1 = trinodes.get_node( poly[contour][min_node_index - 1] );
        p2 = trinodes.get_node( poly[contour][min_node_index + 1] );
@@ -151,9 +151,12 @@ void FGPolygon::calc_point_inside( const int contour,
     p3.sety(100);
     
     for ( int i = 0; i < (int)poly.size(); ++i ) {
-       for ( int j = 0; j < (int)(poly[i].size()) - 1; ++j ) {
-           p1 = trinodes.get_node( poly[contour][j] );
-           p2 = trinodes.get_node( poly[contour][j+1] );
+       cout << "contour = " << i << " size = " << poly[i].size() << endl;
+       for ( int j = 0; j < (int)(poly[i].size() - 1); ++j ) {
+           cout << "  p1 = " << poly[i][j] << " p2 = " 
+                << poly[i][j+1] << endl;
+           p1 = trinodes.get_node( poly[i][j] );
+           p2 = trinodes.get_node( poly[i][j+1] );
 
            if ( intersects(p1, p2, m.x(), &result) ) {
                // cout << "intersection = " << result << endl;
@@ -163,8 +166,10 @@ void FGPolygon::calc_point_inside( const int contour,
                }
            }
        }
-       p1 = trinodes.get_node( poly[contour][0] );
-       p2 = trinodes.get_node( poly[contour][poly.size() - 1] );
+       cout << "  p1 = " << poly[i][0] << " p2 = " 
+            << poly[i][poly[i].size() - 1] << endl;
+       p1 = trinodes.get_node( poly[i][0] );
+       p2 = trinodes.get_node( poly[i][poly[i].size() - 1] );
        if ( intersects(p1, p2, m.x(), &result) ) {
            // cout << "intersection = " << result << endl;
            if ( ( result.y() < p3.y() ) &&
index 2db6bc6b4797681f7a43655852d906c2f4b46b3b..80a8d5d38e5c3b73d186ef131abb3efba9270611 100644 (file)
@@ -98,8 +98,9 @@ FGTriangle::build( const point_list& corner_list,
            int j;
 
            for ( j = 0; j < gpc_poly->num_contours; j++ ) {
-               cout << " processing contour = " << j << ", nodes = " 
-                    << gpc_poly->contour[j].num_vertices << endl;
+               cout << "  processing contour = " << j << ", nodes = " 
+                    << gpc_poly->contour[j].num_vertices << ", hole = "
+                    << gpc_poly->hole[j] << endl;
 
                // sprintf(junkn, "g.%d", junkc++);
                // junkfp = fopen(junkn, "w");
@@ -112,7 +113,7 @@ FGTriangle::build( const point_list& corner_list,
                    // junkp = in_nodes.get_node( index );
                    // fprintf(junkfp, "%.4f %.4f\n", junkp.x(), junkp.y());
                    poly.add_node(j, index);
-                   // cout << index << endl;
+                   cout << "  - " << index << endl;
                }
                // fprintf(junkfp, "%.4f %.4f\n", 
                //    gpc_poly->contour[j].vertex[0].x, 
@@ -120,12 +121,13 @@ FGTriangle::build( const point_list& corner_list,
                // fclose(junkfp);
 
                poly.set_hole_flag( j, gpc_poly->hole[j] );
-               polylist[i].push_back( poly );
            }
 
            for ( j = 0; j < gpc_poly->num_contours; j++ ) {
                poly.calc_point_inside( j, in_nodes );
            }
+
+           polylist[i].push_back( poly );
        }
     }
 
@@ -299,7 +301,17 @@ int FGTriangle::run_triangulate() {
     // region list
     in.numberofregions = 0;
     for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
-       in.numberofregions += polylist[i].size();
+       poly_list_iterator h_current, h_last;
+       h_current = polylist[i].begin();
+       h_last = polylist[i].end();
+       for ( ; h_current != h_last; ++h_current ) {
+           poly = *h_current;
+           for ( int j = 0; j < poly.contours(); j++ ) {
+               if ( ! poly.get_hole_flag( j ) ) {
+                   ++in.numberofregions;
+               }
+           }
+       }
     }
 
     in.regionlist = (REAL *) malloc(in.numberofregions * 4 * sizeof(REAL));
@@ -311,11 +323,15 @@ int FGTriangle::run_triangulate() {
        for ( ; h_current != h_last; ++h_current ) {
            poly = *h_current;
            for ( int j = 0; j < poly.contours(); j++ ) {
-               p = poly.get_point_inside( j );
-               in.regionlist[counter++] = p.x();  // x coord
-               in.regionlist[counter++] = p.y();  // y coord
-               in.regionlist[counter++] = i;      // region attribute
-               in.regionlist[counter++] = -1.0;   // area constraint (unused)
+               if ( ! poly.get_hole_flag( j ) ) {
+                   p = poly.get_point_inside( j );
+                   cout << "Region point = " << p << endl;
+                   in.regionlist[counter++] = p.x();  // x coord
+                   in.regionlist[counter++] = p.y();  // y coord
+                   in.regionlist[counter++] = i;      // region attribute
+                   in.regionlist[counter++] = -1.0;   // area constraint
+                                                      // (unused)
+               }
            }
        }
     }