/* Store in the rightface field of each edge the number of the face on the right hand side of that edge. Faces are numbered 0,1,.... Also store in facestart[i] an example of an edge in the clockwise orientation of the face boundary, and the size of the face in facesize[i], for each i. Returns the number of faces. */ void makeDual() { register int i, sz; register EDGE *e, *ex, *ef, *efx; RESETMARKS; nf = 0; for (i = 0; i < nv; ++i) { e = ex = firstedge[i]; do { if (!ISMARKEDLO(e)) { facestart[nf] = ef = efx = e; faceSets[nf] = EMPTY_SET; sz = 0; do { ef->rightface = nf; ADD(faceSets[nf], ef->end); MARKLO(ef); ef = ef->inverse->prev; ++sz; } while (ef != efx); faceSize[nf] = sz; ++nf; } e = e->next; } while (e != ex); } }
/* Store in the rightface field of each edge the number of the face on the right hand side of that edge. Faces are numbered 0,1,.... Also store in facestart[i] an example of an edge in the clockwise orientation of the face boundary, and the size of the face in facesize[i], for each i. Returns the number of faces. */ void makeDual(PLANE_GRAPH *pg) { register int i, sz; register PG_EDGE *e, *ex, *ef, *efx; RESETMARKS(pg); //first allocate the memory to store faces if this has not yet been done int maxf = 2*pg->maxn - 4; if(pg->maxf < maxf){ if(pg->facestart!=NULL){ free(pg->facestart); } if(pg->faceSize!=NULL){ free(pg->faceSize); } pg->maxf = maxf; pg->facestart = (PG_EDGE **)malloc(sizeof(PG_EDGE *)*maxf); if(pg->facestart == NULL){ pg->maxf = 0; return; } pg->faceSize = (int *)malloc(sizeof(int)*maxf); if(pg->faceSize == NULL){ pg->maxf = 0; free(pg->facestart); return; } } int nf = 0; for (i = 0; i < pg->nv; ++i) { e = ex = pg->firstedge[i]; do { if (!ISMARKEDLO(e)) { pg->facestart[nf] = ef = efx = e; sz = 0; do { ef->rightface = nf; MARKLO(ef); ef = ef->inverse->prev; ++sz; } while (ef != efx); pg->faceSize[nf] = sz; ++nf; } e = e->next; } while (e != ex); } pg->nf = nf; pg->dualComputed = TRUE; }