File: strips.cmd

package info (click to toggle)
evolver 2.70+ds-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 17,148 kB
  • sloc: ansic: 127,395; makefile: 209; sh: 98
file content (263 lines) | stat: -rw-r--r-- 8,613 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// strips.cmd
// Creates strips as for OpenGL GL_TRIANGLE_STRIPS.  Just colors the strips.

// But also see the graphics window 'S' and 'Y' commands.

// Programmer:  Ken Brakke  brakke@susqu.edu  www.susqu.edu/brakke

// "strips" just takes one stab at a strip for each facet.
strips := {
    local stripcolor,stripcount,testcolor;
    local trystart,whichwaystart,whichway;
    local eid,fid,fffid,eeid,goodstart,striplength;
    local firstcount,secondcount,trucfacet;

    set facet color white;
    stripcolor := 1;
    stripcount := 0;
    foreach facet ff where  color == white do
    { ff.color := stripcolor;

      whichwaystart := 0;
      while whichwaystart <= 1 do
      { 
        eid := ff.edge[whichwaystart+1].oid;
        fid := ff.id;
        whichway := whichwaystart;   // alternating directions of triangles

        while edge[eid].valence >= 2 do
        {
          foreach edge[eid].facet fff do 
          { if fff.id != fid then {fffid := fff.id; break;} };
          if facet[fffid].color != white then break;
          facet[fffid].color := stripcolor;
          foreach facet[fffid].edge ee do 
          { eeid := ee.oid;
            if whichway then
            { if ee.vertex[2].id == edge[eid].vertex[2].id then break; }
            else 
            { if ee.vertex[1].id == edge[eid].vertex[1].id then break; }
          };
          eid := eeid;
          fid := fffid;
          whichway := !whichway;
        };
        whichwaystart += 1;
      };


      stripcolor := (stripcolor imod 14) + 1;
      stripcount += 1;
    };
  printf "%g strips, average %g facets.\n",stripcount,facet_count/stripcount;
}
     
// "strips2" searches for longest strip through facet, out of 3 ways
strips2 := {
    local stripcolor,stripcount,testcolor;
    local trystart,whichwaystart,whichway;
    local eid,fid,fffid,eeid,maxlength,goodstart,striplength;

    set facet color white;
    stripcolor := 1;
    stripcount := 0;
    testcolor := 100;
    foreach facet ff where  color == white do
    { ff.color := stripcolor;

      // three-way trial first
      trystart := 1; maxlength := 0; goodstart := 1;
      while trystart <= 3 do
      { striplength := 1;

      whichwaystart := 0;
      while whichwaystart <= 1 do
      { 
        eid := ff.edge[((whichwaystart+trystart)imod 3)+1].oid;
        fid := ff.id;
        whichway := whichwaystart;   // alternating directions of triangles

        while edge[eid].valence >= 2 do
        {
          foreach edge[eid].facet fff do 
          { if fff.id != fid then {fffid := fff.id; break;} };
          if facet[fffid].color != white then break;
          facet[fffid].color := testcolor; striplength += 1;
          foreach facet[fffid].edge ee do 
          { eeid := ee.oid;
            if whichway then
            { if ee.vertex[2].id == edge[eid].vertex[2].id then break; }
            else 
            { if ee.vertex[1].id == edge[eid].vertex[1].id then break; }
          };
          eid := eeid;
          fid := fffid;
          whichway := !whichway;
        };
        whichwaystart += 1;
      };
      if ( striplength > maxlength ) then
      { maxlength := striplength; goodstart := trystart; };
      trystart += 1;
      set facet color white where color==testcolor;
      };


      // now for real
      whichwaystart := 0;
      while whichwaystart <= 1 do
      { 
        eid := ff.edge[((whichwaystart+goodstart)imod 3)+1].oid;
        fid := ff.id;
        whichway := whichwaystart;   // alternating directions of triangles

        while edge[eid].valence >= 2 do
        {
          foreach edge[eid].facet fff do 
          { if fff.id != fid then {fffid := fff.id; break;} };
          if facet[fffid].color != white then break;
          facet[fffid].color := stripcolor;
          foreach facet[fffid].edge ee do 
          { eeid := ee.oid;
            if whichway then
            { if ee.vertex[2].id == edge[eid].vertex[2].id then break; }
            else 
            { if ee.vertex[1].id == edge[eid].vertex[1].id then break; }
          };
          eid := eeid;
          fid := fffid;
          whichway := !whichway;
        };
        whichwaystart += 1;
      };



      stripcolor := (stripcolor imod 14) + 1;
      stripcount += 1;
    };
  printf "%g strips, average %g facets.\n",stripcount,facet_count/stripcount;
}
     
