// Customized triangulation call. void custom_triangulate(char *triswitches, struct triangulateio *in, struct triangulateio *out, struct triangulateio *vorout, const int *outside, const int *inside) { struct mesh m; struct behavior b; //REAL *holearray; //REAL *regionarray; triangleinit(& m); parsecommandline(1, & triswitches, & b); //b.verbose=2; m.steinerleft = b.steiner; transfernodes(& m, & b, in->pointlist, in->pointattributelist, in->pointmarkerlist, in->numberofpoints, in->numberofpointattributes); if ( b.refine ) { m.hullsize = reconstruct(& m, & b, in->trianglelist, in->triangleattributelist, in->trianglearealist, in->numberoftriangles, in->numberofcorners, in->numberoftriangleattributes, in->segmentlist, in->segmentmarkerlist, in->numberofsegments); } else { m.hullsize = delaunay(& m, & b); } m.infvertex1 = ( vertex ) NULL; m.infvertex2 = ( vertex ) NULL; m.infvertex3 = ( vertex ) NULL; if ( b.usesegments ) { m.checksegments = 1; if ( !b.refine ) { formskeleton(& m, & b, in->segmentlist, in->segmentmarkerlist, in->numberofsegments); } } #if 0 struct osub subsegloop; traversalinit(& m.subsegs); subsegloop.ss = subsegtraverse(& m); subsegloop.ssorient = 0; while ( subsegloop.ss != ( subseg * ) NULL ) { if ( subsegloop.ss != m.dummysub ) { REAL *p1, *p2; sorg(subsegloop, p1); sdest(subsegloop, p2); printf(" Connected (%f,%f) to (%f,%f)\n", p1 [ 0 ], p1 [ 1 ], p2 [ 0 ], p2 [ 1 ]); subsegloop.ss = subsegtraverse(& m); } } #endif if ( b.poly && ( m.triangles.items > 0 ) ) { //holearray = in->holelist; m.holes = in->numberofholes; //regionarray = in->regionlist; m.regions = in->numberofregions; if ( !b.refine ) { /* Only increase quality if the regions are properly defined. */ int sane = custom_carveholes(& m, & b, outside, inside); b.quality *= sane; if ( sane == 0 ) { printf("Probably bad PSLG\n"); exit(-1); } } } else { m.holes = 0; m.regions = 0; } if ( b.quality && ( m.triangles.items > 0 ) ) { enforcequality(& m, & b); } m.edges = ( 3l * m.triangles.items + m.hullsize ) / 2l; if ( b.order > 1 ) { highorder(& m, & b); } if ( !b.quiet ) { printf("\n"); } if ( b.jettison ) { out->numberofpoints = m.vertices.items - m.undeads; } else { out->numberofpoints = m.vertices.items; } out->numberofpointattributes = m.nextras; out->numberoftriangles = m.triangles.items; out->numberofcorners = ( b.order + 1 ) * ( b.order + 2 ) / 2; out->numberoftriangleattributes = m.eextras; out->numberofedges = m.edges; if ( b.usesegments ) { out->numberofsegments = m.subsegs.items; } else { out->numberofsegments = m.hullsize; } if ( vorout != ( struct triangulateio * ) NULL ) { vorout->numberofpoints = m.triangles.items; vorout->numberofpointattributes = m.nextras; vorout->numberofedges = m.edges; } if ( b.nonodewritten || ( b.noiterationnum && m.readnodefile ) ) { if ( !b.quiet ) { printf("NOT writing vertices.\n"); } numbernodes(& m, & b); } else { writenodes(& m, & b, & out->pointlist, & out->pointattributelist, & out->pointmarkerlist); } // Simp. always write the triangles. writeelements(& m, & b, & out->trianglelist, & out->triangleattributelist); if ( b.poly || b.convex ) { writepoly(& m, & b, & out->segmentlist, & out->segmentmarkerlist); out->numberofholes = m.holes; out->numberofregions = m.regions; if ( b.poly ) { out->holelist = in->holelist; out->regionlist = in->regionlist; } else { out->holelist = ( REAL * ) NULL; out->regionlist = ( REAL * ) NULL; } } if ( b.edgesout ) { writeedges(& m, & b, & out->edgelist, & out->edgemarkerlist); } // Simp. no voronoi if ( b.neighbors ) { writeneighbors(& m, & b, & out->neighborlist); } // Simp. No statistics. if ( b.docheck ) { checkmesh(& m, & b); checkdelaunay(& m, & b); } triangledeinit(& m, & b); }
void TIN::create(const mydefs::Points3d& thePoints3d) { // Set input values for triangulation TTriangulationIO in; // Number of points in.numberofpoints = thePoints3d.size(); // One attribute for Z coordinate in.numberofpointattributes = 1; // Allocate memory for array of X and Y coordinates in.pointlist = (double *) malloc(in.numberofpoints * 2 * sizeof(double)); // Allocate memory for array of Z coordinates in.pointattributelist = (double *) malloc(in.numberofpoints * in.numberofpointattributes * sizeof(double)); in.pointmarkerlist = (int *) malloc(in.numberofpoints * sizeof(int)); // Zero segments, holes and regions in.numberofsegments = 0; in.numberofholes = 0; in.numberofregions = 0; // Populate arrays of coordinates int i = 0; for(mydefs::Points3d::const_iterator iter = thePoints3d.begin(); iter != thePoints3d.end(); ++iter) { in.pointlist[2*i] = (*iter)[0]; in.pointlist[2*i+1] = (*iter)[1]; in.pointattributelist[i] = (*iter)[2]; if(mMinZ > (*iter)[2]) { mMinZ = (*iter)[2]; } if(mMaxZ < (*iter)[2]) { mMaxZ = (*iter)[2]; } ++i; } // Prepare for triangulation transfernodes(mMesh, mBehavior, in.pointlist, in.pointattributelist, in.pointmarkerlist, in.numberofpoints, in.numberofpointattributes); // Triangulate points mMesh->hullsize = delaunay(mMesh, mBehavior); // Necessary maintenance mMesh->infvertex1 = (TVertex) NULL; mMesh->infvertex2 = (TVertex) NULL; mMesh->infvertex3 = (TVertex) NULL; mMesh->edges = (3l * mMesh->triangles.items + mMesh->hullsize) / 2l; // Set most recent triangle traversalinit(&mMesh->triangles); mRecentTri->tri = triangletraverse(mMesh); mRecentTri->orient = 0; // Free memory free(in.pointmarkerlist); free(in.pointattributelist); free(in.pointlist); }