/********************************************************************/ /* STRIPE: converting a polygonal model to triangle strips Francine Evans, 1996. SUNY @ Stony Brook Advisors: Steven Skiena and Amitabh Varshney */ /********************************************************************/ /*---------------------------------------------------------------------*/ /* STRIPE: sgi_triangex.c This file contains routines that are used for various functions in the local algorithm. */ /*---------------------------------------------------------------------*/ #include #include #include #include "global.h" #include "outputex.h" #include "polverts.h" #include "sturctsex.h" #include "common.h" #include "util.h" int AdjacentEx(int id2,int id1, int *list, int size) { /* Return the vertex that is adjacent to id1, but is not id2, in the list of integers. */ register int x=0; while (x < size) { if (*(list+x) == id1) { if ((x != (size -1)) && (x != 0)) { if ( *(list+x+1) != id2) return *(list+x+1); else return *(list+x-1); } else if (x == (size -1)) { if (*(list) != id2) return *(list); else return *(list+x-1); } else { if (*(list+size-1) != id2) return *(list+size-1); else return *(list+x+1); } } x++; } printf("Error in the list\n"); exit(0); } void Delete_From_ListEx(int id,int *list, int size) { /* Delete the occurence of id in the list. (list has size size) */ int *temp; register int x,y=0; temp = (int *) malloc(sizeof(int) * size); for (x=0; x= 0; f--) { *(index+x) = *(temp+f); x++; } /* Finish the rest of the list */ for(f = (size - 1); f > y ; f--) { *(index+x) = *(temp+f); x++; } } } void Blind_TriangulateEx(int size, int *index, FILE *fp, FILE *output, BOOL begin, int where ) { /* save sides in temp array, we need it so we know about swaps. */ int mode, decreasing,increasing,e1,e2,e3; int x = 0; BOOL flag = FALSE; /* Rearrange the index list so that the input edge is first */ if (!begin) Rearrange_IndexEx(index,size); /* We are given a polygon of more than 3 sides and want to triangulate it. We will output the triangles to the output file. */ /* Find where the input edge is in the input list */ Last_Edge(&e1,&e2,&e3,0); if (( (!begin) && (*(index) == e2) ) || (begin)) { Output_TriEx(*(index+0),*(index+1),*(index+size-1),fp,-1,-1,where); /* If we have a quad, (chances are yes), then we know that we can just add one diagonal and be done. (divide the quad into 2 triangles. */ if (size == 4) { Output_TriEx(*(index+1),*(index+size-1),*(index+2),fp,-1,-1,where); return; } increasing = 1; mode = 1; } else if (!begin) { Output_TriEx(*(index+1),*(index+0),*(index+size-1),fp,-1,-1,where); if (size == 4) { Output_TriEx(*(index+0),*(index+size-1),*(index+2),fp,-1,-1,where); return; } Output_TriEx(*(index+0),*(index+size-1),*(index+2),fp,-1,-1,where); increasing = 2; mode = 0; } if (size != 4) { /* We do not have a quad, we have something bigger. */ decreasing = size - 1; do { /* Will be alternating diagonals, so we will be increasing and decreasing around the polygon. */ if (mode) { Output_TriEx(*(index+increasing),*(index+decreasing),*(index+increasing+1),fp,-1,-1,where); increasing++; } else { Output_TriEx(*(index+decreasing),*(index+increasing),*(index+decreasing-1),fp,-1,-1,where); decreasing--; } mode = !mode; } while ((decreasing - increasing) >= 2); } }