]> git.mxchange.org Git - flightgear.git/blob - Stripe_u/local.c
First working version!
[flightgear.git] / Stripe_u / local.c
1 /********************************************************************/
2 /*   STRIPE: converting a polygonal model to triangle strips    
3      Francine Evans, 1996.
4      SUNY @ Stony Brook
5      Advisors: Steven Skiena and Amitabh Varshney
6 */
7 /********************************************************************/
8
9 /*---------------------------------------------------------------------*/
10 /*   STRIPE: local.c
11      This file contains the code that initializes the data structures for
12      the local algorithm, and starts the local algorithm going.
13 */
14 /*---------------------------------------------------------------------*/
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "polverts.h"
19 #include "local.h"
20 #include "triangulatex.h"
21 #include "sturctsex.h"
22 #include "common.h"
23 #include "outputex.h"
24 #include "util.h"
25 #include "init.h"
26
27 void Find_StripsEx(FILE *output,FILE *strip,int *ties,
28                                  int  tie, int triangulate,
29                  int  swaps,int *next_id)
30 {
31         /*      This routine will peel off the strips from the model */
32
33         ListHead *pListHead;
34         P_ADJACENCIES temp = NULL;
35         register int max,bucket=0;
36         BOOL whole_flag = TRUE;
37      int dummy = 0;
38         
39         /*  Set the last known input edge to be null */
40      Last_Edge(&dummy,&dummy,&dummy,1);
41     
42      /* Search for lowest adjacency polygon and output strips */
43         while (whole_flag)
44         {
45                 bucket = -1;
46                 /*      Search for polygons in increasing number of adjacencies */
47                 while (bucket < 59)
48                 {
49                         bucket++;
50                         pListHead = array[bucket];
51                         max = NumOnList(pListHead);
52                         if (max > 0)
53                         {
54                                 temp = (P_ADJACENCIES) PeekList(pListHead,LISTHEAD,0);
55                                 if (temp == NULL)
56                                 {
57                                         printf("Error in the buckets%d %d %d\n",bucket,max,0);
58                                         exit(0);
59                                 }
60                                 Polygon_OutputEx(temp,temp->face_id,bucket,pListHead,
61                                                output,strip,ties,tie,triangulate,swaps,next_id,1);
62                                 /*  Try to extend backwards, if the starting polygon in the
63                         strip had 2 or more adjacencies to begin with
64                     */
65                     if (bucket >= 2)
66                          Extend_BackwardsEx(temp->face_id,output,strip,ties,tie,triangulate,
67                                             swaps,next_id);
68                     break;  
69                         }
70                 }
71                 /*      Went through the whole structure, it is empty and we are done.
72                 */
73                 if ((bucket == 59) && (max == 0))
74                         whole_flag = FALSE;
75         
76           /*  We just finished a strip, send dummy data to signal the end
77               of the strip so that we can output it.
78           */
79          else
80          {
81              Output_TriEx(-1,-2,-3,output,-1,-10,1);
82              Last_Edge(&dummy,&dummy,&dummy,1);
83          }
84         }
85 }
86
87
88
89 void SGI_Strip(int num_verts,int num_faces,FILE *output,
90                            int ties,int triangulate)
91                
92 {
93         FILE *strip;
94      int next_id = -1,t=0;
95
96      strip = fopen("output.d","w");
97      /* We are going to output and find triangle strips
98                 according the the method that SGI uses, ie always
99                 choosing as the next triangle in our strip the triangle
100                 that has the least number of adjacencies. We do not have
101                 all triangles and will be triangulating on the fly those
102                 polygons that have more than 3 sides.
103         */
104
105         /*      Build a table that has all the polygons sorted by the number
106                 of polygons adjacent to it.
107         */
108         /*      Initialize it */
109         Init_Table_SGI();
110         /*      Build it */
111         Build_SGI_Table(num_verts,num_faces);
112
113         /*    We will have a structure to hold all the strips, until
114           outputted.
115      */
116      InitStripTable();
117      /* Now we have the structure built to find the polygons according
118                 to the number of adjacencies. Now use the SGI Method to find
119                 strips according to the adjacencies
120         */
121      Find_StripsEx(output,strip,&t,ties,triangulate,ON,&next_id);
122
123 }