700 |
|
return(f); |
701 |
|
} |
702 |
|
|
703 |
+ |
/* Get neighbor vertices: malloc array with valence in index[0] */ |
704 |
+ |
int * |
705 |
+ |
getVertexNeighbors(Scene *sc, int vid) |
706 |
+ |
{ |
707 |
+ |
int *varr; |
708 |
+ |
Face *f; |
709 |
+ |
int j=0; |
710 |
+ |
|
711 |
+ |
if (sc == NULL || (vid < 0) | (vid >= sc->nverts) || |
712 |
+ |
(f = sc->vert[vid].vflist) == NULL) |
713 |
+ |
return(NULL); |
714 |
+ |
|
715 |
+ |
varr = (int *)emalloc(sizeof(int)*CHUNKSIZ); |
716 |
+ |
varr[0] = 0; /* add unique neighbors */ |
717 |
+ |
for ( ; f != NULL; f = f->v[j].fnext) { |
718 |
+ |
int i, cvi; |
719 |
+ |
for (j = f->nv; j--; ) /* find ourself in poly */ |
720 |
+ |
if (f->v[j].vid == vid) |
721 |
+ |
break; |
722 |
+ |
if (j < 0) /* this is an error */ |
723 |
+ |
break; |
724 |
+ |
if (f->nv < 3) /* also never happens */ |
725 |
+ |
continue; |
726 |
+ |
/* check previous neighbor */ |
727 |
+ |
cvi = f->v[ (j > 0) ? j-1 : f->nv-1 ].vid; |
728 |
+ |
for (i = varr[0]+1; --i; ) /* making sure not in list */ |
729 |
+ |
if (varr[i] == cvi) |
730 |
+ |
break; |
731 |
+ |
if (!i) { /* new neighbor? */ |
732 |
+ |
varr = chunk_alloc(int, varr, varr[0]+1); |
733 |
+ |
varr[++varr[0]] = cvi; |
734 |
+ |
} |
735 |
+ |
/* check next neighbor */ |
736 |
+ |
cvi = f->v[ (j < f->nv-1) ? j+1 : 0 ].vid; |
737 |
+ |
for (i = varr[0]+1; --i; ) |
738 |
+ |
if (varr[i] == cvi) |
739 |
+ |
break; |
740 |
+ |
if (!i) { |
741 |
+ |
varr = chunk_alloc(int, varr, varr[0]+1); |
742 |
+ |
varr[++varr[0]] = cvi; |
743 |
+ |
} |
744 |
+ |
} |
745 |
+ |
if (!varr[0]) { |
746 |
+ |
efree((char *)varr); /* something went awry */ |
747 |
+ |
return(NULL); |
748 |
+ |
} |
749 |
+ |
/* tighten array & return */ |
750 |
+ |
return((int *)erealloc((char *)varr, sizeof(int)*(varr[0]+1))); |
751 |
+ |
} |
752 |
+ |
|
753 |
|
/* Callback for growBoundingBox() */ |
754 |
|
static int |
755 |
|
addBBox(Scene *sc, Face *f, void *p) |