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.99 by greg, Wed Nov 15 18:02:53 2023 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 47 | Line 48 | static const char RCSid[] = "$Id$";
48   CUBE  thescene;                         /* our scene */
49   OBJECT  nsceneobjs;                     /* number of objects in our scene */
50  
51 + extern RGBPRIMP  out_prims;             /* output color primitives (NULL if spectral) */
52 +
53   int  dimlist[MAXDIM];                   /* sampling dimensions */
54   int  ndims = 0;                         /* number of sampling dimensions */
55   int  samplendx;                         /* sample index number */
# Line 91 | Line 94 | double specjitter = 1.;                /* specular sampling jitter *
94   int  backvis = 1;                       /* back face visibility */
95  
96   int  maxdepth = 7;                      /* maximum recursion depth */
97 < double  minweight = 1e-3;               /* minimum ray weight */
97 > double  minweight = 1e-4;               /* minimum ray weight */
98  
99   char  *ambfile = NULL;                  /* ambient file name */
100   COLOR  ambval = BLKCOLOR;               /* ambient value */
# Line 133 | Line 136 | static int pixnumber(int  x, int  y, int  xres, int  y
136  
137  
138  
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
139   void
140 < quit(code)                      /* quit program */
154 < int  code;
140 > quit(int code)                  /* quit program */
141   {
142          if (code)                       /* report status */
143                  report(0);
# Line 167 | Line 153 | int  code;
153   static void
154   report(int dummy)               /* report progress */
155   {
156 +        char                    bcStat [128];
157          double          u, s;
158   #ifdef BSD
159          struct rusage   rubuf;
# Line 192 | Line 179 | report(int dummy)              /* report progress */
179          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
180   #endif
181  
182 +        /* PMAP: Get photon map bias compensation statistics */
183 +        pmapBiasCompReport(bcStat);
184 +        
185          sprintf(errmsg,
186 <            "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
187 <                        nrays, pctdone, u*(1./3600.), s*(1./3600.),
186 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
187 >                        nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
188                          (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
189          eputs(errmsg);
190   #ifdef SIGCONT
# Line 205 | Line 195 | report(int dummy)              /* report progress */
195   static void
196   report(int dummy)               /* report progress */
197   {
198 +        char    bcStat [128];
199 +        
200          tlastrept = time((time_t *)NULL);
201 <        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
202 <                        nrays, pctdone, (tlastrept-tstart)/3600.0);
201 >
202 >        /* PMAP: Get photon map bias compensation statistics */
203 >        pmapBiasCompReport(bcStat);
204 >        
205 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
206 >                        nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
207          eputs(errmsg);
208   }
209   #endif
# Line 293 | Line 289 | rpict(                 /* generate image(s) */
289                          break;
290                  pctdone = 0.0;
291                  if (pout != NULL) {
292 +                        int     myfd;
293 +                        close(1);                       /* reassign stdout */
294                          sprintf(fbuf, pout, seq);
295 <                        if (file_exists(fbuf)) {
296 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
295 >                tryagain:
296 >                        errno = 0;                      /* exclusive open */
297 >                        if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
298 >                                if ((errno != EEXIST) | (prvr != NULL) ||
299 >                                                !strcmp(fbuf, pout)) {
300                                          sprintf(errmsg,
301 <                                                "output file \"%s\" exists",
301 >                                                "cannot open output file \"%s\"",
302                                                  fbuf);
303 <                                        error(USER, errmsg);
303 >                                        error(SYSTEM, errmsg);
304                                  }
305                                  setview(&ourview);
306                                  continue;               /* don't clobber */
307                          }
308 <                        if (freopen(fbuf, "w", stdout) == NULL) {
309 <                                sprintf(errmsg,
310 <                                        "cannot open output file \"%s\"", fbuf);
310 <                                error(SYSTEM, errmsg);
308 >                        if (myfd != 1) {
309 >                                unlink(fbuf);
310 >                                goto tryagain;          /* leave it open */
311                          }
312 <                        SET_FILE_BINARY(stdout);
312 >                        SET_FD_BINARY(1);
313                          dupheader();
314                  }
315                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 342 | Line 342 | rpict(                 /* generate image(s) */
342                  if ((pa < .99) | (pa > 1.01))
343                          fputaspect(pa, stdout);
344                  fputnow(stdout);
345 <                fputformat(COLRFMT, stdout);
346 <                putchar('\n');
345 >                if (out_prims == xyzprims) {
346 >                        fputformat(CIEFMT, stdout);
347 >                } else {
348 >                        fputprims(out_prims, stdout);
349 >                        fputformat(COLRFMT, stdout);
350 >                }
351 >                putchar('\n');          /* close header */
352                  if (zout != NULL)
353                          sprintf(cp=fbuf, zout, seq);
354                  else
# Line 661 | Line 666 | pixvalue(              /* compute pixel value */
666          int  y
667   )
668   {
669 <        extern void  SDsquare2disk(double ds[2], double seedx, double seedy);
669 >        static COLORMAT xyz2myrgbmat;
670          RAY  thisray;
671          FVECT   lorg, ldir;
672 <        double  hpos, vpos, vdist, lmax;
672 >        double  hpos, vpos, lmax;
673          int     i;
674                                                  /* compute view ray */
675          setcolor(col, 0.0, 0.0, 0.0);
# Line 673 | Line 678 | pixvalue(              /* compute pixel value */
678          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
679                                          &ourview, hpos, vpos)) < -FTINY)
680                  return(0.0);
676
677        vdist = ourview.vdist;
681                                                  /* set pixel index */
682          samplendx = pixnumber(x,y,hres,vres);
683                                                  /* optional motion blur */
# Line 689 | Line 692 | pixvalue(              /* compute pixel value */
692                  }
693                  if (normalize(thisray.rdir) == 0.0)
694                          return(0.0);
692                vdist = (1.-d)*vdist + d*lastview.vdist;
695          }
696 <                                                /* optional depth-of-field */
697 <        if (dblur > FTINY) {
698 <                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 <        }
696 >                                                /* depth-of-field */
697 >        if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur))
698 >                return(0.0);
699  
700          rayorigin(&thisray, PRIMARY, NULL, NULL);
701  
702          rayvalue(&thisray);                     /* trace ray */
703  
704 <        copycolor(col, thisray.rcol);           /* return color */
704 >        if (out_prims == stdprims) {            /* return color */
705 >                scolor_rgb(col, thisray.rcol);
706 >        } else if (out_prims == xyzprims) {
707 >                scolor_cie(col, thisray.rcol);
708 >                scalecolor(col, WHTEFFICACY);
709 >        } else if (NCSAMP > 3) {
710 >                COLOR   xyz;
711 >                if (xyz2myrgbmat[0][0] == 0)
712 >                        compxyz2rgbWBmat(xyz2myrgbmat, out_prims);
713 >                scolor_cie(xyz, thisray.rcol);
714 >                colortrans(col, xyz2myrgbmat, xyz);
715 >                clipgamut(col, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite);
716 >        } else
717 >                copycolor(col, thisray.rcol);
718  
719 <        return(thisray.rt);                     /* return distance */
719 >        return(raydistance(&thisray));          /* return distance */
720   }
721  
722  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines