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.85 by greg, Mon Nov 26 07:04:07 2012 UTC vs.
Revision 2.92 by greg, Thu Mar 21 16:52:40 2019 UTC

# Line 33 | Line 33 | static const char RCSid[] = "$Id$";
33   #include  "view.h"
34   #include  "random.h"
35   #include  "paths.h"
36 < #include  "rtmisc.h" /* myhostname() */
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 */
139   int  code;
# Line 167 | Line 152 | int  code;
152   static void
153   report(int dummy)               /* report progress */
154   {
155 <        double  u, s;
155 >        char                    bcStat [128];
156 >        double          u, s;
157   #ifdef BSD
158 <        struct rusage  rubuf;
158 >        struct rusage   rubuf;
159   #else
160 <        struct tms  tbuf;
161 <        double  period;
160 >        double          period = 1.0 / 60.0;
161 >        struct tms      tbuf;
162   #endif
163  
164          tlastrept = time((time_t *)NULL);
165   #ifdef BSD
166          getrusage(RUSAGE_SELF, &rubuf);
167 <        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
168 <        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
167 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
168 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
169          getrusage(RUSAGE_CHILDREN, &rubuf);
170 <        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
171 <        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
170 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
171 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
172   #else
173          times(&tbuf);
174   #ifdef _SC_CLK_TCK
175          period = 1.0 / sysconf(_SC_CLK_TCK);
190 #else
191        period = 1.0 / 60.0;
176   #endif
177          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
178          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
179   #endif
180  
181 +        /* PMAP: Get photon map bias compensation statistics */
182 +        pmapBiasCompReport(bcStat);
183 +        
184          sprintf(errmsg,
185 <                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
186 <                        nrays, pctdone, u/3600., s/3600.,
187 <                        (tlastrept-tstart)/3600., myhostname());
185 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
186 >                        nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
187 >                        (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
188          eputs(errmsg);
189   #ifdef SIGCONT
190          signal(SIGCONT, report);
# Line 207 | Line 194 | report(int dummy)              /* report progress */
194   static void
195   report(int dummy)               /* report progress */
196   {
197 +        char    bcStat [128];
198 +        
199          tlastrept = time((time_t *)NULL);
200 <        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
201 <                        nrays, pctdone, (tlastrept-tstart)/3600.0);
200 >
201 >        /* PMAP: Get photon map bias compensation statistics */
202 >        pmapBiasCompReport(bcStat);
203 >        
204 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
205 >                        nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
206          eputs(errmsg);
207   }
208   #endif
209  
210  
211 < extern void
211 > void
212   rpict(                  /* generate image(s) */
213          int  seq,
214          char  *pout,
# Line 295 | Line 288 | rpict(                 /* generate image(s) */
288                          break;
289                  pctdone = 0.0;
290                  if (pout != NULL) {
291 +                        close(1);                       /* reassign stdout */
292                          sprintf(fbuf, pout, seq);
293 <                        if (file_exists(fbuf)) {
294 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
293 >                        errno = 0;                      /* exclusive open */
294 >                        if (open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666) != 1) {
295 >                                if ((errno != EEXIST) | (prvr != NULL) ||
296 >                                                !strcmp(fbuf, pout)) {
297                                          sprintf(errmsg,
298 <                                                "output file \"%s\" exists",
298 >                                                "cannot open output file \"%s\"",
299                                                  fbuf);
300 <                                        error(USER, errmsg);
300 >                                        error(SYSTEM, errmsg);
301                                  }
302                                  setview(&ourview);
303                                  continue;               /* don't clobber */
304                          }
305 <                        if (freopen(fbuf, "w", stdout) == NULL) {
310 <                                sprintf(errmsg,
311 <                                        "cannot open output file \"%s\"", fbuf);
312 <                                error(SYSTEM, errmsg);
313 <                        }
314 <                        SET_FILE_BINARY(stdout);
305 >                        SET_FD_BINARY(1);
306                          dupheader();
307                  }
308                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 663 | Line 654 | pixvalue(              /* compute pixel value */
654          int  y
655   )
656   {
657 +        extern void  SDsquare2disk(double ds[2], double seedx, double seedy);
658          RAY  thisray;
659          FVECT   lorg, ldir;
660          double  hpos, vpos, vdist, lmax;
# Line 694 | Line 686 | pixvalue(              /* compute pixel value */
686          }
687                                                  /* optional depth-of-field */
688          if (dblur > FTINY) {
689 <                double  vc, dfh, dfv;
690 <                                                /* square/circle conv. */
691 <                dfh = vc = 1. - 2.*frandom();
692 <                dfv = 1. - 2.*frandom();
693 <                dfh *= .5*dblur*sqrt(1. - .5*dfv*dfv);
702 <                dfv *= .5*dblur*sqrt(1. - .5*vc*vc);
689 >                double  vc, df[2];
690 >                                                /* random point on disk */
691 >                SDsquare2disk(df, frandom(), frandom());
692 >                df[0] *= .5*dblur;
693 >                df[1] *= .5*dblur;
694                  if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) {
695                          double  adj = 1.0;
696                          if (ourview.type == VT_PER)
697                                  adj /= DOT(thisray.rdir, ourview.vdir);
698 <                        dfh /= sqrt(ourview.hn2);
699 <                        dfv /= sqrt(ourview.vn2);
698 >                        df[0] /= sqrt(ourview.hn2);
699 >                        df[1] /= sqrt(ourview.vn2);
700                          for (i = 3; i--; ) {
701                                  vc = ourview.vp[i] + adj*vdist*thisray.rdir[i];
702 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
703 <                                                        dfv*ourview.vvec[i] ;
702 >                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
703 >                                                        df[1]*ourview.vvec[i] ;
704                                  thisray.rdir[i] = vc - thisray.rorg[i];
705                          }
706                  } else {                        /* non-standard view case */
707                          double  dfd = PI/4.*dblur*(.5 - frandom());
708                          if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) {
709                                  if (ourview.type != VT_CYL)
710 <                                        dfh /= sqrt(ourview.hn2);
711 <                                dfv /= sqrt(ourview.vn2);
710 >                                        df[0] /= sqrt(ourview.hn2);
711 >                                df[1] /= sqrt(ourview.vn2);
712                          }
713                          for (i = 3; i--; ) {
714                                  vc = ourview.vp[i] + vdist*thisray.rdir[i];
715 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
716 <                                                        dfv*ourview.vvec[i] +
715 >                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
716 >                                                        df[1]*ourview.vvec[i] +
717                                                          dfd*ourview.vdir[i] ;
718                                  thisray.rdir[i] = vc - thisray.rorg[i];
719                          }
# Line 737 | Line 728 | pixvalue(              /* compute pixel value */
728  
729          copycolor(col, thisray.rcol);           /* return color */
730  
731 <        return(thisray.rt);                     /* return distance */
731 >        return(raydistance(&thisray));          /* return distance */
732   }
733  
734  
# Line 802 | Line 793 | writerr:
793   }
794  
795   static int
796 < pixnumber(              /* compute pixel index (brushed) */
796 > pixnumber(              /* compute pixel index (screen door) */
797          int  x,
798          int  y,
799          int  xres,
800          int  yres
801   )
802   {
803 <        x -= y;
804 <        while (x < 0)
805 <                x += xres;
806 <        return((((x>>2)*yres + y) << 2) + (x & 3));
803 >        unsigned        nbits = 0;
804 >        bitmask_t       coord[2];
805 >
806 >        if (xres < yres) xres = yres;
807 >        while (xres > 0) {
808 >                xres >>= 1;
809 >                ++nbits;
810 >        }
811 >        coord[0] = x; coord[1] = y;
812 >        return ((int)hilbert_c2i(2, nbits, coord));
813   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines