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.2 by greg, Thu May 26 06:55:22 2005 UTC vs.
Revision 1.4 by greg, Thu May 26 17:53:28 2005 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * Gather rtrace output to compute contributions from particular sources
6   */
7  
8 + #include  "standard.h"
9   #include  <ctype.h>
9 #include  "rtio.h"
10 #include  "rterror.h"
10   #include  "platform.h"
11   #include  "rtprocess.h"
12   #include  "selcall.h"
# Line 68 | Line 67 | struct rtproc {
67  
68                                          /* rtrace command and defaults */
69   char            *rtargv[256] = { "rtrace", "-dt", "0", "-dj", ".5", "-dr", "3",
70 <                                "-ab", "1", "-ad", "512", };
70 >                                "-ab", "1", "-ad", "128", };
71   int  rtargc = 11;
72                                          /* overriding rtrace options */
73   char            *myrtopts[] = { "-o~~TmWdp", "-h-",
# Line 113 | Line 112 | void init(int np);
112   void tracecontribs(FILE *fp);
113   struct rtproc *wait_rproc(void);
114   struct rtproc *get_rproc(void);
115 < void process_rays(struct rtproc *rtp);
115 > void queue_raytree(struct rtproc *rtp);
116 > void process_queue(void);
117  
118   void putcontrib(const DCOLOR cnt, FILE *fout);
119   void add_contrib(const char *modn);
# Line 188 | Line 188 | main(int argc, char *argv[])
188                                  case '\0':
189                                          header = !header;
190                                          continue;
191 <                                case '+': case '1': case 'T': case 't':
191 >                                case '+': case '1':
192 >                                case 'T': case 't':
193 >                                case 'Y': case 'y':
194                                          header = 1;
195                                          continue;
196 <                                case '-': case '0': case 'F': case 'f':
196 >                                case '-': case '0':
197 >                                case 'F': case 'f':
198 >                                case 'N': case 'n':
199                                          header = 0;
200                                          continue;
201                                  }
# Line 345 | Line 349 | init(int np)
349          scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
350          scompile("Px=$4;Py=$5;Pz=$6;", NULL, 0);
351                                          /* set up signal handling */
352 < #ifdef SIGPIPE /* not present on Windows */
352 >        signal(SIGINT, quit);
353 > #ifdef SIGHUP
354 >        signal(SIGHUP, quit);
355 > #endif
356 > #ifdef SIGTERM
357 >        signal(SIGTERM, quit);
358 > #endif
359 > #ifdef SIGPIPE
360          signal(SIGPIPE, quit);
361   #endif
362          rtp = &rt0;                     /* start rtrace process(es) */
# Line 550 | Line 561 | badspec:
561   int
562   getinp(char *buf, FILE *fp)
563   {
564 +        char    *cp;
565 +        int     i;
566 +
567          switch (inpfmt) {
568          case 'a':
569 <                if (fgets(buf, 128, fp) == NULL)
570 <                        return 0;
569 >                cp = buf;               /* make sure we get 6 floats */
570 >                for (i = 0; i < 6; i++) {
571 >                        if (fgetword(cp, buf+127-cp, fp) == NULL)
572 >                                return 0;
573 >                        if ((cp = fskip(cp)) == NULL || *cp)
574 >                                return 0;
575 >                        *cp++ = ' ';
576 >                }
577 >                getc(fp);               /* get/put eol */
578 >                *cp-- = '\0'; *cp = '\n';
579                  return strlen(buf);
580          case 'f':
581                  if (fread(buf, sizeof(float), 6, fp) < 6)
# Line 679 | Line 701 | done_contrib(void)
701          }
702   }
703  
704 < /* process (or save) ray tree produced by rtrace process */
704 > /* queue completed ray tree produced by rtrace process */
705   void
706 < process_rays(struct rtproc *rtp)
706 > queue_raytree(struct rtproc *rtp)
707   {
708 <        struct rtproc   *rtu;
709 <                                        /* check if time to process it */
710 <        if (rtp->raynum == lastdone+1) {
708 >        struct rtproc   *rtu, *rtl = NULL;
709 >                                        /* insert following ray order */
710 >        for (rtu = rt_unproc; rtu != NULL; rtu = (rtl=rtu)->next)
711 >                if (rtp->raynum < rtu->raynum)
712 >                        break;
713 >        rtu = (struct rtproc *)malloc(sizeof(struct rtproc));
714 >        if (rtu == NULL)
715 >                error(SYSTEM, "out of memory in queue_raytree");
716 >        *rtu = *rtp;
717 >        if (rtl == NULL) {
718 >                rtu->next = rt_unproc;
719 >                rt_unproc = rtu;
720 >        } else {
721 >                rtu->next = rtl->next;
722 >                rtl->next = rtu;
723 >        }
724 >        rtp->raynum = 0;                /* clear path for next ray tree */
725 >        rtp->bsiz = 0;
726 >        rtp->buf = NULL;
727 >        rtp->nbr = 0;
728 > }
729 >
730 > /* process completed ray trees from our queue */
731 > void
732 > process_queue(void)
733 > {
734 >        char    modname[128];
735 >                                        /* ray-ordered queue */
736 >        while (rt_unproc != NULL && rt_unproc->raynum == lastdone+1) {
737 >                struct rtproc   *rtp = rt_unproc;
738                  int             n = rtp->nbr;
739                  const char      *cp = rtp->buf;
691                char            modname[128];
740                  while (n > 0) {         /* process rays */
741                          register char   *mnp = modname;
742                                          /* skip leading tabs */
# Line 712 | Line 760 | process_rays(struct rtproc *rtp)
760                  }
761                  done_contrib();         /* sum up contributions & output */
762                  lastdone = rtp->raynum;
763 <                free(rtp->buf);
764 <                                        /* catch up with unprocessed list */
765 <                while (rt_unproc != NULL && rt_unproc->raynum == lastdone+1) {
718 <                        process_rays(rt_unproc);
719 <                        rt_unproc = (rtu=rt_unproc)->next;
720 <                        free(rtu);
721 <                }
722 <        } else {                        /* else insert in unprocessed list */
723 <                struct rtproc   *rtl = NULL;
724 <                for (rtu = rt_unproc; rtu != NULL; rtu = (rtl=rtu)->next)
725 <                        if (rtp->raynum < rtu->raynum)
726 <                                break;
727 <                rtu = (struct rtproc *)malloc(sizeof(struct rtproc));
728 <                if (rtu == NULL)
729 <                        error(SYSTEM, "out of memory in process_rays");
730 <                *rtu = *rtp;
731 <                if (rtl == NULL) {
732 <                        rtu->next = rt_unproc;
733 <                        rt_unproc = rtu;
734 <                } else {
735 <                        rtu->next = rtl->next;
736 <                        rtl->next = rtu;
737 <                }
763 >                free(rtp->buf);         /* free up buffer space */
764 >                rt_unproc = rtp->next;
765 >                free(rtp);              /* done with this ray tree */
766          }
739        rtp->raynum = 0;                /* clear path for next ray tree */
740        rtp->bsiz = 0;
741        rtp->buf = NULL;
742        rtp->nbr = 0;
767   }
768  
769   /* wait for rtrace process to finish with ray tree */
# Line 796 | Line 820 | wait_rproc(void)
820                          if (rt->nbr >= 4 && !memcmp(rt->buf+rt->nbr-4,
821                                                          "~\t~\t", 4)) {
822                                  rt->nbr -= 4;   /* elide terminator */
823 <                                process_rays(rt);
823 >                                queue_raytree(rt);
824                                  rtfree = rt;    /* ready for next ray */
825                          }
826                  }
# Line 827 | Line 851 | tracecontribs(FILE *fin)
851          while ((iblen = getinp(inpbuf, fin)) > 0) {
852                  if (lastray+1 < lastray) {      /* counter rollover? */
853                          while (wait_rproc() != NULL)
854 <                                ;
854 >                                process_queue();
855                          lastdone = lastray = 0;
856                  }
857                  rtp = get_rproc();              /* get avail. rtrace process */
858 <                rtp->raynum = ++lastray;        /* assign this ray to it */
858 >                rtp->raynum = ++lastray;        /* assign ray to it */
859                  writebuf(rtp->pd.w, inpbuf, iblen);
860                  if (!--raysleft)
861 <                        break;                  /* explicit EOF */
861 >                        break;
862 >                process_queue();                /* catch up with results */
863          }
864          while (wait_rproc() != NULL)            /* process outstanding rays */
865 <                ;
865 >                process_queue();
866          if (raysleft > 0)
867                  error(USER, "unexpected EOF on input");
868   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines