--- ray/src/util/findglare.c 1991/03/21 17:11:46 1.11 +++ ray/src/util/findglare.c 1991/04/22 10:11:23 1.21 @@ -36,15 +36,18 @@ 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 */ +long npixinvw; /* number of pixels in view */ +long npixmiss; /* number of pixels missed */ + main(argc, argv) int argc; char *argv[]; { + int combine = 1; int gotview = 0; int rval, i; char *err; @@ -98,6 +101,9 @@ char *argv[]; case 'p': picture = argv[++i]; break; + case 'c': + combine = !combine; + break; case 'd': case 'l': rtargv[rtargc++] = argv[i]; @@ -176,12 +182,16 @@ char *argv[]; if (threshold <= FTINY) comp_thresh(); /* compute glare threshold */ analyze(); /* analyze view */ + if (combine) + absorb_specks(); /* eliminate tiny sources */ cleanup(); /* tidy up */ /* print header */ 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); @@ -216,13 +226,13 @@ 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)); if (indirect == NULL) memerr("indirect illuminances"); + npixinvw = npixmiss = 0L; copystruct(&leftview, &ourview); copystruct(&rightview, &ourview); spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); @@ -271,11 +281,14 @@ 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) done_rtrace(); + if (npixinvw < 100*npixmiss) + fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", + progname, 100L*npixmiss/npixinvw); } @@ -283,24 +296,47 @@ compdir(vd, x, y) /* compute direction for x,y */ FVECT vd; int x, y; { + int hl; FVECT org; /* dummy variable */ - if (x <= -hlim) /* left region */ + hl = hlim(y); + if (x <= -hl) /* left region */ return(viewray(org, vd, &leftview, - (x+hlim)/(2.*sampdens)+.5, - y/(2.*sampdens)+.5)); - if (x >= hlim) /* right region */ + (double)(x+hl)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); + if (x >= hl) /* right region */ return(viewray(org, vd, &rightview, - (x-hlim)/(2.*sampdens)+.5, - y/(2.*sampdens)+.5)); - /* central region */ - if (viewray(org, vd, &ourview, .5, y/(2.*sampdens)+.5) < 0) + (double)(x-hl)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); + /* 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))); +} + + memerr(s) /* malloc failure */ char *s; { @@ -328,7 +364,8 @@ printillum() /* print out indirect illuminances */ printf("BEGIN indirect illuminance\n"); for (i = 0; i < nglardirs; i++) - printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, - PI * indirect[i].sum / indirect[i].n); + if (indirect[i].n > FTINY) + printf("\t%.0f\t%f\n", (180.0/PI)*indirect[i].theta, + PI * indirect[i].sum / indirect[i].n); printf("END indirect illuminance\n"); }