--- ray/src/util/findglare.c 1991/04/10 15:59:07 1.16 +++ ray/src/util/findglare.c 1991/04/22 14:56:28 1.22 @@ -36,7 +36,6 @@ ANGLE glarang[180] = {AEND}; /* glare calculation ang int nglarangs = 0; double maxtheta; /* maximum angle (in radians) */ int hsize; /* horizontal size */ -int hlim; /* central limit of horizontal */ struct illum *indirect; /* array of indirect illuminances */ @@ -190,7 +189,9 @@ char *argv[]; printargs(argc, argv, stdout); fputs(VIEWSTR, stdout); fprintview(&ourview, stdout); - printf("\n\n"); + printf("\n"); + fputformat("ascii", stdout); + printf("\n"); printsources(); /* print glare sources */ printillum(); /* print illuminances */ exit(0); @@ -225,8 +226,7 @@ init() /* initialize global variables */ maxtheta = (PI/180.)*glarang[nglarangs-1]; else maxtheta = 0.0; - hlim = sampdens*maxtheta; - hsize = hlim + sampdens - 1; + hsize = hlim(0) + sampdens - 1; if (hsize > (int)(PI*sampdens)) hsize = PI*sampdens; indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); @@ -281,7 +281,7 @@ init() /* initialize global variables */ cleanup() /* close files, wait for children */ { if (verbose) - fprintf(stderr, "%s: cleaning up...\n", progname); + fprintf(stderr, "%s: cleaning up... \n", progname); if (picture != NULL) close_pict(); if (octree != NULL) @@ -296,34 +296,50 @@ compdir(vd, x, y) /* compute direction for x,y */ FVECT vd; int x, y; { - static int cury = 10000; - static double err, cmpval; - long t; + int hl; FVECT org; /* dummy variable */ - if (x <= -hlim) /* left region */ + hl = hlim(y); + if (x <= -hl) { /* left region */ + if (x <= -hl-sampdens) + return(-1); return(viewray(org, vd, &leftview, - (double)(x+hlim)/(2*sampdens)+.5, + (double)(x+hl)/(2*sampdens)+.5, (double)y/(2*sampdens)+.5)); - if (x >= hlim) /* right region */ + } + if (x >= hl) { /* right region */ + if (x >= hl+sampdens) + return(-1); return(viewray(org, vd, &rightview, - (double)(x-hlim)/(2*sampdens)+.5, + (double)(x-hl)/(2*sampdens)+.5, (double)y/(2*sampdens)+.5)); - /* central region */ - /* avoid over-counting of poles */ - if (cury != y) { - err = 0.0; - cmpval = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); - cury = y; } - err += cmpval; - if (err <= 0.5) - return(-1); - err -= 1.0; + /* central region */ if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) return(-1); - spinvector(vd, vd, ourview.vup, h_theta(x)); + spinvector(vd, vd, ourview.vup, h_theta(x,y)); return(0); +} + + +double +pixsize(x, y) /* return the solid angle of pixel at (x,y) */ +int x, y; +{ + register int hl, xo; + double disc; + + hl = hlim(y); + if (x < -hl) + xo = x+hl; + else if (x > hl) + xo = x-hl; + else + xo = 0; + disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); + if (disc <= FTINY) + return(0.); + return(1./(sampdens*sampdens*sqrt(disc))); }