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.75 by greg, Tue Apr 19 01:15:06 2005 UTC vs.
Revision 2.96 by greg, Fri Dec 3 16:50:05 2021 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9  
10   #include  <sys/types.h>
11  
12 < #ifndef NON_POSIX
13 < #ifdef BSD
14 < #include  <sys/time.h>
15 < #include  <sys/resource.h>
12 > #include  "platform.h"
13 > #ifdef NON_POSIX
14 > #ifdef MINGW
15 >  #include  <sys/time.h>
16 > #endif
17   #else
18 < #include  <sys/times.h>
19 < #include  <unistd.h>
18 > #ifdef BSD
19 >  #include  <sys/time.h>
20 >  #include  <sys/resource.h>
21 > #else
22 >  #include  <sys/times.h>
23 >  #include  <unistd.h>
24 > #endif
25   #endif
20 #endif
26  
27   #include  <time.h>
28   #include  <signal.h>
29  
25 #include  "platform.h"
30   #include  "ray.h"
31   #include  "paths.h"
32   #include  "ambient.h"
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  
34
40   #define  RFTEMPLATE     "rfXXXXXX"
41  
42   #ifndef SIGCONT
# Line 47 | Line 52 | int  dimlist[MAXDIM];                  /* sampling dimensions */
52   int  ndims = 0;                         /* number of sampling dimensions */
53   int  samplendx;                         /* sample index number */
54  
50 //extern void  ambnotify();
55   void  (*addobjnotify[])() = {ambnotify, NULL};
56  
57   VIEW  ourview = STDVIEW;                /* view parameters */
# Line 67 | Line 71 | void  (*trace)() = NULL;               /* trace call */
71  
72   int  do_irrad = 0;                      /* compute irradiance? */
73  
74 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
75 +
76   double  dstrsrc = 0.0;                  /* square source distribution */
77   double  shadthresh = .05;               /* shadow threshold */
78   double  shadcert = .5;                  /* shadow certainty */
# Line 86 | Line 92 | double specjitter = 1.;                /* specular sampling jitter *
92   int  backvis = 1;                       /* back face visibility */
93  
94   int  maxdepth = 7;                      /* maximum recursion depth */
95 < double  minweight = 4e-3;               /* minimum ray weight */
95 > double  minweight = 1e-3;               /* minimum ray weight */
96  
97   char  *ambfile = NULL;                  /* ambient file name */
98   COLOR  ambval = BLKCOLOR;               /* ambient value */
# Line 113 | Line 119 | int  hres, vres;                       /* resolution for this frame */
119  
120   static VIEW     lastview;               /* the previous view input */
121  
116 //extern char  *mktemp();  /* XXX should be in stdlib.h or unistd.h */
117
118 //double        pixvalue();
119
122   static void report(int);
123   static int nextview(FILE *fp);
124   static void render(char *zfile, char *oldfile);
# Line 132 | Line 134 | static int pixnumber(int  x, int  y, int  xres, int  y
134  
135  
136  
135 #ifdef RHAS_STAT
136 #include  <sys/types.h>
137 #include  <sys/stat.h>
138 int
139 file_exists(fname)                              /* ordinary file exists? */
140 char  *fname;
141 {
142        struct stat  sbuf;
143        if (stat(fname, &sbuf) < 0) return(0);
144        return((sbuf.st_mode & S_IFREG) != 0);
145 }
146 #else
147 #define  file_exists(f) (access(f,F_OK)==0)
148 #endif
149
150
137   void
138 < quit(code)                      /* quit program */
153 < int  code;
138 > quit(int code)                  /* quit program */
139   {
140          if (code)                       /* report status */
141                  report(0);
# Line 166 | Line 151 | int  code;
151   static void
152   report(int dummy)               /* report progress */
153   {
154 <        double  u, s;
154 >        char                    bcStat [128];
155 >        double          u, s;
156   #ifdef BSD
157 <        struct rusage  rubuf;
157 >        struct rusage   rubuf;
158   #else
159 <        struct tms  tbuf;
160 <        double  period;
159 >        double          period = 1.0 / 60.0;
160 >        struct tms      tbuf;
161   #endif
162  
163          tlastrept = time((time_t *)NULL);
164   #ifdef BSD
165          getrusage(RUSAGE_SELF, &rubuf);
166 <        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
167 <        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
166 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
167 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
168          getrusage(RUSAGE_CHILDREN, &rubuf);
169 <        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
170 <        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
169 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
170 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
171   #else
172          times(&tbuf);
173   #ifdef _SC_CLK_TCK
174          period = 1.0 / sysconf(_SC_CLK_TCK);
189 #else
190        period = 1.0 / 60.0;
175   #endif
176          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
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\n",
185 <                        nrays, pctdone, u/3600., s/3600.,
186 <                        (tlastrept-tstart)/3600., myhostname());
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
189          signal(SIGCONT, report);
# Line 206 | 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
208  
209  
210 < extern void
210 > void
211   rpict(                  /* generate image(s) */
212          int  seq,
213          char  *pout,
# Line 235 | Line 228 | rpict(                 /* generate image(s) */
228   {
229          char  fbuf[128], fbuf2[128];
230          int  npicts;
231 <        register char  *cp;
231 >        char  *cp;
232          RESOLU  rs;
233          double  pa;
234                                          /* check sampling */
# Line 251 | Line 244 | rpict(                 /* generate image(s) */
244          if (seq <= 0)
245                  seq = 0;
246          else if (prvr != NULL && isint(prvr)) {
247 <                register int  rn;               /* skip to specified view */
247 >                int  rn;                /* skip to specified view */
248                  if ((rn = atoi(prvr)) < seq)
249                          error(USER, "recover frame less than start frame");
250                  if (pout == NULL)
# Line 294 | 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);
311 <                                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 340 | Line 337 | rpict(                 /* generate image(s) */
337                  fputs(VIEWSTR, stdout);
338                  fprintview(&ourview, stdout);
339                  putchar('\n');
340 <                if (pa < .99 || pa > 1.01)
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 389 | Line 387 | render(                                /* render the scene */
387          int  zfd;
388          COLOR  *colptr;
389          float  *zptr;
390 <        register int  i;
390 >        int  i;
391                                          /* check for empty image */
392 <        if (hres <= 0 || vres <= 0) {
392 >        if ((hres <= 0) | (vres <= 0)) {
393                  error(WARNING, "empty output picture");
394                  fprtresolu(0, 0, stdout);
395                  return;
# Line 435 | Line 433 | render(                                /* render the scene */
433          i = salvage(oldfile);
434          if (i >= vres)
435                  goto alldone;
436 <        if (zfd != -1 && i > 0 &&
436 >        if ((zfd != -1) & (i > 0) &&
437                          lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0)
438                  error(SYSTEM, "z-file seek error in render");
439          pctdone = 100.0*i/vres;
# Line 529 | Line 527 | memerr:
527  
528   static void
529   fillscanline(   /* fill scan at y */
530 <        register COLOR  *scanline,
531 <        register float  *zline,
532 <        register char  *sd,
530 >        COLOR   *scanline,
531 >        float   *zline,
532 >        char  *sd,
533          int  xres,
534          int  y,
535          int  xstep
# Line 540 | Line 538 | fillscanline(  /* fill scan at y */
538          static int  nc = 0;             /* number of calls */
539          int  bl = xstep, b = xstep;
540          double  z;
541 <        register int  i;
541 >        int  i;
542  
543          z = pixvalue(scanline[0], 0, y);
544          if (zline) zline[0] = z;
# Line 568 | Line 566 | fillscanline(  /* fill scan at y */
566  
567   static void
568   fillscanbar(    /* fill interior */
569 <        register COLOR  *scanbar[],
570 <        register float  *zbar[],
569 >        COLOR   *scanbar[],
570 >        float   *zbar[],
571          int  xres,
572          int  y,
573          int  ysize
# Line 578 | Line 576 | fillscanbar(   /* fill interior */
576          COLOR  vline[MAXDIV+1];
577          float  zline[MAXDIV+1];
578          int  b = ysize;
579 <        register int  i, j;
579 >        int  i, j;
580  
581          for (i = 0; i < xres; i++) {
582                  copycolor(vline[0], scanbar[0][i]);
# Line 601 | Line 599 | fillscanbar(   /* fill interior */
599  
600   static int
601   fillsample( /* fill interior points */
602 <        register COLOR  *colline,
603 <        register float  *zline,
602 >        COLOR   *colline,
603 >        float   *zline,
604          int  x,
605          int  y,
606          int  xlen,
# Line 614 | Line 612 | fillsample( /* fill interior points */
612          double  z;
613          COLOR  ctmp;
614          int  ncut;
615 <        register int  len;
615 >        int  len;
616  
617          if (xlen > 0)                   /* x or y length is zero */
618                  len = xlen;
# Line 665 | Line 663 | pixvalue(              /* compute pixel value */
663          RAY  thisray;
664          FVECT   lorg, ldir;
665          double  hpos, vpos, vdist, lmax;
666 <        register int    i;
666 >        int     i;
667                                                  /* compute view ray */
668 +        setcolor(col, 0.0, 0.0, 0.0);
669          hpos = (x+pixjitter())/hres;
670          vpos = (y+pixjitter())/vres;
671          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
672 <                                        &ourview, hpos, vpos)) < -FTINY) {
674 <                setcolor(col, 0.0, 0.0, 0.0);
672 >                                        &ourview, hpos, vpos)) < -FTINY)
673                  return(0.0);
676        }
677        vdist = ourview.vdist;
674  
675 <        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
676 <
675 >        vdist = ourview.vdist;
676 >                                                /* set pixel index */
677 >        samplendx = pixnumber(x,y,hres,vres);
678                                                  /* optional motion blur */
679          if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
680                                          &lastview, hpos, vpos)) >= -FTINY) {
681 <                register double  d = mblur*(.5-urand(281+samplendx));
681 >                double  d = mblur*(.5-urand(281+samplendx));
682  
683                  thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
684                  for (i = 3; i--; ) {
# Line 693 | Line 690 | pixvalue(              /* compute pixel value */
690                  vdist = (1.-d)*vdist + d*lastview.vdist;
691          }
692                                                  /* optional depth-of-field */
693 <        if (dblur > FTINY && vdist > FTINY) {
694 <                double  vc, dfh, dfv;
695 <                                                /* PI/4. square/circle conv. */
696 <                dfh = PI/4.*dblur*(.5 - frandom());
697 <                dfv = PI/4.*dblur*(.5 - frandom());
698 <                if (ourview.type == VT_PER || ourview.type == VT_PAR) {
699 <                        dfh /= sqrt(ourview.hn2);
700 <                        dfv /= sqrt(ourview.vn2);
693 >        if (dblur > FTINY) {
694 >                double  vc, df[2];
695 >                                                /* random point on disk */
696 >                SDsquare2disk(df, frandom(), frandom());
697 >                df[0] *= .5*dblur;
698 >                df[1] *= .5*dblur;
699 >                if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) {
700 >                        double  adj = 1.0;
701 >                        if (ourview.type == VT_PER)
702 >                                adj /= DOT(thisray.rdir, ourview.vdir);
703 >                        df[0] /= sqrt(ourview.hn2);
704 >                        df[1] /= sqrt(ourview.vn2);
705                          for (i = 3; i--; ) {
706 <                                vc = thisray.rorg[i] + vdist*thisray.rdir[i];
707 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
708 <                                                        dfv*ourview.vvec[i] ;
706 >                                vc = ourview.vp[i] + adj*vdist*thisray.rdir[i];
707 >                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
708 >                                                        df[1]*ourview.vvec[i] ;
709                                  thisray.rdir[i] = vc - thisray.rorg[i];
710                          }
711                  } else {                        /* non-standard view case */
712                          double  dfd = PI/4.*dblur*(.5 - frandom());
713 <                        if (ourview.type != VT_ANG) {
713 >                        if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) {
714                                  if (ourview.type != VT_CYL)
715 <                                        dfh /= sqrt(ourview.hn2);
716 <                                dfv /= sqrt(ourview.vn2);
715 >                                        df[0] /= sqrt(ourview.hn2);
716 >                                df[1] /= sqrt(ourview.vn2);
717                          }
718                          for (i = 3; i--; ) {
719 <                                vc = thisray.rorg[i] + vdist*thisray.rdir[i];
720 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
721 <                                                        dfv*ourview.vvec[i] +
719 >                                vc = ourview.vp[i] + vdist*thisray.rdir[i];
720 >                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
721 >                                                        df[1]*ourview.vvec[i] +
722                                                          dfd*ourview.vdir[i] ;
723                                  thisray.rdir[i] = vc - thisray.rorg[i];
724                          }
# Line 732 | Line 733 | pixvalue(              /* compute pixel value */
733  
734          copycolor(col, thisray.rcol);           /* return color */
735  
736 <        return(thisray.rt);                     /* return distance */
736 >        return(raydistance(&thisray));          /* return distance */
737   }
738  
739  
# Line 765 | Line 766 | salvage(               /* salvage scanlines from killed program */
766                  goto gotzip;
767          }
768  
769 <        if (x != hres || y != vres) {
769 >        if ((x != hres) | (y != vres)) {
770                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
771                                  oldfile);
772                  error(USER, errmsg);
# Line 797 | Line 798 | writerr:
798   }
799  
800   static int
801 < pixnumber(              /* compute pixel index (brushed) */
802 <        register int  x,
803 <        register int  y,
801 > pixnumber(              /* compute pixel index (screen door) */
802 >        int  x,
803 >        int  y,
804          int  xres,
805          int  yres
806   )
807   {
808 <        x -= y;
809 <        while (x < 0)
810 <                x += xres;
811 <        return((((x>>2)*yres + y) << 2) + (x & 3));
808 >        unsigned        nbits = 0;
809 >        bitmask_t       coord[2];
810 >
811 >        if (xres < yres) xres = yres;
812 >        while (xres > 0) {
813 >                xres >>= 1;
814 >                ++nbits;
815 >        }
816 >        coord[0] = x; coord[1] = y;
817 >        return ((int)hilbert_c2i(2, nbits, coord));
818   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines