--- ray/src/util/findglare.c 1991/03/19 17:21:34 1.8 +++ ray/src/util/findglare.c 1991/04/18 15:18:22 1.18 @@ -40,11 +40,15 @@ 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 +102,9 @@ char *argv[]; case 'p': picture = argv[++i]; break; + case 'c': + combine = !combine; + break; case 'd': case 'l': rtargv[rtargc++] = argv[i]; @@ -176,12 +183,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); @@ -204,7 +215,7 @@ init() /* initialize global variables */ /* set direction vectors */ for (i = 0; glarang[i] != AEND; i++) ; - if (i > 0 && glarang[0] <= 0 || glarang[i-1] >= 180) { + if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { fprintf(stderr, "%s: glare angles must be between 1 and 179\n", progname); exit(1); @@ -223,6 +234,7 @@ init() /* initialize global variables */ 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); @@ -231,22 +243,22 @@ init() /* initialize global variables */ setview(&rightview); indirect[nglarangs].lcos = indirect[nglarangs].rcos = cos(maxtheta); - indirect[nglarangs].lsin = - -(indirect[nglarangs].rsin = sin(maxtheta)); + indirect[nglarangs].rsin = + -(indirect[nglarangs].lsin = sin(maxtheta)); indirect[nglarangs].theta = 0.0; for (i = 0; i < nglarangs; i++) { d = (glarang[nglarangs-1] - glarang[i])*(PI/180.); indirect[nglarangs-i-1].lcos = indirect[nglarangs+i+1].rcos = cos(d); - indirect[nglarangs-i-1].lsin = - -(indirect[nglarangs+i+1].rsin = sin(d)); + indirect[nglarangs+i+1].rsin = + -(indirect[nglarangs-i-1].lsin = sin(d)); d = (glarang[nglarangs-1] + glarang[i])*(PI/180.); indirect[nglarangs-i-1].rcos = indirect[nglarangs+i+1].lcos = cos(d); - indirect[nglarangs+i+1].lsin = - -(indirect[nglarangs-i-1].rsin = sin(d)); - indirect[nglarangs-i-1].theta = -(PI/180.)*glarang[i]; - indirect[nglarangs+i+1].theta = (PI/180.)*glarang[i]; + indirect[nglarangs-i-1].rsin = + -(indirect[nglarangs+i+1].lsin = sin(d)); + indirect[nglarangs-i-1].theta = (PI/180.)*glarang[i]; + indirect[nglarangs+i+1].theta = -(PI/180.)*glarang[i]; } /* open picture */ if (picture != NULL) { @@ -271,36 +283,55 @@ 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); } -compdir(vd, x, y) /* compute direction for x,y */ +compdir(vd, x, y, se) /* compute direction for x,y */ FVECT vd; int x, y; +SPANERR *se; { FVECT org; /* dummy variable */ if (x <= -hlim) /* left region */ return(viewray(org, vd, &leftview, - (x+hlim)/(2.*sampdens)+.5, - y/(2.*sampdens)+.5)); + (double)(x+hlim)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); if (x >= hlim) /* 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-hlim)/(2*sampdens)+.5, + (double)y/(2*sampdens)+.5)); + /* central region */ + if (se != NULL) { /* avoid over-counting of poles */ + se->err += se->prob; + if (se->err <= 0.5) + return(-1); + se->err -= 1.0; + } + if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) return(-1); spinvector(vd, vd, ourview.vup, h_theta(x)); return(0); } +setspanerr(se, y) /* initialize span error at y */ +register SPANERR *se; +int y; +{ + se->err = 0.0; + se->prob = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); +} + + memerr(s) /* malloc failure */ char *s; { @@ -328,7 +359,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 / (double)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"); }