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.49 by greg, Fri Apr 18 18:06:29 2008 UTC vs.
Revision 1.59 by greg, Sun Oct 10 01:26:51 2010 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include  "color.h"
15   #include  "resolu.h"
16   #include  "lookup.h"
17 + #include  "random.h"
18   #include  "calcomp.h"
19  
20   #ifndef MAXMODLIST
21   #define MAXMODLIST      1024            /* maximum modifiers we'll track */
22   #endif
23  
24 < int     treebufsiz = BUFSIZ;            /* current tree buffer size */
24 > size_t  treebufsiz = BUFSIZ;            /* current tree buffer size */
25  
26   typedef double  DCOLOR[3];              /* double-precision color */
27  
# Line 92 | Line 93 | struct rtproc {
93          struct rtproc   *next;          /* next in list of processes */
94          SUBPROC         pd;             /* rtrace pipe descriptors */
95          unsigned long   raynum;         /* ray number for this tree */
96 <        int             bsiz;           /* ray tree buffer length */
96 >        size_t          bsiz;           /* ray tree buffer length */
97          char            *buf;           /* ray tree buffer */
98 <        int             nbr;            /* number of bytes from rtrace */
98 >        size_t          nbr;            /* number of bytes from rtrace */
99   };                              /* rtrace process buffer */
100  
101                                          /* rtrace command and defaults */
102   char            *rtargv[256+2*MAXMODLIST] = { "rtrace",
103 <                                "-dj", ".5", "-dr", "3",
103 >                                "-dj", ".9", "-dr", "3",
104                                  "-ab", "1", "-ad", "350", };
105  
106   int  rtargc = 9;
# Line 246 | Line 247 | main(int argc, char *argv[])
247                  while ((j = expandarg(&argc, &argv, i)) > 0)
248                          ;
249                  if (j < 0) {
250 <                        fprintf(stderr, "%s: cannot expand '%s'",
250 >                        fprintf(stderr, "%s: cannot expand '%s'\n",
251                                          argv[0], argv[i]);
252                          exit(1);
253                  }
# Line 340 | Line 341 | main(int argc, char *argv[])
341                          case 'b':               /* bin expression/count */
342                                  if (i >= argc-2) break;
343                                  if (argv[i][2] == 'n') {
344 <                                        bincnt = atoi(argv[++i]);
344 >                                        bincnt = (int)(eval(argv[++i]) + .5);
345                                          continue;
346                                  }
347                                  if (argv[i][2]) break;
# Line 378 | Line 379 | main(int argc, char *argv[])
379          rtargv[rtargc++] = contrib ? RTCONTRIB : RTCOEFF;
380                                  /* just asking for defaults? */
381          if (!strcmp(argv[i], "-defaults")) {
382 <                char    sxres[16], syres[16];
382 >                char    nps[8], sxres[16], syres[16];
383                  char    *rtpath;
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");
388                  fflush(stdout);                 /* report OUR options */
389 +                rtargv[rtargc++] = "-n";
390 +                sprintf(nps, "%d", nprocs);
391 +                rtargv[rtargc++] = nps;
392                  rtargv[rtargc++] = header ? "-h+" : "-h-";
393                  sprintf(fmt, "-f%c%c", inpfmt, outfmt);
394                  rtargv[rtargc++] = fmt;
# Line 543 | Line 546 | init(int np)
546                  raysleft = 0;
547          if ((account = accumulate) > 0)
548                  raysleft *= accumulate;
549 <        waitflush = xres;
549 >        waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
550          if (!recover)
551                  return;
552                                          /* recover previous values */
# Line 580 | Line 583 | addmodifier(char *modn, char *outf, char *binv, int bi
583                  error(USER, errmsg);
584          }
585          if (nmods >= MAXMODLIST)
586 <                error(USER, "too many modifiers");
586 >                error(INTERNAL, "too many modifiers");
587          modname[nmods++] = modn;        /* XXX assumes static string */
588          lep->key = modn;                /* XXX assumes static string */
589          mp = (MODCONT *)malloc(sizeof(MODCONT));
# Line 588 | Line 591 | addmodifier(char *modn, char *outf, char *binv, int bi
591                  error(SYSTEM, "out of memory in addmodifier");
592          mp->outspec = outf;             /* XXX assumes static string */
593          mp->modname = modn;             /* XXX assumes static string */
594 <        if (binv != NULL)
595 <                mp->binv = eparse(binv);
596 <        else
597 <                mp->binv = eparse("0");
598 <        mp->nbins = 1;
594 >        if (binv == NULL)
595 >                binv = "0";             /* use single bin if unspecified */
596 >        mp->binv = eparse(binv);
597 >        if (mp->binv->type == NUM) {    /* check value if constant */
598 >                bincnt = (int)(evalue(mp->binv) + 1.5);
599 >                if (bincnt != 1) {
600 >                        sprintf(errmsg, "illegal non-zero constant for bin (%s)",
601 >                                        binv);
602 >                        error(USER, errmsg);
603 >                }
604 >        }
605 >        mp->nbins = 1;                  /* initialize results holder */
606          setcolor(mp->cbin[0], 0., 0., 0.);
607 <        if (mp->binv->type == NUM)      /* assume one bin if constant */
598 <                bincnt = 1;
599 <        else if (bincnt > 1)
607 >        if (bincnt > 1)
608                  mp = growmodifier(mp, bincnt);
609          lep->data = (char *)mp;
610                                          /* allocate output streams */
# Line 659 | Line 667 | ofname(char *oname, const char *ospec, const char *mna
667                                  mnp = cp;
668                                  break;
669                          case 'd':
670 +                        case 'i':
671 +                        case 'o':
672 +                        case 'x':
673 +                        case 'X':
674                                  if (bnp != NULL)
675                                          return -1;
676                                  bnp = cp;
# Line 725 | Line 737 | printresolu(FILE *fout, int xr, int yr)
737   {
738          if ((xr > 0) & (yr > 0))        /* resolution string */
739                  fprtresolu(xr, yr, fout);
728        if (xres > 0)                   /* global flush flag */
729                fflush(fout);
740   }
741  
742   /* Get output stream pointer (open and write header if new and noopen==0) */
# Line 747 | Line 757 | getostream(const char *ospec, const char *mname, int b
757                          if (header)
758                                  printheader(stdout, NULL);
759                          printresolu(stdout, xres, yres);
760 +                        if (waitflush > 0)
761 +                                fflush(stdout);
762                          stdos.xr = xres; stdos.yr = yres;
763                          using_stdout = 1;
764                  }
# Line 815 | Line 827 | getostream(const char *ospec, const char *mname, int b
827                          if (outfmt == 'a')
828                                  putc('\n', sop->ofp);
829                  }
830 <                if (xres > 0)
830 >                if (waitflush > 0)
831                          fflush(sop->ofp);
832          }
833          sop->reclen += noopen;                  /* add to length if noopen */
# Line 982 | Line 994 | done_contrib(int navg)
994          if (using_stdout & (outfmt == 'a'))
995                  putc('\n', stdout);
996          if (!waitflush) {
997 <                waitflush = xres;
997 >                waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
998                  if (using_stdout)
999                          fflush(stdout);
1000          }
# Line 1064 | Line 1076 | wait_rproc(void)
1076   {
1077          struct rtproc   *rtfree = NULL;
1078          fd_set          readset, errset;
1079 <        int             nr;
1079 >        ssize_t         nr;
1080          struct rtproc   *rt;
1081          int             n;
1082          
# Line 1148 | Line 1160 | trace_contribs(FILE *fin)
1160                                  "dummy ray(s) ignored during accumulation\n");
1161                          continue;
1162                  }
1163 <                if (!iblen ||                   /* need reset? */
1163 >                if (!iblen ||                   /* need flush/reset? */
1164                                  queue_length() > 10*nrtprocs() ||
1165                                  lastray+1 < lastray) {
1166                          while (wait_rproc() != NULL)
# Line 1161 | Line 1173 | trace_contribs(FILE *fin)
1173                  if (iblen) {                    /* trace ray if valid */
1174                          writebuf(rtp->pd.w, inpbuf, iblen);
1175                  } else {                        /* else bypass dummy ray */
1176 <                        queue_raytree(rtp);     /* empty tree */
1177 <                        if ((yres <= 0) | (waitflush > 1))
1178 <                                waitflush = 1;  /* flush after this */
1176 >                        queue_raytree(rtp);     /* queue empty ray/record */
1177 >                        if ((yres <= 0) | (xres <= 0))
1178 >                                waitflush = 1;  /* flush right after */
1179                  }
1180                  process_queue();                /* catch up with results */
1181                  if (raysleft && !--raysleft)
# Line 1218 | Line 1230 | myclose(const LUENT *e, void *p)
1230          STREAMOUT       *sop = (STREAMOUT *)e->data;
1231          
1232          if (sop->ofp == NULL)
1233 <                return;
1233 >                return(0);
1234          fclose(sop->ofp);
1235          sop->ofp = NULL;
1236 +        return(0);
1237   }
1238  
1239   /* load previously accumulated values */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines