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.35 by greg, Tue Oct 11 16:54:26 2005 UTC vs.
Revision 1.36 by greg, Tue Oct 11 19:02:51 2005 UTC

# Line 760 | Line 760 | getostream(const char *ospec, const char *mname, int b
760   int
761   getinp(char *buf, FILE *fp)
762   {
763 +        double  dv[3];
764 +        float   fv[3];
765          char    *cp;
766          int     i;
767  
# Line 768 | Line 770 | getinp(char *buf, FILE *fp)
770                  cp = buf;               /* make sure we get 6 floats */
771                  for (i = 0; i < 6; i++) {
772                          if (fgetword(cp, buf+127-cp, fp) == NULL)
773 <                                return 0;
773 >                                return -1;
774 >                        if (i >= 3)
775 >                                dv[i-3] = atof(cp);
776                          if ((cp = fskip(cp)) == NULL || *cp)
777 <                                return 0;
777 >                                return -1;
778                          *cp++ = ' ';
779                  }
780                  getc(fp);               /* get/put eol */
781                  *cp-- = '\0'; *cp = '\n';
782 +                if (DOT(dv,dv) <= FTINY*FTINY)
783 +                        return 0;       /* dummy ray */
784                  return strlen(buf);
785          case 'f':
786                  if (fread(buf, sizeof(float), 6, fp) < 6)
787 <                        return 0;
787 >                        return -1;
788 >                memcpy(fv, buf+3*sizeof(float), 3*sizeof(float));
789 >                if (DOT(fv,fv) <= FTINY*FTINY)
790 >                        return 0;       /* dummy ray */
791                  return sizeof(float)*6;
792          case 'd':
793                  if (fread(buf, sizeof(double), 6, fp) < 6)
794 <                        return 0;
794 >                        return -1;
795 >                memcpy(dv, buf+3*sizeof(double), 3*sizeof(double));
796 >                if (DOT(dv,dv) <= FTINY*FTINY)
797 >                        return 0;       /* dummy ray */
798                  return sizeof(double)*6;
799          }
800          error(INTERNAL, "botched input format");
801 <        return 0;       /* pro forma return */
801 >        return -1;      /* pro forma return */
802   }
803  
804   static float    rparams[9];             /* traced ray parameters */
# Line 960 | Line 972 | process_queue(void)
972                  }
973                  done_contrib();         /* sum up contributions & output */
974                  lastdone = rtp->raynum;
975 <                free(rtp->buf);         /* free up buffer space */
975 >                if (rtp->buf != NULL)   /* free up buffer space */
976 >                        free(rtp->buf);
977                  rt_unproc = rtp->next;
978                  free(rtp);              /* done with this ray tree */
979          }
# Line 1048 | Line 1061 | trace_contribs(FILE *fin)
1061          int             iblen;
1062          struct rtproc   *rtp;
1063                                                  /* loop over input */
1064 <        while ((iblen = getinp(inpbuf, fin)) > 0) {
1065 <                if (lastray+1 < lastray ||      /* need reset? */
1066 <                                queue_length() > 10*nrtprocs()) {
1064 >        while ((iblen = getinp(inpbuf, fin)) >= 0) {
1065 >                if (!iblen ||                   /* need reset? */
1066 >                                queue_length() > 10*nrtprocs() ||
1067 >                                lastray+1 < lastray) {
1068                          while (wait_rproc() != NULL)
1069                                  process_queue();
1070                          if (lastray+1 < lastray)
1071                                  lastdone = lastray = 0;
1072                  }
1073                  rtp = get_rproc();              /* get avail. rtrace process */
1074 <                rtp->raynum = ++lastray;        /* assign ray to it */
1075 <                writebuf(rtp->pd.w, inpbuf, iblen);
1074 >                rtp->raynum = ++lastray;        /* assign ray */
1075 >                if (iblen) {                    /* trace ray if valid */
1076 >                        writebuf(rtp->pd.w, inpbuf, iblen);
1077 >                } else {                        /* else bypass dummy ray */
1078 >                        queue_raytree(rtp);     /* empty tree */
1079 >                        if ((yres <= 0) & (waitflush > 0))
1080 >                                waitflush = 1;  /* flush after this */
1081 >                }
1082                  if (raysleft && !--raysleft)
1083                          break;
1084                  process_queue();                /* catch up with results */
# Line 1219 | Line 1239 | recover_output(FILE *fin)
1239          lu_doall(&ofiletab, myseeko, &nvals);
1240                                                  /* skip repeated input */
1241          for (nvals = 0; nvals < lastout; nvals++)
1242 <                if (getinp(oname, fin) <= 0)
1242 >                if (getinp(oname, fin) < 0)
1243                          error(USER, "unexpected EOF on input");
1244          lastray = lastdone = (unsigned long)lastout;
1245          if (raysleft)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines