--- ray/src/rt/rpict.c 2012/11/26 07:04:07 2.85 +++ ray/src/rt/rpict.c 2014/05/09 23:28:57 2.88 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rpict.c,v 2.85 2012/11/26 07:04:07 greg Exp $"; +static const char RCSid[] = "$Id: rpict.c,v 2.88 2014/05/09 23:28:57 greg Exp $"; #endif /* * rpict.c - routines and variables for picture generation. @@ -33,7 +33,7 @@ static const char RCSid[] = "$Id: rpict.c,v 2.85 2012/ #include "view.h" #include "random.h" #include "paths.h" -#include "rtmisc.h" /* myhostname() */ +#include "hilbert.h" #define RFTEMPLATE "rfXXXXXX" @@ -167,37 +167,35 @@ int code; static void report(int dummy) /* report progress */ { - double u, s; + double u, s; #ifdef BSD - struct rusage rubuf; + struct rusage rubuf; #else - struct tms tbuf; - double period; + double period = 1.0 / 60.0; + struct tms tbuf; #endif tlastrept = time((time_t *)NULL); #ifdef BSD getrusage(RUSAGE_SELF, &rubuf); - u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; - s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; + u = rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; + s = rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; getrusage(RUSAGE_CHILDREN, &rubuf); - u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec/1e6; - s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec/1e6; + u += rubuf.ru_utime.tv_sec + rubuf.ru_utime.tv_usec*1e-6; + s += rubuf.ru_stime.tv_sec + rubuf.ru_stime.tv_usec*1e-6; #else times(&tbuf); #ifdef _SC_CLK_TCK period = 1.0 / sysconf(_SC_CLK_TCK); -#else - period = 1.0 / 60.0; #endif u = ( tbuf.tms_utime + tbuf.tms_cutime ) * period; s = ( tbuf.tms_stime + tbuf.tms_cstime ) * period; #endif sprintf(errmsg, - "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s\n", - nrays, pctdone, u/3600., s/3600., - (tlastrept-tstart)/3600., myhostname()); + "%lu rays, %4.2f%% after %.3fu %.3fs %.3fr hours on %s (PID %d)\n", + nrays, pctdone, u*(1./3600.), s*(1./3600.), + (tlastrept-tstart)*(1./3600.), myhostname(), getpid()); eputs(errmsg); #ifdef SIGCONT signal(SIGCONT, report); @@ -215,7 +213,7 @@ report(int dummy) /* report progress */ #endif -extern void +void rpict( /* generate image(s) */ int seq, char *pout, @@ -663,6 +661,7 @@ pixvalue( /* compute pixel value */ int y ) { + extern void SDsquare2disk(double ds[2], double seedx, double seedy); RAY thisray; FVECT lorg, ldir; double hpos, vpos, vdist, lmax; @@ -694,35 +693,34 @@ pixvalue( /* compute pixel value */ } /* optional depth-of-field */ if (dblur > FTINY) { - double vc, dfh, dfv; - /* square/circle conv. */ - dfh = vc = 1. - 2.*frandom(); - dfv = 1. - 2.*frandom(); - dfh *= .5*dblur*sqrt(1. - .5*dfv*dfv); - dfv *= .5*dblur*sqrt(1. - .5*vc*vc); + double vc, df[2]; + /* random point on disk */ + SDsquare2disk(df, frandom(), frandom()); + df[0] *= .5*dblur; + df[1] *= .5*dblur; if ((ourview.type == VT_PER) | (ourview.type == VT_PAR)) { double adj = 1.0; if (ourview.type == VT_PER) adj /= DOT(thisray.rdir, ourview.vdir); - dfh /= sqrt(ourview.hn2); - dfv /= sqrt(ourview.vn2); + df[0] /= sqrt(ourview.hn2); + df[1] /= sqrt(ourview.vn2); for (i = 3; i--; ) { vc = ourview.vp[i] + adj*vdist*thisray.rdir[i]; - thisray.rorg[i] += dfh*ourview.hvec[i] + - dfv*ourview.vvec[i] ; + thisray.rorg[i] += df[0]*ourview.hvec[i] + + df[1]*ourview.vvec[i] ; thisray.rdir[i] = vc - thisray.rorg[i]; } } else { /* non-standard view case */ double dfd = PI/4.*dblur*(.5 - frandom()); if ((ourview.type != VT_ANG) & (ourview.type != VT_PLS)) { if (ourview.type != VT_CYL) - dfh /= sqrt(ourview.hn2); - dfv /= sqrt(ourview.vn2); + df[0] /= sqrt(ourview.hn2); + df[1] /= sqrt(ourview.vn2); } for (i = 3; i--; ) { vc = ourview.vp[i] + vdist*thisray.rdir[i]; - thisray.rorg[i] += dfh*ourview.hvec[i] + - dfv*ourview.vvec[i] + + thisray.rorg[i] += df[0]*ourview.hvec[i] + + df[1]*ourview.vvec[i] + dfd*ourview.vdir[i] ; thisray.rdir[i] = vc - thisray.rorg[i]; } @@ -802,15 +800,21 @@ writerr: } static int -pixnumber( /* compute pixel index (brushed) */ +pixnumber( /* compute pixel index (screen door) */ int x, int y, int xres, int yres ) { - x -= y; - while (x < 0) - x += xres; - return((((x>>2)*yres + y) << 2) + (x & 3)); + unsigned nbits = 0; + bitmask_t coord[2]; + + if (xres < yres) xres = yres; + while (xres > 0) { + xres >>= 1; + ++nbits; + } + coord[0] = x; coord[1] = y; + return ((int)hilbert_c2i(2, nbits, coord)); }