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.70 by greg, Tue Sep 28 17:54:19 2004 UTC vs.
Revision 2.88 by greg, Fri May 9 23:28:57 2014 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  
38  
39   #define  RFTEMPLATE     "rfXXXXXX"
# Line 47 | Line 51 | int  dimlist[MAXDIM];                  /* sampling dimensions */
51   int  ndims = 0;                         /* number of sampling dimensions */
52   int  samplendx;                         /* sample index number */
53  
50 //extern void  ambnotify();
54   void  (*addobjnotify[])() = {ambnotify, NULL};
55  
56   VIEW  ourview = STDVIEW;                /* view parameters */
# Line 61 | Line 64 | double dstrpix = 0.67;                 /* square pixel distribution
64  
65   double  mblur = 0.;                     /* motion blur parameter */
66  
67 + double  dblur = 0.;                     /* depth-of-field blur parameter */
68 +
69   void  (*trace)() = NULL;                /* trace call */
70  
71   int  do_irrad = 0;                      /* compute irradiance? */
72  
73 + int  rand_samp = 0;                     /* pure Monte Carlo sampling? */
74 +
75   double  dstrsrc = 0.0;                  /* square source distribution */
76   double  shadthresh = .05;               /* shadow threshold */
77   double  shadcert = .5;                  /* shadow certainty */
# Line 84 | Line 91 | double specjitter = 1.;                /* specular sampling jitter *
91   int  backvis = 1;                       /* back face visibility */
92  
93   int  maxdepth = 7;                      /* maximum recursion depth */
94 < double  minweight = 4e-3;               /* minimum ray weight */
94 > double  minweight = 1e-3;               /* minimum ray weight */
95  
96   char  *ambfile = NULL;                  /* ambient file name */
97   COLOR  ambval = BLKCOLOR;               /* ambient value */
# Line 94 | Line 101 | int  ambres = 64;                      /* ambient resolution */
101   int  ambdiv = 512;                      /* ambient divisions */
102   int  ambssamp = 128;                    /* ambient super-samples */
103   int  ambounce = 0;                      /* ambient bounces */
104 < char  *amblist[128];                    /* ambient include/exclude list */
104 > char  *amblist[AMBLLEN];                /* ambient include/exclude list */
105   int  ambincl = -1;                      /* include == 1, exclude == 0 */
106  
107   int  ralrm = 0;                         /* seconds between reports */
# Line 111 | Line 118 | int  hres, vres;                       /* resolution for this frame */
118  
119   static VIEW     lastview;               /* the previous view input */
120  
114 //extern char  *mktemp();  /* XXX should be in stdlib.h or unistd.h */
115
116 //double        pixvalue();
117
121   static void report(int);
122   static int nextview(FILE *fp);
123   static void render(char *zfile, char *oldfile);
# Line 164 | Line 167 | int  code;
167   static void
168   report(int dummy)               /* report progress */
169   {
170 <        double  u, s;
170 >        double          u, s;
171   #ifdef BSD
172 <        struct rusage  rubuf;
172 >        struct rusage   rubuf;
173   #else
174 <        struct tms  tbuf;
175 <        double  period;
174 >        double          period = 1.0 / 60.0;
175 >        struct tms      tbuf;
176   #endif
177  
178          tlastrept = time((time_t *)NULL);
179   #ifdef BSD
180          getrusage(RUSAGE_SELF, &rubuf);
181 <        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
182 <        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
181 >        u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
182 >        s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
183          getrusage(RUSAGE_CHILDREN, &rubuf);
184 <        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6;
185 <        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6;
184 >        u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6;
185 >        s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6;
186   #else
187          times(&tbuf);
188   #ifdef _SC_CLK_TCK
189          period = 1.0 / sysconf(_SC_CLK_TCK);
187 #else
188        period = 1.0 / 60.0;
190   #endif
191          u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period;
192          s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period;
193   #endif
194  
195          sprintf(errmsg,
196 <                "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n",
197 <                        nrays, pctdone, u/3600., s/3600.,
198 <                        (tlastrept-tstart)/3600., myhostname());
196 >            "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n",
197 >                        nrays, pctdone, u*(1./3600.), s*(1./3600.),
198 >                        (tlastrept-tstart)*(1./3600.), myhostname(), getpid());
199          eputs(errmsg);
200   #ifdef SIGCONT
201          signal(SIGCONT, report);
# Line 202 | Line 203 | report(int dummy)              /* report progress */
203   }
204   #else
205   static void
206 < report(int)             /* report progress */
206 > report(int dummy)               /* report progress */
207   {
208          tlastrept = time((time_t *)NULL);
209          sprintf(errmsg, "%lu rays, %4.2f%% after %5.4f hours\n",
# Line 212 | Line 213 | report(int)            /* report progress */
213   #endif
214  
215  
216 < extern void
216 > void
217   rpict(                  /* generate image(s) */
218          int  seq,
219          char  *pout,
# Line 233 | Line 234 | rpict(                 /* generate image(s) */
234   {
235          char  fbuf[128], fbuf2[128];
236          int  npicts;
237 <        register char  *cp;
237 >        char  *cp;
238          RESOLU  rs;
239          double  pa;
240                                          /* check sampling */
# Line 249 | Line 250 | rpict(                 /* generate image(s) */
250          if (seq <= 0)
251                  seq = 0;
252          else if (prvr != NULL && isint(prvr)) {
253 <                register int  rn;               /* skip to specified view */
253 >                int  rn;                /* skip to specified view */
254                  if ((rn = atoi(prvr)) < seq)
255                          error(USER, "recover frame less than start frame");
256                  if (pout == NULL)
# Line 338 | Line 339 | rpict(                 /* generate image(s) */
339                  fputs(VIEWSTR, stdout);
340                  fprintview(&ourview, stdout);
341                  putchar('\n');
342 <                if (pa < .99 || pa > 1.01)
342 >                if ((pa < .99) | (pa > 1.01))
343                          fputaspect(pa, stdout);
344                  fputnow(stdout);
345                  fputformat(COLRFMT, stdout);
# Line 387 | Line 388 | render(                                /* render the scene */
388          int  zfd;
389          COLOR  *colptr;
390          float  *zptr;
391 <        register int  i;
391 >        int  i;
392                                          /* check for empty image */
393 <        if (hres <= 0 || vres <= 0) {
393 >        if ((hres <= 0) | (vres <= 0)) {
394                  error(WARNING, "empty output picture");
395                  fprtresolu(0, 0, stdout);
396                  return;
# Line 433 | Line 434 | render(                                /* render the scene */
434          i = salvage(oldfile);
435          if (i >= vres)
436                  goto alldone;
437 <        if (zfd != -1 && i > 0 &&
437 >        if ((zfd != -1) & (i > 0) &&
438                          lseek(zfd, (off_t)i*hres*sizeof(float), SEEK_SET) < 0)
439                  error(SYSTEM, "z-file seek error in render");
440          pctdone = 100.0*i/vres;
# Line 527 | Line 528 | memerr:
528  
529   static void
530   fillscanline(   /* fill scan at y */
531 <        register COLOR  *scanline,
532 <        register float  *zline,
533 <        register char  *sd,
531 >        COLOR   *scanline,
532 >        float   *zline,
533 >        char  *sd,
534          int  xres,
535          int  y,
536          int  xstep
# Line 538 | Line 539 | fillscanline(  /* fill scan at y */
539          static int  nc = 0;             /* number of calls */
540          int  bl = xstep, b = xstep;
541          double  z;
542 <        register int  i;
542 >        int  i;
543  
544          z = pixvalue(scanline[0], 0, y);
545          if (zline) zline[0] = z;
# Line 566 | Line 567 | fillscanline(  /* fill scan at y */
567  
568   static void
569   fillscanbar(    /* fill interior */
570 <        register COLOR  *scanbar[],
571 <        register float  *zbar[],
570 >        COLOR   *scanbar[],
571 >        float   *zbar[],
572          int  xres,
573          int  y,
574          int  ysize
# Line 576 | Line 577 | fillscanbar(   /* fill interior */
577          COLOR  vline[MAXDIV+1];
578          float  zline[MAXDIV+1];
579          int  b = ysize;
580 <        register int  i, j;
580 >        int  i, j;
581  
582          for (i = 0; i < xres; i++) {
583                  copycolor(vline[0], scanbar[0][i]);
# Line 599 | Line 600 | fillscanbar(   /* fill interior */
600  
601   static int
602   fillsample( /* fill interior points */
603 <        register COLOR  *colline,
604 <        register float  *zline,
603 >        COLOR   *colline,
604 >        float   *zline,
605          int  x,
606          int  y,
607          int  xlen,
# Line 612 | Line 613 | fillsample( /* fill interior points */
613          double  z;
614          COLOR  ctmp;
615          int  ncut;
616 <        register int  len;
616 >        int  len;
617  
618          if (xlen > 0)                   /* x or y length is zero */
619                  len = xlen;
# Line 660 | Line 661 | pixvalue(              /* compute pixel value */
661          int  y
662   )
663   {
664 +        extern void  SDsquare2disk(double ds[2], double seedx, double seedy);
665          RAY  thisray;
666          FVECT   lorg, ldir;
667 <        double  hpos, vpos, lmax;
667 >        double  hpos, vpos, vdist, lmax;
668 >        int     i;
669                                                  /* compute view ray */
670 +        setcolor(col, 0.0, 0.0, 0.0);
671          hpos = (x+pixjitter())/hres;
672          vpos = (y+pixjitter())/vres;
673          if ((thisray.rmax = viewray(thisray.rorg, thisray.rdir,
674 <                                        &ourview, hpos, vpos)) < -FTINY) {
671 <                setcolor(col, 0.0, 0.0, 0.0);
674 >                                        &ourview, hpos, vpos)) < -FTINY)
675                  return(0.0);
673        }
676  
677 <        samplendx = pixnumber(x,y,hres,vres);   /* set pixel index */
678 <
677 >        vdist = ourview.vdist;
678 >                                                /* set pixel index */
679 >        samplendx = pixnumber(x,y,hres,vres);
680                                                  /* optional motion blur */
681          if (lastview.type && mblur > FTINY && (lmax = viewray(lorg, ldir,
682                                          &lastview, hpos, vpos)) >= -FTINY) {
683 <                register int    i;
681 <                register double  d = mblur*(.5-urand(281+samplendx));
683 >                double  d = mblur*(.5-urand(281+samplendx));
684  
685                  thisray.rmax = (1.-d)*thisray.rmax + d*lmax;
686                  for (i = 3; i--; ) {
# Line 687 | Line 689 | pixvalue(              /* compute pixel value */
689                  }
690                  if (normalize(thisray.rdir) == 0.0)
691                          return(0.0);
692 +                vdist = (1.-d)*vdist + d*lastview.vdist;
693          }
694 +                                                /* optional depth-of-field */
695 +        if (dblur > FTINY) {
696 +                double  vc, df[2];
697 +                                                /* random point on disk */
698 +                SDsquare2disk(df, frandom(), frandom());
699 +                df[0] *= .5*dblur;
700 +                df[1] *= .5*dblur;
701 +                if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) {
702 +                        double  adj = 1.0;
703 +                        if (ourview.type == VT_PER)
704 +                                adj /= DOT(thisray.rdir, ourview.vdir);
705 +                        df[0] /= sqrt(ourview.hn2);
706 +                        df[1] /= sqrt(ourview.vn2);
707 +                        for (i = 3; i--; ) {
708 +                                vc = ourview.vp[i] + adj*vdist*thisray.rdir[i];
709 +                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
710 +                                                        df[1]*ourview.vvec[i] ;
711 +                                thisray.rdir[i] = vc - thisray.rorg[i];
712 +                        }
713 +                } else {                        /* non-standard view case */
714 +                        double  dfd = PI/4.*dblur*(.5 - frandom());
715 +                        if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) {
716 +                                if (ourview.type != VT_CYL)
717 +                                        df[0] /= sqrt(ourview.hn2);
718 +                                df[1] /= sqrt(ourview.vn2);
719 +                        }
720 +                        for (i = 3; i--; ) {
721 +                                vc = ourview.vp[i] + vdist*thisray.rdir[i];
722 +                                thisray.rorg[i] += df[0]*ourview.hvec[i] +
723 +                                                        df[1]*ourview.vvec[i] +
724 +                                                        dfd*ourview.vdir[i] ;
725 +                                thisray.rdir[i] = vc - thisray.rorg[i];
726 +                        }
727 +                }
728 +                if (normalize(thisray.rdir) == 0.0)
729 +                        return(0.0);
730 +        }
731  
732 <        rayorigin(&thisray, NULL, PRIMARY, 1.0);
732 >        rayorigin(&thisray, PRIMARY, NULL, NULL);
733  
734          rayvalue(&thisray);                     /* trace ray */
735  
# Line 728 | Line 768 | salvage(               /* salvage scanlines from killed program */
768                  goto gotzip;
769          }
770  
771 <        if (x != hres || y != vres) {
771 >        if ((x != hres) | (y != vres)) {
772                  sprintf(errmsg, "resolution mismatch in recover file \"%s\"",
773                                  oldfile);
774                  error(USER, errmsg);
# Line 759 | Line 799 | writerr:
799          return -1; /* pro forma return */
800   }
801  
762
802   static int
803 < pixnumber(              /* compute pixel index (brushed) */
804 <        register int  x,
805 <        register int  y,
803 > pixnumber(              /* compute pixel index (screen door) */
804 >        int  x,
805 >        int  y,
806          int  xres,
807          int  yres
808   )
809   {
810 <        x -= y;
811 <        while (x < 0)
812 <                x += xres;
813 <        return((((x>>2)*yres + y) << 2) + (x & 3));
810 >        unsigned        nbits = 0;
811 >        bitmask_t       coord[2];
812 >
813 >        if (xres < yres) xres = yres;
814 >        while (xres > 0) {
815 >                xres >>= 1;
816 >                ++nbits;
817 >        }
818 >        coord[0] = x; coord[1] = y;
819 >        return ((int)hilbert_c2i(2, nbits, coord));
820   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines