ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rad.c
(Generate patch)

Comparing ray/src/util/rad.c (file contents):
Revision 2.2 by greg, Thu Mar 11 11:39:48 1993 UTC vs.
Revision 2.23 by greg, Tue Sep 7 11:57:04 1993 UTC

# Line 76 | Line 76 | 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)        (vval(vc)[0]&~0x20)
85 > #define vlet(vc)        UPPER(vval(vc)[0])
86   #define vbool(vc)       (vlet(vc)=='T')
87  
88   #define HIGH            2
# Line 92 | Line 94 | 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 + long    matdate;                /* date of latest material file */
109  
110   int     explicate = 0;          /* explicate variables */
111   int     silent = 0;             /* do work silently */
112   int     noaction = 0;           /* don't do anything */
113 + int     sayview = 0;            /* print view out */
114   char    *rvdevice = NULL;       /* rview output device */
115   char    *viewselect = NULL;     /* specific view only */
116  
117   int     overture = 0;           /* overture calculation needed */
118  
119   char    *progname;              /* global argv[0] */
120 + char    *rifname;               /* global rad input file name */
121  
122   char    radname[MAXPATH];       /* root Radiance file name */
123  
# Line 133 | Line 145 | char   *argv[];
145                  case 'o':
146                          rvdevice = argv[++i];
147                          break;
148 +                case 'V':
149 +                        sayview++;
150 +                        break;
151                  case 'v':
152                          viewselect = argv[++i];
153                          break;
# Line 141 | Line 156 | char   *argv[];
156                  }
157          if (i >= argc)
158                  goto userr;
159 +        rifname = argv[i];
160                                  /* assign Radiance root file name */
161 <        rootname(radname, argv[i]);
161 >        rootname(radname, rifname);
162                                  /* load variable values */
163 <        load(argv[i]);
163 >        load(rifname);
164                                  /* get any additional assignments */
165          for (i++; i < argc; i++)
166                  setvariable(argv[i]);
# Line 157 | Line 173 | char   *argv[];
173                                  /* print all values if requested */
174          if (explicate)
175                  printvals();
176 <                                /* run simulation */
176 >                                /* build octree */
177          oconv();
178 +                                /* check date on ambient file */
179 +        checkambfile();
180 +                                /* run simulation */
181          renderopts(ropts);
182          xferopts(ropts);
183          if (rvdevice != NULL)
# Line 168 | Line 187 | char   *argv[];
187          exit(0);
188   userr:
189          fprintf(stderr,
190 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
190 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
191                          progname);
192          exit(1);
193   }
# Line 193 | Line 212 | load(rfname)                   /* load Radiance simulation file */
212   char    *rfname;
213   {
214          FILE    *fp;
215 <        char    buf[256];
215 >        char    buf[512];
216          register char   *cp;
217  
218          if (rfname == NULL)
219                  fp = stdin;
220 <        else if ((fp = fopen(rfname, "r")) == NULL) {
221 <                perror(rfname);
203 <                exit(1);
204 <        }
220 >        else if ((fp = fopen(rfname, "r")) == NULL)
221 >                syserr(rfname);
222          while (fgetline(buf, sizeof(buf), fp) != NULL) {
223                  for (cp = buf; *cp; cp++) {
224                          switch (*cp) {
# Line 212 | Line 229 | char   *rfname;
229                          case '#':
230                                  *cp = '\0';
231                                  break;
232 +                        default:
233 +                                continue;
234                          }
235                          break;
236                  }
# Line 260 | Line 279 | register char  *ass;
279                  exit(1);
280          }
281                                          /* assign new value */
282 <        cp = vp->value; i = vp->nass;
283 <        while (i--)
284 <                while (*cp++)
285 <                        ;
286 <        i = cp - vp->value;
287 <        vp->value = realloc(vp->value, i+n+1);
288 <        if (vp->value == NULL) {
289 <                perror(progname);
290 <                exit(1);
291 <        }
282 >        if (i = vp->nass) {
283 >                cp = vp->value;
284 >                while (i--)
285 >                        while (*cp++)
286 >                                ;
287 >                i = cp - vp->value;
288 >                vp->value = realloc(vp->value, i+n+1);
289 >        } else
290 >                vp->value = malloc(n+1);
291 >        if (vp->value == NULL)
292 >                syserr(progname);
293          strcpy(vp->value+i, ass);
294          vp->nass++;
295   }
# Line 296 | Line 316 | register int   n;
316   {
317          register char   *cp;
318  
319 <        if (vp == NULL || n < 0 || n >= vp->nass)
319 >        if (vp == NULL | n < 0 | n >= vp->nass)
320                  return(NULL);
321          cp = vp->value;
322          while (n--)
# Line 318 | Line 338 | int    vc;
338          case 'L':
339                  return(LOW);
340          }
341 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
341 >        badvalue(vc);
342   }
343  
344  
# Line 373 | Line 391 | register char  *fnames;
391          while (*fnames) {
392                  while (isspace(*fnames)) fnames++;
393                  cp = thisfile;
394 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
394 >                while (*fnames && !isspace(*fnames))
395 >                        *cp++ = *fnames++;
396                  *cp = '\0';
397 <                if ((thisdate = fdate(thisfile)) < 0) {
398 <                        perror(thisfile);
380 <                        exit(1);
381 <                }
397 >                if ((thisdate = fdate(thisfile)) < 0)
398 >                        syserr(thisfile);
399                  if (thisdate > lastdate)
400                          lastdate = thisdate;
401          }
# Line 392 | Line 409 | checkfiles()                   /* check for existence and modified tim
409          long    objdate;
410  
411          if (!vdef(OCTREE)) {
412 <                if ((cp = bmalloc(strlen(radname)+5)) == NULL) {
413 <                        perror(progname);
397 <                        exit(1);
398 <                }
412 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
413 >                        syserr(progname);
414                  sprintf(cp, "%s.oct", radname);
415                  vval(OCTREE) = cp;
416                  vdef(OCTREE)++;
# Line 415 | Line 430 | checkfiles()                   /* check for existence and modified tim
430                                  vnam(OCTREE), vnam(SCENE));
431                  exit(1);
432          }
433 +        matdate = -1;
434 +        if (vdef(MATERIAL))
435 +                matdate = checklast(vval(MATERIAL));
436   }      
437  
438  
# Line 429 | Line 447 | double org[3], *sizp;
447          if (osiz <= FTINY) {
448                  oconv();                /* does nothing if done already */
449                  sprintf(buf, "getinfo -d < %s", vval(OCTREE));
450 <                if ((fp = popen(buf, "r")) == NULL) {
451 <                        perror("getinfo");
434 <                        exit(1);
435 <                }
450 >                if ((fp = popen(buf, "r")) == NULL)
451 >                        syserr("getinfo");
452                  if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
453                                  &oorg[2], &osiz) != 4) {
454                          fprintf(stderr,
# Line 458 | Line 474 | setdefaults()                  /* set default values for unassigned v
474                  vval(ZONE) = savqstr(buf);
475                  vdef(ZONE)++;
476          }
461        if (!vdef(UP)) {
462                vval(UP) = "Z";
463                vdef(UP)++;
464        }
477          if (!vdef(INDIRECT)) {
478                  vval(INDIRECT) = "0";
479                  vdef(INDIRECT)++;
# Line 502 | Line 514 | printvals()                    /* print variable values */
514          register int    i, j;
515  
516          for (i = 0; i < NVARS; i++)
517 <                for (j = 0; j < vv[i].nass; j++)
518 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
517 >                for (j = 0; j < vdef(i); j++)
518 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
519          fflush(stdout);
520   }
521  
# Line 516 | Line 528 | oconv()                                /* run oconv if necessary */
528                  return;
529                                          /* build command */
530          oconvopts(ocopts);
531 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
532 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
533 <                        vval(SCENE), vval(OCTREE));
534 <        if (!silent) {                  /* echo it */
535 <                printf("\t%s\n", combuf);
536 <                fflush(stdout);
537 <        }
538 <        if (noaction)
527 <                return;
528 <        if (system(combuf)) {           /* run it */
531 >        if (vdef(MATERIAL))
532 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
533 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
534 >        else
535 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
536 >                                vval(SCENE), vval(OCTREE));
537 >        
538 >        if (runcom(combuf)) {           /* run it */
539                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
540                                  progname, vval(OCTREE));
541                  unlink(vval(OCTREE));
# Line 557 | Line 567 | register char  *oo;
567   }
568  
569  
570 + checkambfile()                  /* check date on ambient file */
571 + {
572 +        long    afdate;
573 +
574 +        if (!vdef(AMBFILE))
575 +                return;
576 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
577 +                return;
578 +        if (octreedate > afdate | matdate > afdate)
579 +                rmfile(vval(AMBFILE));
580 + }
581 +
582 +
583   double
584   ambval()                                /* compute ambient value */
585   {
586 <        if (vdef(EXPOSURE))
586 >        if (vdef(EXPOSURE)) {
587 >                if (!isflt(vval(EXPOSURE)))
588 >                        badvalue(EXPOSURE);
589                  if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
590                          return(.5/pow(2.,atof(vval(EXPOSURE))));
591 <                else
592 <                        return(.5/atof(vval(EXPOSURE)));
591 >                return(.5/atof(vval(EXPOSURE)));
592 >        }
593          if (vlet(ZONE) == 'E')
594                  return(10.);
595 <        else
595 >        if (vlet(ZONE) == 'I')
596                  return(.01);
597 +        badvalue(ZONE);
598   }
599  
600  
# Line 579 | Line 605 | register char  *op;
605  
606          *op = '\0';
607          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
608 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
609 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
584 <                                progname, vnam(ZONE));
585 <                exit(1);
586 <        }
608 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
609 >                badvalue(ZONE);
610          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
611          getoctcube(org, &d);
612          d *= 3./(siz[0]+siz[1]+siz[2]);
613          switch (vscale(DETAIL)) {
614          case LOW:
615 <                op = addarg(op, "-ps 16");
593 <                op = addarg(op, "-dp 16");
615 >                op = addarg(op, "-ps 16 -dp 64");
616                  sprintf(op, " -ar %d", (int)(4*d));
617                  op += strlen(op);
618                  break;
619          case MEDIUM:
620 <                op = addarg(op, "-ps 8");
599 <                op = addarg(op, "-dp 32");
620 >                op = addarg(op, "-ps 8 -dp 128");
621                  sprintf(op, " -ar %d", (int)(8*d));
622                  op += strlen(op);
623                  break;
624          case HIGH:
625 <                op = addarg(op, "-ps 4");
605 <                op = addarg(op, "-dp 64");
625 >                op = addarg(op, "-ps 4 -dp 256");
626                  sprintf(op, " -ar %d", (int)(16*d));
627                  op += strlen(op);
628                  break;
# Line 610 | Line 630 | register char  *op;
630          op = addarg(op, "-pt .16");
631          if (vbool(PENUMBRAS))
632                  op = addarg(op, "-ds .4");
633 <        op = addarg(op, "-dt .2");
634 <        op = addarg(op, "-dc .25");
635 <        op = addarg(op, "-dr 0");
616 <        op = addarg(op, "-sj 0");
617 <        op = addarg(op, "-st .7");
618 <        op = addarg(op, "-ab 0");
633 >        else
634 >                op = addarg(op, "-ds 0");
635 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
636          if (vdef(AMBFILE)) {
637                  sprintf(op, " -af %s", vval(AMBFILE));
638                  op += strlen(op);
# Line 623 | Line 640 | register char  *op;
640                  overture = 0;
641          switch (vscale(VARIABILITY)) {
642          case LOW:
643 <                op = addarg(op, "-aa .4");
627 <                op = addarg(op, "-ad 32");
643 >                op = addarg(op, "-aa .4 -ad 64");
644                  break;
645          case MEDIUM:
646 <                op = addarg(op, "-aa .3");
631 <                op = addarg(op, "-ad 64");
646 >                op = addarg(op, "-aa .3 -ad 128");
647                  break;
648          case HIGH:
649 <                op = addarg(op, "-aa .25");
635 <                op = addarg(op, "-ad 128");
649 >                op = addarg(op, "-aa .25 -ad 256");
650                  break;
651          }
652          op = addarg(op, "-as 0");
653          d = ambval();
654          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
655          op += strlen(op);
656 <        op = addarg(op, "-lr 3");
643 <        op = addarg(op, "-lw .02");
656 >        op = addarg(op, "-lr 3 -lw .02");
657          if (vdef(RENDER))
658                  op = addarg(op, vval(RENDER));
659   }
# Line 653 | Line 666 | register char  *op;
666  
667          *op = '\0';
668          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
669 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
670 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
658 <                                progname, vnam(ZONE));
659 <                exit(1);
660 <        }
669 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
670 >                badvalue(ZONE);
671          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
672          getoctcube(org, &d);
673          d *= 3./(siz[0]+siz[1]+siz[2]);
674          switch (vscale(DETAIL)) {
675          case LOW:
676                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
677 <                op = addarg(op, "-dp 64");
677 >                op = addarg(op, "-dp 256");
678                  sprintf(op, " -ar %d", (int)(8*d));
679                  op += strlen(op);
680                  break;
681          case MEDIUM:
682                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
683 <                op = addarg(op, "-dp 128");
683 >                op = addarg(op, "-dp 512");
684                  sprintf(op, " -ar %d", (int)(16*d));
685                  op += strlen(op);
686                  break;
687          case HIGH:
688                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
689 <                op = addarg(op, "-dp 256");
689 >                op = addarg(op, "-dp 1024");
690                  sprintf(op, " -ar %d", (int)(32*d));
691                  op += strlen(op);
692                  break;
693          }
694          op = addarg(op, "-pt .08");
695 <        if (vbool(PENUMBRAS)) {
696 <                op = addarg(op, "-ds .2");
697 <                op = addarg(op, "-dj .35");
688 <        } else
695 >        if (vbool(PENUMBRAS))
696 >                op = addarg(op, "-ds .2 -dj .35");
697 >        else
698                  op = addarg(op, "-ds .3");
699 <        op = addarg(op, "-dt .1");
700 <        op = addarg(op, "-dc .5");
701 <        op = addarg(op, "-dr 1");
702 <        op = addarg(op, "-sj .7");
703 <        op = addarg(op, "-st .15");
695 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
696 <        op += strlen(op);
699 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
700 >        if (overture = vint(INDIRECT)) {
701 >                sprintf(op, " -ab %d", overture);
702 >                op += strlen(op);
703 >        }
704          if (vdef(AMBFILE)) {
705                  sprintf(op, " -af %s", vval(AMBFILE));
706                  op += strlen(op);
# Line 701 | Line 708 | register char  *op;
708                  overture = 0;
709          switch (vscale(VARIABILITY)) {
710          case LOW:
711 <                op = addarg(op, "-aa .25");
705 <                op = addarg(op, "-ad 128");
706 <                op = addarg(op, "-as 0");
711 >                op = addarg(op, "-aa .25 -ad 196 -as 0");
712                  break;
713          case MEDIUM:
714 <                op = addarg(op, "-aa .2");
710 <                op = addarg(op, "-ad 300");
711 <                op = addarg(op, "-as 64");
714 >                op = addarg(op, "-aa .2 -ad 400 -as 64");
715                  break;
716          case HIGH:
717 <                op = addarg(op, "-aa .15");
715 <                op = addarg(op, "-ad 500");
716 <                op = addarg(op, "-as 128");
717 >                op = addarg(op, "-aa .15 -ad 768 -as 196");
718                  break;
719          }
720          d = ambval();
721          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
722          op += strlen(op);
723 <        op = addarg(op, "-lr 6");
723 <        op = addarg(op, "-lw .002");
723 >        op = addarg(op, "-lr 6 -lw .002");
724          if (vdef(RENDER))
725                  op = addarg(op, vval(RENDER));
726   }
# Line 733 | Line 733 | register char  *op;
733  
734          *op = '\0';
735          if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
736 <                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6) {
737 <                fprintf(stderr, "%s: bad value for variable '%s'\n",
738 <                                progname, vnam(ZONE));
739 <                exit(1);
740 <        }
736 >                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
737 >                badvalue(ZONE);
738          siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
739          getoctcube(org, &d);
740          d *= 3./(siz[0]+siz[1]+siz[2]);
741          switch (vscale(DETAIL)) {
742          case LOW:
743                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
744 <                op = addarg(op, "-dp 256");
744 >                op = addarg(op, "-dp 1024");
745                  sprintf(op, " -ar %d", (int)(16*d));
746                  op += strlen(op);
747                  break;
748          case MEDIUM:
749                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
750 <                op = addarg(op, "-dp 512");
750 >                op = addarg(op, "-dp 2048");
751                  sprintf(op, " -ar %d", (int)(32*d));
752                  op += strlen(op);
753                  break;
754          case HIGH:
755                  op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
756 <                op = addarg(op, "-dp 1024");
756 >                op = addarg(op, "-dp 4096");
757                  sprintf(op, " -ar %d", (int)(64*d));
758                  op += strlen(op);
759                  break;
760          }
761          op = addarg(op, "-pt .04");
762 <        if (vbool(PENUMBRAS)) {
763 <                op = addarg(op, "-ds .1");
764 <                op = addarg(op, "-dj .7");
768 <        } else
762 >        if (vbool(PENUMBRAS))
763 >                op = addarg(op, "-ds .1 -dj .7");
764 >        else
765                  op = addarg(op, "-ds .2");
766 <        op = addarg(op, "-dt .05");
771 <        op = addarg(op, "-dc .75");
772 <        op = addarg(op, "-dr 3");
773 <        op = addarg(op, "-sj 1");
774 <        op = addarg(op, "-st .03");
766 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
767          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
768          op += strlen(op);
769          if (vdef(AMBFILE)) {
# Line 781 | Line 773 | register char  *op;
773                  overture = 0;
774          switch (vscale(VARIABILITY)) {
775          case LOW:
776 <                op = addarg(op, "-aa .15");
785 <                op = addarg(op, "-ad 200");
786 <                op = addarg(op, "-as 0");
776 >                op = addarg(op, "-aa .15 -ad 256 -as 0");
777                  break;
778          case MEDIUM:
779 <                op = addarg(op, "-aa .125");
790 <                op = addarg(op, "-ad 512");
791 <                op = addarg(op, "-as 128");
779 >                op = addarg(op, "-aa .125 -ad 512 -as 256");
780                  break;
781          case HIGH:
782 <                op = addarg(op, "-aa .08");
795 <                op = addarg(op, "-ad 850");
796 <                op = addarg(op, "-as 256");
782 >                op = addarg(op, "-aa .08 -ad 1024 -as 512");
783                  break;
784          }
785          d = ambval();
786          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
787          op += strlen(op);
788 <        op = addarg(op, "-lr 12");
803 <        op = addarg(op, "-lw .0005");
788 >        op = addarg(op, "-lr 12 -lw .0005");
789          if (vdef(RENDER))
790                  op = addarg(op, vval(RENDER));
791   }
# Line 810 | Line 795 | xferopts(ro)                           /* transfer options if indicated */
795   char    *ro;
796   {
797          int     fd, n;
798 +        register char   *cp;
799          
800          n = strlen(ro);
801          if (n < 2)
802                  return;
803          if (vdef(OPTFILE)) {
804 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
805 <                        perror(vval(OPTFILE));
806 <                        exit(1);
807 <                }
808 <                if (write(fd, ro+1, n-1) != n-1) {
809 <                        perror(vval(OPTFILE));
810 <                        exit(1);
811 <                }
812 <                write(fd, "\n", 1);
813 <                close(fd);
828 <                ro[0] = ' ';
829 <                ro[1] = '^';
830 <                strcpy(ro+2, vval(OPTFILE));
804 >                for (cp = ro; cp[1]; cp++)
805 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
806 >                                *cp = '\n';
807 >                        else
808 >                                *cp = cp[1];
809 >                *cp = '\n';
810 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
811 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
812 >                        syserr(vval(OPTFILE));
813 >                sprintf(ro, " @%s", vval(OPTFILE));
814          }
815   #ifdef MSDOS
816          else if (n > 50) {
817 <                register char   *evp = bmalloc(n+6);
835 <                if (evp == NULL) {
836 <                        perror(progname);
837 <                        exit(1);
838 <                }
839 <                strcpy(evp, "ROPT=");
840 <                strcat(evp, ro);
841 <                if (putenv(evp) != 0) {
842 <                        fprintf(stderr, "%s: out of environment space\n",
843 <                                        progname);
844 <                        exit(1);
845 <                }
817 >                setenv("ROPT", ro+1);
818                  strcpy(ro, " $ROPT");
819          }
820   #endif
# Line 857 | Line 829 | register char  *po;
829                  po = addarg(po, "-1 -e");
830                  po = addarg(po, vval(EXPOSURE));
831          }
832 <        if (vscale(QUALITY) == HIGH)
833 <                po = addarg(po, "-r .65");
832 >        switch (vscale(QUALITY)) {
833 >        case MEDIUM:
834 >                po = addarg(po, "-r 1");
835 >                break;
836 >        case HIGH:
837 >                po = addarg(po, "-m .25");
838 >                break;
839 >        }
840          if (vdef(PFILT))
841                  po = addarg(po, vval(PFILT));
842   }
# Line 880 | Line 858 | char *
858   specview(vs)                            /* get proper view spec from vs */
859   register char   *vs;
860   {
861 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
862 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
863          static char     viewopts[128];
864          register char   *cp;
865 <        int     xpos, ypos, zpos, viewtype;
866 <        int     exterior;
865 >        int     xpos, ypos, zpos, viewtype, upax;
866 >        register int    i;
867          double  cent[3], dim[3], mult, d;
868  
869          if (vs == NULL || *vs == '-')
870                  return(vs);
871 +        upax = 0;                       /* get the up vector */
872 +        if (vdef(UP)) {
873 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
874 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
875 +                else
876 +                        upax = 1-'X'+vlet(UP);
877 +                if (upax < 1 | upax > 3)
878 +                        badvalue(UP);
879 +                if (vval(UP)[0] == '-')
880 +                        upax = -upax;
881 +        }
882                                          /* check standard view names */
883          xpos = ypos = zpos = 0;
893        viewtype = 0;
884          if (*vs == 'X') {
885                  xpos = 1; vs++;
886          } else if (*vs == 'x') {
# Line 906 | Line 896 | register char  *vs;
896          } else if (*vs == 'z') {
897                  zpos = -1; vs++;
898          }
899 +        viewtype = 'v';
900          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
901                  viewtype = *vs++;
911        else if (!*vs || isspace(*vs))
912                viewtype = 'v';
902          cp = viewopts;
903 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
903 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
904                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
905                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
906                                  &cent[0], &dim[0], &cent[1], &dim[1],
907 <                                &cent[2], &dim[2]) != 6) {
908 <                        fprintf(stderr, "%s: bad zone specification\n",
909 <                                        progname);
910 <                        exit(1);
907 >                                &cent[2], &dim[2]) != 6)
908 >                        badvalue(ZONE);
909 >                for (i = 0; i < 3; i++) {
910 >                        dim[i] -= cent[i];
911 >                        cent[i] += .5*dim[i];
912                  }
913 <                dim[0] -= cent[0]; cent[0] += .5*dim[0];
924 <                dim[1] -= cent[1]; cent[1] += .5*dim[1];
925 <                dim[2] -= cent[2]; cent[2] += .5*dim[2];
926 <                exterior = vlet(ZONE) == 'E';
927 <                mult = exterior ? 2. : .45 ;
913 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
914                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
915                                  cent[0]+xpos*mult*dim[0],
916                                  cent[1]+ypos*mult*dim[1],
917                                  cent[2]+zpos*mult*dim[2],
918                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
919                  cp += strlen(cp);
920 <                switch (vlet(UP)) {
921 <                case 'Z':
922 <                        if (xpos|ypos) {
923 <                                cp = addarg(cp, "-vu 0 0 1");
924 <                                break;
925 <                        }
926 <                /* fall through */
941 <                case 'Y':
942 <                        if (xpos|zpos) {
943 <                                cp = addarg(cp, "-vu 0 1 0");
944 <                                break;
945 <                        }
946 <                /* fall through */
947 <                case 'X':
948 <                        if (ypos|zpos)
949 <                                cp = addarg(cp, "-vu 1 0 0");
950 <                        else
951 <                                cp = addarg(cp, "-vu 0 0 1");
920 >                                        /* redirect up axis if necessary */
921 >                switch (upax) {
922 >                case 3:                 /* plus or minus Z axis */
923 >                case -3:
924 >                case 0:
925 >                        if (!(xpos|ypos))
926 >                                upax = 2;
927                          break;
928 <                default:
929 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
930 <                                        progname, vnam(UP));
931 <                        exit(1);
928 >                case 2:                 /* plus or minus Y axis */
929 >                case -2:
930 >                        if (!(xpos|zpos))
931 >                                upax = 1;
932 >                        break;
933 >                case 1:                 /* plus or minus X axis */
934 >                case -1:
935 >                        if (!(ypos|zpos))
936 >                                upax = 3;
937 >                        break;
938                  }
939 +                cp = addarg(cp, vup[upax+3]);
940                  switch (viewtype) {
941                  case 'v':
942                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 969 | Line 951 | register char  *vs;
951                          cp = addarg(cp, "-vh 180 -vv 180");
952                          break;
953                  }
954 <        } else
955 <                while (*vs && !isspace(*vs))    /* else skip id */
956 <                        vs++;
957 <                                        /* append any additional options */
958 <        while (isspace(*vs)) vs++;
959 <        strcpy(cp, vs);
954 >        } else {
955 >                while (!isspace(*vs))           /* else skip id */
956 >                        if (!*vs++)
957 >                                return(NULL);
958 >                if (upax) {                     /* specify up vector */
959 >                        strcpy(cp, vup[upax+3]);
960 >                        cp += strlen(cp);
961 >                }
962 >        }
963 >        strcpy(cp, vs);                 /* append any additional options */
964 > #ifdef MSDOS
965 >        if (strlen(viewopts) > 40) {
966 >                setenv("VIEW", viewopts);
967 >                return("$VIEW");
968 >        }
969 > #endif
970          return(viewopts);
971   }
972  
# Line 982 | Line 974 | register char  *vs;
974   char *
975   getview(n, vn)                          /* get view n, or NULL if none */
976   int     n;
977 < char    *vn;
977 > char    *vn;            /* returned view name */
978   {
979          register char   *mv;
980  
981 <        if (viewselect != NULL) {
981 >        if (viewselect != NULL) {               /* command-line selected */
982                  if (n)                          /* only do one */
983                          return(NULL);
984                  if (viewselect[0] == '-') {     /* already specified */
# Line 999 | Line 991 | char   *vn;
991                                  ;
992                          *vn = '\0';
993                  }
994 +                                                /* view number? */
995 +                if (isint(viewselect))
996 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
997                                                  /* check list */
998                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
999                          if (matchword(viewselect, mv))
1000                                  return(specview(mv));
1001                  return(specview(viewselect));   /* standard view? */
1002          }
1003 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1004 <                if (*mv != '-')
1005 <                        while (*mv && !isspace(*mv))
1006 <                                *vn++ = *mv++;
1003 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1004 >        if (vn != NULL & mv != NULL) {
1005 >                register char   *mv2 = mv;
1006 >                if (*mv2 != '-')
1007 >                        while (*mv2 && !isspace(*mv2))
1008 >                                *vn++ = *mv2++;
1009                  *vn = '\0';
1010          }
1011 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1011 >        return(specview(mv));
1012   }
1013  
1014  
1015 + printview(vopts)                        /* print out selected view */
1016 + register char   *vopts;
1017 + {
1018 +        extern char     *atos();
1019 +        char    buf[256];
1020 +        FILE    *fp;
1021 +        register char   *cp;
1022 +
1023 +        if (vopts == NULL)
1024 +                return(-1);
1025 +        fputs("VIEW=", stdout);
1026 +        do {
1027 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1028 +                        vopts = sskip(vopts);
1029 +                        if (!*atos(buf, sizeof(buf), vopts))
1030 +                                return(-1);
1031 +                        if ((fp = fopen(buf, "r")) == NULL)
1032 +                                return(-1);
1033 +                        for (buf[sizeof(buf)-2] = '\n';
1034 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1035 +                                                buf[0] != '\n';
1036 +                                        buf[sizeof(buf)-2] = '\n') {
1037 +                                if (buf[sizeof(buf)-2] != '\n') {
1038 +                                        ungetc(buf[sizeof(buf)-2], fp);
1039 +                                        buf[sizeof(buf)-2] = '\0';
1040 +                                }
1041 +                                if (matchword(buf, "VIEW=") ||
1042 +                                                matchword(buf, "rview")) {
1043 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1044 +                                                putchar(*cp);
1045 +                                }
1046 +                        }
1047 +                        fclose(fp);
1048 +                        vopts = sskip(vopts);
1049 +                } else {
1050 +                        while (isspace(*vopts))
1051 +                                vopts++;
1052 +                        putchar(' ');
1053 +                        while (*vopts && !isspace(*vopts))
1054 +                                putchar(*vopts++);
1055 +                }
1056 +        } while (*vopts++);
1057 +        putchar('\n');
1058 +        return(0);
1059 + }
1060 +
1061 +
1062   rview(opts)                             /* run rview with first view */
1063   char    *opts;
1064   {
1065 +        char    *vw;
1066          char    combuf[512];
1067                                          /* build command */
1068 <        sprintf(combuf, "rview %s%s ", getview(0, NULL), opts);
1068 >        if ((vw = getview(0, NULL)) == NULL)
1069 >                return;
1070 >        if (sayview)
1071 >                printview(vw);
1072 >        sprintf(combuf, "rview %s%s -R %s ", vw, opts, rifname);
1073          if (rvdevice != NULL)
1074                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1075          strcat(combuf, vval(OCTREE));
1076 <        if (!silent) {                  /* echo it */
1028 <                printf("\t%s\n", combuf);
1029 <                fflush(stdout);
1030 <        }
1031 <        if (noaction)
1032 <                return;
1033 <        if (system(combuf)) {           /* run it */
1076 >        if (runcom(combuf)) {           /* run it */
1077                  fprintf(stderr, "%s: error running rview\n", progname);
1078                  exit(1);
1079          }
# Line 1041 | Line 1084 | rpict(opts)                            /* run rpict and pfilt for each view */
1084   char    *opts;
1085   {
1086          char    combuf[1024];
1087 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1088 <        char    pfopts[64];
1087 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1088 >        char    pfopts[128];
1089          char    vs[32], *vw;
1090          int     vn, mult;
1091 +        long    lastdate;
1092                                          /* get pfilt options */
1093          pfiltopts(pfopts);
1094                                          /* get resolution, reporting */
# Line 1060 | Line 1104 | char   *opts;
1104                  else if (n) {
1105                          if (n == 1) yres = xres;
1106                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1107 <                } else {
1108 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1065 <                                        progname, vnam(RESOLUTION));
1066 <                        exit(1);
1067 <                }
1107 >                } else
1108 >                        badvalue(RESOLUTION);
1109          }
1110          rep[0] = '\0';
1111          if (vdef(REPORT)) {
# Line 1075 | Line 1116 | char   *opts;
1116                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1117                  else if (n == 1)
1118                          sprintf(rep, " -t %d", (int)(minutes*60));
1119 <                else {
1120 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
1080 <                                        progname, vnam(REPORT));
1081 <                        exit(1);
1082 <                }
1119 >                else
1120 >                        badvalue(REPORT);
1121          }
1122 +                                        /* get update time */
1123 +        lastdate = octreedate > matdate ? octreedate : matdate;
1124                                          /* do each view */
1125          vn = 0;
1126          while ((vw = getview(vn++, vs)) != NULL) {
1127 +                if (sayview)
1128 +                        printview(vw);
1129                  if (!vs[0])
1130                          sprintf(vs, "%d", vn);
1131                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1132                                                  /* check date on picture */
1133 <                if (fdate(picfile) > octreedate)
1133 >                if (fdate(picfile) >= lastdate)
1134                          continue;
1135                                                  /* build rpict command */
1136                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1137 <                if (fdate(rawfile) > octreedate)        /* recover */
1137 >                if (fdate(rawfile) >= octreedate)       /* recover */
1138                          sprintf(combuf, "rpict%s%s -ro %s %s",
1139                                          rep, opts, rawfile, vval(OCTREE));
1140                  else {
# Line 1100 | Line 1142 | char   *opts;
1142                                  sprintf(combuf,
1143                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1144                                                  rep, vw, opts,
1145 <                                                vval(OCTREE), rawfile);
1146 <                                if (!silent) {
1105 <                                        printf("\t%s\n", combuf);
1106 <                                        fflush(stdout);
1107 <                                }
1108 <                                if (!noaction && system(combuf)) {
1145 >                                                vval(OCTREE), overfile);
1146 >                                if (runcom(combuf)) {
1147                                          fprintf(stderr,
1148 <                        "%s: error in overture for view %s\n\t%s removed\n",
1149 <                                                progname, vs, rawfile);
1112 <                                        unlink(rawfile);
1148 >                                        "%s: error in overture for view %s\n",
1149 >                                                progname, vs);
1150                                          exit(1);
1151                                  }
1152 + #ifdef NIX
1153 +                                rmfile(overfile);
1154 + #endif
1155                          }
1156                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1157                                          rep, vw, res, opts,
1158                                          vval(OCTREE), rawfile);
1159                  }
1160 <                if (!silent) {                  /* echo rpict command */
1121 <                        printf("\t%s\n", combuf);
1122 <                        fflush(stdout);
1123 <                }
1124 <                if (!noaction && system(combuf)) {      /* run rpict */
1160 >                if (runcom(combuf)) {           /* run rpict */
1161                          fprintf(stderr, "%s: error rendering view %s\n",
1162                                          progname, vs);
1163                          exit(1);
# Line 1133 | Line 1169 | char   *opts;
1169                  else
1170                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1171                                          rawfile, picfile);
1172 <                if (!silent) {                  /* echo pfilt command */
1137 <                        printf("\t%s\n", combuf);
1138 <                        fflush(stdout);
1139 <                }
1140 <                if (!noaction && system(combuf)) {      /* run pfilt */
1172 >                if (runcom(combuf)) {           /* run pfilt */
1173                          fprintf(stderr,
1174                          "%s: error filtering view %s\n\t%s removed\n",
1175                                          progname, vs, picfile);
# Line 1145 | Line 1177 | char   *opts;
1177                          exit(1);
1178                  }
1179                                                  /* remove raw file */
1180 <                if (!silent)
1180 >                rmfile(rawfile);
1181 >        }
1182 > }
1183 >
1184 >
1185 > runcom(cs)                      /* run command */
1186 > char    *cs;
1187 > {
1188 >        if (!silent)            /* echo it */
1189 >                printf("\t%s\n", cs);
1190 >        if (noaction)
1191 >                return(0);
1192 >        fflush(stdout);         /* flush output and pass to shell */
1193 >        return(system(cs));
1194 > }
1195 >
1196 >
1197 > rmfile(fn)                      /* remove a file */
1198 > char    *fn;
1199 > {
1200 >        if (!silent)
1201   #ifdef MSDOS
1202 <                        printf("\tdel %s\n", rawfile);
1202 >                printf("\tdel %s\n", fn);
1203   #else
1204 <                        printf("\trm %s\n", rawfile);
1204 >                printf("\trm -f %s\n", fn);
1205   #endif
1206 <                if (!noaction)
1207 <                        unlink(rawfile);
1206 >        if (noaction)
1207 >                return(0);
1208 >        return(unlink(fn));
1209 > }
1210 >
1211 >
1212 > #ifdef MSDOS
1213 > setenv(vname, value)            /* set an environment variable */
1214 > char    *vname, *value;
1215 > {
1216 >        register char   *evp;
1217 >
1218 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1219 >        if (evp == NULL)
1220 >                syserr(progname);
1221 >        sprintf(evp, "%s=%s", vname, value);
1222 >        if (putenv(evp) != 0) {
1223 >                fprintf(stderr, "%s: out of environment space\n", progname);
1224 >                exit(1);
1225          }
1226 +        if (!silent)
1227 +                printf("set %s\n", evp);
1228 + }
1229 + #endif
1230 +
1231 +
1232 + badvalue(vc)                    /* report bad variable value and exit */
1233 + int     vc;
1234 + {
1235 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1236 +                        progname, vnam(vc));
1237 +        exit(1);
1238 + }
1239 +
1240 +
1241 + syserr(s)                       /* report a system error and exit */
1242 + char    *s;
1243 + {
1244 +        perror(s);
1245 +        exit(1);
1246   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines