ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rpict.c
(Generate patch)

Comparing ray/src/rt/rpict.c (file contents):
Revision 2.88 by greg, Fri May 9 23:28:57 2014 UTC vs.
Revision 2.97 by greg, Fri Dec 3 18:10:48 2021 UTC

# Line 34 | Line 34 | static const char RCSid[] = "$Id$";
34   #include  "random.h"
35   #include  "paths.h"
36   #include  "hilbert.h"
37 + #include  "pmapbias.h"
38 + #include  "pmapdiag.h"
39  
38
40   #define  RFTEMPLATE     "rfXXXXXX"
41  
42   #ifndef SIGCONT
# Line 133 | Line 134 | static int pixnumber(int  x, int  y, int  xres, int  y
134  
135  
136  
136 #ifdef RHAS_STAT
137 #include  <sys/types.h>
138 #include  <sys/stat.h>
139 int
140 file_exists(fname)                              /* ordinary file exists? */
141 char  *fname;
142 {
143        struct stat  sbuf;
144        if (stat(fname, &sbuf) < 0) return(0);
145        return((sbuf.st_mode & S_IFREG) != 0);
146 }
147 #else
148 #define  file_exists(f) (access(f,F_OK)==0)
149 #endif
150
151
137   void
138 < quit(code)                      /* quit program */
154 < int  code;
138 > quit(int code)                  /* quit program */
139   {
140          if (code)                       /* report status */
141                  report(0);
# Line 167 | Line 151 | int  code;
151   static void
152   report(int dummy)               /* report progress */
153   {
154 +        char                    bcStat [128];
155          double          u, s;
156   #ifdef BSD
157          struct rusage   rubuf;
# Line 192 | Line 177 | report(int dummy)              /* report progress */
177          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
178   #endif
179  
180 +        /* PMAP: Get photon map bias compensation statistics */
181 +        pmapBiasCompReport(bcStat);
182 +        
183          sprintf(errmsg,
184 <            "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
185 <                        nrays, pctdone, u*(1./3600.), s*(1./3600.),
184 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
185 >                        nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
186                          (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
187          eputs(errmsg);
188   #ifdef SIGCONT
# Line 205 | Line 193 | report(int dummy)              /* report progress */
193   static void
194   report(int dummy)               /* report progress */
195   {
196 +        char    bcStat [128];
197 +        
198          tlastrept = time((time_t *)NULL);
199 <        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
200 <                        nrays, pctdone, (tlastrept-tstart)/3600.0);
199 >
200 >        /* PMAP: Get photon map bias compensation statistics */
201 >        pmapBiasCompReport(bcStat);
202 >        
203 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
204 >                        nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
205          eputs(errmsg);
206   }
207   #endif
# Line 293 | Line 287 | rpict(                 /* generate image(s) */
287                          break;
288                  pctdone = 0.0;
289                  if (pout != NULL) {
290 +                        int     myfd;
291 +                        close(1);                       /* reassign stdout */
292                          sprintf(fbuf, pout, seq);
293 <                        if (file_exists(fbuf)) {
294 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
293 >                tryagain:
294 >                        errno = 0;                      /* exclusive open */
295 >                        if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
296 >                                if ((errno != EEXIST) | (prvr != NULL) ||
297 >                                                !strcmp(fbuf, pout)) {
298                                          sprintf(errmsg,
299 <                                                "output file \"%s\" exists",
299 >                                                "cannot open output file \"%s\"",
300                                                  fbuf);
301 <                                        error(USER, errmsg);
301 >                                        error(SYSTEM, errmsg);
302                                  }
303                                  setview(&ourview);
304                                  continue;               /* don't clobber */
305                          }
306 <                        if (freopen(fbuf, "w", stdout) == NULL) {
307 <                                sprintf(errmsg,
308 <                                        "cannot open output file \"%s\"", fbuf);
310 <                                error(SYSTEM, errmsg);
306 >                        if (myfd != 1) {
307 >                                unlink(fbuf);
308 >                                goto tryagain;          /* leave it open */
309                          }
310 <                        SET_FILE_BINARY(stdout);
310 >                        SET_FD_BINARY(1);
311                          dupheader();
312                  }
313                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 342 | Line 340 | rpict(                 /* generate image(s) */
340                  if ((pa < .99) | (pa > 1.01))
341                          fputaspect(pa, stdout);
342                  fputnow(stdout);
343 +                fputprims(stdprims, stdout);
344                  fputformat(COLRFMT, stdout);
345                  putchar('\n');
346                  if (zout != NULL)
# Line 661 | Line 660 | pixvalue(              /* compute pixel value */
660          int  y
661   )
662   {
664        extern void  SDsquare2disk(double ds[2], double seedx, double seedy);
663          RAY  thisray;
664          FVECT   lorg, ldir;
665 <        double  hpos, vpos, vdist, lmax;
665 >        double  hpos, vpos, lmax;
666          int     i;
667                                                  /* compute view ray */
668          setcolor(col, 0.0, 0.0, 0.0);
# Line 673 | Line 671 | pixvalue(              /* compute pixel value */
671          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
672                                          &ourview, hpos, vpos)) < -FTINY)
673                  return(0.0);
676
677        vdist = ourview.vdist;
674                                                  /* set pixel index */
675          samplendx = pixnumber(x,y,hres,vres);
676                                                  /* optional motion blur */
# Line 689 | Line 685 | pixvalue(              /* compute pixel value */
685                  }
686                  if (normalize(thisray.rdir) == 0.0)
687                          return(0.0);
692                vdist = (1.-d)*vdist + d*lastview.vdist;
688          }
689 <                                                /* optional depth-of-field */
690 <        if (dblur > FTINY) {
691 <                double  vc, df[2];
697 <                                                /* random point on disk */
698 <                SDsquare2disk(df, frandom(), frandom());
699 <                df[0] *= .5*dblur;
700 <                df[1] *= .5*dblur;
701 <                if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) {
702 <                        double  adj = 1.0;
703 <                        if (ourview.type == VT_PER)
704 <                                adj /= DOT(thisray.rdir, ourview.vdir);
705 <                        df[0] /= sqrt(ourview.hn2);
706 <                        df[1] /= sqrt(ourview.vn2);
707 <                        for (i = 3; i--; ) {
708 <                                vc = ourview.vp[i] + adj*vdist*thisray.rdir[i];
709 <                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
710 <                                                        df[1]*ourview.vvec[i] ;
711 <                                thisray.rdir[i] = vc - thisray.rorg[i];
712 <                        }
713 <                } else {                        /* non-standard view case */
714 <                        double  dfd = PI/4.*dblur*(.5 - frandom());
715 <                        if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) {
716 <                                if (ourview.type != VT_CYL)
717 <                                        df[0] /= sqrt(ourview.hn2);
718 <                                df[1] /= sqrt(ourview.vn2);
719 <                        }
720 <                        for (i = 3; i--; ) {
721 <                                vc = ourview.vp[i] + vdist*thisray.rdir[i];
722 <                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
723 <                                                        df[1]*ourview.vvec[i] +
724 <                                                        dfd*ourview.vdir[i] ;
725 <                                thisray.rdir[i] = vc - thisray.rorg[i];
726 <                        }
727 <                }
728 <                if (normalize(thisray.rdir) == 0.0)
729 <                        return(0.0);
730 <        }
689 >                                                /* depth-of-field */
690 >        if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur))
691 >                return(0.0);
692  
693          rayorigin(&thisray, PRIMARY, NULL, NULL);
694  
# Line 735 | Line 696 | pixvalue(              /* compute pixel value */
696  
697          copycolor(col, thisray.rcol);           /* return color */
698  
699 <        return(thisray.rt);                     /* return distance */
699 >        return(raydistance(&thisray));          /* return distance */
700   }
701  
702  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines