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.36 by greg, Sun Dec 12 13:56:08 1993 UTC vs.
Revision 2.49 by gwlarson, Tue Mar 3 19:14:28 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1993 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 6 | Line 6 | static char SCCSid[] = "$SunId$ LBL";
6  
7   /*
8   *  rpict.c - routines and variables for picture generation.
9 *
10 *     8/14/85
9   */
10  
11   #include  "ray.h"
# Line 20 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18   #include  <sys/resource.h>
19   #else
20   #include  <sys/times.h>
23 #include  <sys/utsname.h>
21   #include  <unistd.h>
22   #endif
23   #endif
# Line 56 | Line 53 | int  psample = 4;                      /* pixel sample size */
53   double  maxdiff = .05;                  /* max. difference for interpolation */
54   double  dstrpix = 0.67;                 /* square pixel distribution */
55  
56 + double  mblur = 0.;                     /* motion blur parameter */
57 +
58   double  dstrsrc = 0.0;                  /* square source distribution */
59   double  shadthresh = .05;               /* shadow threshold */
60   double  shadcert = .5;                  /* shadow certainty */
# Line 64 | Line 63 | int  vspretest = 512;                  /* virtual source pretest dens
63   int  directvis = 1;                     /* sources visible? */
64   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
65  
66 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
67 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
68 + double  seccg = 0.;                     /* global scattering eccentricity */
69 + double  ssampdist = 0.;                 /* scatter sampling distance */
70 +
71   double  specthresh = .15;               /* specular sampling threshold */
72   double  specjitter = 1.;                /* specular sampling jitter */
73  
74 + int  backvis = 1;                       /* back face visibility */
75 +
76   int  maxdepth = 6;                      /* maximum recursion depth */
77   double  minweight = 5e-3;               /* minimum ray weight */
78  
79   COLOR  ambval = BLKCOLOR;               /* ambient value */
80 + int  ambvwt = 0;                        /* initial weight for ambient value */
81   double  ambacc = 0.2;                   /* ambient accuracy */
82   int  ambres = 32;                       /* ambient resolution */
83   int  ambdiv = 128;                      /* ambient divisions */
# Line 97 | Line 104 | extern unsigned long  nrays;           /* number of rays traced
104  
105   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
106  
107 < static int  hres, vres;                 /* resolution for this frame */
107 > int  hres, vres;                        /* resolution for this frame */
108  
109 + static VIEW     lastview;               /* the previous view input */
110 +
111   extern char  *mktemp();
112  
113   double  pixvalue();
# Line 133 | Line 142 | int  code;
142   #ifndef NIX
143   report()                /* report progress */
144   {
145 +        extern char  *myhostname();
146          double  u, s;
147   #ifdef BSD
138        char  hostname[257];
148          struct rusage  rubuf;
149   #else
150          struct tms  tbuf;
142        struct utsname  nambuf;
151          double  period;
144 #define hostname  nambuf.nodename
152   #endif
153  
154          tlastrept = time((time_t *)NULL);
# Line 152 | Line 159 | report()               /* report progress */
159          getrusage(RUSAGE_CHILDREN, &rubuf);
160          u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
161          s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
155        gethostname(hostname, sizeof(hostname));
162   #else
163          times(&tbuf);
164   #ifdef _SC_CLK_TCK
# Line 162 | Line 168 | report()               /* report progress */
168   #endif
169          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
170          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
165        uname(&nambuf);
171   #endif
172  
173          sprintf(errmsg,
174                  "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
175                          nrays, pctdone, u/3600., s/3600.,
176 <                        (tlastrept-tstart)/3600., hostname);
176 >                        (tlastrept-tstart)/3600., myhostname());
177          eputs(errmsg);
178   #ifndef BSD
179          signal(SIGCONT, report);
175 #undef hostname
180   #endif
181   }
182   #else
# Line 331 | Line 335 | FILE  *fp;
335   {
336          char  linebuf[256];
337  
338 +        copystruct(&lastview, &ourview);
339          while (fgets(linebuf, sizeof(linebuf), fp) != NULL)
340                  if (isview(linebuf) && sscanview(&ourview, linebuf) > 0)
341                          return(0);
# Line 391 | Line 396 | char  *zfile, *oldfile;
396          fprtresolu(hres, vres, stdout);
397                                          /* recover file and compute first */
398          i = salvage(oldfile);
399 +        if (i >= vres)
400 +                goto alldone;
401          if (zfd != -1 && i > 0 &&
402                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
403                  error(SYSTEM, "z-file seek error in render");
# Line 401 | Line 408 | char  *zfile, *oldfile;
408          else
409   #endif
410          signal(SIGCONT, report);
411 <        ypos = vres-1 - i;
411 >        ypos = vres-1 - i;                      /* initialize sampling */
412 >        if (directvis)
413 >                init_drawsources(psample);
414          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
415                                                  /* compute scanlines */
416          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
# Line 421 | Line 430 | char  *zfile, *oldfile;
430                                  hres, ypos, hstep);
431                                                          /* fill bar */
432                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
433 +                if (directvis)                          /* add bitty sources */
434 +                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
435                                                          /* write it out */
436   #ifndef  BSD
437                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 446 | Line 457 | char  *zfile, *oldfile;
457          }
458                                                  /* clean up */
459          signal(SIGCONT, SIG_IGN);
460 <        if (zfd != -1) {
450 <                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
460 >        if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float))
461                                  < hres*sizeof(float))
462 <                        goto writerr;
462 >                goto writerr;
463 >        fwritescan(scanbar[0], hres, stdout);
464 >        if (fflush(stdout) == EOF)
465 >                goto writerr;
466 > alldone:
467 >        if (zfd != -1) {
468                  if (close(zfd) == -1)
469                          goto writerr;
470                  for (i = 0; i <= psample; i++)
471                          free((char *)zbar[i]);
472          }
458        fwritescan(scanbar[0], hres, stdout);
459        if (fflush(stdout) == EOF)
460                goto writerr;
473          for (i = 0; i <= psample; i++)
474                  free((char *)scanbar[i]);
475          if (sampdens != NULL)
# Line 484 | Line 496 | int  xres, y, xstep;
496          int  bl = xstep, b = xstep;
497          double  z;
498          register int  i;
499 <        
499 >
500          z = pixvalue(scanline[0], 0, y);
501          if (zline) zline[0] = z;
502                                  /* zig-zag start for quincunx pattern */
# Line 500 | Line 512 | int  xres, y, xstep;
512                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
513                  else
514                          b = fillsample(scanline+i-xstep,
515 <                                        zline ? zline+i-xstep : NULL,
515 >                                        zline ? zline+i-xstep : (float *)NULL,
516                                          i-xstep, y, xstep, 0, b/2);
517                  if (sd) *sd++ = nc & 1 ? bl : b;
518                  bl = b;
# Line 518 | Line 530 | int  xres, y, ysize;
530          float  zline[MAXDIV+1];
531          int  b = ysize;
532          register int  i, j;
533 <        
533 >
534          for (i = 0; i < xres; i++) {
523                
535                  copycolor(vline[0], scanbar[0][i]);
536                  copycolor(vline[ysize], scanbar[ysize][i]);
537                  if (zbar[0]) {
538                          zline[0] = zbar[0][i];
539                          zline[ysize] = zbar[ysize][i];
540                  }
541 <                
531 <                b = fillsample(vline, zbar[0] ? zline : NULL,
541 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
542                                  i, y, 0, ysize, b/2);
543 <                
543 >
544                  for (j = 1; j < ysize; j++)
545                          copycolor(scanbar[j][i], vline[j]);
546                  if (zbar[0])
# Line 553 | Line 563 | int  b;
563          COLOR  ctmp;
564          int  ncut;
565          register int  len;
566 <        
566 >
567          if (xlen > 0)                   /* x or y length is zero */
568                  len = xlen;
569          else
570                  len = ylen;
571 <                
571 >
572          if (len <= 1)                   /* limit recursion */
573                  return(0);
574 <        
575 <        if (b > 0
576 <        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
574 >
575 >        if (b > 0 ||
576 >        (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
577                          || bigdiff(colline[0], colline[len], maxdiff)) {
578 <        
578 >
579                  z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
580                  if (zline) zline[len>>1] = z;
581                  ncut = 1;
572                
582          } else {                                        /* interpolate */
574        
583                  copycolor(colline[len>>1], colline[len]);
584                  ratio = (double)(len>>1) / len;
585                  scalecolor(colline[len>>1], ratio);
# Line 585 | Line 593 | int  b;
593          }
594                                                          /* recurse */
595          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
596 <        
597 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
596 >
597 >        ncut += fillsample(colline+(len>>1),
598 >                        zline ? zline+(len>>1) : (float *)NULL,
599                          x+(xlen>>1), y+(ylen>>1),
600                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
601  
# Line 599 | Line 608 | pixvalue(col, x, y)            /* compute pixel value */
608   COLOR  col;                     /* returned color */
609   int  x, y;                      /* pixel position */
610   {
611 <        static RAY  thisray;
612 <
613 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
614 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
611 >        RAY  thisray;
612 >        FVECT   lorg, ldir;
613 >        double  hpos, vpos, lmax, d;
614 >                                                /* compute view ray */
615 >        hpos = (x+pixjitter())/hres;
616 >        vpos = (y+pixjitter())/vres;
617 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
618 >                                        &ourview, hpos, vpos)) < -FTINY) {
619                  setcolor(col, 0.0, 0.0, 0.0);
620                  return(0.0);
621          }
622  
610        rayorigin(&thisray, NULL, PRIMARY, 1.0);
611
623          samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
624  
625 +                                                /* optional motion blur */
626 +        if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
627 +                                        &lastview, hpos, vpos)) >= -FTINY) {
628 +                register int    i;
629 +                register double  d = mblur*(.5-urand(281+samplendx));
630 +
631 +                thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
632 +                for (i = 3; i--; ) {
633 +                        thisray.rorg[i] = (1.-d)*thisray.rorg[i] + d*lorg[i];
634 +                        thisray.rdir[i] = (1.-d)*thisray.rdir[i] + d*ldir[i];
635 +                }
636 +                if (normalize(thisray.rdir) == 0.0)
637 +                        return(0.0);
638 +        }
639 +
640 +        rayorigin(&thisray, NULL, PRIMARY, 1.0);
641 +
642          rayvalue(&thisray);                     /* trace ray */
643  
644          copycolor(col, thisray.rcol);           /* return color */
645 <        
645 >
646          return(thisray.rt);                     /* return distance */
647   }
648  
# Line 628 | Line 656 | char  *oldfile;
656          int  x, y;
657  
658          if (oldfile == NULL)
659 <                return(0);
660 <        
659 >                goto gotzip;
660 >
661          if ((fp = fopen(oldfile, "r")) == NULL) {
662                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
663                  error(WARNING, errmsg);
664 <                return(0);
664 >                goto gotzip;
665          }
666   #ifdef MSDOS
667          setmode(fileno(fp), O_BINARY);
# Line 646 | Line 674 | char  *oldfile;
674                                  oldfile);
675                  error(WARNING, errmsg);
676                  fclose(fp);
677 <                return(0);
677 >                goto gotzip;
678          }
679  
680          if (x != hres || y != vres) {
# Line 670 | Line 698 | char  *oldfile;
698          fclose(fp);
699          unlink(oldfile);
700          return(y);
701 + gotzip:
702 +        if (fflush(stdout) == EOF)
703 +                error(SYSTEM, "error writing picture header");
704 +        return(0);
705   writerr:
706          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
707          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines