304 |
|
register int sn; |
305 |
|
register CONTRIB *srccnt; |
306 |
|
register CNTPTR *cntord; |
307 |
< |
int ncnts; |
308 |
< |
double ourthresh, prob, hwt, test2, hit2; |
307 |
> |
double prob, ourthresh, hwt, test2, hit2; |
308 |
|
RAY sr; |
309 |
|
|
310 |
|
srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB)); |
339 |
|
} |
340 |
|
/* sort contributions */ |
341 |
|
qsort(cntord, nsources, sizeof(CNTPTR), cntcmp); |
342 |
< |
hit2 = 0.0; test2 = FTINY; |
343 |
< |
/* find last */ |
344 |
< |
sn = 0; ncnts = nsources; |
345 |
< |
while (sn < ncnts-1) { |
346 |
< |
register int m; |
348 |
< |
m = (sn + ncnts) >> 1; |
349 |
< |
if (cntord[m].brt > 0.0) |
350 |
< |
sn = m; |
351 |
< |
else |
352 |
< |
ncnts = m; |
353 |
< |
} |
354 |
< |
/* accumulate tail */ |
355 |
< |
for (sn = ncnts-1; sn > 0; sn--) |
356 |
< |
cntord[sn-1].brt += cntord[sn].brt; |
357 |
< |
/* shadow testing */ |
358 |
< |
for (sn = 0; sn < ncnts; sn++) { |
359 |
< |
/* tail below threshold? */ |
360 |
< |
if (cntord[sn].brt < ourthresh*bright(r->rcol)) |
342 |
> |
hit2 = 0.5; test2 = 1.0; /* start with prob=.5 */ |
343 |
> |
/* test for shadows */ |
344 |
> |
for (sn = 0; sn < nsources; sn++) { |
345 |
> |
/* check threshold */ |
346 |
> |
if (cntord[sn].brt <= ourthresh*bright(r->rcol)) |
347 |
|
break; |
348 |
|
/* get statistics */ |
349 |
|
hwt = (double)source[cntord[sn].sno].nhits / |
375 |
|
/* weighted hit rate */ |
376 |
|
hwt = hit2 / test2; |
377 |
|
#ifdef DEBUG |
378 |
< |
fprintf(stderr, "%d tested, %d untested, %f hit rate\n", |
379 |
< |
sn, ncnts-sn, hwt); |
378 |
> |
{ |
379 |
> |
int ntested = sn; |
380 |
|
#endif |
381 |
|
/* add in untested sources */ |
382 |
< |
for ( ; sn < ncnts; sn++) { |
382 |
> |
for ( ; sn < nsources; sn++) { |
383 |
> |
if (cntord[sn].brt <= 0.0) |
384 |
> |
break; |
385 |
|
prob = hwt * (double)source[cntord[sn].sno].nhits / |
386 |
|
(double)source[cntord[sn].sno].ntests; |
387 |
|
scalecolor(srccnt[cntord[sn].sno].val, prob); |
388 |
|
addcolor(r->rcol, srccnt[cntord[sn].sno].val); |
389 |
|
} |
390 |
+ |
#ifdef DEBUG |
391 |
+ |
fprintf(stderr, "%d tested, %d untested, %f hit rate\n", |
392 |
+ |
ntested, sn-ntested, hwt); |
393 |
+ |
} |
394 |
+ |
#endif |
395 |
+ |
|
396 |
|
free(srccnt); |
397 |
|
free(cntord); |
398 |
|
} |