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.91 by greg, Tue Nov 13 19:58:33 2018 UTC vs.
Revision 2.103 by greg, Mon Aug 12 18:57:00 2024 UTC

# Line 48 | 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 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 = 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 134 | Line 136 | static int pixnumber(int  x, int  y, int  xres, int  y
136  
137  
138  
137 #ifdef RHAS_STAT
138 #include  <sys/types.h>
139 #include  <sys/stat.h>
140 int
141 file_exists(fname)                              /* ordinary file exists? */
142 char  *fname;
143 {
144        struct stat  sbuf;
145        if (stat(fname, &sbuf) < 0) return(0);
146        return((sbuf.st_mode & S_IFREG) != 0);
147 }
148 #else
149 #define  file_exists(f) (access(f,F_OK)==0)
150 #endif
151
152
139   void
140 < quit(code)                      /* quit program */
155 < int  code;
140 > quit(int code)                  /* quit program */
141   {
142          if (code)                       /* report status */
143                  report(0);
# Line 304 | 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);
321 <                                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 353 | 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 390 | Line 384 | render(                                /* render the scene */
384          char  *oldfile
385   )
386   {
387 +        const int  srcdrawing =         /* manually draw tiny light sources? */
388 +                (directvis && dblur <= FTINY && (mblur <= FTINY) | !lastview.type);
389          COLOR  *scanbar[MAXDIV+1];      /* scanline arrays of pixel values */
390          float  *zbar[MAXDIV+1];         /* z values */
391          char  *sampdens;                /* previous sample density */
# Line 456 | Line 452 | render(                                /* render the scene */
452          signal(SIGCONT, report);
453   #endif
454          ypos = vres-1 - i;                      /* initialize sampling */
455 <        if (directvis)
455 >        if (srcdrawing)
456                  init_drawsources(psample);
457          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
458                                                  /* compute scanlines */
# Line 477 | Line 473 | render(                                /* render the scene */
473                                  hres, ypos, hstep);
474                                                          /* fill bar */
475                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
476 <                if (directvis)                          /* add bitty sources */
477 <                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
476 >                if (srcdrawing)                         /* add bitty sources */
477 >                        drawsources((COLORV **)scanbar, 3, zbar, 0, hres, ypos, ystep);
478                                                          /* write it out */
479   #ifdef SIGCONT
480                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 672 | Line 668 | pixvalue(              /* compute pixel value */
668          int  y
669   )
670   {
675        extern void  SDsquare2disk(double ds[2], double seedx, double seedy);
671          RAY  thisray;
672          FVECT   lorg, ldir;
673 <        double  hpos, vpos, vdist, lmax;
673 >        double  hpos, vpos, lmax;
674          int     i;
675                                                  /* compute view ray */
676          setcolor(col, 0.0, 0.0, 0.0);
# Line 684 | Line 679 | pixvalue(              /* compute pixel value */
679          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
680                                          &ourview, hpos, vpos)) < -FTINY)
681                  return(0.0);
687
688        vdist = ourview.vdist;
682                                                  /* set pixel index */
683          samplendx = pixnumber(x,y,hres,vres);
684                                                  /* optional motion blur */
# Line 700 | Line 693 | pixvalue(              /* compute pixel value */
693                  }
694                  if (normalize(thisray.rdir) == 0.0)
695                          return(0.0);
703                vdist = (1.-d)*vdist + d*lastview.vdist;
696          }
697 <                                                /* optional depth-of-field */
698 <        if (dblur > FTINY) {
699 <                double  vc, df[2];
708 <                                                /* random point on disk */
709 <                SDsquare2disk(df, frandom(), frandom());
710 <                df[0] *= .5*dblur;
711 <                df[1] *= .5*dblur;
712 <                if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) {
713 <                        double  adj = 1.0;
714 <                        if (ourview.type == VT_PER)
715 <                                adj /= DOT(thisray.rdir, ourview.vdir);
716 <                        df[0] /= sqrt(ourview.hn2);
717 <                        df[1] /= sqrt(ourview.vn2);
718 <                        for (i = 3; i--; ) {
719 <                                vc = ourview.vp[i] + adj*vdist*thisray.rdir[i];
720 <                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
721 <                                                        df[1]*ourview.vvec[i] ;
722 <                                thisray.rdir[i] = vc - thisray.rorg[i];
723 <                        }
724 <                } else {                        /* non-standard view case */
725 <                        double  dfd = PI/4.*dblur*(.5 - frandom());
726 <                        if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) {
727 <                                if (ourview.type != VT_CYL)
728 <                                        df[0] /= sqrt(ourview.hn2);
729 <                                df[1] /= sqrt(ourview.vn2);
730 <                        }
731 <                        for (i = 3; i--; ) {
732 <                                vc = ourview.vp[i] + vdist*thisray.rdir[i];
733 <                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
734 <                                                        df[1]*ourview.vvec[i] +
735 <                                                        dfd*ourview.vdir[i] ;
736 <                                thisray.rdir[i] = vc - thisray.rorg[i];
737 <                        }
738 <                }
739 <                if (normalize(thisray.rdir) == 0.0)
740 <                        return(0.0);
741 <        }
697 >                                                /* depth-of-field */
698 >        if (!jitteraperture(thisray.rorg, thisray.rdir, &ourview, dblur))
699 >                return(0.0);
700  
701          rayorigin(&thisray, PRIMARY, NULL, NULL);
702  
703          rayvalue(&thisray);                     /* trace ray */
704 <
705 <        copycolor(col, thisray.rcol);           /* return color */
704 >                                                /* -> color */
705 >        scolor_out(col, out_prims, thisray.rcol);
706  
707          return(raydistance(&thisray));          /* return distance */
708   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines