File: multiplicate.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 (276 lines) | stat: -rw-r--r-- 9,542 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
264
265
266
267
268
269
270
271
272
273
274
275
276
// multiplicate.cmd

// Surface Evolver script to create datafile with surface duplicated
// according to view transforms in effect.  Writes datafile to stdout.
// Does not create new elements in current surface, since together 
// with view transforms, that would result in quadratic explosion.

// WARNING: This loses all element attributes in the output datafile.
// But does preserve "edgetype" attribute

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

// usage: multiplicate >>> "newdatafile.fe"

define edge attribute edgetype integer // in case doesn't exist

eps := 1e-4  // tolerance for identifying vertices

// Hash table for finding identified vertices.  Generates hash value
// from skew plane.
mskew1 := 0.361234123413728768
mskew2 := 0.725423451231725277
mskew3 := 0.5227723243451234514
vertex_hash_init := {
  vertex_hash_table_size := vertex_count*transform_count;
  define vertex_hash_table integer[vertex_hash_table_size];
  define vertex_hash_chain integer[vertex_hash_table_size];
  define newcoord real[vertex_hash_table_size][3];
  vertex_entry_count := 0;
}

// deallocate memory
vertex_hash_end := {
  define vertex_hash_table integer[0];
  define vertex_hash_chain integer[0];
  define newcoord real[0][0];
}

// Returns sequential number of found or new vertex.
function integer vertex_hash_add(real xx, real yy, real zz)
{ local hashval,hashspot;
  local vnum,dist;

  hashval := floor((mskew1*xx + mskew2*yy + mskew3*zz)/eps);
  hashspot := (hashval imod vertex_hash_table_size) + 1;

  // See if there
  for ( vnum := vertex_hash_table[hashspot] ; vnum != 0 ;
             vnum := vertex_hash_chain[vnum] )
  {
    dist := sqrt((xx-newcoord[vnum][1])^2 + (yy-newcoord[vnum][2])^2 +
                 (zz-newcoord[vnum][3])^2);
    if dist < eps then return vnum;
  };

  // Not there, so add
  vertex_entry_count += 1;
  vnum := vertex_entry_count;
  vertex_hash_chain[vnum] := vertex_hash_table[hashspot];
  vertex_hash_table[hashspot] := vnum;
  newcoord[vnum][1] := xx;
  newcoord[vnum][2] := yy;
  newcoord[vnum][3] := zz;
  return vnum;
 
}

// Hash table for finding identified edges.
edge_hash_init := {
  edge_hash_table_size := edge_count*transform_count;
  define edge_hash_table integer[edge_hash_table_size];
  define edge_hash_chain integer[edge_hash_table_size];
  define new_edge_verts integer[edge_hash_table_size][2];
  edge_entry_count := 0;
}

// deallocate memory
edge_hash_end := {
  define edge_hash_table integer[0];
  define edge_hash_chain integer[0];
  define new_edge_verts integer[0][0];
}

// Edge hasher. Returns sequential number (signed) of found or new edge.
function integer edge_hash_add(integer tailv, integer headv)
{ local temp,signflag;
  local hashval,hashspot;
  local edgenum;

  // get vertices in canonical order
  if tailv > headv then
  { temp := tailv;
    tailv := headv;
    headv := temp;
    signflag := -1;
  }
  else signflag := 1;

  hashval := tailv*737 + headv;
  hashspot := (hashval imod edge_hash_table_size)+1;

  // See if there
  for ( edgenum := edge_hash_table[hashspot] ; edgenum != 0 ;
             edgenum := edge_hash_chain[edgenum] )
  {
    if (tailv == new_edge_verts[edgenum][1]) and 
               (headv == new_edge_verts[edgenum][2])
      then return signflag*edgenum;
  };

  // Not there, so add
  edge_entry_count += 1;
  edgenum := edge_entry_count;
  edge_hash_chain[edgenum] := edge_hash_table[hashspot];
  edge_hash_table[hashspot] := edgenum;
  new_edge_verts[edgenum][1] := tailv;
  new_edge_verts[edgenum][2] := headv;
  return signflag*edgenum;
 
}
multiplicate :=  {

   local tcount,high_vertex,vx,vy,vz;
   local high_edge,thistail,thishead,fstride,tdet,edge1,edge2,edge3;

   list topinfo;

   define vertex attribute tx real[transform_count];
   define vertex attribute ty real[transform_count];
   define vertex attribute tz real[transform_count];
   define vertex attribute valias integer[transform_count];
   define edge attribute ehead integer[transform_count];
   define edge attribute etail integer[transform_count];
   define edge attribute ealias integer[transform_count];

   printf "\nVertices\n";
   vertex_hash_init;
   tcount := 1;
   high_vertex := 0;
   while ( tcount <= transform_count ) do
   { foreach vertex vv do
     { 
       vx := view_transforms[tcount][1][1]*vv.x
                       + view_transforms[tcount][1][2]*vv.y
                       + view_transforms[tcount][1][3]*vv.z
                       + view_transforms[tcount][1][4]*1;
       vy := view_transforms[tcount][2][1]*vv.x
                       + view_transforms[tcount][2][2]*vv.y
                       + view_transforms[tcount][2][3]*vv.z
                       + view_transforms[tcount][2][4]*1;
       vz := view_transforms[tcount][3][1]*vv.x
                       + view_transforms[tcount][3][2]*vv.y
                       + view_transforms[tcount][3][3]*vv.z
                       + view_transforms[tcount][3][4]*1;
       vv.tx[tcount] := vx; vv.ty[tcount] := vy; vv.tz[tcount] := vz;
       // search for alias
       vv.valias[tcount] := vertex_hash_add(vx,vy,vz);
       if vv.valias[tcount] > high_vertex then
       { printf "%d  %18.15f %18.15f %18.15f ",vv.valias[tcount],
             vx,vy,vz;
         printf "\n";
         high_vertex := vv.valias[tcount];
       };
     };
     tcount += 1;
   };
   vertex_hash_end;

   printf "\nEdges\n";
   tcount := 1;
   edge_hash_init;
   high_edge := 0;
   while ( tcount <= transform_count ) do
   { foreach edge ee do
     { 
       thistail :=  vertex[ee.vertex[1].id].valias[tcount];
       thishead :=  vertex[ee.vertex[2].id].valias[tcount];
       ee.ehead[tcount] := thishead;
       ee.etail[tcount] := thistail;
       // search for aliases
       ee.ealias[tcount] := edge_hash_add(thistail,thishead);
       if ( abs(ee.ealias[tcount]) > high_edge ) then
       { printf "%d   %d %d edgetype %d",abs(ee.ealias[tcount]),
              minimum(thistail,thishead),maximum(thistail,thishead),edgetype;
         if ee.bare then printf " bare ";
         printf "\n";
         high_edge := abs(ee.ealias[tcount]);
       };
     };
     tcount += 1;

   };
   edge_hash_end;

   printf "\nFaces\n";
   fstride := max(facet,id);
   tcount := 1;
   while ( tcount <= transform_count ) do
   { tdet := view_transforms[tcount][1][1]*
         (view_transforms[tcount][2][2]*view_transforms[tcount][3][3] 
          - view_transforms[tcount][3][2]*view_transforms[tcount][2][3]) 
        - view_transforms[tcount][1][2]*
         (view_transforms[tcount][2][1]*view_transforms[tcount][3][3] 
          - view_transforms[tcount][3][1]*view_transforms[tcount][2][3]) 
        + view_transforms[tcount][1][3]*
         (view_transforms[tcount][2][1]*view_transforms[tcount][3][2] 
          - view_transforms[tcount][3][1]*view_transforms[tcount][2][2]);
     foreach facet ff do 
     { edge1 := edge[ff.edge[1].id].ealias[tcount];
       edge2 := edge[ff.edge[2].id].ealias[tcount];
       edge3 := edge[ff.edge[3].id].ealias[tcount];
       if ( view_transform_swap_colors[tcount] != (tdet < 0.0) ) then
       // inverted
       printf "%d   %d %d %d\n",ff.id + (tcount-1)*fstride,
         ((ff.edge[3].oid > 0) ? -edge3 : edge3),
         ((ff.edge[2].oid > 0) ? -edge2 : edge2),
         ((ff.edge[1].oid > 0) ? -edge1 : edge1)
       else
       printf "%d   %d %d %d\n",ff.id + (tcount-1)*fstride,
         ((ff.edge[1].oid > 0) ? edge1 : -edge1),
         ((ff.edge[2].oid > 0) ? edge2 : -edge2),
         ((ff.edge[3].oid > 0) ? edge3 : -edge3);
     };
     tcount += 1;
   };

   // not listing bottominfo on purpose; too much extraneous stuff

   // free attribute storage
   define vertex attribute tx real[0];
   define vertex attribute ty real[0];
   define vertex attribute tz real[0];
   define vertex attribute valias integer[0];
   define edge attribute ehead integer[0];
   define edge attribute etail integer[0];
   define edge attribute ealias integer[0];

}

aa := 1
pview := { 
   printf "%f %f %f %f\n",view_transforms[aa][1][1],view_transforms[aa][1][2],
         view_transforms[aa][1][3],view_transforms[aa][1][4];
   printf "%f %f %f %f\n",view_transforms[aa][2][1],view_transforms[aa][2][2],
         view_transforms[aa][2][3],view_transforms[aa][2][4];
   printf "%f %f %f %f\n",view_transforms[aa][3][1],view_transforms[aa][3][2],
         view_transforms[aa][3][3],view_transforms[aa][3][4];
   printf "%f %f %f %f\n",view_transforms[aa][4][1],view_transforms[aa][4][2],
         view_transforms[aa][4][3],view_transforms[aa][4][4];
}

// Paste things together that didn't get pasted, by finding edges that
// come out of vertices in the same direction.
paste := { 
  local paste_count;

  paste_count := 0;  // track how many found, so know when no more left
  foreach vertex vv do
  { foreach vv.edge ee do
    { 
       foreach vv.edge eee do
       { if ee.id == eee.id then continue;
         if (ee.x-eee.x)^2 + (ee.y-eee.y)^2 + (ee.z-eee.z)^2 < eps^2 then
         { edge_merge(ee.oid,eee.oid);
           paste_count += 1;
           break;
         }
       }
     }
   };
   printf "Edges pasted: %d\n",paste_count;
}
 

// usage: Set view transforms as desired, then do
//        multiplicate >>> "newdatafile.fe"