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

Comparing ray/src/util/rtcontrib.c (file contents):
Revision 1.48 by greg, Sat Nov 17 16:27:14 2007 UTC vs.
Revision 1.54 by greg, Sun Jun 14 18:21:58 2009 UTC

# Line 99 | Line 99 | struct rtproc {
99  
100                                          /* rtrace command and defaults */
101   char            *rtargv[256+2*MAXMODLIST] = { "rtrace",
102 <                                "-dj", ".5", "-dr", "3",
102 >                                "-dj", ".9", "-dr", "3",
103                                  "-ab", "1", "-ad", "350", };
104  
105   int  rtargc = 9;
# Line 131 | Line 131 | int            inpfmt = 'a';           /* input format */
131   int             outfmt = 'a';           /* output format */
132  
133   int             header = 1;             /* output header? */
134 int             accumulate = 0;         /* accumulate ray values? */
134   int             force_open = 0;         /* truncate existing output? */
135   int             recover = 0;            /* recover previous output? */
136 + int             accumulate = 1;         /* input rays per output record */
137   int             xres = 0;               /* horiz. output resolution */
138   int             yres = 0;               /* vert. output resolution */
139  
140 + int             account;                /* current accumulation count */
141   unsigned long   raysleft;               /* number of rays left to trace */
142   long            waitflush;              /* how long until next flush */
143  
# Line 166 | Line 167 | void process_queue(void);
167  
168   void put_contrib(const DCOLOR cnt, FILE *fout);
169   void add_contrib(const char *modn);
170 < void done_contrib(void);
170 > void done_contrib(int navg);
171  
172   /* return number of open rtrace processes */
173   static int
# Line 245 | Line 246 | main(int argc, char *argv[])
246                  while ((j = expandarg(&argc, &argv, i)) > 0)
247                          ;
248                  if (j < 0) {
249 <                        fprintf(stderr, "%s: cannot expand '%s'",
249 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
250                                          argv[0], argv[i]);
251                          exit(1);
252                  }
# Line 274 | Line 275 | main(int argc, char *argv[])
275                                          continue;
276                                  }
277                                  break;
278 <                        case 'c':               /* accumulate ray values */
279 <                                switch (argv[i][2]) {
280 <                                case '\0':
281 <                                        accumulate = !accumulate;
281 <                                        continue;
282 <                                case '+': case '1':
283 <                                case 'T': case 't':
284 <                                case 'Y': case 'y':
285 <                                        accumulate = 1;
286 <                                        continue;
287 <                                case '-': case '0':
288 <                                case 'F': case 'f':
289 <                                case 'N': case 'n':
290 <                                        accumulate = 0;
291 <                                        continue;
292 <                                }
293 <                                break;
278 >                        case 'c':               /* input rays per output */
279 >                                if (argv[i][2] || i >= argc-2) break;
280 >                                accumulate = atoi(argv[++i]);
281 >                                continue;
282                          case 'r':               /* recover output */
283                                  if (argv[i][2]) break;
284                                  recover = 1;
# Line 352 | Line 340 | main(int argc, char *argv[])
340                          case 'b':               /* bin expression/count */
341                                  if (i >= argc-2) break;
342                                  if (argv[i][2] == 'n') {
343 <                                        bincnt = atoi(argv[++i]);
343 >                                        bincnt = (int)(eval(argv[++i]) + .5);
344                                          continue;
345                                  }
346                                  if (argv[i][2]) break;
# Line 380 | Line 368 | main(int argc, char *argv[])
368                          }
369                  rtargv[rtargc++] = argv[i];     /* assume rtrace option */
370          }
371 <        if (accumulate)         /* no output flushing for single record */
371 >        if (accumulate <= 0)    /* no output flushing for single record */
372                  xres = yres = 0;
373                                  /* set global argument list */
374          gargc = argc; gargv = argv;
# Line 392 | Line 380 | main(int argc, char *argv[])
380          if (!strcmp(argv[i], "-defaults")) {
381                  char    sxres[16], syres[16];
382                  char    *rtpath;
383 <                printf("-n  %-2d\t\t\t\t# number of processes\n", nprocs);
383 >                printf("-n %-2d\t\t\t\t# number of processes\n", nprocs);
384 >                printf("-c %-5d\t\t\t# accumulated rays per record\n",
385 >                                accumulate);
386                  printf("-V%c\t\t\t\t# output %s\n", contrib ? '+' : '-',
387                                  contrib ? "contributions" : "coefficients");
398                printf("-c%c\t\t\t\t# %s\n", accumulate ? '+' : '-',
399                                accumulate ? "accumulate ray values" :
400                                        "one output record per ray");
388                  fflush(stdout);                 /* report OUR options */
389                  rtargv[rtargc++] = header ? "-h+" : "-h-";
390                  sprintf(fmt, "-f%c%c", inpfmt, outfmt);
# Line 554 | Line 541 | init(int np)
541                          raysleft = yres;
542          } else
543                  raysleft = 0;
544 +        if ((account = accumulate) > 0)
545 +                raysleft *= accumulate;
546          waitflush = xres;
547          if (!recover)
548                  return;
549                                          /* recover previous values */
550 <        if (accumulate)
550 >        if (accumulate <= 0)
551                  reload_output();
552          else
553                  recover_output(stdin);
# Line 591 | Line 580 | addmodifier(char *modn, char *outf, char *binv, int bi
580                  error(USER, errmsg);
581          }
582          if (nmods >= MAXMODLIST)
583 <                error(USER, "too many modifiers");
583 >                error(INTERNAL, "too many modifiers");
584          modname[nmods++] = modn;        /* XXX assumes static string */
585          lep->key = modn;                /* XXX assumes static string */
586          mp = (MODCONT *)malloc(sizeof(MODCONT));
# Line 599 | Line 588 | addmodifier(char *modn, char *outf, char *binv, int bi
588                  error(SYSTEM, "out of memory in addmodifier");
589          mp->outspec = outf;             /* XXX assumes static string */
590          mp->modname = modn;             /* XXX assumes static string */
591 <        if (binv != NULL)
592 <                mp->binv = eparse(binv);
593 <        else
594 <                mp->binv = eparse("0");
595 <        mp->nbins = 1;
591 >        if (binv == NULL)
592 >                binv = "0";             /* use single bin if unspecified */
593 >        mp->binv = eparse(binv);
594 >        if (mp->binv->type == NUM) {    /* check value if constant */
595 >                bincnt = (int)(evalue(mp->binv) + 1.5);
596 >                if (bincnt != 1) {
597 >                        sprintf(errmsg, "illegal non-zero constant for bin (%s)",
598 >                                        binv);
599 >                        error(USER, errmsg);
600 >                }
601 >        }
602 >        mp->nbins = 1;                  /* initialize results holder */
603          setcolor(mp->cbin[0], 0., 0., 0.);
604 <        if (mp->binv->type == NUM)      /* assume one bin if constant */
609 <                bincnt = 1;
610 <        else if (bincnt > 1)
604 >        if (bincnt > 1)
605                  mp = growmodifier(mp, bincnt);
606          lep->data = (char *)mp;
607                                          /* allocate output streams */
# Line 813 | Line 807 | getostream(const char *ospec, const char *mname, int b
807                          *cp = '\0';
808                          printheader(sop->ofp, info);
809                  }
810 <                if (!accumulate) {              /* global res. for -c- */
810 >                if (accumulate > 0) {           /* global resolution */
811                          sop->xr = xres; sop->yr = yres;
812                  }
813                  printresolu(sop->ofp, sop->xr, sop->yr);
814                                                  /* play catch-up */
815 <                for (i = accumulate ? 0 : lastdone; i--; ) {
815 >                for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) {
816                          int     j = sop->reclen;
817                          if (j <= 0) j = 1;
818                          while (j--)
# Line 960 | Line 954 | put_contrib(const DCOLOR cnt, FILE *fout)
954  
955   /* output ray tallies and clear for next accumulation */
956   void
957 < done_contrib(void)
957 > done_contrib(int navg)
958   {
959 +        double          sf = 1.;
960          int             i, j;
961          MODCONT         *mp;
962          STREAMOUT       *sop;
963 +                                                /* set average scaling */
964 +        if (navg > 1)
965 +                sf = 1. / (double)navg;
966                                                  /* output modifiers in order */
967          for (i = 0; i < nmods; i++) {
968                  mp = (MODCONT *)lu_find(&modconttab,modname[i])->data;
969 +                if (navg > 1)                   /* average scaling */
970 +                        for (j = mp->nbins; j--; )
971 +                                scalecolor(mp->cbin[j], sf);
972                  sop = getostream(mp->outspec, mp->modname, 0,0);
973                  put_contrib(mp->cbin[0], sop->ofp);
974                  if (mp->nbins > 3 &&            /* minor optimization */
# Line 1051 | Line 1052 | process_queue(void)
1052                          cp += sizeof(float)*9; n -= sizeof(float)*9;
1053                          add_contrib(modname);
1054                  }
1055 <                if (!accumulate)
1056 <                        done_contrib(); /* sum up contributions & output */
1055 >                                        /* time to produce record? */
1056 >                if (account > 0 && !--account)
1057 >                        done_contrib(account = accumulate);
1058                  lastdone = rtp->raynum;
1059                  if (rtp->buf != NULL)   /* free up buffer space */
1060                          free(rtp->buf);
# Line 1139 | Line 1141 | get_rproc(void)
1141   void
1142   trace_contribs(FILE *fin)
1143   {
1144 +        static int      ignore_warning_given = 0;
1145          char            inpbuf[128];
1146          int             iblen;
1147          struct rtproc   *rtp;
1148                                                  /* loop over input */
1149          while ((iblen = getinp(inpbuf, fin)) >= 0) {
1150 <                if (!iblen ||                   /* need reset? */
1150 >                if (!iblen && accumulate != 1) {
1151 >                        if (!ignore_warning_given++)
1152 >                                error(WARNING,
1153 >                                "dummy ray(s) ignored during accumulation\n");
1154 >                        continue;
1155 >                }
1156 >                if (!iblen ||                   /* need flush/reset? */
1157                                  queue_length() > 10*nrtprocs() ||
1158                                  lastray+1 < lastray) {
1159                          while (wait_rproc() != NULL)
# Line 1157 | Line 1166 | trace_contribs(FILE *fin)
1166                  if (iblen) {                    /* trace ray if valid */
1167                          writebuf(rtp->pd.w, inpbuf, iblen);
1168                  } else {                        /* else bypass dummy ray */
1169 <                        queue_raytree(rtp);     /* empty tree */
1170 <                        if ((yres <= 0) | (waitflush > 1))
1171 <                                waitflush = 1;  /* flush after this */
1169 >                        queue_raytree(rtp);     /* queue empty ray/record */
1170 >                        if ((yres <= 0) | (xres <= 0))
1171 >                                waitflush = 1;  /* flush right after */
1172                  }
1173                  process_queue();                /* catch up with results */
1174                  if (raysleft && !--raysleft)
# Line 1167 | Line 1176 | trace_contribs(FILE *fin)
1176          }
1177          while (wait_rproc() != NULL)            /* process outstanding rays */
1178                  process_queue();
1179 <        if (accumulate)
1180 <                done_contrib();                 /* output tallies */
1179 >        if (accumulate <= 0)
1180 >                done_contrib(0);                /* output tallies */
1181 >        else if (account < accumulate) {
1182 >                error(WARNING, "partial accumulation in final record");
1183 >                done_contrib(accumulate - account);
1184 >        }
1185          if (raysleft)
1186                  error(USER, "unexpected EOF on input");
1187          lu_done(&ofiletab);                     /* close output files */
# Line 1210 | Line 1223 | myclose(const LUENT *e, void *p)
1223          STREAMOUT       *sop = (STREAMOUT *)e->data;
1224          
1225          if (sop->ofp == NULL)
1226 <                return;
1226 >                return(0);
1227          fclose(sop->ofp);
1228          sop->ofp = NULL;
1229 +        return(0);
1230   }
1231  
1232   /* load previously accumulated values */
# Line 1463 | Line 1477 | recover_output(FILE *fin)
1477                  error(WARNING, "no output files to recover");
1478                  return;
1479          }
1480 <        if (raysleft && lastout >= raysleft) {
1480 >        if (raysleft && lastout >= raysleft/accumulate) {
1481                  error(WARNING, "output appears to be complete");
1482                  /* XXX should read & discard input? */
1483                  quit(0);
# Line 1475 | Line 1489 | recover_output(FILE *fin)
1489          for (nvals = 0; nvals < lastout; nvals++)
1490                  if (getinp(oname, fin) < 0)
1491                          error(USER, "unexpected EOF on input");
1492 <        lastray = lastdone = (unsigned long)lastout;
1492 >        lastray = lastdone = (unsigned long)lastout * accumulate;
1493          if (raysleft)
1494                  raysleft -= lastray;
1495   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines