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.60 by greg, Sun Oct 10 09:25:04 2010 UTC vs.
Revision 1.64 by greg, Sat Apr 16 00:39:07 2011 UTC

# Line 20 | Line 20 | static const char RCSid[] = "$Id$";
20   #define MAXMODLIST      1024            /* maximum modifiers we'll track */
21   #endif
22  
23 < size_t  treebufsiz = BUFSIZ;            /* current tree buffer size */
23 > ssize_t treebufsiz = BUFSIZ;            /* current tree buffer size */
24  
25   typedef double  DCOLOR[3];              /* double-precision color */
26  
# Line 107 | Line 107 | int  rtargc = 9;
107   char            *myrtopts[] = { "-h-", "-x", "1", "-y", "0",
108                                  "-dt", "0", "-as", "0", "-aa", "0", NULL };
109  
110 < #define RTCOEFF         "-o~~TmWdp"     /* compute coefficients only */
111 < #define RTCONTRIB       "-o~~TmVdp"     /* compute ray contributions */
110 > #define RTCOEFF         "-o~~~TmWdp"    /* compute coefficients only */
111 > #define RTCONTRIB       "-o~~~TmVdp"    /* compute ray contributions */
112  
113   struct rtproc   rt0;                    /* head of rtrace process list */
114  
# Line 702 | Line 702 | void
702   printheader(FILE *fout, const char *info)
703   {
704          extern char     VersionID[];
705 <        FILE            *fin = fopen(octree, "r");
706 <        
707 <        if (fin == NULL)
708 <                quit(1);
709 <        checkheader(fin, "ignore", fout);       /* copy octree header */
710 <        fclose(fin);
705 >                                                /* copy octree header */
706 >        if (octree[0] == '!') {
707 >                newheader("RADIANCE", fout);
708 >                fputs(octree+1, fout);
709 >                if (octree[strlen(octree)-1] != '\n')
710 >                        fputc('\n', fout);
711 >        } else {
712 >                FILE    *fin = fopen(octree, "r");
713 >                if (fin == NULL)
714 >                        quit(1);
715 >                checkheader(fin, "ignore", fout);
716 >                fclose(fin);
717 >        }
718          printargs(gargc-1, gargv, fout);        /* add our command */
719          fprintf(fout, "SOFTWARE= %s\n", VersionID);
720          fputnow(fout);
# Line 1106 | Line 1113 | wait_rproc(void)
1113                                  continue;
1114                          if (rt->buf == NULL) {
1115                                  rt->bsiz = treebufsiz;
1116 <                                rt->buf = (char *)malloc(treebufsiz);
1116 >                                rt->buf = (char *)malloc(rt->bsiz);
1117                          } else if (rt->nbr + BUFSIZ > rt->bsiz) {
1118                                  if (rt->bsiz + BUFSIZ <= treebufsiz)
1119                                          rt->bsiz = treebufsiz;
1120 <                                else
1121 <                                        treebufsiz = rt->bsiz += BUFSIZ;
1120 >                                else if ((treebufsiz = rt->bsiz += BUFSIZ) < 0)
1121 >                                        error(INTERNAL,
1122 >                                            "ray buffer does not fit memory");
1123                                  rt->buf = (char *)realloc(rt->buf, rt->bsiz);
1124                          }
1125                          if (rt->buf == NULL)
1126                                  error(SYSTEM, "out of memory in wait_rproc");
1127 <                        nr = read(rt->pd.r, rt->buf+rt->nbr, rt->bsiz-rt->nbr);
1128 <                        if (nr <= 0)
1127 >                        nr = rt->bsiz - rt->nbr;
1128 >                        if (nr & ~0x7fffffff)   /* avoid 32-bit OS issues */
1129 >                                nr = 0x7fffffff;
1130 >                        nr = read(rt->pd.r, rt->buf+rt->nbr, nr);
1131 >                        if (nr < 0)
1132 >                                error(SYSTEM, "read error from rtrace");
1133 >                        if (!nr)
1134                                  error(USER, "rtrace process died");
1135                          rt->nbr += nr;          /* advance & check */
1136 <                        if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4,
1137 <                                                        "~\t~\t", 4)) {
1138 <                                rt->nbr -= 4;   /* elide terminator */
1136 >                        if (rt->nbr >= 6 && !memcmp(rt->buf+rt->nbr-6,
1137 >                                                        "~\t~\t~\t", 6)) {
1138 >                                rt->nbr -= 6;   /* elide terminator */
1139                                  queue_raytree(rt);
1140                                  rtfree = rt;    /* ready for next ray */
1141                          }
# Line 1164 | Line 1177 | trace_contribs(FILE *fin)
1177                                  lastray+1 < lastray) {
1178                          while (wait_rproc() != NULL)
1179                                  process_queue();
1180 <                        if (lastray+1 < lastray)
1168 <                                lastdone = lastray = 0;
1180 >                        lastdone = lastray = 0;
1181                  }
1182                  rtp = get_rproc();              /* get avail. rtrace process */
1183                  rtp->raynum = ++lastray;        /* assign ray */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines