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