static void ConnectLeftDegenerate( TESStesselator *tess, ActiveRegion *regUp, TESSvertex *vEvent ) /* * The event vertex lies exacty on an already-processed edge or vertex. * Adding the new vertex involves splicing it into the already-processed * part of the mesh. */ { TESShalfEdge *e, *eTopLeft, *eTopRight, *eLast; ActiveRegion *reg; e = regUp->eUp; if( VertEq( e->Org, vEvent )) { /* e->Org is an unprocessed vertex - just combine them, and wait * for e->Org to be pulled from the queue */ assert( TOLERANCE_NONZERO ); SpliceMergeVertices( tess, e, vEvent->anEdge ); return; } if( ! VertEq( e->Dst, vEvent )) { /* General case -- splice vEvent into edge e which passes through it */ if (tessMeshSplitEdge( tess->mesh, e->Sym ) == NULL) longjmp(tess->env,1); if( regUp->fixUpperEdge ) { /* This edge was fixable -- delete unused portion of original edge */ if ( !tessMeshDelete( tess->mesh, e->Onext ) ) longjmp(tess->env,1); regUp->fixUpperEdge = FALSE; } if ( !tessMeshSplice( tess->mesh, vEvent->anEdge, e ) ) longjmp(tess->env,1); SweepEvent( tess, vEvent ); /* recurse */ return; } /* vEvent coincides with e->Dst, which has already been processed. * Splice in the additional right-going edges. */ assert( TOLERANCE_NONZERO ); regUp = TopRightRegion( regUp ); reg = RegionBelow( regUp ); eTopRight = reg->eUp->Sym; eTopLeft = eLast = eTopRight->Onext; if( reg->fixUpperEdge ) { /* Here e->Dst has only a single fixable edge going right. * We can delete it since now we have some real right-going edges. */ assert( eTopLeft != eTopRight ); /* there are some left edges too */ DeleteRegion( tess, reg ); if ( !tessMeshDelete( tess->mesh, eTopRight ) ) longjmp(tess->env,1); eTopRight = eTopLeft->Oprev; } if ( !tessMeshSplice( tess->mesh, vEvent->anEdge, eTopRight ) ) longjmp(tess->env,1); if( ! EdgeGoesLeft( eTopLeft )) { /* e->Dst had no left-going edges -- indicate this to AddRightEdges() */ eTopLeft = NULL; } AddRightEdges( tess, regUp, eTopRight->Onext, eLast, eTopLeft, TRUE ); }
/* tessMeshTessellateMonoRegion( face ) tessellates a monotone region * (what else would it do??) The region must consist of a single * loop of half-edges (see mesh.h) oriented CCW. "Monotone" in this * case means that any vertical line intersects the interior of the * region in a single interval. * * Tessellation consists of adding interior edges (actually pairs of * half-edges), to split the region into non-overlapping triangles. * * The basic idea is explained in Preparata and Shamos (which I don''t * have handy right now), although their implementation is more * complicated than this one. The are two edge chains, an upper chain * and a lower chain. We process all vertices from both chains in order, * from right to left. * * The algorithm ensures that the following invariant holds after each * vertex is processed: the untessellated region consists of two * chains, where one chain (say the upper) is a single edge, and * the other chain is concave. The left vertex of the single edge * is always to the left of all vertices in the concave chain. * * Each step consists of adding the rightmost unprocessed vertex to one * of the two chains, and forming a fan of triangles from the rightmost * of two chain endpoints. Determining whether we can add each triangle * to the fan is a simple orientation test. By making the fan as large * as possible, we restore the invariant (check it yourself). */ int tessMeshTessellateMonoRegion( TESSmesh *mesh, TESSface *face ) { TESShalfEdge *up, *lo; /* All edges are oriented CCW around the boundary of the region. * First, find the half-edge whose origin vertex is rightmost. * Since the sweep goes from left to right, face->anEdge should * be close to the edge we want. */ up = face->anEdge; if(!( up->Lnext != up && up->Lnext->Lnext != up )) return 1; for( ; VertLeq( up->Dst, up->Org ); up = up->Lprev ) ; for( ; VertLeq( up->Org, up->Dst ); up = up->Lnext ) ; lo = up->Lprev; while( up->Lnext != lo ) { if( VertLeq( up->Dst, lo->Org )) { /* up->Dst is on the left. It is safe to form triangles from lo->Org. * The EdgeGoesLeft test guarantees progress even when some triangles * are CW, given that the upper and lower chains are truly monotone. */ while( lo->Lnext != up && (EdgeGoesLeft( lo->Lnext ) || EdgeSign( lo->Org, lo->Dst, lo->Lnext->Dst ) <= 0 )) { TESShalfEdge *tempHalfEdge= tessMeshConnect( mesh, lo->Lnext, lo ); if (tempHalfEdge == NULL) return 0; lo = tempHalfEdge->Sym; } lo = lo->Lprev; } else { /* lo->Org is on the left. We can make CCW triangles from up->Dst. */ while( lo->Lnext != up && (EdgeGoesRight( up->Lprev ) || EdgeSign( up->Dst, up->Org, up->Lprev->Org ) >= 0 )) { TESShalfEdge *tempHalfEdge= tessMeshConnect( mesh, up, up->Lprev ); if (tempHalfEdge == NULL) return 0; up = tempHalfEdge->Sym; } up = up->Lnext; } } /* Now lo->Org == up->Dst == the leftmost vertex. The remaining region * can be tessellated in a fan from this leftmost vertex. */ if( lo->Lnext == up ) return 1; while( lo->Lnext->Lnext != up ) { TESShalfEdge *tempHalfEdge= tessMeshConnect( mesh, lo->Lnext, lo ); if (tempHalfEdge == NULL) return 0; lo = tempHalfEdge->Sym; } return 1; }