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.80 by schorsch, Sun Apr 27 17:22:49 2008 UTC vs.
Revision 2.107 by greg, Sat Jan 25 04:57:56 2025 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 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 */
56  
54 //extern void  ambnotify();
57   void  (*addobjnotify[])() = {ambnotify, NULL};
58  
59   VIEW  ourview = STDVIEW;                /* view parameters */
# Line 92 | 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 = 4e-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 117 | Line 119 | time_t  tstart;                                /* starting time */
119  
120   int  hres, vres;                        /* resolution for this frame */
121  
122 + extern void     sskip_ray(RAY *r, double h, double v);
123 +
124   static VIEW     lastview;               /* the previous view input */
125  
122 //extern char  *mktemp();  /* XXX should be in stdlib.h or unistd.h */
123
124 //double        pixvalue();
125
126   static void report(int);
127   static int nextview(FILE *fp);
128   static void render(char *zfile, char *oldfile);
# Line 138 | Line 138 | static int pixnumber(int  x, int  y, int  xres, int  y
138  
139  
140  
141 #ifdef RHAS_STAT
142 #include  <sys/types.h>
143 #include  <sys/stat.h>
144 int
145 file_exists(fname)                              /* ordinary file exists? */
146 char  *fname;
147 {
148        struct stat  sbuf;
149        if (stat(fname, &sbuf) < 0) return(0);
150        return((sbuf.st_mode & S_IFREG) != 0);
151 }
152 #else
153 #define  file_exists(f) (access(f,F_OK)==0)
154 #endif
155
156
141   void
142 < quit(code)                      /* quit program */
159 < int  code;
142 > quit(int code)                  /* quit program */
143   {
144          if (code)                       /* report status */
145                  report(0);
# Line 172 | Line 155 | int  code;
155   static void
156   report(int dummy)               /* report progress */
157   {
158 <        double  u, s;
158 >        char                    bcStat [128];
159 >        double          u, s;
160   #ifdef BSD
161 <        struct rusage  rubuf;
161 >        struct rusage   rubuf;
162   #else
163 <        struct tms  tbuf;
164 <        double  period;
163 >        double          period = 1.0 / 60.0;
164 >        struct tms      tbuf;
165   #endif
166  
167          tlastrept = time((time_t *)NULL);
168   #ifdef BSD
169          getrusage(RUSAGE_SELF, &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          getrusage(RUSAGE_CHILDREN, &rubuf);
173 <        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
174 <        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
173 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
174 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
175   #else
176          times(&tbuf);
177   #ifdef _SC_CLK_TCK
178          period = 1.0 / sysconf(_SC_CLK_TCK);
195 #else
196        period = 1.0 / 60.0;
179   #endif
180          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
181          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
182   #endif
183  
184 +        /* PMAP: Get photon map bias compensation statistics */
185 +        pmapBiasCompReport(bcStat);
186 +        
187          sprintf(errmsg,
188 <                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
189 <                        nrays, pctdone, u/3600., s/3600.,
190 <                        (tlastrept-tstart)/3600., myhostname());
188 >                        "%lu rays, %s%4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
189 >                        nrays, bcStat, pctdone, u*(1./3600.), s*(1./3600.),
190 >                        (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
191          eputs(errmsg);
192   #ifdef SIGCONT
193          signal(SIGCONT, report);
# Line 212 | Line 197 | report(int dummy)              /* report progress */
197   static void
198   report(int dummy)               /* report progress */
199   {
200 +        char    bcStat [128];
201 +        
202          tlastrept = time((time_t *)NULL);
203 <        sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
204 <                        nrays, pctdone, (tlastrept-tstart)/3600.0);
203 >
204 >        /* PMAP: Get photon map bias compensation statistics */
205 >        pmapBiasCompReport(bcStat);
206 >        
207 >        sprintf(errmsg, "%lu rays, %s%4.2f%% after %5.4f hours\n",
208 >                        nrays, bcStat, pctdone, (tlastrept-tstart)/3600.0);
209          eputs(errmsg);
210   }
211   #endif
212  
213  
214 < extern void
214 > void
215   rpict(                  /* generate image(s) */
216          int  seq,
217          char  *pout,
# Line 241 | Line 232 | rpict(                 /* generate image(s) */
232   {
233          char  fbuf[128], fbuf2[128];
234          int  npicts;
235 <        register char  *cp;
235 >        char  *cp;
236          RESOLU  rs;
237          double  pa;
238                                          /* check sampling */
# Line 257 | Line 248 | rpict(                 /* generate image(s) */
248          if (seq <= 0)
249                  seq = 0;
250          else if (prvr != NULL && isint(prvr)) {
251 <                register int  rn;               /* skip to specified view */
251 >                int  rn;                /* skip to specified view */
252                  if ((rn = atoi(prvr)) < seq)
253                          error(USER, "recover frame less than start frame");
254                  if (pout == NULL)
# Line 298 | Line 289 | rpict(                 /* generate image(s) */
289          do {
290                  if (seq && nextview(stdin) == EOF)
291                          break;
292 +                lastview.type *= seq > 1;
293                  pctdone = 0.0;
294                  if (pout != NULL) {
295 +                        int     myfd;
296 +                        close(1);                       /* reassign stdout */
297                          sprintf(fbuf, pout, seq);
298 <                        if (file_exists(fbuf)) {
299 <                                if (prvr != NULL || !strcmp(fbuf, pout)) {
298 >                tryagain:
299 >                        errno = 0;                      /* exclusive open */
300 >                        if ((myfd = open(fbuf, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0) {
301 >                                if ((errno != EEXIST) | (prvr != NULL) ||
302 >                                                !strcmp(fbuf, pout)) {
303                                          sprintf(errmsg,
304 <                                                "output file \"%s\" exists",
304 >                                                "cannot open output file \"%s\"",
305                                                  fbuf);
306 <                                        error(USER, errmsg);
306 >                                        error(SYSTEM, errmsg);
307                                  }
308                                  setview(&ourview);
309                                  continue;               /* don't clobber */
310                          }
311 <                        if (freopen(fbuf, "w", stdout) == NULL) {
312 <                                sprintf(errmsg,
313 <                                        "cannot open output file \"%s\"", fbuf);
317 <                                error(SYSTEM, errmsg);
311 >                        if (myfd != 1) {
312 >                                unlink(fbuf);
313 >                                goto tryagain;          /* leave it open */
314                          }
315 <                        SET_FILE_BINARY(stdout);
315 >                        SET_FD_BINARY(1);
316                          dupheader();
317                  }
318                  hres = hresolu; vres = vresolu; pa = pixaspect;
# Line 346 | Line 342 | rpict(                 /* generate image(s) */
342                  fputs(VIEWSTR, stdout);
343                  fprintview(&ourview, stdout);
344                  putchar('\n');
345 <                if (pa < .99 || pa > 1.01)
345 >                if ((pa < .99) | (pa > 1.01))
346                          fputaspect(pa, stdout);
347                  fputnow(stdout);
348 <                fputformat(COLRFMT, stdout);
349 <                putchar('\n');
348 >                if (out_prims == xyzprims) {
349 >                        fputformat(CIEFMT, stdout);
350 >                } else {
351 >                        fputprims(out_prims, stdout);
352 >                        fputformat(COLRFMT, stdout);
353 >                }
354 >                putchar('\n');          /* close header */
355                  if (zout != NULL)
356                          sprintf(cp=fbuf, zout, seq);
357                  else
# Line 386 | Line 387 | render(                                /* render the scene */
387          char  *oldfile
388   )
389   {
390 +        const int  srcdrawing =         /* manually draw tiny light sources? */
391 +                (directvis && dblur <= FTINY && (mblur <= FTINY) | !lastview.type);
392          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
393          float  *zbar[MAXDIV+1];         /* z values */
394          char  *sampdens;                /* previous sample density */
# Line 395 | Line 398 | render(                                /* render the scene */
398          int  zfd;
399          COLOR  *colptr;
400          float  *zptr;
401 <        register int  i;
401 >        int  i;
402                                          /* check for empty image */
403 <        if (hres <= 0 || vres <= 0) {
403 >        if ((hres <= 0) | (vres <= 0)) {
404                  error(WARNING, "empty output picture");
405                  fprtresolu(0, 0, stdout);
406                  return;
# Line 441 | Line 444 | render(                                /* render the scene */
444          i = salvage(oldfile);
445          if (i >= vres)
446                  goto alldone;
447 <        if (zfd != -1 && i > 0 &&
447 >        if ((zfd != -1) & (i > 0) &&
448                          lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0)
449                  error(SYSTEM, "z-file seek error in render");
450          pctdone = 100.0*i/vres;
# Line 452 | Line 455 | render(                                /* render the scene */
455          signal(SIGCONT, report);
456   #endif
457          ypos = vres-1 - i;                      /* initialize sampling */
458 <        if (directvis)
458 >        if (srcdrawing)
459                  init_drawsources(psample);
460          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
461                                                  /* compute scanlines */
# Line 473 | Line 476 | render(                                /* render the scene */
476                                  hres, ypos, hstep);
477                                                          /* fill bar */
478                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
479 <                if (directvis)                          /* add bitty sources */
480 <                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
479 >                if (srcdrawing)                         /* add bitty sources */
480 >                        drawsources((COLORV **)scanbar, out_prims, zbar, 0, hres, ypos, ystep);
481                                                          /* write it out */
482   #ifdef SIGCONT
483                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 535 | Line 538 | memerr:
538  
539   static void
540   fillscanline(   /* fill scan at y */
541 <        register COLOR  *scanline,
542 <        register float  *zline,
543 <        register char  *sd,
541 >        COLOR   *scanline,
542 >        float   *zline,
543 >        char  *sd,
544          int  xres,
545          int  y,
546          int  xstep
# Line 546 | Line 549 | fillscanline(  /* fill scan at y */
549          static int  nc = 0;             /* number of calls */
550          int  bl = xstep, b = xstep;
551          double  z;
552 <        register int  i;
552 >        int  i;
553  
554          z = pixvalue(scanline[0], 0, y);
555          if (zline) zline[0] = z;
# Line 574 | Line 577 | fillscanline(  /* fill scan at y */
577  
578   static void
579   fillscanbar(    /* fill interior */
580 <        register COLOR  *scanbar[],
581 <        register float  *zbar[],
580 >        COLOR   *scanbar[],
581 >        float   *zbar[],
582          int  xres,
583          int  y,
584          int  ysize
# Line 584 | Line 587 | fillscanbar(   /* fill interior */
587          COLOR  vline[MAXDIV+1];
588          float  zline[MAXDIV+1];
589          int  b = ysize;
590 <        register int  i, j;
590 >        int  i, j;
591  
592          for (i = 0; i < xres; i++) {
593                  copycolor(vline[0], scanbar[0][i]);
# Line 607 | Line 610 | fillscanbar(   /* fill interior */
610  
611   static int
612   fillsample( /* fill interior points */
613 <        register COLOR  *colline,
614 <        register float  *zline,
613 >        COLOR   *colline,
614 >        float   *zline,
615          int  x,
616          int  y,
617          int  xlen,
# Line 620 | Line 623 | fillsample( /* fill interior points */
623          double  z;
624          COLOR  ctmp;
625          int  ncut;
626 <        register int  len;
626 >        int  len;
627  
628          if (xlen > 0)                   /* x or y length is zero */
629                  len = xlen;
# Line 670 | Line 673 | pixvalue(              /* compute pixel value */
673   {
674          RAY  thisray;
675          FVECT   lorg, ldir;
676 <        double  hpos, vpos, vdist, lmax;
677 <        register int    i;
676 >        double  hpos, vpos, lmax;
677 >        int     i;
678                                                  /* compute view ray */
679 +        setcolor(col, 0.0, 0.0, 0.0);
680          hpos = (x+pixjitter())/hres;
681          vpos = (y+pixjitter())/vres;
682          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
683 <                                        &ourview, hpos, vpos)) < -FTINY) {
680 <                setcolor(col, 0.0, 0.0, 0.0);
683 >                                        &ourview, hpos, vpos)) < -FTINY)
684                  return(0.0);
682        }
683        vdist = ourview.vdist;
685                                                  /* set pixel index */
686          samplendx = pixnumber(x,y,hres,vres);
687                                                  /* optional motion blur */
688          if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
689                                          &lastview, hpos, vpos)) >= -FTINY) {
690 <                register double  d = mblur*(.5-urand(281+samplendx));
690 >                double  d = mblur*(.5-urand(281+samplendx));
691  
692                  thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
693                  for (i = 3; i--; ) {
# Line 695 | Line 696 | pixvalue(              /* compute pixel value */
696                  }
697                  if (normalize(thisray.rdir) == 0.0)
698                          return(0.0);
698                vdist = (1.-d)*vdist + d*lastview.vdist;
699          }
700 <                                                /* optional depth-of-field */
701 <        if (dblur > FTINY && vdist > FTINY) {
702 <                double  vc, dfh, dfv;
703 <                                                /* PI/4. square/circle conv. */
704 <                dfh = PI/4.*dblur*(.5 - frandom());
705 <                dfv = PI/4.*dblur*(.5 - frandom());
706 <                if (ourview.type == VT_PER || ourview.type == VT_PAR) {
707 <                        dfh /= sqrt(ourview.hn2);
708 <                        dfv /= sqrt(ourview.vn2);
709 <                        for (i = 3; i--; ) {
710 <                                vc = thisray.rorg[i] + vdist*thisray.rdir[i];
711 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
712 <                                                        dfv*ourview.vvec[i] ;
713 <                                thisray.rdir[i] = vc - thisray.rorg[i];
714 <                        }
715 <                } else {                        /* non-standard view case */
716 <                        double  dfd = PI/4.*dblur*(.5 - frandom());
717 <                        if (ourview.type != VT_ANG && ourview.type != VT_PLS) {
718 <                                if (ourview.type != VT_CYL)
719 <                                        dfh /= sqrt(ourview.hn2);
720 <                                dfv /= sqrt(ourview.vn2);
721 <                        }
722 <                        for (i = 3; i--; ) {
723 <                                vc = thisray.rorg[i] + vdist*thisray.rdir[i];
724 <                                thisray.rorg[i] += dfh*ourview.hvec[i] +
725 <                                                        dfv*ourview.vvec[i] +
726 <                                                        dfd*ourview.vdir[i] ;
727 <                                thisray.rdir[i] = vc - thisray.rorg[i];
728 <                        }
729 <                }
730 <                if (normalize(thisray.rdir) == 0.0)
731 <                        return(0.0);
732 <        }
700 >                                                /* depth-of-field */
701 >        if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur))
702 >                return(0.0);
703  
704          rayorigin(&thisray, PRIMARY, NULL, NULL);
705  
706          rayvalue(&thisray);                     /* trace ray */
707 +                                                /* -> color */
708 +        scolor_out(col, out_prims, thisray.rcol);
709  
710 <        copycolor(col, thisray.rcol);           /* return color */
739 <
740 <        return(thisray.rt);                     /* return distance */
710 >        return(raydistance(&thisray));          /* return distance */
711   }
712  
713  
# Line 770 | Line 740 | salvage(               /* salvage scanlines from killed program */
740                  goto gotzip;
741          }
742  
743 <        if (x != hres || y != vres) {
743 >        if ((x != hres) | (y != vres)) {
744                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
745                                  oldfile);
746                  error(USER, errmsg);
# Line 802 | Line 772 | writerr:
772   }
773  
774   static int
775 < pixnumber(              /* compute pixel index (brushed) */
776 <        register int  x,
777 <        register int  y,
775 > pixnumber(              /* compute pixel index (screen door) */
776 >        int  x,
777 >        int  y,
778          int  xres,
779          int  yres
780   )
781   {
782 <        x -= y;
783 <        while (x < 0)
784 <                x += xres;
785 <        return((((x>>2)*yres + y) << 2) + (x & 3));
782 >        unsigned        nbits = 0;
783 >        bitmask_t       coord[2];
784 >
785 >        if (xres < yres) xres = yres;
786 >        while (xres > 0) {
787 >                xres >>= 1;
788 >                ++nbits;
789 >        }
790 >        coord[0] = x; coord[1] = y;
791 >        return ((int)hilbert_c2i(2, nbits, coord));
792   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines