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.3 by greg, Thu Mar 11 17:23:33 1993 UTC vs.
Revision 2.9 by greg, Wed May 26 11:37:42 1993 UTC

# Line 94 | 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 */
# Line 159 | Line 166 | char   *argv[];
166                                  /* print all values if requested */
167          if (explicate)
168                  printvals();
169 <                                /* run simulation */
169 >                                /* build octree */
170          oconv();
171 +                                /* check date on ambient file */
172 +        checkambfile();
173 +                                /* run simulation */
174          renderopts(ropts);
175          xferopts(ropts);
176          if (rvdevice != NULL)
# Line 195 | Line 205 | load(rfname)                   /* load Radiance simulation file */
205   char    *rfname;
206   {
207          FILE    *fp;
208 <        char    buf[256];
208 >        char    buf[512];
209          register char   *cp;
210  
211          if (rfname == NULL)
# Line 212 | Line 222 | char   *rfname;
222                          case '#':
223                                  *cp = '\0';
224                                  break;
225 +                        default:
226 +                                continue;
227                          }
228                          break;
229                  }
# Line 260 | Line 272 | register char  *ass;
272                  exit(1);
273          }
274                                          /* assign new value */
275 <        cp = vp->value; i = vp->nass;
276 <        while (i--)
277 <                while (*cp++)
278 <                        ;
279 <        i = cp - vp->value;
280 <        vp->value = realloc(vp->value, i+n+1);
275 >        if (i = vp->nass) {
276 >                cp = vp->value;
277 >                while (i--)
278 >                        while (*cp++)
279 >                                ;
280 >                i = cp - vp->value;
281 >                vp->value = realloc(vp->value, i+n+1);
282 >        } else
283 >                vp->value = malloc(n+1);
284          if (vp->value == NULL)
285                  syserr(progname);
286          strcpy(vp->value+i, ass);
# Line 369 | Line 384 | register char  *fnames;
384          while (*fnames) {
385                  while (isspace(*fnames)) fnames++;
386                  cp = thisfile;
387 <                while (*fnames && !isspace(*fnames)) *cp++ = *fnames++;
387 >                while (*fnames && !isspace(*fnames))
388 >                        *cp++ = *fnames++;
389                  *cp = '\0';
390                  if ((thisdate = fdate(thisfile)) < 0)
391                          syserr(thisfile);
# Line 488 | Line 504 | printvals()                    /* print variable values */
504          register int    i, j;
505  
506          for (i = 0; i < NVARS; i++)
507 <                for (j = 0; j < vv[i].nass; j++)
508 <                        printf("%s= %s\n", vv[i].name, nvalue(vv+i, j));
507 >                for (j = 0; j < vdef(i); j++)
508 >                        printf("%s= %s\n", vnam(i), nvalue(vv+i, j));
509          fflush(stdout);
510   }
511  
# Line 502 | Line 518 | oconv()                                /* run oconv if necessary */
518                  return;
519                                          /* build command */
520          oconvopts(ocopts);
521 <        sprintf(combuf, "oconv%s %s %s > %s", ocopts,
522 <                        vdef(MATERIAL) ? vval(MATERIAL) : "",
523 <                        vval(SCENE), vval(OCTREE));
524 <        if (!silent) {                  /* echo it */
525 <                printf("\t%s\n", combuf);
526 <                fflush(stdout);
527 <        }
528 <        if (noaction)
513 <                return;
514 <        if (system(combuf)) {           /* run it */
521 >        if (vdef(MATERIAL))
522 >                sprintf(combuf, "oconv%s %s %s > %s", ocopts,
523 >                                vval(MATERIAL), vval(SCENE), vval(OCTREE));
524 >        else
525 >                sprintf(combuf, "oconv%s %s > %s", ocopts,
526 >                                vval(SCENE), vval(OCTREE));
527 >        
528 >        if (runcom(combuf)) {           /* run it */
529                  fprintf(stderr, "%s: error generating octree\n\t%s removed\n",
530                                  progname, vval(OCTREE));
531                  unlink(vval(OCTREE));
# Line 543 | Line 557 | register char  *oo;
557   }
558  
559  
560 + checkambfile()                  /* check date on ambient file */
561 + {
562 +        long    afdate;
563 +
564 +        if (vdef(AMBFILE)) {
565 +                afdate = fdate(vval(AMBFILE));
566 +                if (afdate >= 0 & octreedate > afdate)
567 +                        rmfile(vval(AMBFILE));
568 +        }
569 + }
570 +
571 +
572   double
573   ambval()                                /* compute ambient value */
574   {
# Line 575 | Line 601 | register char  *op;
601          d *= 3./(siz[0]+siz[1]+siz[2]);
602          switch (vscale(DETAIL)) {
603          case LOW:
604 <                op = addarg(op, "-ps 16");
579 <                op = addarg(op, "-dp 16");
604 >                op = addarg(op, "-ps 16 -dp 16");
605                  sprintf(op, " -ar %d", (int)(4*d));
606                  op += strlen(op);
607                  break;
608          case MEDIUM:
609 <                op = addarg(op, "-ps 8");
585 <                op = addarg(op, "-dp 32");
609 >                op = addarg(op, "-ps 8 -dp 32");
610                  sprintf(op, " -ar %d", (int)(8*d));
611                  op += strlen(op);
612                  break;
613          case HIGH:
614 <                op = addarg(op, "-ps 4");
591 <                op = addarg(op, "-dp 64");
614 >                op = addarg(op, "-ps 4 -dp 64");
615                  sprintf(op, " -ar %d", (int)(16*d));
616                  op += strlen(op);
617                  break;
# Line 596 | Line 619 | register char  *op;
619          op = addarg(op, "-pt .16");
620          if (vbool(PENUMBRAS))
621                  op = addarg(op, "-ds .4");
622 <        op = addarg(op, "-dt .2");
623 <        op = addarg(op, "-dc .25");
624 <        op = addarg(op, "-dr 0");
602 <        op = addarg(op, "-sj 0");
603 <        op = addarg(op, "-st .7");
604 <        op = addarg(op, "-ab 0");
622 >        else
623 >                op = addarg(op, "-ds 0");
624 >        op = addarg(op, "-dt .2 -dc .25 -dr 0 -sj 0 -st .7");
625          if (vdef(AMBFILE)) {
626                  sprintf(op, " -af %s", vval(AMBFILE));
627                  op += strlen(op);
# Line 609 | Line 629 | register char  *op;
629                  overture = 0;
630          switch (vscale(VARIABILITY)) {
631          case LOW:
632 <                op = addarg(op, "-aa .4");
613 <                op = addarg(op, "-ad 32");
632 >                op = addarg(op, "-aa .4 -ad 32");
633                  break;
634          case MEDIUM:
635 <                op = addarg(op, "-aa .3");
617 <                op = addarg(op, "-ad 64");
635 >                op = addarg(op, "-aa .3 -ad 64");
636                  break;
637          case HIGH:
638 <                op = addarg(op, "-aa .25");
621 <                op = addarg(op, "-ad 128");
638 >                op = addarg(op, "-aa .25 -ad 128");
639                  break;
640          }
641          op = addarg(op, "-as 0");
642          d = ambval();
643          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
644          op += strlen(op);
645 <        op = addarg(op, "-lr 3");
629 <        op = addarg(op, "-lw .02");
645 >        op = addarg(op, "-lr 3 -lw .02");
646          if (vdef(RENDER))
647                  op = addarg(op, vval(RENDER));
648   }
# Line 665 | Line 681 | register char  *op;
681                  break;
682          }
683          op = addarg(op, "-pt .08");
684 <        if (vbool(PENUMBRAS)) {
685 <                op = addarg(op, "-ds .2");
686 <                op = addarg(op, "-dj .35");
671 <        } else
684 >        if (vbool(PENUMBRAS))
685 >                op = addarg(op, "-ds .2 -dj .35");
686 >        else
687                  op = addarg(op, "-ds .3");
688 <        op = addarg(op, "-dt .1");
689 <        op = addarg(op, "-dc .5");
690 <        op = addarg(op, "-dr 1");
691 <        op = addarg(op, "-sj .7");
692 <        op = addarg(op, "-st .15");
678 <        sprintf(op, " -ab %d", overture=vint(INDIRECT));
679 <        op += strlen(op);
688 >        op = addarg(op, "-dt .1 -dc .5 -dr 1 -sj .7 -st .15");
689 >        if (overture = vint(INDIRECT)) {
690 >                sprintf(op, " -ab %d", overture);
691 >                op += strlen(op);
692 >        }
693          if (vdef(AMBFILE)) {
694                  sprintf(op, " -af %s", vval(AMBFILE));
695                  op += strlen(op);
# Line 684 | Line 697 | register char  *op;
697                  overture = 0;
698          switch (vscale(VARIABILITY)) {
699          case LOW:
700 <                op = addarg(op, "-aa .25");
688 <                op = addarg(op, "-ad 128");
689 <                op = addarg(op, "-as 0");
700 >                op = addarg(op, "-aa .25 -ad 128 -as 0");
701                  break;
702          case MEDIUM:
703 <                op = addarg(op, "-aa .2");
693 <                op = addarg(op, "-ad 300");
694 <                op = addarg(op, "-as 64");
703 >                op = addarg(op, "-aa .2 -ad 300 -as 64");
704                  break;
705          case HIGH:
706 <                op = addarg(op, "-aa .15");
698 <                op = addarg(op, "-ad 500");
699 <                op = addarg(op, "-as 128");
706 >                op = addarg(op, "-aa .15 -ad 500 -as 128");
707                  break;
708          }
709          d = ambval();
710          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
711          op += strlen(op);
712 <        op = addarg(op, "-lr 6");
706 <        op = addarg(op, "-lw .002");
712 >        op = addarg(op, "-lr 6 -lw .002");
713          if (vdef(RENDER))
714                  op = addarg(op, vval(RENDER));
715   }
# Line 742 | Line 748 | register char  *op;
748                  break;
749          }
750          op = addarg(op, "-pt .04");
751 <        if (vbool(PENUMBRAS)) {
752 <                op = addarg(op, "-ds .1");
753 <                op = addarg(op, "-dj .7");
748 <        } else
751 >        if (vbool(PENUMBRAS))
752 >                op = addarg(op, "-ds .1 -dj .7");
753 >        else
754                  op = addarg(op, "-ds .2");
755 <        op = addarg(op, "-dt .05");
751 <        op = addarg(op, "-dc .75");
752 <        op = addarg(op, "-dr 3");
753 <        op = addarg(op, "-sj 1");
754 <        op = addarg(op, "-st .03");
755 >        op = addarg(op, "-dt .05 -dc .75 -dr 3 -sj 1 -st .03");
756          sprintf(op, " -ab %d", overture=vint(INDIRECT)+1);
757          op += strlen(op);
758          if (vdef(AMBFILE)) {
# Line 761 | Line 762 | register char  *op;
762                  overture = 0;
763          switch (vscale(VARIABILITY)) {
764          case LOW:
765 <                op = addarg(op, "-aa .15");
765 <                op = addarg(op, "-ad 200");
766 <                op = addarg(op, "-as 0");
765 >                op = addarg(op, "-aa .15 -ad 200 -as 0");
766                  break;
767          case MEDIUM:
768 <                op = addarg(op, "-aa .125");
770 <                op = addarg(op, "-ad 512");
771 <                op = addarg(op, "-as 128");
768 >                op = addarg(op, "-aa .125 -ad 512 -as 128");
769                  break;
770          case HIGH:
771 <                op = addarg(op, "-aa .08");
775 <                op = addarg(op, "-ad 850");
776 <                op = addarg(op, "-as 256");
771 >                op = addarg(op, "-aa .08 -ad 850 -as 256");
772                  break;
773          }
774          d = ambval();
775          sprintf(op, " -av %.2g %.2g %.2g", d, d, d);
776          op += strlen(op);
777 <        op = addarg(op, "-lr 12");
783 <        op = addarg(op, "-lw .0005");
777 >        op = addarg(op, "-lr 12 -lw .0005");
778          if (vdef(RENDER))
779                  op = addarg(op, vval(RENDER));
780   }
# Line 801 | Line 795 | char   *ro;
795                          syserr(vval(OPTFILE));
796                  write(fd, "\n", 1);
797                  close(fd);
798 <                ro[0] = ' ';
805 <                ro[1] = '^';
806 <                strcpy(ro+2, vval(OPTFILE));
798 >                sprintf(ro, " \"^%s\"", vval(OPTFILE));
799          }
800   #ifdef MSDOS
801          else if (n > 50) {
802 <                register char   *evp = bmalloc(n+6);
811 <                if (evp == NULL)
812 <                        syserr(progname);
813 <                strcpy(evp, "ROPT=");
814 <                strcat(evp, ro);
815 <                if (putenv(evp) != 0) {
816 <                        fprintf(stderr, "%s: out of environment space\n",
817 <                                        progname);
818 <                        exit(1);
819 <                }
802 >                setenv("ROPT", ro+1);
803                  strcpy(ro, " $ROPT");
804          }
805   #endif
# Line 948 | Line 931 | register char  *vs;
931                          break;
932                  }
933          } else {
934 <                while (*vs && !isspace(*vs))    /* else skip id */
935 <                        vs++;
934 >                while (!isspace(*vs))           /* else skip id */
935 >                        if (!*vs++)
936 >                                return(NULL);
937                  if (upax) {                     /* specify up vector */
938                          strcpy(cp, vup[upax+3]);
939                          cp += strlen(cp);
940                  }
941          }
942 <                                        /* append any additional options */
943 <        strcpy(cp, vs);
942 >        strcpy(cp, vs);                 /* append any additional options */
943 > #ifdef MSDOS
944 >        if (strlen(viewopts) > 40) {
945 >                setenv("VIEW", viewopts);
946 >                return("$VIEW");
947 >        }
948 > #endif
949          return(viewopts);
950   }
951  
# Line 964 | Line 953 | register char  *vs;
953   char *
954   getview(n, vn)                          /* get view n, or NULL if none */
955   int     n;
956 < char    *vn;
956 > char    *vn;            /* returned view name */
957   {
958 <        register char   *mv;
958 >        register char   *mv = NULL;
959  
960 <        if (viewselect != NULL) {
960 >        if (viewselect != NULL) {               /* command-line selected */
961                  if (n)                          /* only do one */
962                          return(NULL);
963                  if (viewselect[0] == '-') {     /* already specified */
# Line 987 | Line 976 | char   *vn;
976                                  return(specview(mv));
977                  return(specview(viewselect));   /* standard view? */
978          }
979 <        if (vn != NULL && (mv = nvalue(vv+VIEW, n)) != NULL) {
979 >        mv = nvalue(vv+VIEW, n);                /* use view n */
980 >        if (vn != NULL & mv != NULL) {
981                  if (*mv != '-')
982                          while (*mv && !isspace(*mv))
983                                  *vn++ = *mv++;
984                  *vn = '\0';
985          }
986 <        return(specview(nvalue(vv+VIEW, n)));   /* use view n */
986 >        return(specview(mv));
987   }
988  
989  
# Line 1006 | Line 996 | char   *opts;
996          if (rvdevice != NULL)
997                  sprintf(combuf+strlen(combuf), "-o %s ", rvdevice);
998          strcat(combuf, vval(OCTREE));
999 <        if (!silent) {                  /* echo it */
1010 <                printf("\t%s\n", combuf);
1011 <                fflush(stdout);
1012 <        }
1013 <        if (noaction)
1014 <                return;
1015 <        if (system(combuf)) {           /* run it */
999 >        if (runcom(combuf)) {           /* run it */
1000                  fprintf(stderr, "%s: error running rview\n", progname);
1001                  exit(1);
1002          }
# Line 1057 | Line 1041 | char   *opts;
1041                  else
1042                          badvalue(REPORT);
1043          }
1060                                        /* check date on ambient file */
1061        if (vdef(AMBFILE)) {
1062                long    afdate = fdate(vval(AMBFILE));
1063                if (afdate >= 0 & octreedate > afdate) {
1064                        if (!silent)
1065 #ifdef MSDOS
1066                                printf("\tdel %s\n", vval(AMBFILE));
1067 #else
1068                                printf("\trm %s\n", vval(AMBFILE));
1069 #endif
1070                        if (!noaction)
1071                                unlink(vval(AMBFILE));
1072                }
1073        }
1044                                          /* do each view */
1045          vn = 0;
1046          while ((vw = getview(vn++, vs)) != NULL) {
# Line 1090 | Line 1060 | char   *opts;
1060                                  sprintf(combuf,
1061                                  "rpict%s %s%s -x 64 -y 64 -ps 1 %s > %s",
1062                                                  rep, vw, opts,
1063 <                                                vval(OCTREE), rawfile);
1064 <                                if (!silent) {
1095 <                                        printf("\t%s\n", combuf);
1096 <                                        fflush(stdout);
1097 <                                }
1098 <                                if (!noaction && system(combuf)) {
1063 >                                                vval(OCTREE), overfile);
1064 >                                if (runcom(combuf)) {
1065                                          fprintf(stderr,
1066 <                        "%s: error in overture for view %s\n\t%s removed\n",
1067 <                                                progname, vs, rawfile);
1102 <                                        unlink(rawfile);
1066 >                                        "%s: error in overture for view %s\n",
1067 >                                                progname, vs);
1068                                          exit(1);
1069                                  }
1070 + #ifdef NIX
1071 +                                rmfile(overfile);
1072 + #endif
1073                          }
1074                          sprintf(combuf, "rpict%s %s %s%s %s > %s",
1075                                          rep, vw, res, opts,
1076                                          vval(OCTREE), rawfile);
1077                  }
1078 <                if (!silent) {                  /* echo rpict command */
1111 <                        printf("\t%s\n", combuf);
1112 <                        fflush(stdout);
1113 <                }
1114 <                if (!noaction && system(combuf)) {      /* run rpict */
1078 >                if (runcom(combuf)) {           /* run rpict */
1079                          fprintf(stderr, "%s: error rendering view %s\n",
1080                                          progname, vs);
1081                          exit(1);
# Line 1123 | Line 1087 | char   *opts;
1087                  else
1088                          sprintf(combuf, "pfilt%s %s > %s", pfopts,
1089                                          rawfile, picfile);
1090 <                if (!silent) {                  /* echo pfilt command */
1127 <                        printf("\t%s\n", combuf);
1128 <                        fflush(stdout);
1129 <                }
1130 <                if (!noaction && system(combuf)) {      /* run pfilt */
1090 >                if (runcom(combuf)) {           /* run pfilt */
1091                          fprintf(stderr,
1092                          "%s: error filtering view %s\n\t%s removed\n",
1093                                          progname, vs, picfile);
# Line 1135 | Line 1095 | char   *opts;
1095                          exit(1);
1096                  }
1097                                                  /* remove raw file */
1098 <                if (!silent)
1098 >                rmfile(rawfile);
1099 >        }
1100 > }
1101 >
1102 >
1103 > runcom(cs)                      /* run command */
1104 > char    *cs;
1105 > {
1106 >        if (!silent)            /* echo it */
1107 >                printf("\t%s\n", cs);
1108 >        if (noaction)
1109 >                return(0);
1110 >        fflush(stdout);         /* flush output and pass to shell */
1111 >        return(system(cs));
1112 > }
1113 >
1114 >
1115 > rmfile(fn)                      /* remove a file */
1116 > char    *fn;
1117 > {
1118 >        if (!silent)
1119   #ifdef MSDOS
1120 <                        printf("\tdel %s\n", rawfile);
1120 >                printf("\tdel %s\n", fn);
1121   #else
1122 <                        printf("\trm %s\n", rawfile);
1122 >                printf("\trm -f %s\n", fn);
1123   #endif
1124 <                if (!noaction)
1125 <                        unlink(rawfile);
1124 >        if (noaction)
1125 >                return(0);
1126 >        return(unlink(fn));
1127 > }
1128 >
1129 >
1130 > #ifdef MSDOS
1131 > setenv(vname, value)            /* set an environment variable */
1132 > char    *vname, *value;
1133 > {
1134 >        register char   *evp;
1135 >
1136 >        evp = bmalloc(strlen(vname)+strlen(value)+2);
1137 >        if (evp == NULL)
1138 >                syserr(progname);
1139 >        sprintf(evp, "%s=%s", vname, value);
1140 >        if (putenv(evp) != 0) {
1141 >                fprintf(stderr, "%s: out of environment space\n", progname);
1142 >                exit(1);
1143          }
1144 +        if (!silent)
1145 +                printf("set %s\n", evp);
1146   }
1147 + #endif
1148  
1149  
1150   badvalue(vc)                    /* report bad variable value and exit */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines