+
+ // prep the output structures
+ out.pointlist = (REAL *) NULL; // Not needed if -N switch used.
+ // Not needed if -N switch used or number of point attributes is zero:
+ out.pointattributelist = (REAL *) NULL;
+ out.pointmarkerlist = (int *) NULL; // Not needed if -N or -B switch used.
+ out.trianglelist = (int *) NULL; // Not needed if -E switch used.
+ // Not needed if -E switch used or number of triangle attributes is zero:
+ out.triangleattributelist = (REAL *) NULL;
+ out.neighborlist = (int *) NULL; // Needed only if -n switch used.
+ // Needed only if segments are output (-p or -c) and -P not used:
+ out.segmentlist = (int *) NULL;
+ // Needed only if segments are output (-p or -c) and -P and -B not used:
+ out.segmentmarkerlist = (int *) NULL;
+ out.edgelist = (int *) NULL; // Needed only if -e switch used.
+ out.edgemarkerlist = (int *) NULL; // Needed if -e used and -B not used.
+
+ vorout.pointlist = (REAL *) NULL; // Needed only if -v switch used.
+ // Needed only if -v switch used and number of attributes is not zero:
+ vorout.pointattributelist = (REAL *) NULL;
+ vorout.edgelist = (int *) NULL; // Needed only if -v switch used.
+ vorout.normlist = (REAL *) NULL; // Needed only if -v switch used.
+
+ // Triangulate the points. Switches are chosen to read and write
+ // a PSLG (p), preserve the convex hull (c), number everything
+ // from zero (z), assign a regional attribute to each element (A),
+ // and produce an edge list (e), and a triangle neighbor list (n).
+
+ triangulate("pczAen", &in, &out, &vorout);
+
+ // TEMPORARY
+ //
+
+ // Write out the triangulated data to files so we can check
+ // visually that things seem reasonable
+
+ FILE *node = fopen("tile.node", "w");
+ fprintf(node, "%d 2 %d 0\n",
+ out.numberofpoints, out.numberofpointattributes);
+ for (int i = 0; i < out.numberofpoints; i++) {
+ fprintf(node, "%d %.6f %.6f %.2f\n",
+ i, out.pointlist[2*i], out.pointlist[2*i + 1], 0.0);
+ }
+ fclose(node);
+
+ FILE *ele = fopen("tile.ele", "w");
+ fprintf(ele, "%d 3 0\n", out.numberoftriangles);
+ for (int i = 0; i < out.numberoftriangles; i++) {
+ fprintf(ele, "%d ", i);
+ for (int j = 0; j < out.numberofcorners; j++) {
+ fprintf(ele, "%d ", out.trianglelist[i * out.numberofcorners + j]);
+ }
+ fprintf(ele, "\n");
+ }
+ fclose(ele);
+
+ // free mem allocated to the "Triangle" structures
+ free(in.pointlist);
+ free(in.pointattributelist);
+ free(in.pointmarkerlist);
+ free(in.regionlist);
+ free(out.pointlist);
+ free(out.pointattributelist);
+ free(out.pointmarkerlist);
+ free(out.trianglelist);
+ free(out.triangleattributelist);
+ // free(out.trianglearealist);
+ free(out.neighborlist);
+ free(out.segmentlist);
+ free(out.segmentmarkerlist);
+ free(out.edgelist);
+ free(out.edgemarkerlist);
+ free(vorout.pointlist);
+ free(vorout.pointattributelist);
+ free(vorout.edgelist);
+ free(vorout.normlist);
+