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.56 by greg, Fri Jun 11 20:26:09 2010 UTC vs.
Revision 1.65 by greg, Wed Oct 5 17:20:55 2011 UTC

# Line 16 | Line 16 | static const char RCSid[] = "$Id$";
16   #include  "lookup.h"
17   #include  "calcomp.h"
18  
19 + #ifdef _WIN32
20 + typedef long    ssize_t;
21 + #endif
22 +
23   #ifndef MAXMODLIST
24   #define MAXMODLIST      1024            /* maximum modifiers we'll track */
25   #endif
26  
27 < int     treebufsiz = BUFSIZ;            /* current tree buffer size */
27 > ssize_t treebufsiz = BUFSIZ;            /* current tree buffer size */
28  
29   typedef double  DCOLOR[3];              /* double-precision color */
30  
# Line 92 | Line 96 | struct rtproc {
96          struct rtproc   *next;          /* next in list of processes */
97          SUBPROC         pd;             /* rtrace pipe descriptors */
98          unsigned long   raynum;         /* ray number for this tree */
99 <        int             bsiz;           /* ray tree buffer length */
99 >        size_t          bsiz;           /* ray tree buffer length */
100          char            *buf;           /* ray tree buffer */
101 <        int             nbr;            /* number of bytes from rtrace */
101 >        size_t          nbr;            /* number of bytes from rtrace */
102   };                              /* rtrace process buffer */
103  
104                                          /* rtrace command and defaults */
# Line 107 | Line 111 | int  rtargc = 9;
111   char            *myrtopts[] = { "-h-", "-x", "1", "-y", "0",
112                                  "-dt", "0", "-as", "0", "-aa", "0", NULL };
113  
114 < #define RTCOEFF         "-o~~TmWdp"     /* compute coefficients only */
115 < #define RTCONTRIB       "-o~~TmVdp"     /* compute ray contributions */
114 > #define RTCOEFF         "-o~~~TmWdp"    /* compute coefficients only */
115 > #define RTCONTRIB       "-o~~~TmVdp"    /* compute ray contributions */
116  
117   struct rtproc   rt0;                    /* head of rtrace process list */
118  
# Line 545 | Line 549 | init(int np)
549                  raysleft = 0;
550          if ((account = accumulate) > 0)
551                  raysleft *= accumulate;
552 <        waitflush = xres;
552 >        waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
553          if (!recover)
554                  return;
555                                          /* recover previous values */
# Line 702 | Line 706 | void
706   printheader(FILE *fout, const char *info)
707   {
708          extern char     VersionID[];
709 <        FILE            *fin = fopen(octree, "r");
710 <        
711 <        if (fin == NULL)
712 <                quit(1);
713 <        checkheader(fin, "ignore", fout);       /* copy octree header */
714 <        fclose(fin);
709 >                                                /* copy octree header */
710 >        if (octree[0] == '!') {
711 >                newheader("RADIANCE", fout);
712 >                fputs(octree+1, fout);
713 >                if (octree[strlen(octree)-1] != '\n')
714 >                        fputc('\n', fout);
715 >        } else {
716 >                FILE    *fin = fopen(octree, "r");
717 >                if (fin == NULL)
718 >                        quit(1);
719 >                checkheader(fin, "ignore", fout);
720 >                fclose(fin);
721 >        }
722          printargs(gargc-1, gargv, fout);        /* add our command */
723          fprintf(fout, "SOFTWARE= %s\n", VersionID);
724          fputnow(fout);
# Line 736 | Line 747 | printresolu(FILE *fout, int xr, int yr)
747   {
748          if ((xr > 0) & (yr > 0))        /* resolution string */
749                  fprtresolu(xr, yr, fout);
739        if (xres > 0)                   /* global flush flag */
740                fflush(fout);
750   }
751  
752   /* Get output stream pointer (open and write header if new and noopen==0) */
# Line 758 | Line 767 | getostream(const char *ospec, const char *mname, int b
767                          if (header)
768                                  printheader(stdout, NULL);
769                          printresolu(stdout, xres, yres);
770 +                        if (waitflush > 0)
771 +                                fflush(stdout);
772                          stdos.xr = xres; stdos.yr = yres;
773                          using_stdout = 1;
774                  }
# Line 826 | Line 837 | getostream(const char *ospec, const char *mname, int b
837                          if (outfmt == 'a')
838                                  putc('\n', sop->ofp);
839                  }
840 <                if (xres > 0)
840 >                if (waitflush > 0)
841                          fflush(sop->ofp);
842          }
843          sop->reclen += noopen;                  /* add to length if noopen */
# Line 993 | Line 1004 | done_contrib(int navg)
1004          if (using_stdout & (outfmt == 'a'))
1005                  putc('\n', stdout);
1006          if (!waitflush) {
1007 <                waitflush = xres;
1007 >                waitflush = (yres > 0) & (xres > 1) ? 0 : xres;
1008                  if (using_stdout)
1009                          fflush(stdout);
1010          }
# Line 1075 | Line 1086 | wait_rproc(void)
1086   {
1087          struct rtproc   *rtfree = NULL;
1088          fd_set          readset, errset;
1089 <        int             nr;
1089 >        ssize_t         nr;
1090          struct rtproc   *rt;
1091          int             n;
1092          
# Line 1106 | Line 1117 | wait_rproc(void)
1117                                  continue;
1118                          if (rt->buf == NULL) {
1119                                  rt->bsiz = treebufsiz;
1120 <                                rt->buf = (char *)malloc(treebufsiz);
1120 >                                rt->buf = (char *)malloc(rt->bsiz);
1121                          } else if (rt->nbr + BUFSIZ > rt->bsiz) {
1122                                  if (rt->bsiz + BUFSIZ <= treebufsiz)
1123                                          rt->bsiz = treebufsiz;
1124 <                                else
1125 <                                        treebufsiz = rt->bsiz += BUFSIZ;
1124 >                                else if ((treebufsiz = rt->bsiz += BUFSIZ) < 0)
1125 >                                        error(INTERNAL,
1126 >                                            "ray buffer does not fit memory");
1127                                  rt->buf = (char *)realloc(rt->buf, rt->bsiz);
1128                          }
1129                          if (rt->buf == NULL)
1130                                  error(SYSTEM, "out of memory in wait_rproc");
1131 <                        nr = read(rt->pd.r, rt->buf+rt->nbr, rt->bsiz-rt->nbr);
1132 <                        if (nr <= 0)
1131 >                        nr = rt->bsiz - rt->nbr;
1132 >                        if (nr & ~0x7fffffff)   /* avoid 32-bit OS issues */
1133 >                                nr = 0x7fffffff;
1134 >                        nr = read(rt->pd.r, rt->buf+rt->nbr, nr);
1135 >                        if (nr < 0)
1136 >                                error(SYSTEM, "read error from rtrace");
1137 >                        if (!nr)
1138                                  error(USER, "rtrace process died");
1139                          rt->nbr += nr;          /* advance & check */
1140 <                        if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4,
1141 <                                                        "~\t~\t", 4)) {
1142 <                                rt->nbr -= 4;   /* elide terminator */
1140 >                        if (rt->nbr >= 6 && !memcmp(rt->buf+rt->nbr-6,
1141 >                                                        "~\t~\t~\t", 6)) {
1142 >                                rt->nbr -= 6;   /* elide terminator */
1143                                  queue_raytree(rt);
1144                                  rtfree = rt;    /* ready for next ray */
1145                          }
# Line 1164 | Line 1181 | trace_contribs(FILE *fin)
1181                                  lastray+1 < lastray) {
1182                          while (wait_rproc() != NULL)
1183                                  process_queue();
1184 <                        if (lastray+1 < lastray)
1168 <                                lastdone = lastray = 0;
1184 >                        lastdone = lastray = 0;
1185                  }
1186                  rtp = get_rproc();              /* get avail. rtrace process */
1187                  rtp->raynum = ++lastray;        /* assign ray */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines