1 /********************************************************************/
2 /* STRIPE: converting a polygonal model to triangle strips
5 Advisors: Steven Skiena and Amitabh Varshney
7 /********************************************************************/
9 /*---------------------------------------------------------------------*/
11 This file contains routines that are used for various functions
13 /*---------------------------------------------------------------------*/
19 void switch_lower (int *x, int *y)
23 /* Put lower value in x */
32 BOOL member(int x , int id1, int id2, int id3)
34 /* Is x in the triangle specified by id1,id2,id3 */
35 if ((x != id1) && (x != id2) && (x != id3))
41 int Compare (P_ADJACENCIES node1, P_ADJACENCIES node2)
43 /* This will only return whether 2 adjacency nodes
46 if (node1->face_id == node2->face_id)
53 BOOL Exist(int face_id, int id1, int id2)
55 /* Does the edge specified by id1 and id2 exist in this
56 face currently? Maybe we deleted in partial triangulation
61 BOOL a=FALSE,b =FALSE;
63 pListHead = PolFaces[face_id];
64 temp = ( PF_FACES ) PeekList( pListHead, LISTHEAD, 0 );
65 size = temp->nPolSize;
66 for (x=0; x<size; x++)
68 if (*(temp->pPolygon+x) == id1)
70 if (*(temp->pPolygon+x) == id2)
78 int Get_Next_Id(int *index,int e3, int size)
80 /* Return the id following e3 in the list of vertices */
84 for (x = 0; x< size; x++)
86 if ((*(index+x) == e3) && (x != (size-1)))
88 else if (*(index+x) == e3)
91 printf("There is an error in the next id\n");
95 int Different (int id1,int id2,int id3,int id4,int id5, int id6, int *x, int *y)
97 /* Find the vertex in the first 3 numbers that does not exist in
98 the last three numbers
100 if ((id1 != id4) && (id1 != id5) && (id1 != id6))
106 if ((id2 != id4) && (id2 != id5) && (id2 != id6))
112 if ((id3 != id4) && (id3 != id5) && (id3 != id6))
119 /* Because there are degeneracies in the data, this might occur */
125 int Return_Other(int *index,int e1,int e2)
127 /* We have a triangle and want to know the third vertex of it */
132 if ((*(index+x) != e1) && (*(index+x) != e2))
135 /* If there is a degenerate triangle return arbitrary */
139 int Get_Other_Vertex(int id1,int id2,int id3,int *index)
141 /* We have a list index of 4 numbers and we wish to
142 return the number that is not id1,id2 or id3
148 if ((*(index+x) != id1) && (*(index+x) != id2) &&
152 /* If there is some sort of degeneracy this might occur,
160 PLISTINFO Done(int face_id, int size, int *bucket)
162 /* Check to see whether the polygon with face_id was used
163 already, return NULL if it was, otherwise return a pointer to the face.
165 P_ADJACENCIES pfNode;
167 PLISTINFO lpListInfo;
169 pfNode = (P_ADJACENCIES) malloc(sizeof(ADJACENCIES) );
171 pfNode->face_id = face_id;
175 lpListInfo = SearchList(array[y], pfNode,
176 (int (*)(void *,void *)) (Compare));
177 if (lpListInfo != NULL)
183 /* This adjacent face was done already */
189 void Output_Edge(int *index,int e2,int e3,int *output1,int *output2)
191 /* Given a quad and an input edge return the other 2 vertices of the
198 if ((*(index) != e2) && (*(index) != e3))
201 if ((*(index+1) != e2) && (*(index+1) != e3))
204 *output1 = *(index+1);
207 *output2 = *(index+1);
212 if ((*(index+2) != e2) && (*(index+2) != e3))
215 *output1 = *(index+2);
218 *output2 = *(index+2);
223 *output2 = *(index+3);
227 void First_Edge(int *id1,int *id2, int *id3)
229 /* Get the first triangle in the strip we just found, we will use this to
230 try to extend backwards in the strip
235 P_STRIPS temp1,temp2,temp3;
237 pListHead = strips[0];
238 num = NumOnList(pListHead);
240 /* Did not have a strip */
244 temp1 = ( P_STRIPS ) PeekList( pListHead, LISTHEAD, 0);
245 temp2 = ( P_STRIPS ) PeekList( pListHead, LISTHEAD, 1);
246 temp3 = ( P_STRIPS ) PeekList( pListHead, LISTHEAD, 2);
247 *id1 = temp1->face_id;
248 *id2 = temp2->face_id;
249 *id3 = temp3->face_id;
253 void Last_Edge(int *id1, int *id2, int *id3, BOOL save)
255 /* We need the last edge that we had */
256 static int v1, v2, v3;