| 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; |
| 338 |
|
} |
| 339 |
|
/* sort contributions */ |
| 340 |
|
qsort(srccnt, nsources, sizeof(CONTRIB), cntcmp); |
| 341 |
< |
hit2 = test2 = 0.0; |
| 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) |
| 341 |
> |
hit2 = 0.0; test2 = FTINY; |
| 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 / |
| 382 |
|
hit2 += hwt; |
| 383 |
|
source[srccnt[sn].sno].nhits++; |
| 384 |
|
} |
| 385 |
< |
if (test2 > FTINY) /* weighted hit rate */ |
| 386 |
< |
hwt = hit2 / test2; |
| 371 |
< |
else |
| 372 |
< |
hwt = 0.0; |
| 385 |
> |
/* weighted hit rate */ |
| 386 |
> |
hwt = hit2 / test2; |
| 387 |
|
#ifdef DEBUG |
| 388 |
< |
fprintf(stderr, "%d tested, %f hit rate\n", sn, hwt); |
| 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) |
| 379 |
< |
break; |
| 380 |
< |
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 |
|
} |
| 385 |
– |
|
| 398 |
|
free(srccnt); |
| 399 |
|
} |
| 400 |
|
|