303 |
|
{ |
304 |
|
register int sn; |
305 |
|
register CONTRIB *srccnt; |
306 |
< |
double dtmp, hwt, test2, hit2; |
306 |
> |
int ncnts; |
307 |
> |
double ourthresh, prob, hwt, test2, hit2; |
308 |
|
RAY sr; |
309 |
|
|
310 |
|
if ((srccnt = (CONTRIB *)malloc(nsources*sizeof(CONTRIB))) == NULL) |
311 |
|
error(SYSTEM, "out of memory in direct"); |
312 |
+ |
/* modify threshold */ |
313 |
+ |
ourthresh = shadthresh / r->rweight; |
314 |
|
/* potential contributions */ |
315 |
|
for (sn = 0; sn < nsources; sn++) { |
316 |
|
srccnt[sn].sno = sn; |
339 |
|
/* sort contributions */ |
340 |
|
qsort(srccnt, nsources, sizeof(CONTRIB), cntcmp); |
341 |
|
hit2 = 0.0; test2 = FTINY; |
342 |
< |
/* test for shadows */ |
343 |
< |
for (sn = 0; sn < nsources; sn++) { |
344 |
< |
/* check threshold */ |
345 |
< |
if (srccnt[sn].brt <= shadthresh*bright(r->rcol)/r->rweight) |
342 |
> |
/* find last */ |
343 |
> |
sn = 0; ncnts = nsources; |
344 |
> |
while (sn < ncnts-1) { |
345 |
> |
register int m; |
346 |
> |
m = (sn + ncnts) >> 1; |
347 |
> |
if (srccnt[m].brt > 0.0) |
348 |
> |
sn = m; |
349 |
> |
else |
350 |
> |
ncnts = m; |
351 |
> |
} |
352 |
> |
/* accumulate tail */ |
353 |
> |
for (sn = ncnts-1; sn > 0; sn--) |
354 |
> |
srccnt[sn-1].brt += srccnt[sn].brt; |
355 |
> |
/* shadow testing */ |
356 |
> |
for (sn = 0; sn < ncnts; sn++) { |
357 |
> |
/* tail below threshold? */ |
358 |
> |
if (srccnt[sn].brt < ourthresh*bright(r->rcol)) |
359 |
|
break; |
360 |
|
/* get statistics */ |
361 |
|
hwt = (double)source[srccnt[sn].sno].nhits / |
385 |
|
/* weighted hit rate */ |
386 |
|
hwt = hit2 / test2; |
387 |
|
#ifdef DEBUG |
388 |
< |
{ |
389 |
< |
int ntested = sn; |
388 |
> |
fprintf(stderr, "%d tested, %d untested, %f hit rate\n", |
389 |
> |
sn, ncnts-sn, hwt); |
390 |
|
#endif |
391 |
|
/* add in untested sources */ |
392 |
< |
for ( ; sn < nsources; sn++) { |
393 |
< |
if (srccnt[sn].brt <= 0.0) |
378 |
< |
break; |
379 |
< |
dtmp = hwt * (double)source[srccnt[sn].sno].nhits / |
392 |
> |
for ( ; sn < ncnts; sn++) { |
393 |
> |
prob = hwt * (double)source[srccnt[sn].sno].nhits / |
394 |
|
(double)source[srccnt[sn].sno].ntests; |
395 |
< |
scalecolor(srccnt[sn].val, dtmp); |
395 |
> |
scalecolor(srccnt[sn].val, prob); |
396 |
|
addcolor(r->rcol, srccnt[sn].val); |
397 |
|
} |
384 |
– |
#ifdef DEBUG |
385 |
– |
fprintf(stderr, "%d tested, %d untested, %f hit rate\n", |
386 |
– |
ntested, sn-ntested, hwt); |
387 |
– |
} |
388 |
– |
#endif |
389 |
– |
|
398 |
|
free(srccnt); |
399 |
|
} |
400 |
|
|