76 |
|
char *nvalue(); |
77 |
|
int vscale(); |
78 |
|
|
79 |
+ |
#define UPPER(c) ((c)&~0x20) /* ASCII trick */ |
80 |
+ |
|
81 |
|
#define vnam(vc) (vv[vc].name) |
82 |
|
#define vdef(vc) (vv[vc].nass) |
83 |
|
#define vval(vc) (vv[vc].value) |
84 |
|
#define vint(vc) atoi(vval(vc)) |
85 |
< |
#define vlet(vc) (vval(vc)[0]&~0x20) |
85 |
> |
#define vlet(vc) UPPER(vval(vc)[0]) |
86 |
|
#define vbool(vc) (vlet(vc)=='T') |
87 |
|
|
88 |
|
#define HIGH 2 |
94 |
|
|
95 |
|
#define renderopts (*setqopts[vscale(QUALITY)]) |
96 |
|
|
97 |
< |
extern long fdate(); |
97 |
> |
/* overture calculation file */ |
98 |
> |
#ifdef NIX |
99 |
> |
char overfile[] = "overture.raw"; |
100 |
> |
#else |
101 |
> |
char overfile[] = "/dev/null"; |
102 |
> |
#endif |
103 |
|
|
104 |
+ |
extern long fdate(), time(); |
105 |
+ |
|
106 |
|
long scenedate; /* date of latest scene or object file */ |
107 |
|
long octreedate; /* date of octree */ |
108 |
|
|
166 |
|
/* print all values if requested */ |
167 |
|
if (explicate) |
168 |
|
printvals(); |
169 |
< |
/* run simulation */ |
169 |
> |
/* build octree */ |
170 |
|
oconv(); |
171 |
+ |
/* check date on ambient file */ |
172 |
+ |
checkambfile(); |
173 |
+ |
/* run simulation */ |
174 |
|
renderopts(ropts); |
175 |
|
xferopts(ropts); |
176 |
|
if (rvdevice != NULL) |
180 |
|
exit(0); |
181 |
|
userr: |
182 |
|
fprintf(stderr, |
183 |
< |
"Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n", |
183 |
> |
"Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n", |
184 |
|
progname); |
185 |
|
exit(1); |
186 |
|
} |
205 |
|
char *rfname; |
206 |
|
{ |
207 |
|
FILE *fp; |
208 |
< |
char buf[256]; |
208 |
> |
char buf[512]; |
209 |
|
register char *cp; |
210 |
|
|
211 |
|
if (rfname == NULL) |
212 |
|
fp = stdin; |
213 |
< |
else if ((fp = fopen(rfname, "r")) == NULL) { |
214 |
< |
perror(rfname); |
203 |
< |
exit(1); |
204 |
< |
} |
213 |
> |
else if ((fp = fopen(rfname, "r")) == NULL) |
214 |
> |
syserr(rfname); |
215 |
|
while (fgetline(buf, sizeof(buf), fp) != NULL) { |
216 |
|
for (cp = buf; *cp; cp++) { |
217 |
|
switch (*cp) { |
222 |
|
case '#': |
223 |
|
*cp = '\0'; |
224 |
|
break; |
225 |
+ |
default: |
226 |
+ |
continue; |
227 |
|
} |
228 |
|
break; |
229 |
|
} |
272 |
|
exit(1); |
273 |
|
} |
274 |
|
/* assign new value */ |
275 |
< |
cp = vp->value; i = vp->nass; |
276 |
< |
while (i--) |
277 |
< |
while (*cp++) |
278 |
< |
; |
279 |
< |
i = cp - vp->value; |
280 |
< |
vp->value = realloc(vp->value, i+n+1); |
281 |
< |
if (vp->value == NULL) { |
282 |
< |
perror(progname); |
283 |
< |
exit(1); |
284 |
< |
} |
275 |
> |
if (i = vp->nass) { |
276 |
> |
cp = vp->value; |
277 |
> |
while (i--) |
278 |
> |
while (*cp++) |
279 |
> |
; |
280 |
> |
i = cp - vp->value; |
281 |
> |
vp->value = realloc(vp->value, i+n+1); |
282 |
> |
} else |
283 |
> |
vp->value = malloc(n+1); |
284 |
> |
if (vp->value == NULL) |
285 |
> |
syserr(progname); |
286 |
|
strcpy(vp->value+i, ass); |
287 |
|
vp->nass++; |
288 |
|
} |
331 |
|
case 'L': |
332 |
|
return(LOW); |
333 |
|
} |
334 |
< |
fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n", |
322 |
< |
progname, vnam(vc), vval(vc)); |
323 |
< |
exit(1); |
334 |
> |
badvalue(vc); |
335 |
|
} |
336 |
|
|
337 |
|
|
352 |
|
return; |
353 |
|
fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n", |
354 |
|
progname, vp->name); |
355 |
< |
while (vp->nass-- > 1) |
355 |
> |
do |
356 |
|
vp->value += strlen(vp->value)+1; |
357 |
+ |
while (--vp->nass > 1); |
358 |
|
} |
359 |
|
|
360 |
|
|
384 |
|
while (*fnames) { |
385 |
|
while (isspace(*fnames)) fnames++; |
386 |
|
cp = thisfile; |
387 |
< |
while (*fnames && !isspace(*fnames)) *cp++ = *fnames++; |
387 |
> |
while (*fnames && !isspace(*fnames)) |
388 |
> |
*cp++ = *fnames++; |
389 |
|
*cp = '\0'; |
390 |
< |
if ((thisdate = fdate(thisfile)) < 0) { |
391 |
< |
perror(thisfile); |
379 |
< |
exit(1); |
380 |
< |
} |
390 |
> |
if ((thisdate = fdate(thisfile)) < 0) |
391 |
> |
syserr(thisfile); |
392 |
|
if (thisdate > lastdate) |
393 |
|
lastdate = thisdate; |
394 |
|
} |
398 |
|
|
399 |
|
checkfiles() /* check for existence and modified times */ |
400 |
|
{ |
401 |
+ |
char *cp; |
402 |
|
long objdate; |
403 |
|
|
404 |
< |
octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1; |
404 |
> |
if (!vdef(OCTREE)) { |
405 |
> |
if ((cp = bmalloc(strlen(radname)+5)) == NULL) |
406 |
> |
syserr(progname); |
407 |
> |
sprintf(cp, "%s.oct", radname); |
408 |
> |
vval(OCTREE) = cp; |
409 |
> |
vdef(OCTREE)++; |
410 |
> |
} |
411 |
> |
octreedate = fdate(vval(OCTREE)); |
412 |
|
scenedate = -1; |
413 |
|
if (vdef(SCENE)) { |
414 |
|
scenedate = checklast(vval(SCENE)); |
419 |
|
} |
420 |
|
} |
421 |
|
if (octreedate < 0 & scenedate < 0) { |
422 |
< |
fprintf(stderr, "%s: need scene or octree\n", progname); |
422 |
> |
fprintf(stderr, "%s: need '%s' or '%s'\n", progname, |
423 |
> |
vnam(OCTREE), vnam(SCENE)); |
424 |
|
exit(1); |
425 |
|
} |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
< |
setdefaults() /* set default values for unassigned var's */ |
429 |
> |
getoctcube(org, sizp) /* get octree bounding cube */ |
430 |
> |
double org[3], *sizp; |
431 |
|
{ |
432 |
+ |
extern FILE *popen(); |
433 |
+ |
static double oorg[3], osiz = 0.; |
434 |
+ |
char buf[MAXPATH+16]; |
435 |
|
FILE *fp; |
412 |
– |
double xmin, ymin, zmin, size; |
413 |
– |
char buf[512]; |
414 |
– |
char *cp; |
436 |
|
|
437 |
< |
if (!vdef(OCTREE)) { |
438 |
< |
sprintf(buf, "%s.oct", radname); |
439 |
< |
vval(OCTREE) = savqstr(buf); |
440 |
< |
vdef(OCTREE)++; |
437 |
> |
if (osiz <= FTINY) { |
438 |
> |
oconv(); /* does nothing if done already */ |
439 |
> |
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
440 |
> |
if ((fp = popen(buf, "r")) == NULL) |
441 |
> |
syserr("getinfo"); |
442 |
> |
if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1], |
443 |
> |
&oorg[2], &osiz) != 4) { |
444 |
> |
fprintf(stderr, |
445 |
> |
"%s: error reading bounding cube from getinfo\n", |
446 |
> |
progname); |
447 |
> |
exit(1); |
448 |
> |
} |
449 |
> |
pclose(fp); |
450 |
|
} |
451 |
+ |
org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz; |
452 |
+ |
} |
453 |
+ |
|
454 |
+ |
|
455 |
+ |
setdefaults() /* set default values for unassigned var's */ |
456 |
+ |
{ |
457 |
+ |
double org[3], size; |
458 |
+ |
char buf[128]; |
459 |
+ |
|
460 |
|
if (!vdef(ZONE)) { |
461 |
< |
if (scenedate > octreedate) { |
462 |
< |
sprintf(buf, "getbbox -w -h %s", vval(SCENE)); |
463 |
< |
if (!silent) { |
425 |
< |
printf("\t%s\n", buf); |
426 |
< |
fflush(stdout); |
427 |
< |
} |
428 |
< |
if ((fp = popen(buf, "r")) == NULL) { |
429 |
< |
perror("getbbox"); |
430 |
< |
exit(1); |
431 |
< |
} |
432 |
< |
buf[0] = 'E'; buf[1] = ' '; |
433 |
< |
fgetline(buf+2, sizeof(buf)-2, fp); |
434 |
< |
pclose(fp); |
435 |
< |
} else { |
436 |
< |
sprintf(buf, "getinfo -d < %s", vval(OCTREE)); |
437 |
< |
if ((fp = popen(buf, "r")) == NULL) { |
438 |
< |
perror("getinfo"); |
439 |
< |
exit(1); |
440 |
< |
} |
441 |
< |
fscanf(fp, "%lf %lf %lf %lf", |
442 |
< |
&xmin, &ymin, &zmin, &size); |
443 |
< |
sprintf(buf, "E %g %g %g %g %g %g", xmin, xmin+size, |
444 |
< |
ymin, ymin+size, zmin, zmin+size); |
445 |
< |
pclose(fp); |
446 |
< |
} |
461 |
> |
getoctcube(org, &size); |
462 |
> |
sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size, |
463 |
> |
org[1], org[1]+size, org[2], org[2]+size); |
464 |
|
vval(ZONE) = savqstr(buf); |
465 |
|
vdef(ZONE)++; |
466 |
|
} |
450 |
– |
if (!vdef(UP)) { |
451 |
– |
vval(UP) = "Z"; |
452 |
– |
vdef(UP)++; |
453 |
– |
} |
467 |
|
if (!vdef(INDIRECT)) { |
468 |
|
vval(INDIRECT) = "0"; |
469 |
|
vdef(INDIRECT)++; |
480 |
|
vval(PICTURE) = radname; |
481 |
|
vdef(PICTURE)++; |
482 |
|
} |
470 |
– |
if (!vdef(AMBFILE)) { |
471 |
– |
sprintf(buf, "%s.amb", radname); |
472 |
– |
vval(AMBFILE) = savqstr(buf); |
473 |
– |
vdef(AMBFILE)++; |
474 |
– |
} |
483 |
|
if (!vdef(VIEW)) { |
484 |
|
vval(VIEW) = "X"; |
485 |
|
vdef(VIEW)++; |
504 |
|
register int i, j; |
505 |
|
|
506 |
|
for (i = 0; i < NVARS; i++) |
507 |
< |
for (j = 0; j < vv[i].nass; j++) |
508 |
< |
printf("%s= %s\n", vv[i].name, nvalue(vv+i, j)); |
507 |
> |
for (j = 0; j < vdef(i); j++) |
508 |
> |
printf("%s= %s\n", vnam(i), nvalue(vv+i, j)); |
509 |
|
fflush(stdout); |
510 |
|
} |
511 |
|
|
514 |
|
{ |
515 |
|
char combuf[512], ocopts[64]; |
516 |
|
|
517 |
< |
if (octreedate > scenedate) /* check dates */ |
517 |
> |
if (octreedate >= scenedate) /* check dates */ |
518 |
|
return; |
519 |
|
/* build command */ |
520 |
|
oconvopts(ocopts); |
521 |
< |
sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE)); |
522 |
< |
if (!silent) { /* echo it */ |
523 |
< |
printf("\t%s\n", combuf); |
524 |
< |
fflush(stdout); |
525 |
< |
} |
526 |
< |
if (noaction) |
527 |
< |
return; |
528 |
< |
if (system(combuf)) { /* run it */ |
521 |
> |
if (vdef(MATERIAL)) |
522 |
> |
sprintf(combuf, "oconv%s %s %s > %s", ocopts, |
523 |
> |
vval(MATERIAL), vval(SCENE), vval(OCTREE)); |
524 |
> |
else |
525 |
> |
sprintf(combuf, "oconv%s %s > %s", ocopts, |
526 |
> |
vval(SCENE), vval(OCTREE)); |
527 |
> |
|
528 |
> |
if (runcom(combuf)) { /* run it */ |
529 |
|
fprintf(stderr, "%s: error generating octree\n\t%s removed\n", |
530 |
|
progname, vval(OCTREE)); |
531 |
|
unlink(vval(OCTREE)); |
532 |
|
exit(1); |
533 |
|
} |
534 |
+ |
octreedate = time(0); |
535 |
|
} |
536 |
|
|
537 |
|
|
547 |
|
|
548 |
|
|
549 |
|
oconvopts(oo) /* get oconv options */ |
550 |
< |
char *oo; |
550 |
> |
register char *oo; |
551 |
|
{ |
552 |
+ |
/* BEWARE: This may be called via setdefaults(), so no assumptions */ |
553 |
+ |
|
554 |
|
*oo = '\0'; |
555 |
|
if (vdef(OCONV)) |
556 |
|
addarg(oo, vval(OCONV)); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
< |
lowqopts(ro) /* low quality rendering options */ |
550 |
< |
char *ro; |
560 |
> |
checkambfile() /* check date on ambient file */ |
561 |
|
{ |
562 |
< |
register char *op = ro; |
562 |
> |
long afdate; |
563 |
|
|
564 |
+ |
if (vdef(AMBFILE)) { |
565 |
+ |
afdate = fdate(vval(AMBFILE)); |
566 |
+ |
if (afdate >= 0 & octreedate > afdate) |
567 |
+ |
rmfile(vval(AMBFILE)); |
568 |
+ |
} |
569 |
+ |
} |
570 |
+ |
|
571 |
+ |
|
572 |
+ |
double |
573 |
+ |
ambval() /* compute ambient value */ |
574 |
+ |
{ |
575 |
+ |
if (vdef(EXPOSURE)) { |
576 |
+ |
if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-') |
577 |
+ |
return(.5/pow(2.,atof(vval(EXPOSURE)))); |
578 |
+ |
if (isdigit(vval(EXPOSURE)[0]) || vval(EXPOSURE)[0] == '.') |
579 |
+ |
return(.5/atof(vval(EXPOSURE))); |
580 |
+ |
badvalue(EXPOSURE); |
581 |
+ |
} |
582 |
+ |
if (vlet(ZONE) == 'E') |
583 |
+ |
return(10.); |
584 |
+ |
if (vlet(ZONE) == 'I') |
585 |
+ |
return(.01); |
586 |
+ |
badvalue(ZONE); |
587 |
+ |
} |
588 |
+ |
|
589 |
+ |
|
590 |
+ |
lowqopts(op) /* low quality rendering options */ |
591 |
+ |
register char *op; |
592 |
+ |
{ |
593 |
+ |
double d, org[3], siz[3]; |
594 |
+ |
|
595 |
|
*op = '\0'; |
596 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
597 |
+ |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
598 |
+ |
badvalue(ZONE); |
599 |
+ |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
600 |
+ |
getoctcube(org, &d); |
601 |
+ |
d *= 3./(siz[0]+siz[1]+siz[2]); |
602 |
+ |
switch (vscale(DETAIL)) { |
603 |
+ |
case LOW: |
604 |
+ |
op = addarg(op, "-ps 16 -dp 16"); |
605 |
+ |
sprintf(op, " -ar %d", (int)(4*d)); |
606 |
+ |
op += strlen(op); |
607 |
+ |
break; |
608 |
+ |
case MEDIUM: |
609 |
+ |
op = addarg(op, "-ps 8 -dp 32"); |
610 |
+ |
sprintf(op, " -ar %d", (int)(8*d)); |
611 |
+ |
op += strlen(op); |
612 |
+ |
break; |
613 |
+ |
case HIGH: |
614 |
+ |
op = addarg(op, "-ps 4 -dp 64"); |
615 |
+ |
sprintf(op, " -ar %d", (int)(16*d)); |
616 |
+ |
op += strlen(op); |
617 |
+ |
break; |
618 |
+ |
} |
619 |
+ |
op = addarg(op, "-pt .16"); |
620 |
+ |
if (vbool(PENUMBRAS)) |
621 |
+ |
op = addarg(op, "-ds .4"); |
622 |
+ |
else |
623 |
+ |
op = addarg(op, "-ds 0"); |
624 |
+ |
op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7"); |
625 |
+ |
if (vdef(AMBFILE)) { |
626 |
+ |
sprintf(op, " -af %s", vval(AMBFILE)); |
627 |
+ |
op += strlen(op); |
628 |
+ |
} else |
629 |
+ |
overture = 0; |
630 |
+ |
switch (vscale(VARIABILITY)) { |
631 |
+ |
case LOW: |
632 |
+ |
op = addarg(op, "-aa .4 -ad 32"); |
633 |
+ |
break; |
634 |
+ |
case MEDIUM: |
635 |
+ |
op = addarg(op, "-aa .3 -ad 64"); |
636 |
+ |
break; |
637 |
+ |
case HIGH: |
638 |
+ |
op = addarg(op, "-aa .25 -ad 128"); |
639 |
+ |
break; |
640 |
+ |
} |
641 |
+ |
op = addarg(op, "-as 0"); |
642 |
+ |
d = ambval(); |
643 |
+ |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
644 |
+ |
op += strlen(op); |
645 |
+ |
op = addarg(op, "-lr 3 -lw .02"); |
646 |
|
if (vdef(RENDER)) |
647 |
|
op = addarg(op, vval(RENDER)); |
648 |
|
} |
649 |
|
|
650 |
|
|
651 |
< |
medqopts(ro) /* medium quality rendering options */ |
652 |
< |
char *ro; |
651 |
> |
medqopts(op) /* medium quality rendering options */ |
652 |
> |
register char *op; |
653 |
|
{ |
654 |
< |
register char *op = ro; |
654 |
> |
double d, org[3], siz[3]; |
655 |
|
|
656 |
|
*op = '\0'; |
657 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
658 |
+ |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
659 |
+ |
badvalue(ZONE); |
660 |
+ |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
661 |
+ |
getoctcube(org, &d); |
662 |
+ |
d *= 3./(siz[0]+siz[1]+siz[2]); |
663 |
+ |
switch (vscale(DETAIL)) { |
664 |
+ |
case LOW: |
665 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8"); |
666 |
+ |
op = addarg(op, "-dp 64"); |
667 |
+ |
sprintf(op, " -ar %d", (int)(8*d)); |
668 |
+ |
op += strlen(op); |
669 |
+ |
break; |
670 |
+ |
case MEDIUM: |
671 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6"); |
672 |
+ |
op = addarg(op, "-dp 128"); |
673 |
+ |
sprintf(op, " -ar %d", (int)(16*d)); |
674 |
+ |
op += strlen(op); |
675 |
+ |
break; |
676 |
+ |
case HIGH: |
677 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4"); |
678 |
+ |
op = addarg(op, "-dp 256"); |
679 |
+ |
sprintf(op, " -ar %d", (int)(32*d)); |
680 |
+ |
op += strlen(op); |
681 |
+ |
break; |
682 |
+ |
} |
683 |
+ |
op = addarg(op, "-pt .08"); |
684 |
+ |
if (vbool(PENUMBRAS)) |
685 |
+ |
op = addarg(op, "-ds .2 -dj .35"); |
686 |
+ |
else |
687 |
+ |
op = addarg(op, "-ds .3"); |
688 |
+ |
op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15"); |
689 |
+ |
if (overture = vint(INDIRECT)) { |
690 |
+ |
sprintf(op, " -ab %d", overture); |
691 |
+ |
op += strlen(op); |
692 |
+ |
} |
693 |
+ |
if (vdef(AMBFILE)) { |
694 |
+ |
sprintf(op, " -af %s", vval(AMBFILE)); |
695 |
+ |
op += strlen(op); |
696 |
+ |
} else |
697 |
+ |
overture = 0; |
698 |
+ |
switch (vscale(VARIABILITY)) { |
699 |
+ |
case LOW: |
700 |
+ |
op = addarg(op, "-aa .25 -ad 128 -as 0"); |
701 |
+ |
break; |
702 |
+ |
case MEDIUM: |
703 |
+ |
op = addarg(op, "-aa .2 -ad 300 -as 64"); |
704 |
+ |
break; |
705 |
+ |
case HIGH: |
706 |
+ |
op = addarg(op, "-aa .15 -ad 500 -as 128"); |
707 |
+ |
break; |
708 |
+ |
} |
709 |
+ |
d = ambval(); |
710 |
+ |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
711 |
+ |
op += strlen(op); |
712 |
+ |
op = addarg(op, "-lr 6 -lw .002"); |
713 |
|
if (vdef(RENDER)) |
714 |
|
op = addarg(op, vval(RENDER)); |
715 |
|
} |
716 |
|
|
717 |
|
|
718 |
< |
hiqopts(ro) /* high quality rendering options */ |
719 |
< |
char *ro; |
718 |
> |
hiqopts(op) /* high quality rendering options */ |
719 |
> |
register char *op; |
720 |
|
{ |
721 |
< |
register char *op = ro; |
721 |
> |
double d, org[3], siz[3]; |
722 |
|
|
723 |
|
*op = '\0'; |
724 |
+ |
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0], |
725 |
+ |
&siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) |
726 |
+ |
badvalue(ZONE); |
727 |
+ |
siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2]; |
728 |
+ |
getoctcube(org, &d); |
729 |
+ |
d *= 3./(siz[0]+siz[1]+siz[2]); |
730 |
+ |
switch (vscale(DETAIL)) { |
731 |
+ |
case LOW: |
732 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8"); |
733 |
+ |
op = addarg(op, "-dp 256"); |
734 |
+ |
sprintf(op, " -ar %d", (int)(16*d)); |
735 |
+ |
op += strlen(op); |
736 |
+ |
break; |
737 |
+ |
case MEDIUM: |
738 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5"); |
739 |
+ |
op = addarg(op, "-dp 512"); |
740 |
+ |
sprintf(op, " -ar %d", (int)(32*d)); |
741 |
+ |
op += strlen(op); |
742 |
+ |
break; |
743 |
+ |
case HIGH: |
744 |
+ |
op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3"); |
745 |
+ |
op = addarg(op, "-dp 1024"); |
746 |
+ |
sprintf(op, " -ar %d", (int)(64*d)); |
747 |
+ |
op += strlen(op); |
748 |
+ |
break; |
749 |
+ |
} |
750 |
+ |
op = addarg(op, "-pt .04"); |
751 |
+ |
if (vbool(PENUMBRAS)) |
752 |
+ |
op = addarg(op, "-ds .1 -dj .7"); |
753 |
+ |
else |
754 |
+ |
op = addarg(op, "-ds .2"); |
755 |
+ |
op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03"); |
756 |
+ |
sprintf(op, " -ab %d", overture=vint(INDIRECT)+1); |
757 |
+ |
op += strlen(op); |
758 |
+ |
if (vdef(AMBFILE)) { |
759 |
+ |
sprintf(op, " -af %s", vval(AMBFILE)); |
760 |
+ |
op += strlen(op); |
761 |
+ |
} else |
762 |
+ |
overture = 0; |
763 |
+ |
switch (vscale(VARIABILITY)) { |
764 |
+ |
case LOW: |
765 |
+ |
op = addarg(op, "-aa .15 -ad 200 -as 0"); |
766 |
+ |
break; |
767 |
+ |
case MEDIUM: |
768 |
+ |
op = addarg(op, "-aa .125 -ad 512 -as 128"); |
769 |
+ |
break; |
770 |
+ |
case HIGH: |
771 |
+ |
op = addarg(op, "-aa .08 -ad 850 -as 256"); |
772 |
+ |
break; |
773 |
+ |
} |
774 |
+ |
d = ambval(); |
775 |
+ |
sprintf(op, " -av %.2g %.2g %.2g", d, d, d); |
776 |
+ |
op += strlen(op); |
777 |
+ |
op = addarg(op, "-lr 12 -lw .0005"); |
778 |
|
if (vdef(RENDER)) |
779 |
|
op = addarg(op, vval(RENDER)); |
780 |
|
} |
784 |
|
char *ro; |
785 |
|
{ |
786 |
|
int fd, n; |
787 |
+ |
register char *cp; |
788 |
|
|
789 |
|
n = strlen(ro); |
790 |
|
if (n < 2) |
791 |
|
return; |
792 |
|
if (vdef(OPTFILE)) { |
793 |
< |
if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
794 |
< |
perror(vval(OPTFILE)); |
795 |
< |
exit(1); |
796 |
< |
} |
797 |
< |
if (write(fd, ro+1, n-1) != n-1) { |
798 |
< |
perror(vval(OPTFILE)); |
799 |
< |
exit(1); |
800 |
< |
} |
801 |
< |
write(fd, "\n", 1); |
802 |
< |
close(fd); |
601 |
< |
ro[0] = ' '; |
602 |
< |
ro[1] = '^'; |
603 |
< |
strcpy(ro+2, vval(OPTFILE)); |
793 |
> |
for (cp = ro; cp[1]; cp++) |
794 |
> |
if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3])) |
795 |
> |
*cp = '\n'; |
796 |
> |
else |
797 |
> |
*cp = cp[1]; |
798 |
> |
*cp = '\n'; |
799 |
> |
fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666); |
800 |
> |
if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0) |
801 |
> |
syserr(vval(OPTFILE)); |
802 |
> |
sprintf(ro, " \"^%s\"", vval(OPTFILE)); |
803 |
|
} |
804 |
|
#ifdef MSDOS |
805 |
|
else if (n > 50) { |
806 |
< |
register char *evp = bmalloc(n+6); |
608 |
< |
if (evp == NULL) { |
609 |
< |
perror(progname); |
610 |
< |
exit(1); |
611 |
< |
} |
612 |
< |
strcpy(evp, "ROPT="); |
613 |
< |
strcat(evp, ro); |
614 |
< |
putenv(evp); |
806 |
> |
setenv("ROPT", ro+1); |
807 |
|
strcpy(ro, " $ROPT"); |
808 |
|
} |
809 |
|
#endif |
841 |
|
specview(vs) /* get proper view spec from vs */ |
842 |
|
register char *vs; |
843 |
|
{ |
844 |
+ |
static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0", |
845 |
+ |
"-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"}; |
846 |
|
static char viewopts[128]; |
847 |
|
register char *cp; |
848 |
< |
int xpos, ypos, zpos, viewtype; |
849 |
< |
int exterior; |
848 |
> |
int xpos, ypos, zpos, viewtype, upax; |
849 |
> |
register int i; |
850 |
|
double cent[3], dim[3], mult, d; |
851 |
|
|
852 |
|
if (vs == NULL || *vs == '-') |
853 |
|
return(vs); |
854 |
+ |
upax = 0; /* get the up vector */ |
855 |
+ |
if (vdef(UP)) { |
856 |
+ |
if (vval(UP)[0] == '-' || vval(UP)[0] == '+') |
857 |
+ |
upax = 1-'X'+UPPER(vval(UP)[1]); |
858 |
+ |
else |
859 |
+ |
upax = 1-'X'+vlet(UP); |
860 |
+ |
if (upax < 1 | upax > 3) |
861 |
+ |
badvalue(UP); |
862 |
+ |
if (vval(UP)[0] == '-') |
863 |
+ |
upax = -upax; |
864 |
+ |
} |
865 |
|
/* check standard view names */ |
866 |
|
xpos = ypos = zpos = 0; |
662 |
– |
viewtype = 0; |
867 |
|
if (*vs == 'X') { |
868 |
|
xpos = 1; vs++; |
869 |
|
} else if (*vs == 'x') { |
879 |
|
} else if (*vs == 'z') { |
880 |
|
zpos = -1; vs++; |
881 |
|
} |
882 |
+ |
viewtype = 'v'; |
883 |
|
if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h') |
884 |
|
viewtype = *vs++; |
680 |
– |
else if (!*vs || isspace(*vs)) |
681 |
– |
viewtype = 'v'; |
885 |
|
cp = viewopts; |
886 |
< |
if (viewtype && (xpos|ypos|zpos)) { /* got standard view */ |
886 |
> |
if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */ |
887 |
|
*cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype; |
888 |
|
if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", |
889 |
|
¢[0], &dim[0], ¢[1], &dim[1], |
890 |
< |
¢[2], &dim[2]) != 6) { |
891 |
< |
fprintf(stderr, "%s: bad zone specification\n", |
892 |
< |
progname); |
893 |
< |
exit(1); |
890 |
> |
¢[2], &dim[2]) != 6) |
891 |
> |
badvalue(ZONE); |
892 |
> |
for (i = 0; i < 3; i++) { |
893 |
> |
dim[i] -= cent[i]; |
894 |
> |
cent[i] += .5*dim[i]; |
895 |
|
} |
896 |
< |
dim[0] -= cent[0]; |
693 |
< |
dim[1] -= cent[1]; |
694 |
< |
dim[2] -= cent[2]; |
695 |
< |
exterior = vlet(ZONE) == 'E'; |
696 |
< |
mult = exterior ? 2. : .45 ; |
896 |
> |
mult = vlet(ZONE)=='E' ? 2. : .45 ; |
897 |
|
sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g", |
898 |
|
cent[0]+xpos*mult*dim[0], |
899 |
|
cent[1]+ypos*mult*dim[1], |
900 |
|
cent[2]+zpos*mult*dim[2], |
901 |
|
-xpos*dim[0], -ypos*dim[1], -zpos*dim[2]); |
902 |
|
cp += strlen(cp); |
903 |
< |
switch (vlet(UP)) { |
904 |
< |
case 'Z': |
905 |
< |
if (xpos|ypos) { |
906 |
< |
cp = addarg(cp, "-vu 0 0 1"); |
907 |
< |
break; |
908 |
< |
} |
909 |
< |
/* fall through */ |
710 |
< |
case 'Y': |
711 |
< |
if (xpos|zpos) { |
712 |
< |
cp = addarg(cp, "-vu 0 1 0"); |
713 |
< |
break; |
714 |
< |
} |
715 |
< |
/* fall through */ |
716 |
< |
case 'X': |
717 |
< |
if (ypos|zpos) |
718 |
< |
cp = addarg(cp, "-vu 1 0 0"); |
719 |
< |
else |
720 |
< |
cp = addarg(cp, "-vu 0 0 1"); |
903 |
> |
/* redirect up axis if necessary */ |
904 |
> |
switch (upax) { |
905 |
> |
case 3: /* plus or minus Z axis */ |
906 |
> |
case -3: |
907 |
> |
case 0: |
908 |
> |
if (!(xpos|ypos)) |
909 |
> |
upax = 2; |
910 |
|
break; |
911 |
< |
default: |
912 |
< |
fprintf(stderr, "%s: illegal value for variable '%s'\n", |
913 |
< |
progname, vnam(UP)); |
914 |
< |
exit(1); |
911 |
> |
case 2: /* plus or minus Y axis */ |
912 |
> |
case -2: |
913 |
> |
if (!(xpos|zpos)) |
914 |
> |
upax = 1; |
915 |
> |
break; |
916 |
> |
case 1: /* plus or minus X axis */ |
917 |
> |
case -1: |
918 |
> |
if (!(ypos|zpos)) |
919 |
> |
upax = 3; |
920 |
> |
break; |
921 |
|
} |
922 |
+ |
cp = addarg(cp, vup[upax+3]); |
923 |
|
switch (viewtype) { |
924 |
|
case 'v': |
925 |
|
cp = addarg(cp, "-vh 45 -vv 45"); |
934 |
|
cp = addarg(cp, "-vh 180 -vv 180"); |
935 |
|
break; |
936 |
|
} |
937 |
< |
} else |
938 |
< |
while (*vs && !isspace(*vs)) /* else skip id */ |
939 |
< |
vs++; |
940 |
< |
/* append any additional options */ |
941 |
< |
while (isspace(*vs)) vs++; |
942 |
< |
strcpy(cp, vs); |
937 |
> |
} else { |
938 |
> |
while (!isspace(*vs)) /* else skip id */ |
939 |
> |
if (!*vs++) |
940 |
> |
return(NULL); |
941 |
> |
if (upax) { /* specify up vector */ |
942 |
> |
strcpy(cp, vup[upax+3]); |
943 |
> |
cp += strlen(cp); |
944 |
> |
} |
945 |
> |
} |
946 |
> |
strcpy(cp, vs); /* append any additional options */ |
947 |
> |
#ifdef MSDOS |
948 |
> |
if (strlen(viewopts) > 40) { |
949 |
> |
setenv("VIEW", viewopts); |
950 |
> |
return("$VIEW"); |
951 |
> |
} |
952 |
> |
#endif |
953 |
|
return(viewopts); |
954 |
|
} |
955 |
|
|
957 |
|
char * |
958 |
|
getview(n, vn) /* get view n, or NULL if none */ |
959 |
|
int n; |
960 |
< |
char *vn; |
960 |
> |
char *vn; /* returned view name */ |
961 |
|
{ |
962 |
< |
register char *mv; |
962 |
> |
register char *mv = NULL; |
963 |
|
|
964 |
< |
if (viewselect != NULL) { |
964 |
> |
if (viewselect != NULL) { /* command-line selected */ |
965 |
|
if (n) /* only do one */ |
966 |
|
return(NULL); |
967 |
|
if (viewselect[0] == '-') { /* already specified */ |
980 |
|
return(specview(mv)); |
981 |
|
return(specview(viewselect)); /* standard view? */ |
982 |
|
} |
983 |
< |
if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) { |
983 |
> |
mv = nvalue(vv+VIEW, n); /* use view n */ |
984 |
> |
if (vn != NULL & mv != NULL) { |
985 |
|
if (*mv != '-') |
986 |
|
while (*mv && !isspace(*mv)) |
987 |
|
*vn++ = *mv++; |
988 |
|
*vn = '\0'; |
989 |
|
} |
990 |
< |
return(specview(nvalue(vv+VIEW, n))); /* use view n */ |
990 |
> |
return(specview(mv)); |
991 |
|
} |
992 |
|
|
993 |
|
|
1000 |
|
if (rvdevice != NULL) |
1001 |
|
sprintf(combuf+strlen(combuf), "-o %s ", rvdevice); |
1002 |
|
strcat(combuf, vval(OCTREE)); |
1003 |
< |
if (!silent) { /* echo it */ |
797 |
< |
printf("\t%s\n", combuf); |
798 |
< |
fflush(stdout); |
799 |
< |
} |
800 |
< |
if (noaction) |
801 |
< |
return; |
802 |
< |
if (system(combuf)) { /* run it */ |
1003 |
> |
if (runcom(combuf)) { /* run it */ |
1004 |
|
fprintf(stderr, "%s: error running rview\n", progname); |
1005 |
|
exit(1); |
1006 |
|
} |
1010 |
|
rpict(opts) /* run rpict and pfilt for each view */ |
1011 |
|
char *opts; |
1012 |
|
{ |
1013 |
< |
char combuf[512]; |
1014 |
< |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32]; |
1015 |
< |
char pfopts[64]; |
1013 |
> |
char combuf[1024]; |
1014 |
> |
char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32]; |
1015 |
> |
char pfopts[128]; |
1016 |
|
char vs[32], *vw; |
1017 |
|
int vn, mult; |
1018 |
|
/* get pfilt options */ |
1030 |
|
else if (n) { |
1031 |
|
if (n == 1) yres = xres; |
1032 |
|
sprintf(res, "-x %d -y %d", mult*xres, mult*yres); |
1033 |
< |
} else { |
1034 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
834 |
< |
progname, vnam(RESOLUTION)); |
835 |
< |
exit(1); |
836 |
< |
} |
1033 |
> |
} else |
1034 |
> |
badvalue(RESOLUTION); |
1035 |
|
} |
1036 |
|
rep[0] = '\0'; |
1037 |
|
if (vdef(REPORT)) { |
1042 |
|
sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile); |
1043 |
|
else if (n == 1) |
1044 |
|
sprintf(rep, " -t %d", (int)(minutes*60)); |
1045 |
< |
else { |
1046 |
< |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
849 |
< |
progname, vnam(REPORT)); |
850 |
< |
exit(1); |
851 |
< |
} |
1045 |
> |
else |
1046 |
> |
badvalue(REPORT); |
1047 |
|
} |
1048 |
|
/* do each view */ |
1049 |
|
vn = 0; |
1064 |
|
sprintf(combuf, |
1065 |
|
"rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s", |
1066 |
|
rep, vw, opts, |
1067 |
< |
vval(OCTREE), rawfile); |
1068 |
< |
if (!silent) { |
874 |
< |
printf("\t%s\n", combuf); |
875 |
< |
fflush(stdout); |
876 |
< |
} |
877 |
< |
if (!noaction && system(combuf)) { |
1067 |
> |
vval(OCTREE), overfile); |
1068 |
> |
if (runcom(combuf)) { |
1069 |
|
fprintf(stderr, |
1070 |
< |
"%s: error in overture for view %s\n\t%s removed\n", |
1071 |
< |
progname, vs, rawfile); |
881 |
< |
unlink(rawfile); |
1070 |
> |
"%s: error in overture for view %s\n", |
1071 |
> |
progname, vs); |
1072 |
|
exit(1); |
1073 |
|
} |
1074 |
+ |
#ifdef NIX |
1075 |
+ |
rmfile(overfile); |
1076 |
+ |
#endif |
1077 |
|
} |
1078 |
|
sprintf(combuf, "rpict%s %s %s%s %s > %s", |
1079 |
|
rep, vw, res, opts, |
1080 |
|
vval(OCTREE), rawfile); |
1081 |
|
} |
1082 |
< |
if (!silent) { /* echo rpict command */ |
890 |
< |
printf("\t%s\n", combuf); |
891 |
< |
fflush(stdout); |
892 |
< |
} |
893 |
< |
if (!noaction && system(combuf)) { /* run rpict */ |
1082 |
> |
if (runcom(combuf)) { /* run rpict */ |
1083 |
|
fprintf(stderr, "%s: error rendering view %s\n", |
1084 |
|
progname, vs); |
1085 |
|
exit(1); |
1091 |
|
else |
1092 |
|
sprintf(combuf, "pfilt%s %s > %s", pfopts, |
1093 |
|
rawfile, picfile); |
1094 |
< |
if (!silent) { /* echo pfilt command */ |
906 |
< |
printf("\t%s\n", combuf); |
907 |
< |
fflush(stdout); |
908 |
< |
} |
909 |
< |
if (!noaction && system(combuf)) { /* run pfilt */ |
1094 |
> |
if (runcom(combuf)) { /* run pfilt */ |
1095 |
|
fprintf(stderr, |
1096 |
|
"%s: error filtering view %s\n\t%s removed\n", |
1097 |
|
progname, vs, picfile); |
1099 |
|
exit(1); |
1100 |
|
} |
1101 |
|
/* remove raw file */ |
1102 |
< |
if (!silent) |
1102 |
> |
rmfile(rawfile); |
1103 |
> |
} |
1104 |
> |
} |
1105 |
> |
|
1106 |
> |
|
1107 |
> |
runcom(cs) /* run command */ |
1108 |
> |
char *cs; |
1109 |
> |
{ |
1110 |
> |
if (!silent) /* echo it */ |
1111 |
> |
printf("\t%s\n", cs); |
1112 |
> |
if (noaction) |
1113 |
> |
return(0); |
1114 |
> |
fflush(stdout); /* flush output and pass to shell */ |
1115 |
> |
return(system(cs)); |
1116 |
> |
} |
1117 |
> |
|
1118 |
> |
|
1119 |
> |
rmfile(fn) /* remove a file */ |
1120 |
> |
char *fn; |
1121 |
> |
{ |
1122 |
> |
if (!silent) |
1123 |
|
#ifdef MSDOS |
1124 |
< |
printf("\tdel %s\n", rawfile); |
1124 |
> |
printf("\tdel %s\n", fn); |
1125 |
|
#else |
1126 |
< |
printf("\trm %s\n", rawfile); |
1126 |
> |
printf("\trm -f %s\n", fn); |
1127 |
|
#endif |
1128 |
< |
if (!noaction) |
1129 |
< |
unlink(rawfile); |
1128 |
> |
if (noaction) |
1129 |
> |
return(0); |
1130 |
> |
return(unlink(fn)); |
1131 |
> |
} |
1132 |
> |
|
1133 |
> |
|
1134 |
> |
#ifdef MSDOS |
1135 |
> |
setenv(vname, value) /* set an environment variable */ |
1136 |
> |
char *vname, *value; |
1137 |
> |
{ |
1138 |
> |
register char *evp; |
1139 |
> |
|
1140 |
> |
evp = bmalloc(strlen(vname)+strlen(value)+2); |
1141 |
> |
if (evp == NULL) |
1142 |
> |
syserr(progname); |
1143 |
> |
sprintf(evp, "%s=%s", vname, value); |
1144 |
> |
if (putenv(evp) != 0) { |
1145 |
> |
fprintf(stderr, "%s: out of environment space\n", progname); |
1146 |
> |
exit(1); |
1147 |
|
} |
1148 |
+ |
if (!silent) |
1149 |
+ |
printf("set %s\n", evp); |
1150 |
+ |
} |
1151 |
+ |
#endif |
1152 |
+ |
|
1153 |
+ |
|
1154 |
+ |
badvalue(vc) /* report bad variable value and exit */ |
1155 |
+ |
int vc; |
1156 |
+ |
{ |
1157 |
+ |
fprintf(stderr, "%s: bad value for variable '%s'\n", |
1158 |
+ |
progname, vnam(vc)); |
1159 |
+ |
exit(1); |
1160 |
+ |
} |
1161 |
+ |
|
1162 |
+ |
|
1163 |
+ |
syserr(s) /* report a system error and exit */ |
1164 |
+ |
char *s; |
1165 |
+ |
{ |
1166 |
+ |
perror(s); |
1167 |
+ |
exit(1); |
1168 |
|
} |