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.57 by greg, Sun Sep 26 15:44:00 2010 UTC vs.
Revision 1.65 by greg, Wed Oct 5 17:20:55 2011 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"
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 93 | 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 108 | 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 703 | 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 957 | Line 967 | put_contrib(const DCOLOR cnt, FILE *fout)
967          default:
968                  error(INTERNAL, "botched output format");
969          }
960        if (waitflush < 0 && frandom() < 0.001)
961                fflush(fout);                   /* staggers writes */
970   }
971  
972   /* output ray tallies and clear for next accumulation */
# Line 1078 | 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 1109 | 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 1167 | Line 1181 | trace_contribs(FILE *fin)
1181                                  lastray+1 < lastray) {
1182                          while (wait_rproc() != NULL)
1183                                  process_queue();
1184 <                        if (lastray+1 < lastray)
1171 <                                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