1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
22 |
|
#define PI 3.14159265358979323846 |
23 |
|
#endif |
24 |
|
|
25 |
+ |
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
26 |
+ |
|
27 |
|
#define MAXVERT 6 /* maximum number of vertices for markers */ |
28 |
+ |
#define MAXMARK 32 /* maximum number of markers */ |
29 |
|
|
30 |
|
typedef struct { |
31 |
|
short beg, end; /* beginning and ending vertex */ |
32 |
|
float len2; /* length squared */ |
33 |
|
} EDGE; /* a marker edge */ |
34 |
|
|
35 |
< |
int expand = 0; /* expand commands? */ |
35 |
> |
struct mrkr { |
36 |
> |
char *modout; /* output modifier */ |
37 |
> |
double mscale; /* scale by this to get unit */ |
38 |
> |
char *modin; /* input modifier indicating marker */ |
39 |
> |
char *objname; /* output object file or octree */ |
40 |
> |
int doxform; /* true if xform, false if instance */ |
41 |
> |
} marker[MAXMARK]; /* array of markers */ |
42 |
> |
int nmarkers = 0; /* number of markers */ |
43 |
|
|
44 |
< |
char *modout = "void"; /* output modifier (for instances) */ |
44 |
> |
int expand; /* expand commands? */ |
45 |
|
|
36 |
– |
double markscale = 0.0; /* scale markers by this to get unit */ |
37 |
– |
|
38 |
– |
char *modin = NULL; /* input modifier indicating marker */ |
39 |
– |
|
40 |
– |
char *objname = NULL; /* output object file (octree if instance) */ |
41 |
– |
int doxform; /* true if xform, false if instance */ |
42 |
– |
|
46 |
|
char *progname; |
47 |
|
|
48 |
|
|
54 |
|
int i, j; |
55 |
|
|
56 |
|
progname = argv[0]; |
57 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
58 |
< |
switch (argv[i][1]) { |
59 |
< |
case 'i': |
60 |
< |
doxform = 0; |
61 |
< |
objname = argv[++i]; |
62 |
< |
break; |
63 |
< |
case 'x': |
64 |
< |
doxform = 1; |
65 |
< |
objname = argv[++i]; |
66 |
< |
break; |
67 |
< |
case 'e': |
68 |
< |
expand = !expand; |
69 |
< |
break; |
70 |
< |
case 'm': |
71 |
< |
modout = argv[++i]; |
72 |
< |
break; |
73 |
< |
case 's': |
74 |
< |
markscale = atof(argv[++i]); |
75 |
< |
break; |
76 |
< |
default: |
57 |
> |
i = 1; |
58 |
> |
while (i < argc && argv[i][0] == '-') { |
59 |
> |
do { |
60 |
> |
switch (argv[i][1]) { |
61 |
> |
case 'i': |
62 |
> |
marker[nmarkers].doxform = 0; |
63 |
> |
marker[nmarkers].objname = argv[++i]; |
64 |
> |
break; |
65 |
> |
case 'x': |
66 |
> |
marker[nmarkers].doxform = 1; |
67 |
> |
marker[nmarkers].objname = argv[++i]; |
68 |
> |
break; |
69 |
> |
case 'e': |
70 |
> |
expand = 1; |
71 |
> |
break; |
72 |
> |
case 'm': |
73 |
> |
marker[nmarkers].modout = argv[++i]; |
74 |
> |
break; |
75 |
> |
case 's': |
76 |
> |
marker[nmarkers].mscale = atof(argv[++i]); |
77 |
> |
break; |
78 |
> |
default: |
79 |
> |
goto userr; |
80 |
> |
} |
81 |
> |
if (++i >= argc) |
82 |
> |
goto userr; |
83 |
> |
} while (argv[i][0] == '-'); |
84 |
> |
if (marker[nmarkers].objname == NULL) |
85 |
|
goto userr; |
86 |
< |
} |
87 |
< |
if (i < argc) |
88 |
< |
modin = argv[i++]; |
89 |
< |
if (objname == NULL || modin == NULL) |
86 |
> |
marker[nmarkers++].modin = argv[i++]; |
87 |
> |
if (nmarkers >= MAXMARK) |
88 |
> |
break; |
89 |
> |
marker[nmarkers].mscale = marker[nmarkers-1].mscale; |
90 |
> |
} |
91 |
> |
if (nmarkers == 0) |
92 |
|
goto userr; |
93 |
|
/* simple header */ |
94 |
|
putchar('#'); |
111 |
|
exit(0); |
112 |
|
userr: |
113 |
|
fprintf(stderr, |
114 |
< |
"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname [file ..]\n", |
114 |
> |
"Usage: %s [-e][-s size][-m modout] {-x objfile|-i octree} modname .. [file ..]\n", |
115 |
|
progname); |
116 |
|
exit(1); |
117 |
|
} |
171 |
|
FILE *fin; |
172 |
|
{ |
173 |
|
char buf[128], typ[16], nam[128]; |
174 |
< |
int i, j, n; |
174 |
> |
int i, n; |
175 |
> |
register int j; |
176 |
|
|
177 |
|
if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3) |
178 |
|
goto readerr; |
179 |
< |
if (!strcmp(buf, modin) && !strcmp(typ, "polygon")) { |
180 |
< |
replace(fname, nam, fin); |
181 |
< |
return; |
182 |
< |
} |
179 |
> |
if (!strcmp(typ, "polygon")) |
180 |
> |
for (j = 0; j < nmarkers; j++) |
181 |
> |
if (!strcmp(buf, marker[j].modin)) { |
182 |
> |
replace(fname, &marker[j], nam, fin); |
183 |
> |
return; |
184 |
> |
} |
185 |
|
printf("\n%s %s %s\n", buf, typ, nam); |
186 |
|
if (!strcmp(typ, "alias")) { /* alias special case */ |
187 |
|
if (fscanf(fin, "%s", buf) != 1) |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
< |
replace(fname, mark, fin) /* replace marker */ |
213 |
< |
char *fname, *mark; |
212 |
> |
replace(fname, m, mark, fin) /* replace marker */ |
213 |
> |
char *fname; |
214 |
> |
register struct mrkr *m; |
215 |
> |
char *mark; |
216 |
|
FILE *fin; |
217 |
|
{ |
218 |
|
int n; |
219 |
|
char buf[256]; |
220 |
|
|
221 |
< |
if (doxform) { |
221 |
> |
if (m->doxform) { |
222 |
|
sprintf(buf, "xform -e -n %s", mark); |
223 |
< |
if (buildxf(buf+strlen(buf), fin) < 0) |
223 |
> |
if (m->modout != NULL) |
224 |
> |
sprintf(buf+strlen(buf), " -m %s", m->modout); |
225 |
> |
if (buildxf(buf+strlen(buf), m->mscale, fin) < 0) |
226 |
|
goto badxf; |
227 |
< |
sprintf(buf+strlen(buf), " %s", objname); |
227 |
> |
sprintf(buf+strlen(buf), " %s", m->objname); |
228 |
|
if (expand) { |
229 |
|
fflush(stdout); |
230 |
|
system(buf); |
231 |
|
} else |
232 |
|
printf("\n!%s\n", buf); |
233 |
|
} else { |
234 |
< |
if ((n = buildxf(buf, fin)) < 0) |
234 |
> |
if ((n = buildxf(buf, m->mscale, fin)) < 0) |
235 |
|
goto badxf; |
236 |
< |
printf("\n%s instance %s\n", modout, mark); |
237 |
< |
printf("%d %s%s\n", n+1, objname, buf); |
238 |
< |
printf("\n0\n0\n"); |
236 |
> |
printf("\n%s instance %s\n", |
237 |
> |
m->modout==NULL?"void":m->modout, mark); |
238 |
> |
printf("%d %s%s\n0\n0\n", n+1, m->objname, buf); |
239 |
|
} |
240 |
|
return; |
241 |
|
badxf: |
257 |
|
|
258 |
|
|
259 |
|
int |
260 |
< |
buildxf(xf, fin) /* build transform for marker */ |
260 |
> |
buildxf(xf, markscale, fin) /* build transform for marker */ |
261 |
|
char *xf; |
262 |
+ |
double markscale; |
263 |
|
FILE *fin; |
264 |
|
{ |
265 |
|
static FVECT vlist[MAXVERT]; |
342 |
|
char *xf; |
343 |
|
FVECT xp, yp, zp; |
344 |
|
{ |
345 |
< |
double tx, ty, tz; |
345 |
> |
int n; |
346 |
> |
double theta; |
347 |
|
|
348 |
< |
tx = atan2(yp[2], zp[2]); |
349 |
< |
ty = asin(-xp[2]); |
350 |
< |
tz = atan2(xp[1], xp[0]); |
351 |
< |
sprintf(xf, " -rx %f -ry %f -rz %f", tx*(180./PI), |
352 |
< |
ty*(180./PI), tz*(180./PI)); |
353 |
< |
return(6); |
348 |
> |
n = 0; |
349 |
> |
theta = atan2(yp[2], zp[2]); |
350 |
> |
if (!FEQ(theta,0.0)) { |
351 |
> |
sprintf(xf, " -rx %f", theta*(180./PI)); |
352 |
> |
xf += strlen(xf); |
353 |
> |
n += 2; |
354 |
> |
} |
355 |
> |
theta = asin(-xp[2]); |
356 |
> |
if (!FEQ(theta,0.0)) { |
357 |
> |
sprintf(xf, " -ry %f", theta*(180./PI)); |
358 |
> |
xf += strlen(xf); |
359 |
> |
n += 2; |
360 |
> |
} |
361 |
> |
theta = atan2(xp[1], xp[0]); |
362 |
> |
if (!FEQ(theta,0.0)) { |
363 |
> |
sprintf(xf, " -rz %f", theta*(180./PI)); |
364 |
> |
/* xf += strlen(xf); */ |
365 |
> |
n += 2; |
366 |
> |
} |
367 |
> |
return(n); |
368 |
|
} |