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.48 by gregl, Mon Oct 20 16:46:37 1997 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 64 | Line 61 | int  vspretest = 512;                  /* virtual source pretest dens
61   int  directvis = 1;                     /* sources visible? */
62   double  srcsizerat = .25;               /* maximum ratio source size/dist. */
63  
64 + COLOR  cextinction = BLKCOLOR;          /* global extinction coefficient */
65 + COLOR  salbedo = BLKCOLOR;              /* global scattering albedo */
66 + double  seccg = 0.;                     /* global scattering eccentricity */
67 + double  ssampdist = 0.;                 /* scatter sampling distance */
68 +
69   double  specthresh = .15;               /* specular sampling threshold */
70   double  specjitter = 1.;                /* specular sampling jitter */
71  
72 + int  backvis = 1;                       /* back face visibility */
73 +
74   int  maxdepth = 6;                      /* maximum recursion depth */
75   double  minweight = 5e-3;               /* minimum ray weight */
76  
77   COLOR  ambval = BLKCOLOR;               /* ambient value */
78 + int  ambvwt = 0;                        /* initial weight for ambient value */
79   double  ambacc = 0.2;                   /* ambient accuracy */
80   int  ambres = 32;                       /* ambient resolution */
81   int  ambdiv = 128;                      /* ambient divisions */
# Line 97 | Line 102 | extern unsigned long  nrays;           /* number of rays traced
102  
103   #define  pixjitter()    (.5+dstrpix*(.5-frandom()))
104  
105 < static int  hres, vres;                 /* resolution for this frame */
105 > int  hres, vres;                        /* resolution for this frame */
106  
107   extern char  *mktemp();
108  
# Line 133 | Line 138 | int  code;
138   #ifndef NIX
139   report()                /* report progress */
140   {
141 +        extern char  *myhostname();
142          double  u, s;
143   #ifdef BSD
138        char  hostname[257];
144          struct rusage  rubuf;
145   #else
146          struct tms  tbuf;
142        struct utsname  nambuf;
147          double  period;
144 #define hostname  nambuf.nodename
148   #endif
149  
150          tlastrept = time((time_t *)NULL);
# Line 152 | Line 155 | report()               /* report progress */
155          getrusage(RUSAGE_CHILDREN, &rubuf);
156          u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
157          s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
155        gethostname(hostname, sizeof(hostname));
158   #else
159          times(&tbuf);
160   #ifdef _SC_CLK_TCK
# Line 162 | Line 164 | report()               /* report progress */
164   #endif
165          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
166          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
165        uname(&nambuf);
167   #endif
168  
169          sprintf(errmsg,
170                  "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
171                          nrays, pctdone, u/3600., s/3600.,
172 <                        (tlastrept-tstart)/3600., hostname);
172 >                        (tlastrept-tstart)/3600., myhostname());
173          eputs(errmsg);
174   #ifndef BSD
175          signal(SIGCONT, report);
175 #undef hostname
176   #endif
177   }
178   #else
# Line 391 | Line 391 | char  *zfile, *oldfile;
391          fprtresolu(hres, vres, stdout);
392                                          /* recover file and compute first */
393          i = salvage(oldfile);
394 +        if (i >= vres)
395 +                goto alldone;
396          if (zfd != -1 && i > 0 &&
397                          lseek(zfd, (long)i*hres*sizeof(float), 0) == -1)
398                  error(SYSTEM, "z-file seek error in render");
# Line 401 | Line 403 | char  *zfile, *oldfile;
403          else
404   #endif
405          signal(SIGCONT, report);
406 <        ypos = vres-1 - i;
406 >        ypos = vres-1 - i;                      /* initialize sampling */
407 >        if (directvis)
408 >                init_drawsources(psample);
409          fillscanline(scanbar[0], zbar[0], sampdens, hres, ypos, hstep);
410                                                  /* compute scanlines */
411          for (ypos -= ystep; ypos > -ystep; ypos -= ystep) {
# Line 421 | Line 425 | char  *zfile, *oldfile;
425                                  hres, ypos, hstep);
426                                                          /* fill bar */
427                  fillscanbar(scanbar, zbar, hres, ypos, ystep);
428 +                if (directvis)                          /* add bitty sources */
429 +                        drawsources(scanbar, zbar, 0, hres, ypos, ystep);
430                                                          /* write it out */
431   #ifndef  BSD
432                  signal(SIGCONT, SIG_IGN);       /* don't interrupt writes */
# Line 446 | Line 452 | char  *zfile, *oldfile;
452          }
453                                                  /* clean up */
454          signal(SIGCONT, SIG_IGN);
455 <        if (zfd != -1) {
450 <                if (write(zfd, (char *)zbar[0], hres*sizeof(float))
455 >        if (zfd != -1 && write(zfd, (char *)zbar[0], hres*sizeof(float))
456                                  < hres*sizeof(float))
457 <                        goto writerr;
457 >                goto writerr;
458 >        fwritescan(scanbar[0], hres, stdout);
459 >        if (fflush(stdout) == EOF)
460 >                goto writerr;
461 > alldone:
462 >        if (zfd != -1) {
463                  if (close(zfd) == -1)
464                          goto writerr;
465                  for (i = 0; i <= psample; i++)
466                          free((char *)zbar[i]);
467          }
458        fwritescan(scanbar[0], hres, stdout);
459        if (fflush(stdout) == EOF)
460                goto writerr;
468          for (i = 0; i <= psample; i++)
469                  free((char *)scanbar[i]);
470          if (sampdens != NULL)
# Line 484 | Line 491 | int  xres, y, xstep;
491          int  bl = xstep, b = xstep;
492          double  z;
493          register int  i;
494 <        
494 >
495          z = pixvalue(scanline[0], 0, y);
496          if (zline) zline[0] = z;
497                                  /* zig-zag start for quincunx pattern */
# Line 500 | Line 507 | int  xres, y, xstep;
507                          b = fillsample(scanline, zline, 0, y, i, 0, b/2);
508                  else
509                          b = fillsample(scanline+i-xstep,
510 <                                        zline ? zline+i-xstep : NULL,
510 >                                        zline ? zline+i-xstep : (float *)NULL,
511                                          i-xstep, y, xstep, 0, b/2);
512                  if (sd) *sd++ = nc & 1 ? bl : b;
513                  bl = b;
# Line 518 | Line 525 | int  xres, y, ysize;
525          float  zline[MAXDIV+1];
526          int  b = ysize;
527          register int  i, j;
528 <        
528 >
529          for (i = 0; i < xres; i++) {
523                
530                  copycolor(vline[0], scanbar[0][i]);
531                  copycolor(vline[ysize], scanbar[ysize][i]);
532                  if (zbar[0]) {
533                          zline[0] = zbar[0][i];
534                          zline[ysize] = zbar[ysize][i];
535                  }
536 <                
531 <                b = fillsample(vline, zbar[0] ? zline : NULL,
536 >                b = fillsample(vline, zbar[0] ? zline : (float *)NULL,
537                                  i, y, 0, ysize, b/2);
538 <                
538 >
539                  for (j = 1; j < ysize; j++)
540                          copycolor(scanbar[j][i], vline[j]);
541                  if (zbar[0])
# Line 553 | Line 558 | int  b;
558          COLOR  ctmp;
559          int  ncut;
560          register int  len;
561 <        
561 >
562          if (xlen > 0)                   /* x or y length is zero */
563                  len = xlen;
564          else
565                  len = ylen;
566 <                
566 >
567          if (len <= 1)                   /* limit recursion */
568                  return(0);
569 <        
570 <        if (b > 0
571 <        || (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
569 >
570 >        if (b > 0 ||
571 >        (zline && 2.*fabs(zline[0]-zline[len]) > maxdiff*(zline[0]+zline[len]))
572                          || bigdiff(colline[0], colline[len], maxdiff)) {
573 <        
573 >
574                  z = pixvalue(colline[len>>1], x + (xlen>>1), y + (ylen>>1));
575                  if (zline) zline[len>>1] = z;
576                  ncut = 1;
572                
577          } else {                                        /* interpolate */
574        
578                  copycolor(colline[len>>1], colline[len]);
579                  ratio = (double)(len>>1) / len;
580                  scalecolor(colline[len>>1], ratio);
# Line 585 | Line 588 | int  b;
588          }
589                                                          /* recurse */
590          ncut += fillsample(colline, zline, x, y, xlen>>1, ylen>>1, (b-1)/2);
591 <        
592 <        ncut += fillsample(colline+(len>>1), zline ? zline+(len>>1) : NULL,
591 >
592 >        ncut += fillsample(colline+(len>>1),
593 >                        zline ? zline+(len>>1) : (float *)NULL,
594                          x+(xlen>>1), y+(ylen>>1),
595                          xlen-(xlen>>1), ylen-(ylen>>1), b/2);
596  
# Line 601 | Line 605 | int  x, y;                     /* pixel position */
605   {
606          static RAY  thisray;
607  
608 <        if (viewray(thisray.rorg, thisray.rdir, &ourview,
609 <                        (x+pixjitter())/hres, (y+pixjitter())/vres) < 0) {
608 >        if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir, &ourview,
609 >                        (x+pixjitter())/hres, (y+pixjitter())/vres)) < -FTINY) {
610                  setcolor(col, 0.0, 0.0, 0.0);
611                  return(0.0);
612          }
# Line 614 | Line 618 | int  x, y;                     /* pixel position */
618          rayvalue(&thisray);                     /* trace ray */
619  
620          copycolor(col, thisray.rcol);           /* return color */
621 <        
621 >
622          return(thisray.rt);                     /* return distance */
623   }
624  
# Line 628 | Line 632 | char  *oldfile;
632          int  x, y;
633  
634          if (oldfile == NULL)
635 <                return(0);
636 <        
635 >                goto gotzip;
636 >
637          if ((fp = fopen(oldfile, "r")) == NULL) {
638                  sprintf(errmsg, "cannot open recover file \"%s\"", oldfile);
639                  error(WARNING, errmsg);
640 <                return(0);
640 >                goto gotzip;
641          }
642   #ifdef MSDOS
643          setmode(fileno(fp), O_BINARY);
# Line 646 | Line 650 | char  *oldfile;
650                                  oldfile);
651                  error(WARNING, errmsg);
652                  fclose(fp);
653 <                return(0);
653 >                goto gotzip;
654          }
655  
656          if (x != hres || y != vres) {
# Line 670 | Line 674 | char  *oldfile;
674          fclose(fp);
675          unlink(oldfile);
676          return(y);
677 + gotzip:
678 +        if (fflush(stdout) == EOF)
679 +                error(SYSTEM, "error writing picture header");
680 +        return(0);
681   writerr:
682          sprintf(errmsg, "write error during recovery of \"%s\"", oldfile);
683          error(SYSTEM, errmsg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines