]> git.mxchange.org Git - flightgear.git/blobdiff - Triangulate/triangle.cxx
Added trisegs.[ch]xx tripoly.[ch]xx.
[flightgear.git] / Triangulate / triangle.cxx
index 854b5b508188588e4c00493844e520c742cc6ef7..6db46c16c2dc452f4c47c98e92e86a45b62ff3a9 100644 (file)
@@ -23,6 +23,7 @@
 
 
 #include "triangle.hxx"
+#include "tripoly.hxx"
 
 
 // Constructor
@@ -38,8 +39,6 @@ FGTriangle::~FGTriangle( void ) {
 // populate this class based on the specified gpc_polys list
 int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
     int index;
-    tripoly poly;
-
     // traverse the gpc_polys and build a unified node list and a set
     // of Triangle PSLG that reference the node list by index
     // (starting at zero)
@@ -59,7 +58,7 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
            cout << "processing a polygon, contours = " 
                 << gpc_poly->num_contours << endl;
 
-           poly.erase(poly.begin(), poly.end());
+           FGTriPoly poly;
 
            if (gpc_poly->num_contours <= 0 ) {
                cout << "FATAL ERROR! no contours in this polygon" << endl;
@@ -78,9 +77,11 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
                               gpc_poly->contour[j].vertex[k].y,
                               0 );
                    index = trinodes.unique_add( p );
-                   poly.push_back(index);
+                   poly.add_node(index);
                    // cout << index << endl;
                }
+               poly.calc_point_inside( trinodes );
+
                polylist[i].push_back(poly);
            }
        }
@@ -97,18 +98,19 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
 
 
 // do actual triangulation
-int FGTriangle::do_triangulate( const tripoly& poly ) {
-    point_container node_list;
-    struct triangulateio in, mid, out, vorout;
+int FGTriangle::do_triangulate( const FGTriPoly& poly ) {
+    trinode_list node_list;
+    struct triangulateio in, out;
     int counter;
 
     // define input points
     node_list = trinodes.get_node_list();
 
     in.numberofpoints = node_list.size();
+    in.numberofpointattributes = 0;
     in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
 
-    point_iterator current, last;
+    trinode_list_iterator current, last;
     current = node_list.begin();
     last = node_list.end();
     counter = 0;
@@ -116,15 +118,61 @@ int FGTriangle::do_triangulate( const tripoly& poly ) {
        in.pointlist[counter++] = current->x();
        in.pointlist[counter++] = current->y();
     }
+
+    return 0;
 }
 
 
 // triangulate each of the polygon areas
 int FGTriangle::triangulate() {
-    tripoly poly;
+    FGTriPoly poly;
+    struct triangulateio in, out;
 
-    tripoly_list_iterator current, last;
+    trinode_list node_list = trinodes.get_node_list();
+
+    // point list
+    in.numberofpoints = node_list.size();
+    in.numberofpointattributes = 1;
+    in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
+
+    trinode_list_iterator tn_current, tn_last;
+    tn_current = node_list.begin();
+    tn_last = node_list.end();
+    int counter = 0;
+    for ( ; tn_current != tn_last; ++tn_current ) {
+       in.pointlist[counter++] = tn_current->x();
+       in.pointlist[counter++] = tn_current->y();
+    }
+
+    in.pointattributelist = (REAL *) NULL;
+    in.pointmarkerlist = (int *) NULL;
+
+    // segment list
+    in.numberofsegments = 0;
 
+    tripoly_list_iterator tp_current, tp_last;
+    for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
+       cout << "area type = " << i << endl;
+       tp_current = polylist[i].begin();
+       tp_last = polylist[i].end();
+       for ( ; tp_current != tp_last; ++tp_current ) {
+           poly = *tp_current;
+           in.numberofsegments += poly.size() + 1;
+       }
+    }
+
+    in.numberofsegments = 0;
+
+  in.numberofholes = 0;
+  in.numberofregions = 1;
+  in.regionlist = (REAL *) malloc(in.numberofregions * 4 * sizeof(REAL));
+  in.regionlist[0] = 0.5;
+  in.regionlist[1] = 5.0;
+  in.regionlist[2] = 7.0;            /* Regional attribute (for whole mesh). */
+  in.regionlist[3] = 0.1;          /* Area constraint that will not be used. */
+
+  /*
+    tripoly_list_iterator current, last;
     for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
        cout << "area type = " << i << endl;
        current = polylist[i].begin();
@@ -136,12 +184,19 @@ int FGTriangle::triangulate() {
            do_triangulate( poly );
        }
     }
-
+    */
     return 0;
 }
 
 
 // $Log$
+// Revision 1.6  1999/03/20 13:22:11  curt
+// Added trisegs.[ch]xx tripoly.[ch]xx.
+//
+// Revision 1.5  1999/03/20 02:21:52  curt
+// Continue shaping the code towards triangulation bliss.  Added code to
+// calculate some point guaranteed to be inside a polygon.
+//
 // Revision 1.4  1999/03/19 22:29:04  curt
 // Working on preparationsn for triangulation.
 //