ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
Revision: 2.1
Committed: Thu Mar 11 09:11:00 1993 UTC (31 years ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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 vnam(vc) (vv[vc].name)
80 #define vdef(vc) (vv[vc].nass)
81 #define vval(vc) (vv[vc].value)
82 #define vint(vc) atoi(vval(vc))
83 #define vlet(vc) (vval(vc)[0]&~0x20)
84 #define vbool(vc) (vlet(vc)=='T')
85
86 #define HIGH 2
87 #define MEDIUM 1
88 #define LOW 0
89
90 int lowqopts(), medqopts(), hiqopts();
91 int (*setqopts[3])() = {lowqopts, medqopts, hiqopts};
92
93 #define renderopts (*setqopts[vscale(QUALITY)])
94
95 extern long fdate();
96
97 long scenedate; /* date of latest scene or object file */
98 long octreedate; /* date of octree */
99
100 int explicate = 0; /* explicate variables */
101 int silent = 0; /* do work silently */
102 int noaction = 0; /* don't do anything */
103 char *rvdevice = NULL; /* rview output device */
104 char *viewselect = NULL; /* specific view only */
105
106 int overture = 0; /* overture calculation needed */
107
108 char *progname; /* global argv[0] */
109
110 char radname[MAXPATH]; /* root Radiance file name */
111
112
113 main(argc, argv)
114 int argc;
115 char *argv[];
116 {
117 char ropts[512];
118 int i;
119
120 progname = argv[0];
121 /* get options */
122 for (i = 1; i < argc && argv[i][0] == '-'; i++)
123 switch (argv[i][1]) {
124 case 's':
125 silent++;
126 break;
127 case 'n':
128 noaction++;
129 break;
130 case 'e':
131 explicate++;
132 break;
133 case 'o':
134 rvdevice = argv[++i];
135 break;
136 case 'v':
137 viewselect = argv[++i];
138 break;
139 default:
140 goto userr;
141 }
142 if (i >= argc)
143 goto userr;
144 /* assign Radiance root file name */
145 rootname(radname, argv[i]);
146 /* load variable values */
147 load(argv[i]);
148 /* get any additional assignments */
149 for (i++; i < argc; i++)
150 setvariable(argv[i]);
151 /* check assignments */
152 checkvalues();
153 /* check files and dates */
154 checkfiles();
155 /* set default values as necessary */
156 setdefaults();
157 /* print all values if requested */
158 if (explicate)
159 printvals();
160 /* run simulation */
161 oconv();
162 renderopts(ropts);
163 xferopts(ropts);
164 if (rvdevice != NULL)
165 rview(ropts);
166 else
167 rpict(ropts);
168 exit(0);
169 userr:
170 fprintf(stderr,
171 "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
172 progname);
173 exit(1);
174 }
175
176
177 rootname(rn, fn) /* remove tail from end of fn */
178 register char *rn, *fn;
179 {
180 char *tp, *dp;
181
182 for (tp = NULL, dp = rn; *rn = *fn++; rn++)
183 if (ISDIRSEP(*rn))
184 dp = rn;
185 else if (*rn == '.')
186 tp = rn;
187 if (tp != NULL && tp > dp)
188 *tp = '\0';
189 }
190
191
192 load(rfname) /* load Radiance simulation file */
193 char *rfname;
194 {
195 FILE *fp;
196 char buf[256];
197 register char *cp;
198
199 if (rfname == NULL)
200 fp = stdin;
201 else if ((fp = fopen(rfname, "r")) == NULL) {
202 perror(rfname);
203 exit(1);
204 }
205 while (fgetline(buf, sizeof(buf), fp) != NULL) {
206 for (cp = buf; *cp; cp++) {
207 switch (*cp) {
208 case '\\':
209 case '\n':
210 *cp = ' ';
211 continue;
212 case '#':
213 *cp = '\0';
214 break;
215 }
216 break;
217 }
218 setvariable(buf);
219 }
220 fclose(fp);
221 }
222
223
224 setvariable(ass) /* assign variable according to string */
225 register char *ass;
226 {
227 char varname[32];
228 register char *cp;
229 register VARIABLE *vp;
230 register int i;
231 int n;
232
233 while (isspace(*ass)) /* skip leading space */
234 ass++;
235 cp = varname; /* extract name */
236 while (cp < varname+sizeof(varname)-1
237 && *ass && !isspace(*ass) && *ass != '=')
238 *cp++ = *ass++;
239 *cp = '\0';
240 if (!varname[0])
241 return; /* no variable name! */
242 /* trim value */
243 while (isspace(*ass) || *ass == '=')
244 ass++;
245 cp = ass + strlen(ass);
246 do
247 *cp-- = '\0';
248 while (cp >= ass && isspace(*cp));
249 n = cp - ass + 1;
250 if (!n) {
251 fprintf(stderr, "%s: warning - missing value for variable '%s'\n",
252 progname, varname);
253 return;
254 }
255 /* match variable from list */
256 vp = matchvar(varname);
257 if (vp == NULL) {
258 fprintf(stderr, "%s: unknown variable '%s'\n",
259 progname, varname);
260 exit(1);
261 }
262 /* assign new value */
263 cp = vp->value; i = vp->nass;
264 while (i--)
265 while (*cp++)
266 ;
267 i = cp - vp->value;
268 vp->value = realloc(vp->value, i+n+1);
269 if (vp->value == NULL) {
270 perror(progname);
271 exit(1);
272 }
273 strcpy(vp->value+i, ass);
274 vp->nass++;
275 }
276
277
278 VARIABLE *
279 matchvar(nam) /* match a variable by its name */
280 char *nam;
281 {
282 int n = strlen(nam);
283 register int i;
284
285 for (i = 0; i < NVARS; i++)
286 if (n >= vv[i].nick && !strncmp(nam, vv[i].name, n))
287 return(vv+i);
288 return(NULL);
289 }
290
291
292 char *
293 nvalue(vp, n) /* return nth variable value */
294 VARIABLE *vp;
295 register int n;
296 {
297 register char *cp;
298
299 if (vp == NULL || n < 0 || n >= vp->nass)
300 return(NULL);
301 cp = vp->value;
302 while (n--)
303 while (*cp++)
304 ;
305 return(cp);
306 }
307
308
309 int
310 vscale(vc) /* return scale for variable vc */
311 int vc;
312 {
313 switch(vlet(vc)) {
314 case 'H':
315 return(HIGH);
316 case 'M':
317 return(MEDIUM);
318 case 'L':
319 return(LOW);
320 }
321 fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 progname, vnam(vc), vval(vc));
323 exit(1);
324 }
325
326
327 checkvalues() /* check assignments */
328 {
329 register int i;
330
331 for (i = 0; i < NVARS; i++)
332 if (vv[i].fixval != NULL)
333 (*vv[i].fixval)(vv+i);
334 }
335
336
337 onevalue(vp) /* only one assignment for this variable */
338 register VARIABLE *vp;
339 {
340 if (vp->nass < 2)
341 return;
342 fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
343 progname, vp->name);
344 while (vp->nass-- > 1)
345 vp->value += strlen(vp->value)+1;
346 }
347
348
349 catvalues(vp) /* concatenate variable values */
350 register VARIABLE *vp;
351 {
352 register char *cp;
353
354 if (vp->nass < 2)
355 return;
356 for (cp = vp->value; vp->nass > 1; vp->nass--) {
357 while (*cp)
358 cp++;
359 *cp++ = ' ';
360 }
361 }
362
363
364 long
365 checklast(fnames) /* check files and find most recent */
366 register char *fnames;
367 {
368 char thisfile[MAXPATH];
369 long thisdate, lastdate = -1;
370 register char *cp;
371
372 while (*fnames) {
373 while (isspace(*fnames)) fnames++;
374 cp = thisfile;
375 while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
376 *cp = '\0';
377 if ((thisdate = fdate(thisfile)) < 0) {
378 perror(thisfile);
379 exit(1);
380 }
381 if (thisdate > lastdate)
382 lastdate = thisdate;
383 }
384 return(lastdate);
385 }
386
387
388 checkfiles() /* check for existence and modified times */
389 {
390 long objdate;
391
392 octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
393 scenedate = -1;
394 if (vdef(SCENE)) {
395 scenedate = checklast(vval(SCENE));
396 if (vdef(OBJECT)) {
397 objdate = checklast(vval(OBJECT));
398 if (objdate > scenedate)
399 scenedate = objdate;
400 }
401 }
402 if (octreedate < 0 & scenedate < 0) {
403 fprintf(stderr, "%s: need scene or octree\n", progname);
404 exit(1);
405 }
406 }
407
408
409 setdefaults() /* set default values for unassigned var's */
410 {
411 FILE *fp;
412 double xmin, ymin, zmin, size;
413 char buf[512];
414 char *cp;
415
416 if (!vdef(OCTREE)) {
417 sprintf(buf, "%s.oct", radname);
418 vval(OCTREE) = savqstr(buf);
419 vdef(OCTREE)++;
420 }
421 if (!vdef(ZONE)) {
422 if (scenedate > octreedate) {
423 sprintf(buf, "getbbox -w -h %s", vval(SCENE));
424 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 }
447 vval(ZONE) = savqstr(buf);
448 vdef(ZONE)++;
449 }
450 if (!vdef(UP)) {
451 vval(UP) = "Z";
452 vdef(UP)++;
453 }
454 if (!vdef(INDIRECT)) {
455 vval(INDIRECT) = "0";
456 vdef(INDIRECT)++;
457 }
458 if (!vdef(QUALITY)) {
459 vval(QUALITY) = "L";
460 vdef(QUALITY)++;
461 }
462 if (!vdef(RESOLUTION)) {
463 vval(RESOLUTION) = "512";
464 vdef(RESOLUTION)++;
465 }
466 if (!vdef(PICTURE)) {
467 vval(PICTURE) = radname;
468 vdef(PICTURE)++;
469 }
470 if (!vdef(AMBFILE)) {
471 sprintf(buf, "%s.amb", radname);
472 vval(AMBFILE) = savqstr(buf);
473 vdef(AMBFILE)++;
474 }
475 if (!vdef(VIEW)) {
476 vval(VIEW) = "X";
477 vdef(VIEW)++;
478 }
479 if (!vdef(DETAIL)) {
480 vval(DETAIL) = "M";
481 vdef(DETAIL)++;
482 }
483 if (!vdef(PENUMBRAS)) {
484 vval(PENUMBRAS) = "F";
485 vdef(PENUMBRAS)++;
486 }
487 if (!vdef(VARIABILITY)) {
488 vval(VARIABILITY) = "L";
489 vdef(VARIABILITY)++;
490 }
491 }
492
493
494 printvals() /* print variable values */
495 {
496 register int i, j;
497
498 for (i = 0; i < NVARS; i++)
499 for (j = 0; j < vv[i].nass; j++)
500 printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
501 fflush(stdout);
502 }
503
504
505 oconv() /* run oconv if necessary */
506 {
507 char combuf[512], ocopts[64];
508
509 if (octreedate > scenedate) /* check dates */
510 return;
511 /* build command */
512 oconvopts(ocopts);
513 sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
514 if (!silent) { /* echo it */
515 printf("\t%s\n", combuf);
516 fflush(stdout);
517 }
518 if (noaction)
519 return;
520 if (system(combuf)) { /* run it */
521 fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
522 progname, vval(OCTREE));
523 unlink(vval(OCTREE));
524 exit(1);
525 }
526 }
527
528
529 char *
530 addarg(op, arg) /* add argument and advance pointer */
531 register char *op, *arg;
532 {
533 *op = ' ';
534 while (*++op = *arg++)
535 ;
536 return(op);
537 }
538
539
540 oconvopts(oo) /* get oconv options */
541 char *oo;
542 {
543 *oo = '\0';
544 if (vdef(OCONV))
545 addarg(oo, vval(OCONV));
546 }
547
548
549 lowqopts(ro) /* low quality rendering options */
550 char *ro;
551 {
552 register char *op = ro;
553
554 *op = '\0';
555 if (vdef(RENDER))
556 op = addarg(op, vval(RENDER));
557 }
558
559
560 medqopts(ro) /* medium quality rendering options */
561 char *ro;
562 {
563 register char *op = ro;
564
565 *op = '\0';
566 if (vdef(RENDER))
567 op = addarg(op, vval(RENDER));
568 }
569
570
571 hiqopts(ro) /* high quality rendering options */
572 char *ro;
573 {
574 register char *op = ro;
575
576 *op = '\0';
577 if (vdef(RENDER))
578 op = addarg(op, vval(RENDER));
579 }
580
581
582 xferopts(ro) /* transfer options if indicated */
583 char *ro;
584 {
585 int fd, n;
586
587 n = strlen(ro);
588 if (n < 2)
589 return;
590 if (vdef(OPTFILE)) {
591 if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
592 perror(vval(OPTFILE));
593 exit(1);
594 }
595 if (write(fd, ro+1, n-1) != n-1) {
596 perror(vval(OPTFILE));
597 exit(1);
598 }
599 write(fd, "\n", 1);
600 close(fd);
601 ro[0] = ' ';
602 ro[1] = '^';
603 strcpy(ro+2, vval(OPTFILE));
604 }
605 #ifdef MSDOS
606 else if (n > 50) {
607 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);
615 strcpy(ro, " $ROPT");
616 }
617 #endif
618 }
619
620
621 pfiltopts(po) /* get pfilt options */
622 register char *po;
623 {
624 *po = '\0';
625 if (vdef(EXPOSURE)) {
626 po = addarg(po, "-1 -e");
627 po = addarg(po, vval(EXPOSURE));
628 }
629 if (vscale(QUALITY) == HIGH)
630 po = addarg(po, "-r .65");
631 if (vdef(PFILT))
632 po = addarg(po, vval(PFILT));
633 }
634
635
636 matchword(s1, s2) /* match white-delimited words */
637 register char *s1, *s2;
638 {
639 while (isspace(*s1)) s1++;
640 while (isspace(*s2)) s2++;
641 while (*s1 && !isspace(*s1))
642 if (*s1++ != *s2++)
643 return(0);
644 return(!*s2 || isspace(*s2));
645 }
646
647
648 char *
649 specview(vs) /* get proper view spec from vs */
650 register char *vs;
651 {
652 static char viewopts[128];
653 register char *cp;
654 int xpos, ypos, zpos, viewtype;
655 int exterior;
656 double cent[3], dim[3], mult, d;
657
658 if (vs == NULL || *vs == '-')
659 return(vs);
660 /* check standard view names */
661 xpos = ypos = zpos = 0;
662 viewtype = 0;
663 if (*vs == 'X') {
664 xpos = 1; vs++;
665 } else if (*vs == 'x') {
666 xpos = -1; vs++;
667 }
668 if (*vs == 'Y') {
669 ypos = 1; vs++;
670 } else if (*vs == 'y') {
671 ypos = -1; vs++;
672 }
673 if (*vs == 'Z') {
674 zpos = 1; vs++;
675 } else if (*vs == 'z') {
676 zpos = -1; vs++;
677 }
678 if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
679 viewtype = *vs++;
680 else if (!*vs || isspace(*vs))
681 viewtype = 'v';
682 cp = viewopts;
683 if (viewtype && (xpos|ypos|zpos)) { /* got standard view */
684 *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
685 if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
686 &cent[0], &dim[0], &cent[1], &dim[1],
687 &cent[2], &dim[2]) != 6) {
688 fprintf(stderr, "%s: bad zone specification\n",
689 progname);
690 exit(1);
691 }
692 dim[0] -= cent[0];
693 dim[1] -= cent[1];
694 dim[2] -= cent[2];
695 exterior = vlet(ZONE) == 'E';
696 mult = exterior ? 2. : .45 ;
697 sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
698 cent[0]+xpos*mult*dim[0],
699 cent[1]+ypos*mult*dim[1],
700 cent[2]+zpos*mult*dim[2],
701 -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
702 cp += strlen(cp);
703 switch (vlet(UP)) {
704 case 'Z':
705 if (xpos|ypos) {
706 cp = addarg(cp, "-vu 0 0 1");
707 break;
708 }
709 /* 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");
721 break;
722 default:
723 fprintf(stderr, "%s: illegal value for variable '%s'\n",
724 progname, vnam(UP));
725 exit(1);
726 }
727 switch (viewtype) {
728 case 'v':
729 cp = addarg(cp, "-vh 45 -vv 45");
730 break;
731 case 'l':
732 d = sqrt(dim[0]*dim[0]+dim[1]*dim[1]+dim[2]*dim[2]);
733 sprintf(cp, " -vh %.2g -vv %.2g", d, d);
734 cp += strlen(cp);
735 break;
736 case 'a':
737 case 'h':
738 cp = addarg(cp, "-vh 180 -vv 180");
739 break;
740 }
741 } else
742 while (*vs && !isspace(*vs)) /* else skip id */
743 vs++;
744 /* append any additional options */
745 while (isspace(*vs)) vs++;
746 strcpy(cp, vs);
747 return(viewopts);
748 }
749
750
751 char *
752 getview(n, vn) /* get view n, or NULL if none */
753 int n;
754 char *vn;
755 {
756 register char *mv;
757
758 if (viewselect != NULL) {
759 if (n) /* only do one */
760 return(NULL);
761 if (viewselect[0] == '-') { /* already specified */
762 if (vn != NULL) *vn = '\0';
763 return(viewselect);
764 }
765 if (vn != NULL) {
766 for (mv = viewselect; *mv && !isspace(*mv);
767 *vn++ = *mv++)
768 ;
769 *vn = '\0';
770 }
771 /* check list */
772 while ((mv = nvalue(vv+VIEW, n++)) != NULL)
773 if (matchword(viewselect, mv))
774 return(specview(mv));
775 return(specview(viewselect)); /* standard view? */
776 }
777 if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
778 if (*mv != '-')
779 while (*mv && !isspace(*mv))
780 *vn++ = *mv++;
781 *vn = '\0';
782 }
783 return(specview(nvalue(vv+VIEW, n))); /* use view n */
784 }
785
786
787 rview(opts) /* run rview with first view */
788 char *opts;
789 {
790 char combuf[512];
791 /* build command */
792 sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
793 if (rvdevice != NULL)
794 sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
795 strcat(combuf, vval(OCTREE));
796 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 */
803 fprintf(stderr, "%s: error running rview\n", progname);
804 exit(1);
805 }
806 }
807
808
809 rpict(opts) /* run rpict and pfilt for each view */
810 char *opts;
811 {
812 char combuf[512];
813 char rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
814 char pfopts[64];
815 char vs[32], *vw;
816 int vn, mult;
817 /* get pfilt options */
818 pfiltopts(pfopts);
819 /* get resolution, reporting */
820 mult = vscale(QUALITY)+1;
821 {
822 int xres, yres;
823 double aspect;
824 int n;
825 n = sscanf(vval(RESOLUTION), "%d %d %lf", &xres, &yres, &aspect);
826 if (n == 3)
827 sprintf(res, "-x %d -y %d -pa %.3f",
828 mult*xres, mult*yres, aspect);
829 else if (n) {
830 if (n == 1) yres = xres;
831 sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
832 } else {
833 fprintf(stderr, "%s: bad value for variable '%s'\n",
834 progname, vnam(RESOLUTION));
835 exit(1);
836 }
837 }
838 rep[0] = '\0';
839 if (vdef(REPORT)) {
840 double minutes;
841 int n;
842 n = sscanf(vval(REPORT), "%lf %s", &minutes, rawfile);
843 if (n == 2)
844 sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
845 else if (n == 1)
846 sprintf(rep, " -t %d", (int)(minutes*60));
847 else {
848 fprintf(stderr, "%s: bad value for variable '%s'\n",
849 progname, vnam(REPORT));
850 exit(1);
851 }
852 }
853 /* do each view */
854 vn = 0;
855 while ((vw = getview(vn++, vs)) != NULL) {
856 if (!vs[0])
857 sprintf(vs, "%d", vn);
858 sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
859 /* check date on picture */
860 if (fdate(picfile) > octreedate)
861 continue;
862 /* build rpict command */
863 sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
864 if (fdate(rawfile) > octreedate) /* recover */
865 sprintf(combuf, "rpict%s%s -ro %s %s",
866 rep, opts, rawfile, vval(OCTREE));
867 else {
868 if (overture) { /* run overture calculation */
869 sprintf(combuf,
870 "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
871 rep, vw, opts,
872 vval(OCTREE), rawfile);
873 if (!silent) {
874 printf("\t%s\n", combuf);
875 fflush(stdout);
876 }
877 if (!noaction && system(combuf)) {
878 fprintf(stderr,
879 "%s: error in overture for view %s\n\t%s removed\n",
880 progname, vs, rawfile);
881 unlink(rawfile);
882 exit(1);
883 }
884 }
885 sprintf(combuf, "rpict%s %s %s%s %s > %s",
886 rep, vw, res, opts,
887 vval(OCTREE), rawfile);
888 }
889 if (!silent) { /* echo rpict command */
890 printf("\t%s\n", combuf);
891 fflush(stdout);
892 }
893 if (!noaction && system(combuf)) { /* run rpict */
894 fprintf(stderr, "%s: error rendering view %s\n",
895 progname, vs);
896 exit(1);
897 }
898 /* build pfilt command */
899 if (mult > 1)
900 sprintf(combuf, "pfilt%s -x /%d -y /%d %s > %s",
901 pfopts, mult, mult, rawfile, picfile);
902 else
903 sprintf(combuf, "pfilt%s %s > %s", pfopts,
904 rawfile, picfile);
905 if (!silent) { /* echo pfilt command */
906 printf("\t%s\n", combuf);
907 fflush(stdout);
908 }
909 if (!noaction && system(combuf)) { /* run pfilt */
910 fprintf(stderr,
911 "%s: error filtering view %s\n\t%s removed\n",
912 progname, vs, picfile);
913 unlink(picfile);
914 exit(1);
915 }
916 /* remove raw file */
917 if (!silent)
918 #ifdef MSDOS
919 printf("\tdel %s\n", rawfile);
920 #else
921 printf("\trm %s\n", rawfile);
922 #endif
923 if (!noaction)
924 unlink(rawfile);
925 }
926 }