// for testing whether order of trying facets matters much
   define vertex attribute vertex_order_key real
   define edge attribute edge_order_key real
   define facet attribute facet_order_key real
   define body attribute body_order_key real
   define facetedge attribute facetedge_order_key real


   reorder := {
     set vertex vertex_order_key x+y+z;
     set edge ee edge_order_key min(ee.vertex,vertex_order_key);
     set facetedge fe facetedge_order_key fe.edge[1].edge_order_key;
     set facet ff facet_order_key min(ff.vertex,vertex_order_key);
     set body bb body_order_key min(bb.facet,facet_order_key);
     reorder_storage;
     }
     
// searches for longest strip through facet, out of 3 ways
// Uses same strip truncation as Evolver to get properly oriented strip.
strips3 := {
    local  fffid, eeid, maxlength, goodstart, striplength, testcolor, stripcolor;
    local  stripcount, trystart, whichwaystart, eid, fid, whichway, firstcount;
    local  secondcount, truncfacet;

    testcolor := 100;
    set facet color white;
    stripcolor := 1;
    stripcount := 0;
    foreach facet ff where  color == white do
    { ff.color := stripcolor;

      // three-way trial first
      trystart := 1; maxlength := 0; goodstart := 1; 
      while trystart <= 3 do
      { striplength := 1;

      whichwaystart := 0;
      while whichwaystart <= 1 do
      { 
        eid := ff.edge[((whichwaystart+trystart)imod 3)+1].oid;
        fid := ff.id;
        whichway := whichwaystart;   // alternating directions of triangles

        while edge[eid].valence >= 2 do
        {
          firstcount := striplength;
          foreach edge[eid].facet fff do 
          { if fff.id != fid then {fffid := fff.id; break;} };
          if facet[fffid].color != white then break;
          facet[fffid].color := testcolor; striplength += 1;
          foreach facet[fffid].edge ee do 
          { eeid := ee.oid;
            if whichway then
            { if ee.vertex[2].id == edge[eid].vertex[2].id then break; }
            else 
            { if ee.vertex[1].id == edge[eid].vertex[1].id then break; }
          };
          eid := eeid;
          fid := fffid;
          whichway := !whichway;
        };
        secondcount := striplength - firstcount;
        whichwaystart += 1;
      };
      if ( (firstcount imod 2) and (secondcount imod 2) ) then striplength -= 1;
      if ( striplength > maxlength ) then
      { maxlength := striplength; goodstart := trystart; };
      trystart += 1;
      set facet color white where color==testcolor;
      };


      // now for real
      truncfacet := ff.id;
      whichwaystart := 0;
      while whichwaystart <= 1 do
      { 
        firstcount := striplength;
        eid := ff.edge[((whichwaystart+goodstart)imod 3)+1].oid;
        fid := ff.id;
        whichway := whichwaystart;   // alternating directions of triangles

        while edge[eid].valence >= 2 do
        {
          foreach edge[eid].facet fff do 
          { if fff.id != fid then {fffid := fff.id; break;} };
          if facet[fffid].color != white then break;
          facet[fffid].color := stripcolor;
          if ( whichwaystart == 1 ) then truncfacet := fffid;
          foreach facet[fffid].edge ee do 
          { eeid := ee.oid;
            if whichway then
            { if ee.vertex[2].id == edge[eid].vertex[2].id then break; }
            else 
            { if ee.vertex[1].id == edge[eid].vertex[1].id then break; }
          };
          eid := eeid;
          fid := fffid;
          whichway := !whichway;
        };
        secondcount := striplength - firstcount;
        whichwaystart += 1;
      };
      if ( (firstcount imod 2) and (secondcount imod 2) ) then
           set facet[truncfacet] color white;



      stripcolor := (stripcolor imod 14) + 1;
      stripcount += 1;
    };
  printf "%g strips, average %g facets.\n",stripcount,facet_count/stripcount;
}
     

// end strips.cmd

/* Usage:
      strips
      strips2
*/