1 |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* Executive program for oconv, rpict and pfilt |
9 |
*/ |
10 |
|
11 |
#include "standard.h" |
12 |
#include "paths.h" |
13 |
#include <ctype.h> |
14 |
#include <sys/types.h> |
15 |
|
16 |
|
17 |
typedef struct { |
18 |
char *name; /* variable name */ |
19 |
short nick; /* # characters required for nickname */ |
20 |
short nass; /* # assignments made */ |
21 |
char *value; /* assigned value(s) */ |
22 |
int (*fixval)(); /* assignment checking function */ |
23 |
} VARIABLE; |
24 |
|
25 |
int onevalue(), catvalues(), boolvalue(), |
26 |
qualvalue(), fltvalue(), intvalue(); |
27 |
|
28 |
/* variables */ |
29 |
#define OBJECT 0 /* object files */ |
30 |
#define SCENE 1 /* scene files */ |
31 |
#define MATERIAL 2 /* material files */ |
32 |
#define ILLUM 3 /* mkillum input files */ |
33 |
#define MKILLUM 4 /* mkillum options */ |
34 |
#define RENDER 5 /* rendering options */ |
35 |
#define OCONV 6 /* oconv options */ |
36 |
#define PFILT 7 /* pfilt options */ |
37 |
#define VIEW 8 /* view(s) for picture(s) */ |
38 |
#define ZONE 9 /* simulation zone */ |
39 |
#define QUALITY 10 /* desired rendering quality */ |
40 |
#define OCTREE 11 /* octree file name */ |
41 |
#define PICTURE 12 /* picture file root name */ |
42 |
#define AMBFILE 13 /* ambient file name */ |
43 |
#define OPTFILE 14 /* rendering options file */ |
44 |
#define EXPOSURE 15 /* picture exposure setting */ |
45 |
#define RESOLUTION 16 /* maximum picture resolution */ |
46 |
#define UP 17 /* view up (X, Y or Z) */ |
47 |
#define INDIRECT 18 /* indirection in lighting */ |
48 |
#define DETAIL 19 /* level of scene detail */ |
49 |
#define PENUMBRAS 20 /* shadow penumbras are desired */ |
50 |
#define VARIABILITY 21 /* level of light variability */ |
51 |
#define REPORT 22 /* report frequency and errfile */ |
52 |
#define RAWFILE 23 /* raw picture file root name */ |
53 |
#define ZFILE 24 /* distance file root name */ |
54 |
/* total number of variables */ |
55 |
#define NVARS 25 |
56 |
|
57 |
VARIABLE vv[NVARS] = { /* variable-value pairs */ |
58 |
{"objects", 3, 0, NULL, catvalues}, |
59 |
{"scene", 3, 0, NULL, catvalues}, |
60 |
{"materials", 3, 0, NULL, catvalues}, |
61 |
{"illum", 3, 0, NULL, catvalues}, |
62 |
{"mkillum", 3, 0, NULL, catvalues}, |
63 |
{"render", 3, 0, NULL, catvalues}, |
64 |
{"oconv", 3, 0, NULL, catvalues}, |
65 |
{"pfilt", 2, 0, NULL, catvalues}, |
66 |
{"view", 2, 0, NULL, NULL}, |
67 |
{"ZONE", 2, 0, NULL, onevalue}, |
68 |
{"QUALITY", 3, 0, NULL, qualvalue}, |
69 |
{"OCTREE", 3, 0, NULL, onevalue}, |
70 |
{"PICTURE", 3, 0, NULL, onevalue}, |
71 |
{"AMBFILE", 3, 0, NULL, onevalue}, |
72 |
{"OPTFILE", 3, 0, NULL, onevalue}, |
73 |
{"EXPOSURE", 3, 0, NULL, fltvalue}, |
74 |
{"RESOLUTION", 3, 0, NULL, onevalue}, |
75 |
{"UP", 2, 0, NULL, onevalue}, |
76 |
{"INDIRECT", 3, 0, NULL, intvalue}, |
77 |
{"DETAIL", 3, 0, NULL, qualvalue}, |
78 |
{"PENUMBRAS", 3, 0, NULL, boolvalue}, |
79 |
{"VARIABILITY", 3, 0, NULL, qualvalue}, |
80 |
{"REPORT", 3, 0, NULL, onevalue}, |
81 |
{"RAWFILE", 3, 0, NULL, onevalue}, |
82 |
{"ZFILE", 2, 0, NULL, onevalue}, |
83 |
}; |
84 |
|
85 |
VARIABLE *matchvar(); |
86 |
char *nvalue(); |
87 |
|
88 |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
89 |
|
90 |
#define vnam(vc) (vv[vc].name) |
91 |
#define vdef(vc) (vv[vc].nass) |
92 |
#define vval(vc) (vv[vc].value) |
93 |
#define vint(vc) atoi(vval(vc)) |
94 |
#define vlet(vc) UPPER(vval(vc)[0]) |
95 |
#define vscale vlet |
96 |
#define vbool(vc) (vlet(vc)=='T') |
97 |
|
98 |
#define HIGH 'H' |
99 |
#define MEDIUM 'M' |
100 |
#define LOW 'L' |
101 |
|
102 |
/* overture calculation file */ |
103 |
#ifdef NIX |
104 |
char overfile[] = "overture.unf"; |
105 |
#else |
106 |
char overfile[] = "/dev/null"; |
107 |
#endif |
108 |
|
109 |
extern time_t fdate(), time(); |
110 |
|
111 |
time_t scenedate; /* date of latest scene or object file */ |
112 |
time_t octreedate; /* date of octree */ |
113 |
time_t matdate; /* date of latest material file */ |
114 |
time_t illumdate; /* date of last illum file */ |
115 |
|
116 |
char *oct0name; /* name of pre-mkillum octree */ |
117 |
time_t oct0date; /* date of pre-mkillum octree */ |
118 |
char *oct1name; /* name of post-mkillum octree */ |
119 |
time_t oct1date; /* date of post-mkillum octree (>= matdate) */ |
120 |
|
121 |
int nowarn = 0; /* no warnings */ |
122 |
int explicate = 0; /* explicate variables */ |
123 |
int silent = 0; /* do work silently */ |
124 |
int touchonly = 0; /* touch files only */ |
125 |
int noaction = 0; /* don't do anything */ |
126 |
int sayview = 0; /* print view out */ |
127 |
char *rvdevice = NULL; /* rview output device */ |
128 |
char *viewselect = NULL; /* specific view only */ |
129 |
|
130 |
int overture = 0; /* overture calculation needed */ |
131 |
|
132 |
char *progname; /* global argv[0] */ |
133 |
char *rifname; /* global rad input file name */ |
134 |
|
135 |
char radname[MAXPATH]; /* root Radiance file name */ |
136 |
|
137 |
|
138 |
main(argc, argv) |
139 |
int argc; |
140 |
char *argv[]; |
141 |
{ |
142 |
char ropts[512]; |
143 |
char popts[64]; |
144 |
int i; |
145 |
|
146 |
progname = argv[0]; |
147 |
/* get options */ |
148 |
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
149 |
switch (argv[i][1]) { |
150 |
case 's': |
151 |
silent++; |
152 |
break; |
153 |
case 'n': |
154 |
noaction++; |
155 |
break; |
156 |
case 't': |
157 |
touchonly++; |
158 |
break; |
159 |
case 'e': |
160 |
explicate++; |
161 |
break; |
162 |
case 'o': |
163 |
rvdevice = argv[++i]; |
164 |
break; |
165 |
case 'V': |
166 |
sayview++; |
167 |
break; |
168 |
case 'v': |
169 |
viewselect = argv[++i]; |
170 |
break; |
171 |
case 'w': |
172 |
nowarn++; |
173 |
break; |
174 |
default: |
175 |
goto userr; |
176 |
} |
177 |
if (i >= argc) |
178 |
goto userr; |
179 |
rifname = argv[i]; |
180 |
/* assign Radiance root file name */ |
181 |
rootname(radname, rifname); |
182 |
/* load variable values */ |
183 |
load(rifname); |
184 |
/* get any additional assignments */ |
185 |
for (i++; i < argc; i++) |
186 |
setvariable(argv[i]); |
187 |
/* check assignments */ |
188 |
checkvalues(); |
189 |
/* check files and dates */ |
190 |
checkfiles(); |
191 |
/* set default values as necessary */ |
192 |
setdefaults(); |
193 |
/* print all values if requested */ |
194 |
if (explicate) |
195 |
printvals(); |
196 |
/* build octree (and run mkillum) */ |
197 |
oconv(); |
198 |
/* check date on ambient file */ |
199 |
checkambfile(); |
200 |
/* run simulation */ |
201 |
renderopts(ropts, popts); |
202 |
xferopts(ropts); |
203 |
if (rvdevice != NULL) |
204 |
rview(ropts, popts); |
205 |
else |
206 |
rpict(ropts, popts); |
207 |
exit(0); |
208 |
userr: |
209 |
fprintf(stderr, |
210 |
"Usage: %s [-s][-n][-t][-e][-V][-v view][-o dev] rfile [VAR=value ..]\n", |
211 |
progname); |
212 |
exit(1); |
213 |
} |
214 |
|
215 |
|
216 |
rootname(rn, fn) /* remove tail from end of fn */ |
217 |
register char *rn, *fn; |
218 |
{ |
219 |
char *tp, *dp; |
220 |
|
221 |
for (tp = NULL, dp = rn; *rn = *fn++; rn++) |
222 |
if (ISDIRSEP(*rn)) |
223 |
dp = rn; |
224 |
else if (*rn == '.') |
225 |
tp = rn; |
226 |
if (tp != NULL && tp > dp) |
227 |
*tp = '\0'; |
228 |
} |
229 |
|
230 |
|
231 |
#define NOCHAR 127 /* constant for character to delete */ |
232 |
|
233 |
|
234 |
load(rfname) /* load Radiance simulation file */ |
235 |
char *rfname; |
236 |
{ |
237 |
FILE *fp; |
238 |
char buf[512]; |
239 |
register char *cp; |
240 |
|
241 |
if (rfname == NULL) |
242 |
fp = stdin; |
243 |
else if ((fp = fopen(rfname, "r")) == NULL) |
244 |
syserr(rfname); |
245 |
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
246 |
for (cp = buf; *cp; cp++) { |
247 |
switch (*cp) { |
248 |
case '\\': |
249 |
*cp++ = NOCHAR; |
250 |
continue; |
251 |
case '#': |
252 |
*cp = '\0'; |
253 |
break; |
254 |
default: |
255 |
continue; |
256 |
} |
257 |
break; |
258 |
} |
259 |
setvariable(buf); |
260 |
} |
261 |
fclose(fp); |
262 |
} |
263 |
|
264 |
|
265 |
setvariable(ass) /* assign variable according to string */ |
266 |
register char *ass; |
267 |
{ |
268 |
char varname[32]; |
269 |
int n; |
270 |
register char *cp; |
271 |
register VARIABLE *vp; |
272 |
register int i; |
273 |
|
274 |
while (isspace(*ass)) /* skip leading space */ |
275 |
ass++; |
276 |
cp = varname; /* extract name */ |
277 |
while (cp < varname+sizeof(varname)-1 |
278 |
&& *ass && !isspace(*ass) && *ass != '=') |
279 |
*cp++ = *ass++; |
280 |
*cp = '\0'; |
281 |
if (!varname[0]) |
282 |
return; /* no variable name! */ |
283 |
/* trim value */ |
284 |
while (isspace(*ass) || *ass == '=') |
285 |
ass++; |
286 |
for (n = strlen(ass); n > 0; n--) |
287 |
if (!isspace(ass[n-1])) |
288 |
break; |
289 |
if (!n && !nowarn) { |
290 |
fprintf(stderr, "%s: warning - missing value for variable '%s'\n", |
291 |
progname, varname); |
292 |
return; |
293 |
} |
294 |
/* match variable from list */ |
295 |
vp = matchvar(varname); |
296 |
if (vp == NULL) { |
297 |
fprintf(stderr, "%s: unknown variable '%s'\n", |
298 |
progname, varname); |
299 |
exit(1); |
300 |
} |
301 |
/* assign new value */ |
302 |
if (i = vp->nass) { |
303 |
cp = vp->value; |
304 |
while (i--) |
305 |
while (*cp++) |
306 |
; |
307 |
i = cp - vp->value; |
308 |
vp->value = realloc(vp->value, i+n+1); |
309 |
} else |
310 |
vp->value = malloc(n+1); |
311 |
if (vp->value == NULL) |
312 |
syserr(progname); |
313 |
cp = vp->value+i; /* copy value, squeezing spaces */ |
314 |
*cp = *ass; |
315 |
for (i = 1; i <= n; i++) { |
316 |
if (ass[i] == NOCHAR) |
317 |
continue; |
318 |
if (isspace(*cp)) |
319 |
while (isspace(ass[i])) |
320 |
i++; |
321 |
*++cp = ass[i]; |
322 |
} |
323 |
if (isspace(*cp)) /* remove trailing space */ |
324 |
*cp = '\0'; |
325 |
vp->nass++; |
326 |
} |
327 |
|
328 |
|
329 |
VARIABLE * |
330 |
matchvar(nam) /* match a variable by its name */ |
331 |
char *nam; |
332 |
{ |
333 |
int n = strlen(nam); |
334 |
register int i; |
335 |
|
336 |
for (i = 0; i < NVARS; i++) |
337 |
if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n)) |
338 |
return(vv+i); |
339 |
return(NULL); |
340 |
} |
341 |
|
342 |
|
343 |
char * |
344 |
nvalue(vp, n) /* return nth variable value */ |
345 |
VARIABLE *vp; |
346 |
register int n; |
347 |
{ |
348 |
register char *cp; |
349 |
|
350 |
if (vp == NULL | n < 0 | n >= vp->nass) |
351 |
return(NULL); |
352 |
cp = vp->value; |
353 |
while (n--) |
354 |
while (*cp++) |
355 |
; |
356 |
return(cp); |
357 |
} |
358 |
|
359 |
|
360 |
checkvalues() /* check assignments */ |
361 |
{ |
362 |
register int i; |
363 |
|
364 |
for (i = 0; i < NVARS; i++) |
365 |
if (vv[i].fixval != NULL) |
366 |
(*vv[i].fixval)(vv+i); |
367 |
} |
368 |
|
369 |
|
370 |
onevalue(vp) /* only one assignment for this variable */ |
371 |
register VARIABLE *vp; |
372 |
{ |
373 |
if (vp->nass < 2) |
374 |
return; |
375 |
if (!nowarn) |
376 |
fprintf(stderr, |
377 |
"%s: warning - multiple assignment of variable '%s'\n", |
378 |
progname, vp->name); |
379 |
do |
380 |
vp->value += strlen(vp->value)+1; |
381 |
while (--vp->nass > 1); |
382 |
} |
383 |
|
384 |
|
385 |
catvalues(vp) /* concatenate variable values */ |
386 |
register VARIABLE *vp; |
387 |
{ |
388 |
register char *cp; |
389 |
|
390 |
if (vp->nass < 2) |
391 |
return; |
392 |
for (cp = vp->value; vp->nass > 1; vp->nass--) { |
393 |
while (*cp) |
394 |
cp++; |
395 |
*cp++ = ' '; |
396 |
} |
397 |
} |
398 |
|
399 |
|
400 |
int |
401 |
badmatch(tv, cv) /* case insensitive truncated comparison */ |
402 |
register char *tv, *cv; |
403 |
{ |
404 |
if (!*tv) return(1); /* null string cannot match */ |
405 |
do |
406 |
if (UPPER(*tv) != *cv++) |
407 |
return(1); |
408 |
while (*++tv); |
409 |
return(0); /* OK */ |
410 |
} |
411 |
|
412 |
|
413 |
boolvalue(vp) /* check boolean for legal values */ |
414 |
register VARIABLE *vp; |
415 |
{ |
416 |
if (!vp->nass) return; |
417 |
onevalue(vp); |
418 |
switch (UPPER(vp->value[0])) { |
419 |
case 'T': |
420 |
if (badmatch(vp->value, "TRUE")) break; |
421 |
return; |
422 |
case 'F': |
423 |
if (badmatch(vp->value, "FALSE")) break; |
424 |
return; |
425 |
} |
426 |
fprintf(stderr, "%s: illegal value for boolean variable '%s'\n", |
427 |
progname, vp->name); |
428 |
exit(1); |
429 |
} |
430 |
|
431 |
|
432 |
qualvalue(vp) /* check qualitative var. for legal values */ |
433 |
register VARIABLE *vp; |
434 |
{ |
435 |
if (!vp->nass) return; |
436 |
onevalue(vp); |
437 |
switch (UPPER(vp->value[0])) { |
438 |
case 'L': |
439 |
if (badmatch(vp->value, "LOW")) break; |
440 |
return; |
441 |
case 'M': |
442 |
if (badmatch(vp->value, "MEDIUM")) break; |
443 |
return; |
444 |
case 'H': |
445 |
if (badmatch(vp->value, "HIGH")) break; |
446 |
return; |
447 |
} |
448 |
fprintf(stderr, "%s: illegal value for qualitative variable '%s'\n", |
449 |
progname, vp->name); |
450 |
exit(1); |
451 |
} |
452 |
|
453 |
|
454 |
intvalue(vp) /* check integer variable for legal values */ |
455 |
register VARIABLE *vp; |
456 |
{ |
457 |
if (!vp->nass) return; |
458 |
onevalue(vp); |
459 |
if (isint(vp->value)) return; |
460 |
fprintf(stderr, "%s: illegal value for integer variable '%s'\n", |
461 |
progname, vp->name); |
462 |
exit(1); |
463 |
} |
464 |
|
465 |
|
466 |
fltvalue(vp) /* check float variable for legal values */ |
467 |
register VARIABLE *vp; |
468 |
{ |
469 |
if (!vp->nass) return; |
470 |
onevalue(vp); |
471 |
if (isflt(vp->value)) return; |
472 |
fprintf(stderr, "%s: illegal value for real variable '%s'\n", |
473 |
progname, vp->name); |
474 |
exit(1); |
475 |
} |
476 |
|
477 |
|
478 |
time_t |
479 |
checklast(fnames) /* check files and find most recent */ |
480 |
register char *fnames; |
481 |
{ |
482 |
char thisfile[MAXPATH]; |
483 |
time_t thisdate, lastdate = 0; |
484 |
register char *cp; |
485 |
|
486 |
if (fnames == NULL) |
487 |
return(0); |
488 |
while (*fnames) { |
489 |
while (isspace(*fnames)) fnames++; |
490 |
cp = thisfile; |
491 |
while (*fnames && !isspace(*fnames)) |
492 |
*cp++ = *fnames++; |
493 |
*cp = '\0'; |
494 |
if (!(thisdate = fdate(thisfile))) |
495 |
syserr(thisfile); |
496 |
if (thisdate > lastdate) |
497 |
lastdate = thisdate; |
498 |
} |
499 |
return(lastdate); |
500 |
} |
501 |
|
502 |
|
503 |
char * |
504 |
newfname(orig, pred) /* create modified file name */ |
505 |
char *orig; |
506 |
int pred; |
507 |
{ |
508 |
extern char *rindex(); |
509 |
register char *cp; |
510 |
register int n; |
511 |
int suffix; |
512 |
|
513 |
n = 0; cp = orig; suffix = -1; /* suffix position, length */ |
514 |
while (*cp) { |
515 |
if (*cp == '.') suffix = n; |
516 |
else if (ISDIRSEP(*cp)) suffix = -1; |
517 |
cp++; n++; |
518 |
} |
519 |
if (suffix == -1) suffix = n; |
520 |
if ((cp = bmalloc(n+2)) == NULL) |
521 |
syserr(progname); |
522 |
strncpy(cp, orig, suffix); |
523 |
cp[suffix] = pred; /* root name + pred + suffix */ |
524 |
strcpy(cp+suffix+1, orig+suffix); |
525 |
return(cp); |
526 |
} |
527 |
|
528 |
|
529 |
checkfiles() /* check for existence and modified times */ |
530 |
{ |
531 |
time_t objdate; |
532 |
|
533 |
if (!vdef(OCTREE)) { |
534 |
if ((vval(OCTREE) = bmalloc(strlen(radname)+5)) == NULL) |
535 |
syserr(progname); |
536 |
sprintf(vval(OCTREE), "%s.oct", radname); |
537 |
vdef(OCTREE)++; |
538 |
} |
539 |
octreedate = fdate(vval(OCTREE)); |
540 |
if (vdef(ILLUM)) { /* illum requires secondary octrees */ |
541 |
oct0name = newfname(vval(OCTREE), '0'); |
542 |
oct1name = newfname(vval(OCTREE), '1'); |
543 |
oct0date = fdate(oct0name); |
544 |
oct1date = fdate(oct1name); |
545 |
} else |
546 |
oct0name = oct1name = vval(OCTREE); |
547 |
if ((scenedate = checklast(vval(SCENE))) && |
548 |
(objdate = checklast(vval(OBJECT))) > scenedate) |
549 |
scenedate = objdate; |
550 |
illumdate = checklast(vval(ILLUM)); |
551 |
if (!octreedate & !scenedate & !illumdate) { |
552 |
fprintf(stderr, "%s: need '%s' or '%s' or '%s'\n", progname, |
553 |
vnam(OCTREE), vnam(SCENE), vnam(ILLUM)); |
554 |
exit(1); |
555 |
} |
556 |
matdate = checklast(vval(MATERIAL)); |
557 |
} |
558 |
|
559 |
|
560 |
getoctcube(org, sizp) /* get octree bounding cube */ |
561 |
double org[3], *sizp; |
562 |
{ |
563 |
extern FILE *popen(); |
564 |
static double oorg[3], osiz = 0.; |
565 |
double min[3], max[3]; |
566 |
char buf[1024]; |
567 |
FILE *fp; |
568 |
register int i; |
569 |
|
570 |
if (osiz <= FTINY) |
571 |
if (noaction && fdate(oct1name) < |
572 |
(scenedate>illumdate?scenedate:illumdate)) { |
573 |
/* run getbbox */ |
574 |
sprintf(buf, "getbbox -w -h %s", |
575 |
vdef(SCENE) ? vval(SCENE) : vval(ILLUM)); |
576 |
if ((fp = popen(buf, "r")) == NULL) |
577 |
syserr("getbbox"); |
578 |
if (fscanf(fp, "%lf %lf %lf %lf %lf %lf", |
579 |
&min[0], &max[0], &min[1], &max[1], |
580 |
&min[2], &max[2]) != 6) { |
581 |
fprintf(stderr, |
582 |
"%s: error reading bounding box from getbbox\n", |
583 |
progname); |
584 |
exit(1); |
585 |
} |
586 |
for (i = 0; i < 3; i++) |
587 |
if (max[i] - min[i] > osiz) |
588 |
osiz = max[i] - min[i]; |
589 |
for (i = 0; i < 3; i++) |
590 |
oorg[i] = (max[i]+min[i]-osiz)*.5; |
591 |
pclose(fp); |
592 |
} else { /* from octree */ |
593 |
oconv(); /* does nothing if done already */ |
594 |
sprintf(buf, "getinfo -d < %s", oct1name); |
595 |
if ((fp = popen(buf, "r")) == NULL) |
596 |
syserr("getinfo"); |
597 |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
598 |
&oorg[2], &osiz) != 4) { |
599 |
fprintf(stderr, |
600 |
"%s: error reading bounding cube from getinfo\n", |
601 |
progname); |
602 |
exit(1); |
603 |
} |
604 |
pclose(fp); |
605 |
} |
606 |
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
607 |
} |
608 |
|
609 |
|
610 |
setdefaults() /* set default values for unassigned var's */ |
611 |
{ |
612 |
double org[3], size; |
613 |
char buf[128]; |
614 |
|
615 |
if (!vdef(ZONE)) { |
616 |
getoctcube(org, &size); |
617 |
sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size, |
618 |
org[1], org[1]+size, org[2], org[2]+size); |
619 |
vval(ZONE) = savqstr(buf); |
620 |
vdef(ZONE)++; |
621 |
} |
622 |
if (!vdef(INDIRECT)) { |
623 |
vval(INDIRECT) = "0"; |
624 |
vdef(INDIRECT)++; |
625 |
} |
626 |
if (!vdef(QUALITY)) { |
627 |
vval(QUALITY) = "L"; |
628 |
vdef(QUALITY)++; |
629 |
} |
630 |
if (!vdef(RESOLUTION)) { |
631 |
vval(RESOLUTION) = "512"; |
632 |
vdef(RESOLUTION)++; |
633 |
} |
634 |
if (!vdef(PICTURE)) { |
635 |
vval(PICTURE) = radname; |
636 |
vdef(PICTURE)++; |
637 |
} |
638 |
if (!vdef(VIEW)) { |
639 |
vval(VIEW) = "X"; |
640 |
vdef(VIEW)++; |
641 |
} |
642 |
if (!vdef(DETAIL)) { |
643 |
vval(DETAIL) = "M"; |
644 |
vdef(DETAIL)++; |
645 |
} |
646 |
if (!vdef(PENUMBRAS)) { |
647 |
vval(PENUMBRAS) = "F"; |
648 |
vdef(PENUMBRAS)++; |
649 |
} |
650 |
if (!vdef(VARIABILITY)) { |
651 |
vval(VARIABILITY) = "L"; |
652 |
vdef(VARIABILITY)++; |
653 |
} |
654 |
} |
655 |
|
656 |
|
657 |
printvals() /* print variable values */ |
658 |
{ |
659 |
int i, j, clipline; |
660 |
register char *cp; |
661 |
register int k; |
662 |
|
663 |
for (i = 0; i < NVARS; i++) /* print each variable */ |
664 |
for (j = 0; j < vdef(i); j++) { /* print each assignment */ |
665 |
fputs(vnam(i), stdout); |
666 |
fputs("= ", stdout); |
667 |
k = clipline = ( vv[i].fixval == catvalues ? 64 : 320 ) |
668 |
- strlen(vnam(i)) ; |
669 |
cp = nvalue(vv+i, j); |
670 |
while (*cp) { |
671 |
putchar(*cp++); |
672 |
if (--k <= 0) { /* line too long */ |
673 |
while (*cp && !isspace(*cp)) |
674 |
putchar(*cp++); /* finish this word */ |
675 |
if (*cp) { /* start new line */ |
676 |
putchar('\n'); |
677 |
fputs(vnam(i), stdout); |
678 |
putchar('='); |
679 |
k = clipline; |
680 |
} |
681 |
} |
682 |
} |
683 |
putchar('\n'); |
684 |
} |
685 |
fflush(stdout); |
686 |
} |
687 |
|
688 |
|
689 |
oconv() /* run oconv and mkillum if necessary */ |
690 |
{ |
691 |
static char illumtmp[] = "ilXXXXXX"; |
692 |
char combuf[1024], ocopts[64], mkopts[64]; |
693 |
|
694 |
oconvopts(ocopts); /* get options */ |
695 |
if (octreedate < scenedate) { /* check date on original octree */ |
696 |
if (touchonly && octreedate) |
697 |
touch(vval(OCTREE)); |
698 |
else { /* build command */ |
699 |
if (vdef(MATERIAL)) |
700 |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
701 |
vval(MATERIAL), vval(SCENE), |
702 |
vval(OCTREE)); |
703 |
else |
704 |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
705 |
vval(SCENE), vval(OCTREE)); |
706 |
|
707 |
if (runcom(combuf)) { /* run it */ |
708 |
fprintf(stderr, |
709 |
"%s: error generating octree\n\t%s removed\n", |
710 |
progname, vval(OCTREE)); |
711 |
unlink(vval(OCTREE)); |
712 |
exit(1); |
713 |
} |
714 |
} |
715 |
octreedate = time((time_t *)NULL); |
716 |
if (octreedate < scenedate) /* in case clock is off */ |
717 |
octreedate = scenedate; |
718 |
} |
719 |
if (oct1name == vval(OCTREE)) /* no mkillum? */ |
720 |
oct1date = octreedate > matdate ? octreedate : matdate; |
721 |
if (oct1date >= octreedate & oct1date >= matdate |
722 |
& oct1date >= illumdate) /* all done */ |
723 |
return; |
724 |
/* make octree0 */ |
725 |
if (oct0date < scenedate | oct0date < illumdate) { |
726 |
if (touchonly && oct0date) |
727 |
touch(oct0name); |
728 |
else { /* build command */ |
729 |
if (octreedate) |
730 |
sprintf(combuf, "oconv%s -i %s %s > %s", ocopts, |
731 |
vval(OCTREE), vval(ILLUM), oct0name); |
732 |
else if (vdef(MATERIAL)) |
733 |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
734 |
vval(MATERIAL), vval(ILLUM), oct0name); |
735 |
else |
736 |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
737 |
vval(ILLUM), oct0name); |
738 |
if (runcom(combuf)) { /* run it */ |
739 |
fprintf(stderr, |
740 |
"%s: error generating octree\n\t%s removed\n", |
741 |
progname, oct0name); |
742 |
unlink(oct0name); |
743 |
exit(1); |
744 |
} |
745 |
} |
746 |
oct0date = time((time_t *)NULL); |
747 |
if (oct0date < octreedate) /* in case clock is off */ |
748 |
oct0date = octreedate; |
749 |
if (oct0date < illumdate) /* ditto */ |
750 |
oct0date = illumdate; |
751 |
} |
752 |
if (touchonly && oct1date) |
753 |
touch(oct1name); |
754 |
else { |
755 |
mkillumopts(mkopts); /* build mkillum command */ |
756 |
mktemp(illumtmp); |
757 |
sprintf(combuf, "mkillum%s %s \"<\" %s > %s", mkopts, |
758 |
oct0name, vval(ILLUM), illumtmp); |
759 |
if (runcom(combuf)) { /* run it */ |
760 |
fprintf(stderr, "%s: error running mkillum\n", |
761 |
progname); |
762 |
unlink(illumtmp); |
763 |
exit(1); |
764 |
} |
765 |
/* make octree1 (frozen) */ |
766 |
if (octreedate) |
767 |
sprintf(combuf, "oconv%s -f -i %s %s > %s", ocopts, |
768 |
vval(OCTREE), illumtmp, oct1name); |
769 |
else if (vdef(MATERIAL)) |
770 |
sprintf(combuf, "oconv%s -f %s %s > %s", ocopts, |
771 |
vval(MATERIAL), illumtmp, oct1name); |
772 |
else |
773 |
sprintf(combuf, "oconv%s -f %s > %s", ocopts, |
774 |
illumtmp, oct1name); |
775 |
if (runcom(combuf)) { /* run it */ |
776 |
fprintf(stderr, |
777 |
"%s: error generating octree\n\t%s removed\n", |
778 |
progname, oct1name); |
779 |
unlink(oct1name); |
780 |
unlink(illumtmp); |
781 |
exit(1); |
782 |
} |
783 |
rmfile(illumtmp); |
784 |
} |
785 |
oct1date = time((time_t *)NULL); |
786 |
if (oct1date < oct0date) /* in case clock is off */ |
787 |
oct1date = oct0date; |
788 |
} |
789 |
|
790 |
|
791 |
char * |
792 |
addarg(op, arg) /* add argument and advance pointer */ |
793 |
register char *op, *arg; |
794 |
{ |
795 |
*op = ' '; |
796 |
while (*++op = *arg++) |
797 |
; |
798 |
return(op); |
799 |
} |
800 |
|
801 |
|
802 |
oconvopts(oo) /* get oconv options */ |
803 |
register char *oo; |
804 |
{ |
805 |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
806 |
|
807 |
*oo = '\0'; |
808 |
if (vdef(OCONV)) |
809 |
addarg(oo, vval(OCONV)); |
810 |
} |
811 |
|
812 |
|
813 |
mkillumopts(mo) /* get mkillum options */ |
814 |
register char *mo; |
815 |
{ |
816 |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
817 |
|
818 |
*mo = '\0'; |
819 |
if (vdef(MKILLUM)) |
820 |
addarg(mo, vval(MKILLUM)); |
821 |
} |
822 |
|
823 |
|
824 |
checkambfile() /* check date on ambient file */ |
825 |
{ |
826 |
time_t afdate; |
827 |
|
828 |
if (!vdef(AMBFILE)) |
829 |
return; |
830 |
if (!(afdate = fdate(vval(AMBFILE)))) |
831 |
return; |
832 |
if (oct1date > afdate) |
833 |
if (touchonly) |
834 |
touch(vval(AMBFILE)); |
835 |
else |
836 |
rmfile(vval(AMBFILE)); |
837 |
} |
838 |
|
839 |
|
840 |
double |
841 |
ambval() /* compute ambient value */ |
842 |
{ |
843 |
if (vdef(EXPOSURE)) { |
844 |
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
845 |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
846 |
return(.5/atof(vval(EXPOSURE))); |
847 |
} |
848 |
if (vlet(ZONE) == 'E') |
849 |
return(10.); |
850 |
if (vlet(ZONE) == 'I') |
851 |
return(.01); |
852 |
badvalue(ZONE); |
853 |
} |
854 |
|
855 |
|
856 |
renderopts(op, po) /* set rendering options */ |
857 |
char *op, *po; |
858 |
{ |
859 |
switch(vscale(QUALITY)) { |
860 |
case LOW: |
861 |
lowqopts(op, po); |
862 |
break; |
863 |
case MEDIUM: |
864 |
medqopts(op, po); |
865 |
break; |
866 |
case HIGH: |
867 |
hiqopts(op, po); |
868 |
break; |
869 |
} |
870 |
} |
871 |
|
872 |
|
873 |
lowqopts(op, po) /* low quality rendering options */ |
874 |
register char *op; |
875 |
char *po; |
876 |
{ |
877 |
double d, org[3], siz[3]; |
878 |
|
879 |
*op = '\0'; |
880 |
*po = '\0'; |
881 |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
882 |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
883 |
badvalue(ZONE); |
884 |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
885 |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
886 |
badvalue(ZONE); |
887 |
getoctcube(org, &d); |
888 |
d *= 3./(siz[0]+siz[1]+siz[2]); |
889 |
switch (vscale(DETAIL)) { |
890 |
case LOW: |
891 |
po = addarg(po, "-ps 16"); |
892 |
op = addarg(op, "-dp 64"); |
893 |
sprintf(op, " -ar %d", (int)(4*d)); |
894 |
op += strlen(op); |
895 |
break; |
896 |
case MEDIUM: |
897 |
po = addarg(po, "-ps 8"); |
898 |
op = addarg(op, "-dp 128"); |
899 |
sprintf(op, " -ar %d", (int)(8*d)); |
900 |
op += strlen(op); |
901 |
break; |
902 |
case HIGH: |
903 |
po = addarg(po, "-ps 4"); |
904 |
op = addarg(op, "-dp 256"); |
905 |
sprintf(op, " -ar %d", (int)(16*d)); |
906 |
op += strlen(op); |
907 |
break; |
908 |
} |
909 |
po = addarg(po, "-pt .16"); |
910 |
if (vbool(PENUMBRAS)) |
911 |
op = addarg(op, "-ds .4"); |
912 |
else |
913 |
op = addarg(op, "-ds 0"); |
914 |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5"); |
915 |
if (vdef(AMBFILE)) { |
916 |
sprintf(op, " -af %s", vval(AMBFILE)); |
917 |
op += strlen(op); |
918 |
} else |
919 |
overture = 0; |
920 |
switch (vscale(VARIABILITY)) { |
921 |
case LOW: |
922 |
op = addarg(op, "-aa .4 -ad 64"); |
923 |
break; |
924 |
case MEDIUM: |
925 |
op = addarg(op, "-aa .3 -ad 128"); |
926 |
break; |
927 |
case HIGH: |
928 |
op = addarg(op, "-aa .25 -ad 256"); |
929 |
break; |
930 |
} |
931 |
op = addarg(op, "-as 0"); |
932 |
d = ambval(); |
933 |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
934 |
op += strlen(op); |
935 |
op = addarg(op, "-lr 3 -lw .02"); |
936 |
if (vdef(RENDER)) |
937 |
op = addarg(op, vval(RENDER)); |
938 |
} |
939 |
|
940 |
|
941 |
medqopts(op, po) /* medium quality rendering options */ |
942 |
register char *op; |
943 |
char *po; |
944 |
{ |
945 |
double d, org[3], siz[3]; |
946 |
|
947 |
*op = '\0'; |
948 |
*po = '\0'; |
949 |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
950 |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
951 |
badvalue(ZONE); |
952 |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
953 |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
954 |
badvalue(ZONE); |
955 |
getoctcube(org, &d); |
956 |
d *= 3./(siz[0]+siz[1]+siz[2]); |
957 |
switch (vscale(DETAIL)) { |
958 |
case LOW: |
959 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
960 |
op = addarg(op, "-dp 256"); |
961 |
sprintf(op, " -ar %d", (int)(8*d)); |
962 |
op += strlen(op); |
963 |
break; |
964 |
case MEDIUM: |
965 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
966 |
op = addarg(op, "-dp 512"); |
967 |
sprintf(op, " -ar %d", (int)(16*d)); |
968 |
op += strlen(op); |
969 |
break; |
970 |
case HIGH: |
971 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
972 |
op = addarg(op, "-dp 1024"); |
973 |
sprintf(op, " -ar %d", (int)(32*d)); |
974 |
op += strlen(op); |
975 |
break; |
976 |
} |
977 |
po = addarg(po, "-pt .08"); |
978 |
if (vbool(PENUMBRAS)) |
979 |
op = addarg(op, "-ds .2 -dj .5"); |
980 |
else |
981 |
op = addarg(op, "-ds .3"); |
982 |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1"); |
983 |
if (overture = vint(INDIRECT)) { |
984 |
sprintf(op, " -ab %d", overture); |
985 |
op += strlen(op); |
986 |
} |
987 |
if (vdef(AMBFILE)) { |
988 |
sprintf(op, " -af %s", vval(AMBFILE)); |
989 |
op += strlen(op); |
990 |
} else |
991 |
overture = 0; |
992 |
switch (vscale(VARIABILITY)) { |
993 |
case LOW: |
994 |
op = addarg(op, "-aa .25 -ad 196 -as 0"); |
995 |
break; |
996 |
case MEDIUM: |
997 |
op = addarg(op, "-aa .2 -ad 400 -as 64"); |
998 |
break; |
999 |
case HIGH: |
1000 |
op = addarg(op, "-aa .15 -ad 768 -as 196"); |
1001 |
break; |
1002 |
} |
1003 |
d = ambval(); |
1004 |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
1005 |
op += strlen(op); |
1006 |
op = addarg(op, "-lr 6 -lw .002"); |
1007 |
if (vdef(RENDER)) |
1008 |
op = addarg(op, vval(RENDER)); |
1009 |
} |
1010 |
|
1011 |
|
1012 |
hiqopts(op, po) /* high quality rendering options */ |
1013 |
register char *op; |
1014 |
char *po; |
1015 |
{ |
1016 |
double d, org[3], siz[3]; |
1017 |
|
1018 |
*op = '\0'; |
1019 |
*po = '\0'; |
1020 |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
1021 |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
1022 |
badvalue(ZONE); |
1023 |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
1024 |
if (siz[0] <= FTINY | siz[1] <= FTINY | siz[2] <= FTINY) |
1025 |
badvalue(ZONE); |
1026 |
getoctcube(org, &d); |
1027 |
d *= 3./(siz[0]+siz[1]+siz[2]); |
1028 |
switch (vscale(DETAIL)) { |
1029 |
case LOW: |
1030 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
1031 |
op = addarg(op, "-dp 1024"); |
1032 |
sprintf(op, " -ar %d", (int)(16*d)); |
1033 |
op += strlen(op); |
1034 |
break; |
1035 |
case MEDIUM: |
1036 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
1037 |
op = addarg(op, "-dp 2048"); |
1038 |
sprintf(op, " -ar %d", (int)(32*d)); |
1039 |
op += strlen(op); |
1040 |
break; |
1041 |
case HIGH: |
1042 |
po = addarg(po, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
1043 |
op = addarg(op, "-dp 4096"); |
1044 |
sprintf(op, " -ar %d", (int)(64*d)); |
1045 |
op += strlen(op); |
1046 |
break; |
1047 |
} |
1048 |
po = addarg(po, "-pt .04"); |
1049 |
if (vbool(PENUMBRAS)) |
1050 |
op = addarg(op, "-ds .1 -dj .65"); |
1051 |
else |
1052 |
op = addarg(op, "-ds .2"); |
1053 |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01"); |
1054 |
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
1055 |
op += strlen(op); |
1056 |
if (vdef(AMBFILE)) { |
1057 |
sprintf(op, " -af %s", vval(AMBFILE)); |
1058 |
op += strlen(op); |
1059 |
} else |
1060 |
overture = 0; |
1061 |
switch (vscale(VARIABILITY)) { |
1062 |
case LOW: |
1063 |
op = addarg(op, "-aa .15 -ad 256 -as 0"); |
1064 |
break; |
1065 |
case MEDIUM: |
1066 |
op = addarg(op, "-aa .125 -ad 512 -as 256"); |
1067 |
break; |
1068 |
case HIGH: |
1069 |
op = addarg(op, "-aa .08 -ad 1024 -as 512"); |
1070 |
break; |
1071 |
} |
1072 |
d = ambval(); |
1073 |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
1074 |
op += strlen(op); |
1075 |
op = addarg(op, "-lr 12 -lw .0005"); |
1076 |
if (vdef(RENDER)) |
1077 |
op = addarg(op, vval(RENDER)); |
1078 |
} |
1079 |
|
1080 |
|
1081 |
xferopts(ro) /* transfer options if indicated */ |
1082 |
char *ro; |
1083 |
{ |
1084 |
int fd, n; |
1085 |
register char *cp; |
1086 |
|
1087 |
n = strlen(ro); |
1088 |
if (n < 2) |
1089 |
return; |
1090 |
if (vdef(OPTFILE)) { |
1091 |
for (cp = ro; cp[1]; cp++) |
1092 |
if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) |
1093 |
*cp = '\n'; |
1094 |
else |
1095 |
*cp = cp[1]; |
1096 |
*cp = '\n'; |
1097 |
fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); |
1098 |
if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) |
1099 |
syserr(vval(OPTFILE)); |
1100 |
sprintf(ro, " @%s", vval(OPTFILE)); |
1101 |
} |
1102 |
#ifdef MSDOS |
1103 |
else if (n > 50) { |
1104 |
setenv("ROPT", ro+1); |
1105 |
strcpy(ro, " $ROPT"); |
1106 |
} |
1107 |
#endif |
1108 |
} |
1109 |
|
1110 |
|
1111 |
pfiltopts(po) /* get pfilt options */ |
1112 |
register char *po; |
1113 |
{ |
1114 |
*po = '\0'; |
1115 |
if (vdef(EXPOSURE)) { |
1116 |
po = addarg(po, "-1 -e"); |
1117 |
po = addarg(po, vval(EXPOSURE)); |
1118 |
} |
1119 |
switch (vscale(QUALITY)) { |
1120 |
case MEDIUM: |
1121 |
po = addarg(po, "-r 1"); |
1122 |
break; |
1123 |
case HIGH: |
1124 |
po = addarg(po, "-m .25"); |
1125 |
break; |
1126 |
} |
1127 |
if (vdef(PFILT)) |
1128 |
po = addarg(po, vval(PFILT)); |
1129 |
} |
1130 |
|
1131 |
|
1132 |
matchword(s1, s2) /* match white-delimited words */ |
1133 |
register char *s1, *s2; |
1134 |
{ |
1135 |
while (isspace(*s1)) s1++; |
1136 |
while (isspace(*s2)) s2++; |
1137 |
while (*s1 && !isspace(*s1)) |
1138 |
if (*s1++ != *s2++) |
1139 |
return(0); |
1140 |
return(!*s2 || isspace(*s2)); |
1141 |
} |
1142 |
|
1143 |
|
1144 |
char * |
1145 |
specview(vs) /* get proper view spec from vs */ |
1146 |
register char *vs; |
1147 |
{ |
1148 |
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
1149 |
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
1150 |
static char viewopts[128]; |
1151 |
register char *cp; |
1152 |
int xpos, ypos, zpos, viewtype, upax; |
1153 |
register int i; |
1154 |
double cent[3], dim[3], mult, d; |
1155 |
|
1156 |
if (vs == NULL || *vs == '-') |
1157 |
return(vs); |
1158 |
upax = 0; /* get the up vector */ |
1159 |
if (vdef(UP)) { |
1160 |
if (vval(UP)[0] == '-' || vval(UP)[0] == '+') |
1161 |
upax = 1-'X'+UPPER(vval(UP)[1]); |
1162 |
else |
1163 |
upax = 1-'X'+vlet(UP); |
1164 |
if (upax < 1 | upax > 3) |
1165 |
badvalue(UP); |
1166 |
if (vval(UP)[0] == '-') |
1167 |
upax = -upax; |
1168 |
} |
1169 |
/* check standard view names */ |
1170 |
xpos = ypos = zpos = 0; |
1171 |
if (*vs == 'X') { |
1172 |
xpos = 1; vs++; |
1173 |
} else if (*vs == 'x') { |
1174 |
xpos = -1; vs++; |
1175 |
} |
1176 |
if (*vs == 'Y') { |
1177 |
ypos = 1; vs++; |
1178 |
} else if (*vs == 'y') { |
1179 |
ypos = -1; vs++; |
1180 |
} |
1181 |
if (*vs == 'Z') { |
1182 |
zpos = 1; vs++; |
1183 |
} else if (*vs == 'z') { |
1184 |
zpos = -1; vs++; |
1185 |
} |
1186 |
viewtype = 'v'; |
1187 |
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h' | *vs == 'c') |
1188 |
viewtype = *vs++; |
1189 |
cp = viewopts; |
1190 |
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
1191 |
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
1192 |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
1193 |
¢[0], &dim[0], ¢[1], &dim[1], |
1194 |
¢[2], &dim[2]) != 6) |
1195 |
badvalue(ZONE); |
1196 |
for (i = 0; i < 3; i++) { |
1197 |
dim[i] -= cent[i]; |
1198 |
if (dim[i] <= FTINY) |
1199 |
badvalue(ZONE); |
1200 |
cent[i] += .5*dim[i]; |
1201 |
} |
1202 |
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
1203 |
sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", |
1204 |
cent[0]+xpos*mult*dim[0], |
1205 |
cent[1]+ypos*mult*dim[1], |
1206 |
cent[2]+zpos*mult*dim[2], |
1207 |
-xpos*dim[0], -ypos*dim[1], -zpos*dim[2]); |
1208 |
cp += strlen(cp); |
1209 |
/* redirect up axis if necessary */ |
1210 |
switch (upax) { |
1211 |
case 3: /* plus or minus Z axis */ |
1212 |
case -3: |
1213 |
case 0: |
1214 |
if (!(xpos|ypos)) |
1215 |
upax = 2; |
1216 |
break; |
1217 |
case 2: /* plus or minus Y axis */ |
1218 |
case -2: |
1219 |
if (!(xpos|zpos)) |
1220 |
upax = 1; |
1221 |
break; |
1222 |
case 1: /* plus or minus X axis */ |
1223 |
case -1: |
1224 |
if (!(ypos|zpos)) |
1225 |
upax = 3; |
1226 |
break; |
1227 |
} |
1228 |
cp = addarg(cp, vup[upax+3]); |
1229 |
switch (viewtype) { |
1230 |
case 'v': |
1231 |
cp = addarg(cp, "-vh 45 -vv 45"); |
1232 |
break; |
1233 |
case 'l': |
1234 |
d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]); |
1235 |
sprintf(cp, " -vh %.2g -vv %.2g", d, d); |
1236 |
cp += strlen(cp); |
1237 |
break; |
1238 |
case 'a': |
1239 |
case 'h': |
1240 |
cp = addarg(cp, "-vh 180 -vv 180"); |
1241 |
break; |
1242 |
case 'c': |
1243 |
cp = addarg(cp, "-vh 180 -vv 90"); |
1244 |
break; |
1245 |
} |
1246 |
} else { |
1247 |
while (!isspace(*vs)) /* else skip id */ |
1248 |
if (!*vs++) |
1249 |
return(NULL); |
1250 |
if (upax) { /* specify up vector */ |
1251 |
strcpy(cp, vup[upax+3]); |
1252 |
cp += strlen(cp); |
1253 |
} |
1254 |
} |
1255 |
if (cp == viewopts) /* append any additional options */ |
1256 |
vs++; /* skip prefixed space if unneeded */ |
1257 |
strcpy(cp, vs); |
1258 |
#ifdef MSDOS |
1259 |
if (strlen(viewopts) > 40) { |
1260 |
setenv("VIEW", viewopts); |
1261 |
return("$VIEW"); |
1262 |
} |
1263 |
#endif |
1264 |
return(viewopts); |
1265 |
} |
1266 |
|
1267 |
|
1268 |
char * |
1269 |
getview(n, vn) /* get view n, or NULL if none */ |
1270 |
int n; |
1271 |
char *vn; /* returned view name */ |
1272 |
{ |
1273 |
register char *mv; |
1274 |
|
1275 |
if (viewselect != NULL) { /* command-line selected */ |
1276 |
if (n) /* only do one */ |
1277 |
return(NULL); |
1278 |
if (viewselect[0] == '-') { /* already specified */ |
1279 |
if (vn != NULL) *vn = '\0'; |
1280 |
return(viewselect); |
1281 |
} |
1282 |
if (vn != NULL) { |
1283 |
for (mv = viewselect; *mv && !isspace(*mv); |
1284 |
*vn++ = *mv++) |
1285 |
; |
1286 |
*vn = '\0'; |
1287 |
} |
1288 |
/* view number? */ |
1289 |
if (isint(viewselect)) |
1290 |
return(specview(nvalue(vv+VIEW, atoi(viewselect)-1))); |
1291 |
/* check list */ |
1292 |
while ((mv = nvalue(vv+VIEW, n++)) != NULL) |
1293 |
if (matchword(viewselect, mv)) |
1294 |
return(specview(mv)); |
1295 |
return(specview(viewselect)); /* standard view? */ |
1296 |
} |
1297 |
mv = nvalue(vv+VIEW, n); /* use view n */ |
1298 |
if (vn != NULL & mv != NULL) { |
1299 |
register char *mv2 = mv; |
1300 |
if (*mv2 != '-') |
1301 |
while (*mv2 && !isspace(*mv2)) |
1302 |
*vn++ = *mv2++; |
1303 |
*vn = '\0'; |
1304 |
} |
1305 |
return(specview(mv)); |
1306 |
} |
1307 |
|
1308 |
|
1309 |
printview(vopts) /* print out selected view */ |
1310 |
register char *vopts; |
1311 |
{ |
1312 |
extern char *atos(), *getenv(); |
1313 |
char buf[256]; |
1314 |
FILE *fp; |
1315 |
register char *cp; |
1316 |
|
1317 |
if (vopts == NULL) |
1318 |
return(-1); |
1319 |
fputs("VIEW=", stdout); |
1320 |
do { |
1321 |
if (matchword(vopts, "-vf")) { /* expand view file */ |
1322 |
vopts = sskip(vopts); |
1323 |
if (!*atos(buf, sizeof(buf), vopts)) |
1324 |
return(-1); |
1325 |
if ((fp = fopen(buf, "r")) == NULL) |
1326 |
return(-1); |
1327 |
for (buf[sizeof(buf)-2] = '\n'; |
1328 |
fgets(buf, sizeof(buf), fp) != NULL && |
1329 |
buf[0] != '\n'; |
1330 |
buf[sizeof(buf)-2] = '\n') { |
1331 |
if (buf[sizeof(buf)-2] != '\n') { |
1332 |
ungetc(buf[sizeof(buf)-2], fp); |
1333 |
buf[sizeof(buf)-2] = '\0'; |
1334 |
} |
1335 |
if (matchword(buf, "VIEW=") || |
1336 |
matchword(buf, "rview")) { |
1337 |
for (cp = sskip(buf); *cp && *cp != '\n'; cp++) |
1338 |
putchar(*cp); |
1339 |
} |
1340 |
} |
1341 |
fclose(fp); |
1342 |
vopts = sskip(vopts); |
1343 |
} else { |
1344 |
while (isspace(*vopts)) |
1345 |
vopts++; |
1346 |
putchar(' '); |
1347 |
#ifdef MSDOS |
1348 |
if (*vopts == '$') { /* expand env. var. */ |
1349 |
if (!*atos(buf, sizeof(buf), vopts+1)) |
1350 |
return(-1); |
1351 |
if ((cp = getenv(buf)) == NULL) |
1352 |
return(-1); |
1353 |
fputs(cp, stdout); |
1354 |
vopts = sskip(vopts); |
1355 |
} else |
1356 |
#endif |
1357 |
while (*vopts && !isspace(*vopts)) |
1358 |
putchar(*vopts++); |
1359 |
} |
1360 |
} while (*vopts++); |
1361 |
putchar('\n'); |
1362 |
return(0); |
1363 |
} |
1364 |
|
1365 |
|
1366 |
rview(opts, po) /* run rview with first view */ |
1367 |
char *opts, *po; |
1368 |
{ |
1369 |
char *vw; |
1370 |
char combuf[512]; |
1371 |
/* build command */ |
1372 |
if (touchonly || (vw = getview(0, NULL)) == NULL) |
1373 |
return; |
1374 |
if (sayview) |
1375 |
printview(vw); |
1376 |
sprintf(combuf, "rview %s%s%s -R %s ", vw, po, opts, rifname); |
1377 |
if (rvdevice != NULL) |
1378 |
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1379 |
if (vdef(EXPOSURE)) |
1380 |
sprintf(combuf+strlen(combuf), "-pe %s ", vval(EXPOSURE)); |
1381 |
strcat(combuf, oct1name); |
1382 |
if (runcom(combuf)) { /* run it */ |
1383 |
fprintf(stderr, "%s: error running rview\n", progname); |
1384 |
exit(1); |
1385 |
} |
1386 |
} |
1387 |
|
1388 |
|
1389 |
rpict(opts, po) /* run rpict and pfilt for each view */ |
1390 |
char *opts, *po; |
1391 |
{ |
1392 |
char combuf[1024]; |
1393 |
char rawfile[MAXPATH], picfile[MAXPATH]; |
1394 |
char zopt[MAXPATH+4], rep[MAXPATH+16], res[32]; |
1395 |
char pfopts[128]; |
1396 |
char vs[32], *vw; |
1397 |
int vn, mult; |
1398 |
time_t rfdt, pfdt; |
1399 |
/* get pfilt options */ |
1400 |
pfiltopts(pfopts); |
1401 |
/* get resolution, reporting */ |
1402 |
switch (vscale(QUALITY)) { |
1403 |
case LOW: |
1404 |
mult = 1; |
1405 |
break; |
1406 |
case MEDIUM: |
1407 |
mult = 2; |
1408 |
break; |
1409 |
case HIGH: |
1410 |
mult = 3; |
1411 |
break; |
1412 |
} |
1413 |
{ |
1414 |
int xres, yres; |
1415 |
double aspect; |
1416 |
int n; |
1417 |
n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect); |
1418 |
if (n == 3) |
1419 |
sprintf(res, "-x %d -y %d -pa %.3f", |
1420 |
mult*xres, mult*yres, aspect); |
1421 |
else if (n) { |
1422 |
if (n == 1) yres = xres; |
1423 |
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1424 |
} else |
1425 |
badvalue(RESOLUTION); |
1426 |
} |
1427 |
rep[0] = '\0'; |
1428 |
if (vdef(REPORT)) { |
1429 |
double minutes; |
1430 |
int n; |
1431 |
n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile); |
1432 |
if (n == 2) |
1433 |
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1434 |
else if (n == 1) |
1435 |
sprintf(rep, " -t %d", (int)(minutes*60)); |
1436 |
else |
1437 |
badvalue(REPORT); |
1438 |
} |
1439 |
/* do each view */ |
1440 |
vn = 0; |
1441 |
while ((vw = getview(vn++, vs)) != NULL) { |
1442 |
if (sayview) |
1443 |
printview(vw); |
1444 |
if (!vs[0]) |
1445 |
sprintf(vs, "%d", vn); |
1446 |
sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs); |
1447 |
if (vdef(ZFILE)) |
1448 |
sprintf(zopt, " -z %s_%s.zbf", vval(ZFILE), vs); |
1449 |
else |
1450 |
zopt[0] = '\0'; |
1451 |
/* check date on picture */ |
1452 |
pfdt = fdate(picfile); |
1453 |
if (pfdt >= oct1date) |
1454 |
continue; |
1455 |
/* get raw file name */ |
1456 |
sprintf(rawfile, "%s_%s.unf", |
1457 |
vdef(RAWFILE) ? vval(RAWFILE) : vval(PICTURE), vs); |
1458 |
rfdt = fdate(rawfile); |
1459 |
if (touchonly) { /* update times only */ |
1460 |
if (rfdt) { |
1461 |
if (rfdt < oct1date) |
1462 |
touch(rawfile); |
1463 |
} else if (pfdt && pfdt < oct1date) |
1464 |
touch(picfile); |
1465 |
continue; |
1466 |
} |
1467 |
/* build rpict command */ |
1468 |
if (rfdt >= oct1date) /* recover */ |
1469 |
sprintf(combuf, "rpict%s%s%s%s -ro %s %s", |
1470 |
rep, po, opts, zopt, rawfile, oct1name); |
1471 |
else { |
1472 |
if (overture) { /* run overture calculation */ |
1473 |
sprintf(combuf, |
1474 |
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1475 |
rep, vw, opts, |
1476 |
oct1name, overfile); |
1477 |
if (runcom(combuf)) { |
1478 |
fprintf(stderr, |
1479 |
"%s: error in overture for view %s\n", |
1480 |
progname, vs); |
1481 |
exit(1); |
1482 |
} |
1483 |
#ifdef NIX |
1484 |
rmfile(overfile); |
1485 |
#endif |
1486 |
} |
1487 |
sprintf(combuf, "rpict%s %s %s%s%s%s %s > %s", |
1488 |
rep, vw, res, po, opts, zopt, |
1489 |
oct1name, rawfile); |
1490 |
} |
1491 |
if (runcom(combuf)) { /* run rpict */ |
1492 |
fprintf(stderr, "%s: error rendering view %s\n", |
1493 |
progname, vs); |
1494 |
exit(1); |
1495 |
} |
1496 |
if (!vdef(RAWFILE) || strcmp(vval(RAWFILE),vval(PICTURE))) { |
1497 |
/* build pfilt command */ |
1498 |
if (mult > 1) |
1499 |
sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s", |
1500 |
pfopts, mult, mult, rawfile, picfile); |
1501 |
else |
1502 |
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1503 |
rawfile, picfile); |
1504 |
if (runcom(combuf)) { /* run pfilt */ |
1505 |
fprintf(stderr, |
1506 |
"%s: error filtering view %s\n\t%s removed\n", |
1507 |
progname, vs, picfile); |
1508 |
unlink(picfile); |
1509 |
exit(1); |
1510 |
} |
1511 |
} |
1512 |
/* remove/rename raw file */ |
1513 |
if (vdef(RAWFILE)) { |
1514 |
sprintf(combuf, "%s_%s.pic", vval(RAWFILE), vs); |
1515 |
mvfile(rawfile, combuf); |
1516 |
} else |
1517 |
rmfile(rawfile); |
1518 |
} |
1519 |
} |
1520 |
|
1521 |
|
1522 |
touch(fn) /* update a file */ |
1523 |
char *fn; |
1524 |
{ |
1525 |
if (!silent) |
1526 |
printf("\ttouch %s\n", fn); |
1527 |
if (noaction) |
1528 |
return(0); |
1529 |
#ifdef notused |
1530 |
if (access(fn, F_OK) == -1) /* create it */ |
1531 |
if (close(open(fn, O_WRONLY|O_CREAT, 0666)) == -1) |
1532 |
return(-1); |
1533 |
#endif |
1534 |
return(setfdate(fn, time((time_t *)NULL))); |
1535 |
} |
1536 |
|
1537 |
|
1538 |
runcom(cs) /* run command */ |
1539 |
char *cs; |
1540 |
{ |
1541 |
if (!silent) /* echo it */ |
1542 |
printf("\t%s\n", cs); |
1543 |
if (noaction) |
1544 |
return(0); |
1545 |
fflush(stdout); /* flush output and pass to shell */ |
1546 |
return(system(cs)); |
1547 |
} |
1548 |
|
1549 |
|
1550 |
rmfile(fn) /* remove a file */ |
1551 |
char *fn; |
1552 |
{ |
1553 |
if (!silent) |
1554 |
#ifdef MSDOS |
1555 |
printf("\tdel %s\n", fn); |
1556 |
#else |
1557 |
printf("\trm -f %s\n", fn); |
1558 |
#endif |
1559 |
if (noaction) |
1560 |
return(0); |
1561 |
return(unlink(fn)); |
1562 |
} |
1563 |
|
1564 |
|
1565 |
mvfile(fold, fnew) /* move a file */ |
1566 |
char *fold, *fnew; |
1567 |
{ |
1568 |
if (!silent) |
1569 |
#ifdef MSDOS |
1570 |
printf("\trename %s %s\n", fold, fnew); |
1571 |
#else |
1572 |
printf("\tmv %s %s\n", fold, fnew); |
1573 |
#endif |
1574 |
if (noaction) |
1575 |
return(0); |
1576 |
return(rename(fold, fnew)); |
1577 |
} |
1578 |
|
1579 |
|
1580 |
#ifdef MSDOS |
1581 |
setenv(vname, value) /* set an environment variable */ |
1582 |
char *vname, *value; |
1583 |
{ |
1584 |
register char *evp; |
1585 |
|
1586 |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1587 |
if (evp == NULL) |
1588 |
syserr(progname); |
1589 |
sprintf(evp, "%s=%s", vname, value); |
1590 |
if (putenv(evp) != 0) { |
1591 |
fprintf(stderr, "%s: out of environment space\n", progname); |
1592 |
exit(1); |
1593 |
} |
1594 |
if (!silent) |
1595 |
printf("set %s\n", evp); |
1596 |
} |
1597 |
#endif |
1598 |
|
1599 |
|
1600 |
badvalue(vc) /* report bad variable value and exit */ |
1601 |
int vc; |
1602 |
{ |
1603 |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1604 |
progname, vnam(vc)); |
1605 |
exit(1); |
1606 |
} |
1607 |
|
1608 |
|
1609 |
syserr(s) /* report a system error and exit */ |
1610 |
char *s; |
1611 |
{ |
1612 |
perror(s); |
1613 |
exit(1); |
1614 |
} |