ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
Revision: 2.7
Committed: Tue Apr 6 17:21:04 1993 UTC (30 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.6: +16 -7 lines
Log Message:
remove outdated ambient file before rview run as well as rpict

File Contents

# Content
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();
25
26 /* variables */
27 #define OBJECT 0 /* object files */
28 #define SCENE 1 /* scene files */
29 #define MATERIAL 2 /* material files */
30 #define RENDER 3 /* rendering options */
31 #define OCONV 4 /* oconv options */
32 #define PFILT 5 /* pfilt options */
33 #define VIEW 6 /* view(s) for picture(s) */
34 #define ZONE 7 /* simulation zone */
35 #define QUALITY 8 /* desired rendering quality */
36 #define OCTREE 9 /* octree file name */
37 #define PICTURE 10 /* picture file name */
38 #define AMBFILE 11 /* ambient file name */
39 #define OPTFILE 12 /* rendering options file */
40 #define EXPOSURE 13 /* picture exposure setting */
41 #define RESOLUTION 14 /* maximum picture resolution */
42 #define UP 15 /* view up (X, Y or Z) */
43 #define INDIRECT 16 /* indirection in lighting */
44 #define DETAIL 17 /* level of scene detail */
45 #define PENUMBRAS 18 /* shadow penumbras are desired */
46 #define VARIABILITY 19 /* level of light variability */
47 #define REPORT 20 /* report frequency and errfile */
48 /* total number of variables */
49 #define NVARS 21
50
51 VARIABLE vv[NVARS] = { /* variable-value pairs */
52 {"objects", 3, 0, NULL, catvalues},
53 {"scene", 3, 0, NULL, catvalues},
54 {"materials", 3, 0, NULL, catvalues},
55 {"render", 3, 0, NULL, catvalues},
56 {"oconv", 3, 0, NULL, catvalues},
57 {"pfilt", 2, 0, NULL, catvalues},
58 {"view", 2, 0, NULL, NULL},
59 {"ZONE", 2, 0, NULL, onevalue},
60 {"QUALITY", 3, 0, NULL, onevalue},
61 {"OCTREE", 3, 0, NULL, onevalue},
62 {"PICTURE", 3, 0, NULL, onevalue},
63 {"AMBFILE", 3, 0, NULL, onevalue},
64 {"OPTFILE", 3, 0, NULL, onevalue},
65 {"EXPOSURE", 3, 0, NULL, onevalue},
66 {"RESOLUTION", 3, 0, NULL, onevalue},
67 {"UP", 2, 0, NULL, onevalue},
68 {"INDIRECT", 3, 0, NULL, onevalue},
69 {"DETAIL", 3, 0, NULL, onevalue},
70 {"PENUMBRAS", 3, 0, NULL, onevalue},
71 {"VARIABILITY", 3, 0, NULL, onevalue},
72 {"REPORT", 3, 0, NULL, onevalue},
73 };
74
75 VARIABLE *matchvar();
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) UPPER(vval(vc)[0])
86 #define vbool(vc) (vlet(vc)=='T')
87
88 #define HIGH 2
89 #define MEDIUM 1
90 #define LOW 0
91
92 int lowqopts(), medqopts(), hiqopts();
93 int (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
94
95 #define renderopts (*setqopts[vscale(QUALITY)])
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 long fdate(), time();
105
106 long scenedate; /* date of latest scene or object file */
107 long octreedate; /* date of octree */
108
109 int explicate = 0; /* explicate variables */
110 int silent = 0; /* do work silently */
111 int noaction = 0; /* don't do anything */
112 char *rvdevice = NULL; /* rview output device */
113 char *viewselect = NULL; /* specific view only */
114
115 int overture = 0; /* overture calculation needed */
116
117 char *progname; /* global argv[0] */
118
119 char radname[MAXPATH]; /* root Radiance file name */
120
121
122 main(argc, argv)
123 int argc;
124 char *argv[];
125 {
126 char ropts[512];
127 int i;
128
129 progname = argv[0];
130 /* get options */
131 for (i = 1; i < argc && argv[i][0] == '-'; i++)
132 switch (argv[i][1]) {
133 case 's':
134 silent++;
135 break;
136 case 'n':
137 noaction++;
138 break;
139 case 'e':
140 explicate++;
141 break;
142 case 'o':
143 rvdevice = argv[++i];
144 break;
145 case 'v':
146 viewselect = argv[++i];
147 break;
148 default:
149 goto userr;
150 }
151 if (i >= argc)
152 goto userr;
153 /* assign Radiance root file name */
154 rootname(radname, argv[i]);
155 /* load variable values */
156 load(argv[i]);
157 /* get any additional assignments */
158 for (i++; i < argc; i++)
159 setvariable(argv[i]);
160 /* check assignments */
161 checkvalues();
162 /* check files and dates */
163 checkfiles();
164 /* set default values as necessary */
165 setdefaults();
166 /* print all values if requested */
167 if (explicate)
168 printvals();
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)
177 rview(ropts);
178 else
179 rpict(ropts);
180 exit(0);
181 userr:
182 fprintf(stderr,
183 "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
184 progname);
185 exit(1);
186 }
187
188
189 rootname(rn, fn) /* remove tail from end of fn */
190 register char *rn, *fn;
191 {
192 char *tp, *dp;
193
194 for (tp = NULL, dp = rn; *rn = *fn++; rn++)
195 if (ISDIRSEP(*rn))
196 dp = rn;
197 else if (*rn == '.')
198 tp = rn;
199 if (tp != NULL && tp > dp)
200 *tp = '\0';
201 }
202
203
204 load(rfname) /* load Radiance simulation file */
205 char *rfname;
206 {
207 FILE *fp;
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 syserr(rfname);
215 while (fgetline(buf, sizeof(buf), fp) != NULL) {
216 for (cp = buf; *cp; cp++) {
217 switch (*cp) {
218 case '\\':
219 case '\n':
220 *cp = ' ';
221 continue;
222 case '#':
223 *cp = '\0';
224 break;
225 default:
226 continue;
227 }
228 break;
229 }
230 setvariable(buf);
231 }
232 fclose(fp);
233 }
234
235
236 setvariable(ass) /* assign variable according to string */
237 register char *ass;
238 {
239 char varname[32];
240 register char *cp;
241 register VARIABLE *vp;
242 register int i;
243 int n;
244
245 while (isspace(*ass)) /* skip leading space */
246 ass++;
247 cp = varname; /* extract name */
248 while (cp < varname+sizeof(varname)-1
249 && *ass && !isspace(*ass) && *ass != '=')
250 *cp++ = *ass++;
251 *cp = '\0';
252 if (!varname[0])
253 return; /* no variable name! */
254 /* trim value */
255 while (isspace(*ass) || *ass == '=')
256 ass++;
257 cp = ass + strlen(ass);
258 do
259 *cp-- = '\0';
260 while (cp >= ass && isspace(*cp));
261 n = cp - ass + 1;
262 if (!n) {
263 fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
264 progname, varname);
265 return;
266 }
267 /* match variable from list */
268 vp = matchvar(varname);
269 if (vp == NULL) {
270 fprintf(stderr, "%s: unknown variable '%s'\n",
271 progname, varname);
272 exit(1);
273 }
274 /* assign new value */
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 }
289
290
291 VARIABLE *
292 matchvar(nam) /* match a variable by its name */
293 char *nam;
294 {
295 int n = strlen(nam);
296 register int i;
297
298 for (i = 0; i < NVARS; i++)
299 if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
300 return(vv+i);
301 return(NULL);
302 }
303
304
305 char *
306 nvalue(vp, n) /* return nth variable value */
307 VARIABLE *vp;
308 register int n;
309 {
310 register char *cp;
311
312 if (vp == NULL || n < 0 || n >= vp->nass)
313 return(NULL);
314 cp = vp->value;
315 while (n--)
316 while (*cp++)
317 ;
318 return(cp);
319 }
320
321
322 int
323 vscale(vc) /* return scale for variable vc */
324 int vc;
325 {
326 switch(vlet(vc)) {
327 case 'H':
328 return(HIGH);
329 case 'M':
330 return(MEDIUM);
331 case 'L':
332 return(LOW);
333 }
334 badvalue(vc);
335 }
336
337
338 checkvalues() /* check assignments */
339 {
340 register int i;
341
342 for (i = 0; i < NVARS; i++)
343 if (vv[i].fixval != NULL)
344 (*vv[i].fixval)(vv+i);
345 }
346
347
348 onevalue(vp) /* only one assignment for this variable */
349 register VARIABLE *vp;
350 {
351 if (vp->nass < 2)
352 return;
353 fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
354 progname, vp->name);
355 do
356 vp->value += strlen(vp->value)+1;
357 while (--vp->nass > 1);
358 }
359
360
361 catvalues(vp) /* concatenate variable values */
362 register VARIABLE *vp;
363 {
364 register char *cp;
365
366 if (vp->nass < 2)
367 return;
368 for (cp = vp->value; vp->nass > 1; vp->nass--) {
369 while (*cp)
370 cp++;
371 *cp++ = ' ';
372 }
373 }
374
375
376 long
377 checklast(fnames) /* check files and find most recent */
378 register char *fnames;
379 {
380 char thisfile[MAXPATH];
381 long thisdate, lastdate = -1;
382 register char *cp;
383
384 while (*fnames) {
385 while (isspace(*fnames)) fnames++;
386 cp = thisfile;
387 while (*fnames && !isspace(*fnames))
388 *cp++ = *fnames++;
389 *cp = '\0';
390 if ((thisdate = fdate(thisfile)) < 0)
391 syserr(thisfile);
392 if (thisdate > lastdate)
393 lastdate = thisdate;
394 }
395 return(lastdate);
396 }
397
398
399 checkfiles() /* check for existence and modified times */
400 {
401 char *cp;
402 long objdate;
403
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));
415 if (vdef(OBJECT)) {
416 objdate = checklast(vval(OBJECT));
417 if (objdate > scenedate)
418 scenedate = objdate;
419 }
420 }
421 if (octreedate < 0 & scenedate < 0) {
422 fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
423 vnam(OCTREE), vnam(SCENE));
424 exit(1);
425 }
426 }
427
428
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;
436
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 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 }
467 if (!vdef(INDIRECT)) {
468 vval(INDIRECT) = "0";
469 vdef(INDIRECT)++;
470 }
471 if (!vdef(QUALITY)) {
472 vval(QUALITY) = "L";
473 vdef(QUALITY)++;
474 }
475 if (!vdef(RESOLUTION)) {
476 vval(RESOLUTION) = "512";
477 vdef(RESOLUTION)++;
478 }
479 if (!vdef(PICTURE)) {
480 vval(PICTURE) = radname;
481 vdef(PICTURE)++;
482 }
483 if (!vdef(VIEW)) {
484 vval(VIEW) = "X";
485 vdef(VIEW)++;
486 }
487 if (!vdef(DETAIL)) {
488 vval(DETAIL) = "M";
489 vdef(DETAIL)++;
490 }
491 if (!vdef(PENUMBRAS)) {
492 vval(PENUMBRAS) = "F";
493 vdef(PENUMBRAS)++;
494 }
495 if (!vdef(VARIABILITY)) {
496 vval(VARIABILITY) = "L";
497 vdef(VARIABILITY)++;
498 }
499 }
500
501
502 printvals() /* print variable values */
503 {
504 register int i, j;
505
506 for (i = 0; i < NVARS; i++)
507 for (j = 0; j < vdef(i); j++)
508 printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
509 fflush(stdout);
510 }
511
512
513 oconv() /* run oconv if necessary */
514 {
515 char combuf[512], ocopts[64];
516
517 if (octreedate >= scenedate) /* check dates */
518 return;
519 /* build command */
520 oconvopts(ocopts);
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
538 char *
539 addarg(op, arg) /* add argument and advance pointer */
540 register char *op, *arg;
541 {
542 *op = ' ';
543 while (*++op = *arg++)
544 ;
545 return(op);
546 }
547
548
549 oconvopts(oo) /* get oconv options */
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 checkambfile() /* check date on ambient file */
561 {
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(op) /* medium quality rendering options */
652 register char *op;
653 {
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(op) /* high quality rendering options */
719 register char *op;
720 {
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 }
781
782
783 xferopts(ro) /* transfer options if indicated */
784 char *ro;
785 {
786 int fd, n;
787
788 n = strlen(ro);
789 if (n < 2)
790 return;
791 if (vdef(OPTFILE)) {
792 if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1)
793 syserr(vval(OPTFILE));
794 if (write(fd, ro+1, n-1) != n-1)
795 syserr(vval(OPTFILE));
796 write(fd, "\n", 1);
797 close(fd);
798 sprintf(ro, " \"^%s\"", vval(OPTFILE));
799 }
800 #ifdef MSDOS
801 else if (n > 50) {
802 register char *evp = bmalloc(n+6);
803 if (evp == NULL)
804 syserr(progname);
805 strcpy(evp, "ROPT=");
806 strcat(evp, ro);
807 if (putenv(evp) != 0) {
808 fprintf(stderr, "%s: out of environment space\n",
809 progname);
810 exit(1);
811 }
812 strcpy(ro, " $ROPT");
813 }
814 #endif
815 }
816
817
818 pfiltopts(po) /* get pfilt options */
819 register char *po;
820 {
821 *po = '\0';
822 if (vdef(EXPOSURE)) {
823 po = addarg(po, "-1 -e");
824 po = addarg(po, vval(EXPOSURE));
825 }
826 if (vscale(QUALITY) == HIGH)
827 po = addarg(po, "-r .65");
828 if (vdef(PFILT))
829 po = addarg(po, vval(PFILT));
830 }
831
832
833 matchword(s1, s2) /* match white-delimited words */
834 register char *s1, *s2;
835 {
836 while (isspace(*s1)) s1++;
837 while (isspace(*s2)) s2++;
838 while (*s1 && !isspace(*s1))
839 if (*s1++ != *s2++)
840 return(0);
841 return(!*s2 || isspace(*s2));
842 }
843
844
845 char *
846 specview(vs) /* get proper view spec from vs */
847 register char *vs;
848 {
849 static char vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
850 "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
851 static char viewopts[128];
852 register char *cp;
853 int xpos, ypos, zpos, viewtype, upax;
854 register int i;
855 double cent[3], dim[3], mult, d;
856
857 if (vs == NULL || *vs == '-')
858 return(vs);
859 upax = 0; /* get the up vector */
860 if (vdef(UP)) {
861 if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
862 upax = 1-'X'+UPPER(vval(UP)[1]);
863 else
864 upax = 1-'X'+vlet(UP);
865 if (upax < 1 | upax > 3)
866 badvalue(UP);
867 if (vval(UP)[0] == '-')
868 upax = -upax;
869 }
870 /* check standard view names */
871 xpos = ypos = zpos = 0;
872 if (*vs == 'X') {
873 xpos = 1; vs++;
874 } else if (*vs == 'x') {
875 xpos = -1; vs++;
876 }
877 if (*vs == 'Y') {
878 ypos = 1; vs++;
879 } else if (*vs == 'y') {
880 ypos = -1; vs++;
881 }
882 if (*vs == 'Z') {
883 zpos = 1; vs++;
884 } else if (*vs == 'z') {
885 zpos = -1; vs++;
886 }
887 viewtype = 'v';
888 if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
889 viewtype = *vs++;
890 cp = viewopts;
891 if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) { /* got one! */
892 *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
893 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
894 &cent[0], &dim[0], &cent[1], &dim[1],
895 &cent[2], &dim[2]) != 6)
896 badvalue(ZONE);
897 for (i = 0; i < 3; i++) {
898 dim[i] -= cent[i];
899 cent[i] += .5*dim[i];
900 }
901 mult = vlet(ZONE)=='E' ? 2. : .45 ;
902 sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
903 cent[0]+xpos*mult*dim[0],
904 cent[1]+ypos*mult*dim[1],
905 cent[2]+zpos*mult*dim[2],
906 -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
907 cp += strlen(cp);
908 /* redirect up axis if necessary */
909 switch (upax) {
910 case 3: /* plus or minus Z axis */
911 case -3:
912 case 0:
913 if (!(xpos|ypos))
914 upax = 2;
915 break;
916 case 2: /* plus or minus Y axis */
917 case -2:
918 if (!(xpos|zpos))
919 upax = 1;
920 break;
921 case 1: /* plus or minus X axis */
922 case -1:
923 if (!(ypos|zpos))
924 upax = 3;
925 break;
926 }
927 cp = addarg(cp, vup[upax+3]);
928 switch (viewtype) {
929 case 'v':
930 cp = addarg(cp, "-vh 45 -vv 45");
931 break;
932 case 'l':
933 d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
934 sprintf(cp, " -vh %.2g -vv %.2g", d, d);
935 cp += strlen(cp);
936 break;
937 case 'a':
938 case 'h':
939 cp = addarg(cp, "-vh 180 -vv 180");
940 break;
941 }
942 } else {
943 while (!isspace(*vs)) /* else skip id */
944 if (!*vs++)
945 return(NULL);
946 if (upax) { /* specify up vector */
947 strcpy(cp, vup[upax+3]);
948 cp += strlen(cp);
949 }
950 }
951 /* append any additional options */
952 strcpy(cp, vs);
953 return(viewopts);
954 }
955
956
957 char *
958 getview(n, vn) /* get view n, or NULL if none */
959 int n;
960 char *vn;
961 {
962 register char *mv;
963
964 if (viewselect != NULL) {
965 if (n) /* only do one */
966 return(NULL);
967 if (viewselect[0] == '-') { /* already specified */
968 if (vn != NULL) *vn = '\0';
969 return(viewselect);
970 }
971 if (vn != NULL) {
972 for (mv = viewselect; *mv && !isspace(*mv);
973 *vn++ = *mv++)
974 ;
975 *vn = '\0';
976 }
977 /* check list */
978 while ((mv = nvalue(vv+VIEW, n++)) != NULL)
979 if (matchword(viewselect, mv))
980 return(specview(mv));
981 return(specview(viewselect)); /* standard view? */
982 }
983 if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
984 if (*mv != '-')
985 while (*mv && !isspace(*mv))
986 *vn++ = *mv++;
987 *vn = '\0';
988 }
989 return(specview(nvalue(vv+VIEW, n))); /* use view n */
990 }
991
992
993 rview(opts) /* run rview with first view */
994 char *opts;
995 {
996 char combuf[512];
997 /* build command */
998 sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
999 if (rvdevice != NULL)
1000 sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1001 strcat(combuf, vval(OCTREE));
1002 if (runcom(combuf)) { /* run it */
1003 fprintf(stderr, "%s: error running rview\n", progname);
1004 exit(1);
1005 }
1006 }
1007
1008
1009 rpict(opts) /* run rpict and pfilt for each view */
1010 char *opts;
1011 {
1012 char combuf[1024];
1013 char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1014 char pfopts[128];
1015 char vs[32], *vw;
1016 int vn, mult;
1017 /* get pfilt options */
1018 pfiltopts(pfopts);
1019 /* get resolution, reporting */
1020 mult = vscale(QUALITY)+1;
1021 {
1022 int xres, yres;
1023 double aspect;
1024 int n;
1025 n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
1026 if (n == 3)
1027 sprintf(res, "-x %d -y %d -pa %.3f",
1028 mult*xres, mult*yres, aspect);
1029 else if (n) {
1030 if (n == 1) yres = xres;
1031 sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1032 } else
1033 badvalue(RESOLUTION);
1034 }
1035 rep[0] = '\0';
1036 if (vdef(REPORT)) {
1037 double minutes;
1038 int n;
1039 n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
1040 if (n == 2)
1041 sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1042 else if (n == 1)
1043 sprintf(rep, " -t %d", (int)(minutes*60));
1044 else
1045 badvalue(REPORT);
1046 }
1047 /* do each view */
1048 vn = 0;
1049 while ((vw = getview(vn++, vs)) != NULL) {
1050 if (!vs[0])
1051 sprintf(vs, "%d", vn);
1052 sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1053 /* check date on picture */
1054 if (fdate(picfile) > octreedate)
1055 continue;
1056 /* build rpict command */
1057 sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1058 if (fdate(rawfile) > octreedate) /* recover */
1059 sprintf(combuf, "rpict%s%s -ro %s %s",
1060 rep, opts, rawfile, vval(OCTREE));
1061 else {
1062 if (overture) { /* run overture calculation */
1063 sprintf(combuf,
1064 "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1065 rep, vw, opts,
1066 vval(OCTREE), overfile);
1067 if (runcom(combuf)) {
1068 fprintf(stderr,
1069 "%s: error in overture for view %s\n",
1070 progname, vs);
1071 exit(1);
1072 }
1073 #ifdef NIX
1074 rmfile(overfile);
1075 #endif
1076 }
1077 sprintf(combuf, "rpict%s %s %s%s %s > %s",
1078 rep, vw, res, opts,
1079 vval(OCTREE), rawfile);
1080 }
1081 if (runcom(combuf)) { /* run rpict */
1082 fprintf(stderr, "%s: error rendering view %s\n",
1083 progname, vs);
1084 exit(1);
1085 }
1086 /* build pfilt command */
1087 if (mult > 1)
1088 sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
1089 pfopts, mult, mult, rawfile, picfile);
1090 else
1091 sprintf(combuf, "pfilt%s %s > %s", pfopts,
1092 rawfile, picfile);
1093 if (runcom(combuf)) { /* run pfilt */
1094 fprintf(stderr,
1095 "%s: error filtering view %s\n\t%s removed\n",
1096 progname, vs, picfile);
1097 unlink(picfile);
1098 exit(1);
1099 }
1100 /* remove raw file */
1101 rmfile(rawfile);
1102 }
1103 }
1104
1105
1106 runcom(cs) /* run command */
1107 char *cs;
1108 {
1109 if (!silent) /* echo it */
1110 printf("\t%s\n", cs);
1111 if (noaction)
1112 return(0);
1113 fflush(stdout); /* flush output and pass to shell */
1114 return(system(cs));
1115 }
1116
1117
1118 rmfile(fn) /* remove a file */
1119 char *fn;
1120 {
1121 if (!silent)
1122 #ifdef MSDOS
1123 printf("\tdel %s\n", fn);
1124 #else
1125 printf("\trm -f %s\n", fn);
1126 #endif
1127 if (noaction)
1128 return(0);
1129 return(unlink(fn));
1130 }
1131
1132
1133 badvalue(vc) /* report bad variable value and exit */
1134 int vc;
1135 {
1136 fprintf(stderr, "%s: bad value for variable '%s'\n",
1137 progname, vnam(vc));
1138 exit(1);
1139 }
1140
1141
1142 syserr(s) /* report a system error and exit */
1143 char *s;
1144 {
1145 perror(s);
1146 exit(1);
1147 }