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.1 by greg, Thu Mar 11 09:11:00 1993 UTC vs.
Revision 2.20 by greg, Tue Aug 24 21:44:55 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 < extern long     fdate();
97 >                                /* overture calculation file */
98 > #ifdef NIX
99 > char    overfile[] = "overture.raw";
100 > #else
101 > char    overfile[] = "/dev/null";
102 > #endif
103  
104 + extern long     fdate(), time();
105 +
106   long    scenedate;              /* date of latest scene or object file */
107   long    octreedate;             /* date of octree */
108 + 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     vwonly = 0;             /* print view only */
114   char    *rvdevice = NULL;       /* rview output device */
115   char    *viewselect = NULL;     /* specific view only */
116  
# Line 133 | Line 144 | char   *argv[];
144                  case 'o':
145                          rvdevice = argv[++i];
146                          break;
147 +                case 'V':
148 +                        vwonly++;
149 +                /* fall through */
150                  case 'v':
151                          viewselect = argv[++i];
152                          break;
# Line 157 | Line 171 | char   *argv[];
171                                  /* print all values if requested */
172          if (explicate)
173                  printvals();
174 <                                /* run simulation */
174 >                                /* print view and exit? */
175 >        if (vwonly)
176 >                exit(printview()==0 ? 0 : 1);
177 >                                /* build octree */
178          oconv();
179 +                                /* check date on ambient file */
180 +        checkambfile();
181 +                                /* run simulation */
182          renderopts(ropts);
183          xferopts(ropts);
184          if (rvdevice != NULL)
# Line 168 | Line 188 | char   *argv[];
188          exit(0);
189   userr:
190          fprintf(stderr,
191 <        "Usage: %s [-s][-n][-v view][-o dev] rfile [VAR=value ..]\n",
191 >        "Usage: %s [-s][-n][-e][-v view][-o dev] rfile [VAR=value ..]\n",
192                          progname);
193          exit(1);
194   }
# Line 193 | Line 213 | load(rfname)                   /* load Radiance simulation file */
213   char    *rfname;
214   {
215          FILE    *fp;
216 <        char    buf[256];
216 >        char    buf[512];
217          register char   *cp;
218  
219          if (rfname == NULL)
220                  fp = stdin;
221 <        else if ((fp = fopen(rfname, "r")) == NULL) {
222 <                perror(rfname);
203 <                exit(1);
204 <        }
221 >        else if ((fp = fopen(rfname, "r")) == NULL)
222 >                syserr(rfname);
223          while (fgetline(buf, sizeof(buf), fp) != NULL) {
224                  for (cp = buf; *cp; cp++) {
225                          switch (*cp) {
# Line 212 | Line 230 | char   *rfname;
230                          case '#':
231                                  *cp = '\0';
232                                  break;
233 +                        default:
234 +                                continue;
235                          }
236                          break;
237                  }
# Line 260 | Line 280 | register char  *ass;
280                  exit(1);
281          }
282                                          /* assign new value */
283 <        cp = vp->value; i = vp->nass;
284 <        while (i--)
285 <                while (*cp++)
286 <                        ;
287 <        i = cp - vp->value;
288 <        vp->value = realloc(vp->value, i+n+1);
289 <        if (vp->value == NULL) {
290 <                perror(progname);
291 <                exit(1);
292 <        }
283 >        if (i = vp->nass) {
284 >                cp = vp->value;
285 >                while (i--)
286 >                        while (*cp++)
287 >                                ;
288 >                i = cp - vp->value;
289 >                vp->value = realloc(vp->value, i+n+1);
290 >        } else
291 >                vp->value = malloc(n+1);
292 >        if (vp->value == NULL)
293 >                syserr(progname);
294          strcpy(vp->value+i, ass);
295          vp->nass++;
296   }
# Line 296 | Line 317 | register int   n;
317   {
318          register char   *cp;
319  
320 <        if (vp == NULL || n < 0 || n >= vp->nass)
320 >        if (vp == NULL | n < 0 | n >= vp->nass)
321                  return(NULL);
322          cp = vp->value;
323          while (n--)
# Line 318 | Line 339 | int    vc;
339          case 'L':
340                  return(LOW);
341          }
342 <        fprintf(stderr, "%s: illegal value for variable '%s' (%s)\n",
322 <                        progname, vnam(vc), vval(vc));
323 <        exit(1);
342 >        badvalue(vc);
343   }
344  
345  
# Line 341 | Line 360 | register VARIABLE      *vp;
360                  return;
361          fprintf(stderr, "%s: warning - multiple assignment of variable '%s'\n",
362                          progname, vp->name);
363 <        while (vp->nass-- > 1)
363 >        do
364                  vp->value += strlen(vp->value)+1;
365 +        while (--vp->nass > 1);
366   }
367  
368  
# Line 372 | Line 392 | register char  *fnames;
392          while (*fnames) {
393                  while (isspace(*fnames)) fnames++;
394                  cp = thisfile;
395 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
395 >                while (*fnames && !isspace(*fnames))
396 >                        *cp++ = *fnames++;
397                  *cp = '\0';
398 <                if ((thisdate = fdate(thisfile)) < 0) {
399 <                        perror(thisfile);
379 <                        exit(1);
380 <                }
398 >                if ((thisdate = fdate(thisfile)) < 0)
399 >                        syserr(thisfile);
400                  if (thisdate > lastdate)
401                          lastdate = thisdate;
402          }
# Line 387 | Line 406 | register char  *fnames;
406  
407   checkfiles()                    /* check for existence and modified times */
408   {
409 +        char    *cp;
410          long    objdate;
411  
412 <        octreedate = vdef(OCTREE) ? fdate(vval(OCTREE)) : -1;
412 >        if (!vdef(OCTREE)) {
413 >                if ((cp = bmalloc(strlen(radname)+5)) == NULL)
414 >                        syserr(progname);
415 >                sprintf(cp, "%s.oct", radname);
416 >                vval(OCTREE) = cp;
417 >                vdef(OCTREE)++;
418 >        }
419 >        octreedate = fdate(vval(OCTREE));
420          scenedate = -1;
421          if (vdef(SCENE)) {
422                  scenedate = checklast(vval(SCENE));
# Line 400 | Line 427 | checkfiles()                   /* check for existence and modified tim
427                  }
428          }
429          if (octreedate < 0 & scenedate < 0) {
430 <                fprintf(stderr, "%s: need scene or octree\n", progname);
430 >                fprintf(stderr, "%s: need '%s' or '%s'\n", progname,
431 >                                vnam(OCTREE), vnam(SCENE));
432                  exit(1);
433          }
434 +        matdate = -1;
435 +        if (vdef(MATERIAL))
436 +                matdate = checklast(vval(MATERIAL));
437   }      
438  
439  
440 < setdefaults()                   /* set default values for unassigned var's */
440 > getoctcube(org, sizp)           /* get octree bounding cube */
441 > double  org[3], *sizp;
442   {
443 +        extern FILE     *popen();
444 +        static double   oorg[3], osiz = 0.;
445 +        char    buf[MAXPATH+16];
446          FILE    *fp;
412        double  xmin, ymin, zmin, size;
413        char    buf[512];
414        char    *cp;
447  
448 <        if (!vdef(OCTREE)) {
449 <                sprintf(buf, "%s.oct", radname);
450 <                vval(OCTREE) = savqstr(buf);
451 <                vdef(OCTREE)++;
448 >        if (osiz <= FTINY) {
449 >                oconv();                /* does nothing if done already */
450 >                sprintf(buf, "getinfo -d < %s", vval(OCTREE));
451 >                if ((fp = popen(buf, "r")) == NULL)
452 >                        syserr("getinfo");
453 >                if (fscanf(fp, "%lf %lf %lf %lf", &oorg[0], &oorg[1],
454 >                                &oorg[2], &osiz) != 4) {
455 >                        fprintf(stderr,
456 >                        "%s: error reading bounding cube from getinfo\n",
457 >                                        progname);
458 >                        exit(1);
459 >                }
460 >                pclose(fp);
461          }
462 +        org[0] = oorg[0]; org[1] = oorg[1]; org[2] = oorg[2]; *sizp = osiz;
463 + }
464 +
465 +
466 + setdefaults()                   /* set default values for unassigned var's */
467 + {
468 +        double  org[3], size;
469 +        char    buf[128];
470 +
471          if (!vdef(ZONE)) {
472 <                if (scenedate > octreedate) {
473 <                        sprintf(buf, "getbbox -w -h %s", vval(SCENE));
474 <                        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 <                }
472 >                getoctcube(org, &size);
473 >                sprintf(buf, "E %g %g %g %g %g %g", org[0], org[0]+size,
474 >                                org[1], org[1]+size, org[2], org[2]+size);
475                  vval(ZONE) = savqstr(buf);
476                  vdef(ZONE)++;
477          }
450        if (!vdef(UP)) {
451                vval(UP) = "Z";
452                vdef(UP)++;
453        }
478          if (!vdef(INDIRECT)) {
479                  vval(INDIRECT) = "0";
480                  vdef(INDIRECT)++;
# Line 467 | Line 491 | setdefaults()                  /* set default values for unassigned v
491                  vval(PICTURE) = radname;
492                  vdef(PICTURE)++;
493          }
470        if (!vdef(AMBFILE)) {
471                sprintf(buf, "%s.amb", radname);
472                vval(AMBFILE) = savqstr(buf);
473                vdef(AMBFILE)++;
474        }
494          if (!vdef(VIEW)) {
495                  vval(VIEW) = "X";
496                  vdef(VIEW)++;
# Line 496 | Line 515 | printvals()                    /* print variable values */
515          register int    i, j;
516  
517          for (i = 0; i < NVARS; i++)
518 <                for (j = 0; j < vv[i].nass; j++)
519 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
518 >                for (j = 0; j < vdef(i); j++)
519 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
520          fflush(stdout);
521   }
522  
# Line 506 | Line 525 | oconv()                                /* run oconv if necessary */
525   {
526          char    combuf[512], ocopts[64];
527  
528 <        if (octreedate > scenedate)     /* check dates */
528 >        if (octreedate >= scenedate)    /* check dates */
529                  return;
530                                          /* build command */
531          oconvopts(ocopts);
532 <        sprintf(combuf, "oconv%s %s > %s", ocopts, vval(SCENE), vval(OCTREE));
533 <        if (!silent) {                  /* echo it */
534 <                printf("\t%s\n", combuf);
535 <                fflush(stdout);
536 <        }
537 <        if (noaction)
538 <                return;
539 <        if (system(combuf)) {           /* run it */
532 >        if (vdef(MATERIAL))
533 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
534 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
535 >        else
536 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
537 >                                vval(SCENE), vval(OCTREE));
538 >        
539 >        if (runcom(combuf)) {           /* run it */
540                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
541                                  progname, vval(OCTREE));
542                  unlink(vval(OCTREE));
543                  exit(1);
544          }
545 +        octreedate = time(0);
546   }
547  
548  
# Line 538 | Line 558 | register char  *op, *arg;
558  
559  
560   oconvopts(oo)                           /* get oconv options */
561 < char    *oo;
561 > register char   *oo;
562   {
563 +        /* BEWARE:  This may be called via setdefaults(), so no assumptions */
564 +
565          *oo = '\0';
566          if (vdef(OCONV))
567                  addarg(oo, vval(OCONV));
568   }
569  
570  
571 < lowqopts(ro)                            /* low quality rendering options */
550 < char    *ro;
571 > checkambfile()                  /* check date on ambient file */
572   {
573 <        register char   *op = ro;
573 >        long    afdate;
574  
575 +        if (!vdef(AMBFILE))
576 +                return;
577 +        if ((afdate = fdate(vval(AMBFILE))) < 0)
578 +                return;
579 +        if (octreedate > afdate | matdate > afdate)
580 +                rmfile(vval(AMBFILE));
581 + }
582 +
583 +
584 + double
585 + ambval()                                /* compute ambient value */
586 + {
587 +        if (vdef(EXPOSURE)) {
588 +                if (!isflt(vval(EXPOSURE)))
589 +                        badvalue(EXPOSURE);
590 +                if (vval(EXPOSURE)[0] == '+' || vval(EXPOSURE)[0] == '-')
591 +                        return(.5/pow(2.,atof(vval(EXPOSURE))));
592 +                return(.5/atof(vval(EXPOSURE)));
593 +        }
594 +        if (vlet(ZONE) == 'E')
595 +                return(10.);
596 +        if (vlet(ZONE) == 'I')
597 +                return(.01);
598 +        badvalue(ZONE);
599 + }
600 +
601 +
602 + lowqopts(op)                            /* low quality rendering options */
603 + register char   *op;
604 + {
605 +        double  d, org[3], siz[3];
606 +
607          *op = '\0';
608 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
609 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
610 +                badvalue(ZONE);
611 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
612 +        getoctcube(org, &d);
613 +        d *= 3./(siz[0]+siz[1]+siz[2]);
614 +        switch (vscale(DETAIL)) {
615 +        case LOW:
616 +                op = addarg(op, "-ps 16 -dp 16");
617 +                sprintf(op, " -ar %d", (int)(4*d));
618 +                op += strlen(op);
619 +                break;
620 +        case MEDIUM:
621 +                op = addarg(op, "-ps 8 -dp 32");
622 +                sprintf(op, " -ar %d", (int)(8*d));
623 +                op += strlen(op);
624 +                break;
625 +        case HIGH:
626 +                op = addarg(op, "-ps 4 -dp 64");
627 +                sprintf(op, " -ar %d", (int)(16*d));
628 +                op += strlen(op);
629 +                break;
630 +        }
631 +        op = addarg(op, "-pt .16");
632 +        if (vbool(PENUMBRAS))
633 +                op = addarg(op, "-ds .4");
634 +        else
635 +                op = addarg(op, "-ds 0");
636 +        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .5");
637 +        if (vdef(AMBFILE)) {
638 +                sprintf(op, " -af %s", vval(AMBFILE));
639 +                op += strlen(op);
640 +        } else
641 +                overture = 0;
642 +        switch (vscale(VARIABILITY)) {
643 +        case LOW:
644 +                op = addarg(op, "-aa .4 -ad 64");
645 +                break;
646 +        case MEDIUM:
647 +                op = addarg(op, "-aa .3 -ad 128");
648 +                break;
649 +        case HIGH:
650 +                op = addarg(op, "-aa .25 -ad 256");
651 +                break;
652 +        }
653 +        op = addarg(op, "-as 0");
654 +        d = ambval();
655 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
656 +        op += strlen(op);
657 +        op = addarg(op, "-lr 3 -lw .02");
658          if (vdef(RENDER))
659                  op = addarg(op, vval(RENDER));
660   }
661  
662  
663 < medqopts(ro)                            /* medium quality rendering options */
664 < char    *ro;
663 > medqopts(op)                            /* medium quality rendering options */
664 > register char   *op;
665   {
666 <        register char   *op = ro;
666 >        double  d, org[3], siz[3];
667  
668          *op = '\0';
669 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
670 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
671 +                badvalue(ZONE);
672 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
673 +        getoctcube(org, &d);
674 +        d *= 3./(siz[0]+siz[1]+siz[2]);
675 +        switch (vscale(DETAIL)) {
676 +        case LOW:
677 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 4" : "-ps 8");
678 +                op = addarg(op, "-dp 64");
679 +                sprintf(op, " -ar %d", (int)(8*d));
680 +                op += strlen(op);
681 +                break;
682 +        case MEDIUM:
683 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 3" : "-ps 6");
684 +                op = addarg(op, "-dp 128");
685 +                sprintf(op, " -ar %d", (int)(16*d));
686 +                op += strlen(op);
687 +                break;
688 +        case HIGH:
689 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 2" : "-ps 4");
690 +                op = addarg(op, "-dp 256");
691 +                sprintf(op, " -ar %d", (int)(32*d));
692 +                op += strlen(op);
693 +                break;
694 +        }
695 +        op = addarg(op, "-pt .08");
696 +        if (vbool(PENUMBRAS))
697 +                op = addarg(op, "-ds .2 -dj .35");
698 +        else
699 +                op = addarg(op, "-ds .3");
700 +        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .1");
701 +        if (overture = vint(INDIRECT)) {
702 +                sprintf(op, " -ab %d", overture);
703 +                op += strlen(op);
704 +        }
705 +        if (vdef(AMBFILE)) {
706 +                sprintf(op, " -af %s", vval(AMBFILE));
707 +                op += strlen(op);
708 +        } else
709 +                overture = 0;
710 +        switch (vscale(VARIABILITY)) {
711 +        case LOW:
712 +                op = addarg(op, "-aa .25 -ad 196 -as 0");
713 +                break;
714 +        case MEDIUM:
715 +                op = addarg(op, "-aa .2 -ad 400 -as 64");
716 +                break;
717 +        case HIGH:
718 +                op = addarg(op, "-aa .15 -ad 768 -as 196");
719 +                break;
720 +        }
721 +        d = ambval();
722 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
723 +        op += strlen(op);
724 +        op = addarg(op, "-lr 6 -lw .002");
725          if (vdef(RENDER))
726                  op = addarg(op, vval(RENDER));
727   }
728  
729  
730 < hiqopts(ro)                             /* high quality rendering options */
731 < char    *ro;
730 > hiqopts(op)                             /* high quality rendering options */
731 > register char   *op;
732   {
733 <        register char   *op = ro;
733 >        double  d, org[3], siz[3];
734  
735          *op = '\0';
736 +        if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf", &org[0],
737 +                        &siz[0], &org[1], &siz[1], &org[2], &siz[2]) != 6)
738 +                badvalue(ZONE);
739 +        siz[0] -= org[0]; siz[1] -= org[1]; siz[2] -= org[2];
740 +        getoctcube(org, &d);
741 +        d *= 3./(siz[0]+siz[1]+siz[2]);
742 +        switch (vscale(DETAIL)) {
743 +        case LOW:
744 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 8");
745 +                op = addarg(op, "-dp 256");
746 +                sprintf(op, " -ar %d", (int)(16*d));
747 +                op += strlen(op);
748 +                break;
749 +        case MEDIUM:
750 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 5");
751 +                op = addarg(op, "-dp 512");
752 +                sprintf(op, " -ar %d", (int)(32*d));
753 +                op += strlen(op);
754 +                break;
755 +        case HIGH:
756 +                op = addarg(op, vbool(PENUMBRAS) ? "-ps 1" : "-ps 3");
757 +                op = addarg(op, "-dp 1024");
758 +                sprintf(op, " -ar %d", (int)(64*d));
759 +                op += strlen(op);
760 +                break;
761 +        }
762 +        op = addarg(op, "-pt .04");
763 +        if (vbool(PENUMBRAS))
764 +                op = addarg(op, "-ds .1 -dj .7");
765 +        else
766 +                op = addarg(op, "-ds .2");
767 +        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .01");
768 +        sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
769 +        op += strlen(op);
770 +        if (vdef(AMBFILE)) {
771 +                sprintf(op, " -af %s", vval(AMBFILE));
772 +                op += strlen(op);
773 +        } else
774 +                overture = 0;
775 +        switch (vscale(VARIABILITY)) {
776 +        case LOW:
777 +                op = addarg(op, "-aa .15 -ad 256 -as 0");
778 +                break;
779 +        case MEDIUM:
780 +                op = addarg(op, "-aa .125 -ad 512 -as 256");
781 +                break;
782 +        case HIGH:
783 +                op = addarg(op, "-aa .08 -ad 1024 -as 512");
784 +                break;
785 +        }
786 +        d = ambval();
787 +        sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
788 +        op += strlen(op);
789 +        op = addarg(op, "-lr 12 -lw .0005");
790          if (vdef(RENDER))
791                  op = addarg(op, vval(RENDER));
792   }
# Line 583 | Line 796 | xferopts(ro)                           /* transfer options if indicated */
796   char    *ro;
797   {
798          int     fd, n;
799 +        register char   *cp;
800          
801          n = strlen(ro);
802          if (n < 2)
803                  return;
804          if (vdef(OPTFILE)) {
805 <                if ((fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
806 <                        perror(vval(OPTFILE));
807 <                        exit(1);
808 <                }
809 <                if (write(fd, ro+1, n-1) != n-1) {
810 <                        perror(vval(OPTFILE));
811 <                        exit(1);
812 <                }
813 <                write(fd, "\n", 1);
814 <                close(fd);
601 <                ro[0] = ' ';
602 <                ro[1] = '^';
603 <                strcpy(ro+2, vval(OPTFILE));
805 >                for (cp = ro; cp[1]; cp++)
806 >                        if (isspace(cp[1]) && cp[2] == '-' && isalpha(cp[3]))
807 >                                *cp = '\n';
808 >                        else
809 >                                *cp = cp[1];
810 >                *cp = '\n';
811 >                fd = open(vval(OPTFILE), O_WRONLY|O_CREAT|O_TRUNC, 0666);
812 >                if (fd < 0 || write(fd, ro, n) != n || close(fd) < 0)
813 >                        syserr(vval(OPTFILE));
814 >                sprintf(ro, " @%s", vval(OPTFILE));
815          }
816   #ifdef MSDOS
817          else if (n > 50) {
818 <                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);
818 >                setenv("ROPT", ro+1);
819                  strcpy(ro, " $ROPT");
820          }
821   #endif
# Line 626 | Line 830 | register char  *po;
830                  po = addarg(po, "-1 -e");
831                  po = addarg(po, vval(EXPOSURE));
832          }
833 <        if (vscale(QUALITY) == HIGH)
834 <                po = addarg(po, "-r .65");
833 >        switch (vscale(QUALITY)) {
834 >        case MEDIUM:
835 >                po = addarg(po, "-r 1");
836 >                break;
837 >        case HIGH:
838 >                po = addarg(po, "-m .25");
839 >                break;
840 >        }
841          if (vdef(PFILT))
842                  po = addarg(po, vval(PFILT));
843   }
# Line 649 | Line 859 | char *
859   specview(vs)                            /* get proper view spec from vs */
860   register char   *vs;
861   {
862 +        static char     vup[7][12] = {"-vu 0 0 -1","-vu 0 -1 0","-vu -1 0 0",
863 +                        "-vu 0 0 1", "-vu 1 0 0","-vu 0 1 0","-vu 0 0 1"};
864          static char     viewopts[128];
865          register char   *cp;
866 <        int     xpos, ypos, zpos, viewtype;
867 <        int     exterior;
866 >        int     xpos, ypos, zpos, viewtype, upax;
867 >        register int    i;
868          double  cent[3], dim[3], mult, d;
869  
870          if (vs == NULL || *vs == '-')
871                  return(vs);
872 +        upax = 0;                       /* get the up vector */
873 +        if (vdef(UP)) {
874 +                if (vval(UP)[0] == '-' || vval(UP)[0] == '+')
875 +                        upax = 1-'X'+UPPER(vval(UP)[1]);
876 +                else
877 +                        upax = 1-'X'+vlet(UP);
878 +                if (upax < 1 | upax > 3)
879 +                        badvalue(UP);
880 +                if (vval(UP)[0] == '-')
881 +                        upax = -upax;
882 +        }
883                                          /* check standard view names */
884          xpos = ypos = zpos = 0;
662        viewtype = 0;
885          if (*vs == 'X') {
886                  xpos = 1; vs++;
887          } else if (*vs == 'x') {
# Line 675 | Line 897 | register char  *vs;
897          } else if (*vs == 'z') {
898                  zpos = -1; vs++;
899          }
900 +        viewtype = 'v';
901          if (*vs == 'v' | *vs == 'l' | *vs == 'a' | *vs == 'h')
902                  viewtype = *vs++;
680        else if (!*vs || isspace(*vs))
681                viewtype = 'v';
903          cp = viewopts;
904 <        if (viewtype && (xpos|ypos|zpos)) {     /* got standard view */
904 >        if ((!*vs || isspace(*vs)) && (xpos|ypos|zpos)) {       /* got one! */
905                  *cp++ = '-'; *cp++ = 'v'; *cp++ = 't'; *cp++ = viewtype;
906                  if (sscanf(vval(ZONE), "%*s %lf %lf %lf %lf %lf %lf",
907                                  &cent[0], &dim[0], &cent[1], &dim[1],
908 <                                &cent[2], &dim[2]) != 6) {
909 <                        fprintf(stderr, "%s: bad zone specification\n",
910 <                                        progname);
911 <                        exit(1);
908 >                                &cent[2], &dim[2]) != 6)
909 >                        badvalue(ZONE);
910 >                for (i = 0; i < 3; i++) {
911 >                        dim[i] -= cent[i];
912 >                        cent[i] += .5*dim[i];
913                  }
914 <                dim[0] -= cent[0];
693 <                dim[1] -= cent[1];
694 <                dim[2] -= cent[2];
695 <                exterior = vlet(ZONE) == 'E';
696 <                mult = exterior ? 2. : .45 ;
914 >                mult = vlet(ZONE)=='E' ? 2. : .45 ;
915                  sprintf(cp, " -vp %.2g %.2g %.2g -vd %.2g %.2g %.2g",
916                                  cent[0]+xpos*mult*dim[0],
917                                  cent[1]+ypos*mult*dim[1],
918                                  cent[2]+zpos*mult*dim[2],
919                                  -xpos*dim[0], -ypos*dim[1], -zpos*dim[2]);
920                  cp += strlen(cp);
921 <                switch (vlet(UP)) {
922 <                case 'Z':
923 <                        if (xpos|ypos) {
924 <                                cp = addarg(cp, "-vu 0 0 1");
925 <                                break;
926 <                        }
927 <                /* 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");
921 >                                        /* redirect up axis if necessary */
922 >                switch (upax) {
923 >                case 3:                 /* plus or minus Z axis */
924 >                case -3:
925 >                case 0:
926 >                        if (!(xpos|ypos))
927 >                                upax = 2;
928                          break;
929 <                default:
930 <                        fprintf(stderr, "%s: illegal value for variable '%s'\n",
931 <                                        progname, vnam(UP));
932 <                        exit(1);
929 >                case 2:                 /* plus or minus Y axis */
930 >                case -2:
931 >                        if (!(xpos|zpos))
932 >                                upax = 1;
933 >                        break;
934 >                case 1:                 /* plus or minus X axis */
935 >                case -1:
936 >                        if (!(ypos|zpos))
937 >                                upax = 3;
938 >                        break;
939                  }
940 +                cp = addarg(cp, vup[upax+3]);
941                  switch (viewtype) {
942                  case 'v':
943                          cp = addarg(cp, "-vh 45 -vv 45");
# Line 738 | Line 952 | register char  *vs;
952                          cp = addarg(cp, "-vh 180 -vv 180");
953                          break;
954                  }
955 <        } else
956 <                while (*vs && !isspace(*vs))    /* else skip id */
957 <                        vs++;
958 <                                        /* append any additional options */
959 <        while (isspace(*vs)) vs++;
960 <        strcpy(cp, vs);
955 >        } else {
956 >                while (!isspace(*vs))           /* else skip id */
957 >                        if (!*vs++)
958 >                                return(NULL);
959 >                if (upax) {                     /* specify up vector */
960 >                        strcpy(cp, vup[upax+3]);
961 >                        cp += strlen(cp);
962 >                }
963 >        }
964 >        strcpy(cp, vs);                 /* append any additional options */
965 > #ifdef MSDOS
966 >        if (strlen(viewopts) > 40) {
967 >                setenv("VIEW", viewopts);
968 >                return("$VIEW");
969 >        }
970 > #endif
971          return(viewopts);
972   }
973  
# Line 751 | Line 975 | register char  *vs;
975   char *
976   getview(n, vn)                          /* get view n, or NULL if none */
977   int     n;
978 < char    *vn;
978 > char    *vn;            /* returned view name */
979   {
980          register char   *mv;
981  
982 <        if (viewselect != NULL) {
982 >        if (viewselect != NULL) {               /* command-line selected */
983                  if (n)                          /* only do one */
984                          return(NULL);
985                  if (viewselect[0] == '-') {     /* already specified */
# Line 768 | Line 992 | char   *vn;
992                                  ;
993                          *vn = '\0';
994                  }
995 +                                                /* view number? */
996 +                if (isint(viewselect))
997 +                        return(specview(nvalue(vv+VIEW, atoi(viewselect)-1)));
998                                                  /* check list */
999                  while ((mv = nvalue(vv+VIEW, n++)) != NULL)
1000                          if (matchword(viewselect, mv))
1001                                  return(specview(mv));
1002                  return(specview(viewselect));   /* standard view? */
1003          }
1004 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
1005 <                if (*mv != '-')
1006 <                        while (*mv && !isspace(*mv))
1007 <                                *vn++ = *mv++;
1004 >        mv = nvalue(vv+VIEW, n);                /* use view n */
1005 >        if (vn != NULL & mv != NULL) {
1006 >                register char   *mv2 = mv;
1007 >                if (*mv2 != '-')
1008 >                        while (*mv2 && !isspace(*mv2))
1009 >                                *vn++ = *mv2++;
1010                  *vn = '\0';
1011          }
1012 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
1012 >        return(specview(mv));
1013   }
1014  
1015  
1016 + printview()                     /* print out selected view */
1017 + {
1018 +        extern char     *atos();
1019 +        char    buf[256];
1020 +        FILE    *fp;
1021 +        register char   *vopts, *cp;
1022 +
1023 +        vopts = getview(0, NULL);
1024 +        if (vopts == NULL)
1025 +                return(-1);
1026 +        fputs("VIEW=", stdout);
1027 +        do {
1028 +                if (matchword(vopts, "-vf")) {          /* expand view file */
1029 +                        vopts = sskip(vopts);
1030 +                        if (!*atos(buf, sizeof(buf), vopts))
1031 +                                return(-1);
1032 +                        if ((fp = fopen(buf, "r")) == NULL)
1033 +                                return(-1);
1034 +                        for (buf[sizeof(buf)-2] = '\n';
1035 +                                        fgets(buf, sizeof(buf), fp) != NULL &&
1036 +                                                buf[0] != '\n';
1037 +                                        buf[sizeof(buf)-2] = '\n') {
1038 +                                if (buf[sizeof(buf)-2] != '\n') {
1039 +                                        ungetc(buf[sizeof(buf)-2], fp);
1040 +                                        buf[sizeof(buf)-2] = '\0';
1041 +                                }
1042 +                                if (matchword(buf, "VIEW=") ||
1043 +                                                matchword(buf, "rview")) {
1044 +                                        for (cp = sskip(buf); *cp && *cp != '\n'; cp++)
1045 +                                                putchar(*cp);
1046 +                                }
1047 +                        }
1048 +                        fclose(fp);
1049 +                        vopts = sskip(vopts);
1050 +                } else {
1051 +                        while (isspace(*vopts))
1052 +                                vopts++;
1053 +                        putchar(' ');
1054 +                        while (*vopts && !isspace(*vopts))
1055 +                                putchar(*vopts++);
1056 +                }
1057 +        } while (*vopts++);
1058 +        putchar('\n');
1059 +        return(0);
1060 + }
1061 +
1062 +
1063   rview(opts)                             /* run rview with first view */
1064   char    *opts;
1065   {
# Line 793 | Line 1069 | char   *opts;
1069          if (rvdevice != NULL)
1070                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
1071          strcat(combuf, vval(OCTREE));
1072 <        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 */
1072 >        if (runcom(combuf)) {           /* run it */
1073                  fprintf(stderr, "%s: error running rview\n", progname);
1074                  exit(1);
1075          }
# Line 809 | Line 1079 | char   *opts;
1079   rpict(opts)                             /* run rpict and pfilt for each view */
1080   char    *opts;
1081   {
1082 <        char    combuf[512];
1083 <        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH], res[32];
1084 <        char    pfopts[64];
1082 >        char    combuf[1024];
1083 >        char    rawfile[MAXPATH], picfile[MAXPATH], rep[MAXPATH+16], res[32];
1084 >        char    pfopts[128];
1085          char    vs[32], *vw;
1086          int     vn, mult;
1087 +        long    lastdate;
1088                                          /* get pfilt options */
1089          pfiltopts(pfopts);
1090                                          /* get resolution, reporting */
# Line 829 | Line 1100 | char   *opts;
1100                  else if (n) {
1101                          if (n == 1) yres = xres;
1102                          sprintf(res, "-x %d -y %d", mult*xres, mult*yres);
1103 <                } else {
1104 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
834 <                                        progname, vnam(RESOLUTION));
835 <                        exit(1);
836 <                }
1103 >                } else
1104 >                        badvalue(RESOLUTION);
1105          }
1106          rep[0] = '\0';
1107          if (vdef(REPORT)) {
# Line 844 | Line 1112 | char   *opts;
1112                          sprintf(rep, " -t %d -e %s", (int)(minutes*60), rawfile);
1113                  else if (n == 1)
1114                          sprintf(rep, " -t %d", (int)(minutes*60));
1115 <                else {
1116 <                        fprintf(stderr, "%s: bad value for variable '%s'\n",
849 <                                        progname, vnam(REPORT));
850 <                        exit(1);
851 <                }
1115 >                else
1116 >                        badvalue(REPORT);
1117          }
1118 +                                        /* get update time */
1119 +        lastdate = octreedate > matdate ? octreedate : matdate;
1120                                          /* do each view */
1121          vn = 0;
1122          while ((vw = getview(vn++, vs)) != NULL) {
# Line 857 | Line 1124 | char   *opts;
1124                          sprintf(vs, "%d", vn);
1125                  sprintf(picfile, "%s_%s.pic", vval(PICTURE), vs);
1126                                                  /* check date on picture */
1127 <                if (fdate(picfile) > octreedate)
1127 >                if (fdate(picfile) >= lastdate)
1128                          continue;
1129                                                  /* build rpict command */
1130                  sprintf(rawfile, "%s_%s.raw", vval(PICTURE), vs);
1131 <                if (fdate(rawfile) > octreedate)        /* recover */
1131 >                if (fdate(rawfile) >= octreedate)       /* recover */
1132                          sprintf(combuf, "rpict%s%s -ro %s %s",
1133                                          rep, opts, rawfile, vval(OCTREE));
1134                  else {
# Line 869 | Line 1136 | char   *opts;
1136                                  sprintf(combuf,
1137                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1138                                                  rep, vw, opts,
1139 <                                                vval(OCTREE), rawfile);
1140 <                                if (!silent) {
874 <                                        printf("\t%s\n", combuf);
875 <                                        fflush(stdout);
876 <                                }
877 <                                if (!noaction && system(combuf)) {
1139 >                                                vval(OCTREE), overfile);
1140 >                                if (runcom(combuf)) {
1141                                          fprintf(stderr,
1142 <                        "%s: error in overture for view %s\n\t%s removed\n",
1143 <                                                progname, vs, rawfile);
881 <                                        unlink(rawfile);
1142 >                                        "%s: error in overture for view %s\n",
1143 >                                                progname, vs);
1144                                          exit(1);
1145                                  }
1146 + #ifdef NIX
1147 +                                rmfile(overfile);
1148 + #endif
1149                          }
1150                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1151                                          rep, vw, res, opts,
1152                                          vval(OCTREE), rawfile);
1153                  }
1154 <                if (!silent) {                  /* echo rpict command */
890 <                        printf("\t%s\n", combuf);
891 <                        fflush(stdout);
892 <                }
893 <                if (!noaction && system(combuf)) {      /* run rpict */
1154 >                if (runcom(combuf)) {           /* run rpict */
1155                          fprintf(stderr, "%s: error rendering view %s\n",
1156                                          progname, vs);
1157                          exit(1);
# Line 902 | Line 1163 | char   *opts;
1163                  else
1164                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1165                                          rawfile, picfile);
1166 <                if (!silent) {                  /* echo pfilt command */
906 <                        printf("\t%s\n", combuf);
907 <                        fflush(stdout);
908 <                }
909 <                if (!noaction && system(combuf)) {      /* run pfilt */
1166 >                if (runcom(combuf)) {           /* run pfilt */
1167                          fprintf(stderr,
1168                          "%s: error filtering view %s\n\t%s removed\n",
1169                                          progname, vs, picfile);
# Line 914 | Line 1171 | char   *opts;
1171                          exit(1);
1172                  }
1173                                                  /* remove raw file */
1174 <                if (!silent)
1174 >                rmfile(rawfile);
1175 >        }
1176 > }
1177 >
1178 >
1179 > runcom(cs)                      /* run command */
1180 > char    *cs;
1181 > {
1182 >        if (!silent)            /* echo it */
1183 >                printf("\t%s\n", cs);
1184 >        if (noaction)
1185 >                return(0);
1186 >        fflush(stdout);         /* flush output and pass to shell */
1187 >        return(system(cs));
1188 > }
1189 >
1190 >
1191 > rmfile(fn)                      /* remove a file */
1192 > char    *fn;
1193 > {
1194 >        if (!silent)
1195   #ifdef MSDOS
1196 <                        printf("\tdel %s\n", rawfile);
1196 >                printf("\tdel %s\n", fn);
1197   #else
1198 <                        printf("\trm %s\n", rawfile);
1198 >                printf("\trm -f %s\n", fn);
1199   #endif
1200 <                if (!noaction)
1201 <                        unlink(rawfile);
1200 >        if (noaction)
1201 >                return(0);
1202 >        return(unlink(fn));
1203 > }
1204 >
1205 >
1206 > #ifdef MSDOS
1207 > setenv(vname, value)            /* set an environment variable */
1208 > char    *vname, *value;
1209 > {
1210 >        register char   *evp;
1211 >
1212 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1213 >        if (evp == NULL)
1214 >                syserr(progname);
1215 >        sprintf(evp, "%s=%s", vname, value);
1216 >        if (putenv(evp) != 0) {
1217 >                fprintf(stderr, "%s: out of environment space\n", progname);
1218 >                exit(1);
1219          }
1220 +        if (!silent)
1221 +                printf("set %s\n", evp);
1222 + }
1223 + #endif
1224 +
1225 +
1226 + badvalue(vc)                    /* report bad variable value and exit */
1227 + int     vc;
1228 + {
1229 +        fprintf(stderr, "%s: bad value for variable '%s'\n",
1230 +                        progname, vnam(vc));
1231 +        exit(1);
1232 + }
1233 +
1234 +
1235 + syserr(s)                       /* report a system error and exit */
1236 + char    *s;
1237 + {
1238 +        perror(s);
1239 +        exit(1);
1240   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines