1 |
+ |
#ifndef lint |
2 |
+ |
static const char RCSid[] = "$Id$"; |
3 |
+ |
#endif |
4 |
|
/* |
5 |
|
================================================================== |
6 |
|
Photon map data structures and kd-tree handling |
11 |
|
supported by the Swiss National Science Foundation (SNSF, #147053) |
12 |
|
================================================================== |
13 |
|
|
11 |
– |
$Id$ |
14 |
|
*/ |
15 |
|
|
16 |
|
|
21 |
|
#include "otypes.h" |
22 |
|
#include "source.h" |
23 |
|
#include "rcontrib.h" |
24 |
+ |
#include "random.h" |
25 |
|
|
26 |
|
|
27 |
|
|
232 |
|
} |
233 |
|
|
234 |
|
/* Reject photon if normal faces away (ignored for volume photons) */ |
235 |
< |
if (norm && DOT(norm, p -> norm) <= 0) |
235 |
> |
if (norm && DOT(norm, p -> norm) <= 0.5 * frandom()) |
236 |
|
return; |
237 |
|
|
238 |
|
if (isContribPmap(pmap) && pmap -> srcContrib) { |
314 |
|
/* Threshold below which we assume increasing max radius won't help */ |
315 |
|
#define PMAP_SHORT_LOOKUP_THRESH 1 |
316 |
|
|
317 |
+ |
/* Coefficient for adaptive maximum search radius */ |
318 |
+ |
#define PMAP_MAXDIST_COEFF 100 |
319 |
+ |
|
320 |
+ |
|
321 |
|
void findPhotons (PhotonMap* pmap, const RAY* ray) |
322 |
|
{ |
323 |
|
float pos [3], norm [3]; |
339 |
|
pmap -> minError = FHUGE; |
340 |
|
pmap -> maxError = -FHUGE; |
341 |
|
pmap -> rmsError = 0; |
342 |
< |
#ifdef PMAP_MAXDIST_ABS |
343 |
< |
/* Treat maxDistCoeff as an *absolute* and *fixed* max search radius. |
337 |
< |
Primarily intended for debugging; FOR ZE ECKSPURTZ ONLY! */ |
338 |
< |
pmap -> maxDist0 = pmap -> maxDistLimit = maxDistCoeff; |
339 |
< |
#else |
340 |
< |
/* Maximum search radius limit based on avg photon distance to |
341 |
< |
* centre of gravity */ |
342 |
> |
/* SQUARED max search radius limit is based on avg photon distance to |
343 |
> |
* centre of gravity, unless fixed by user (maxDistFix > 0) */ |
344 |
|
pmap -> maxDist0 = pmap -> maxDistLimit = |
345 |
< |
maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist / |
346 |
< |
pmap -> heapSize; |
347 |
< |
#endif |
345 |
> |
maxDistFix > 0 ? maxDistFix * maxDistFix |
346 |
> |
: PMAP_MAXDIST_COEFF * pmap -> squeueSize * |
347 |
> |
pmap -> CoGdist / pmap -> heapSize; |
348 |
|
} |
349 |
|
|
350 |
|
do { |
364 |
|
nearestNeighbours(pmap, pos, norm, 1); |
365 |
|
} |
366 |
|
|
367 |
< |
#ifndef PMAP_MAXDIST_ABS |
367 |
> |
#ifdef PMAP_ITSYBITSY |
368 |
> |
if (pmap -> maxDist < FTINY) { |
369 |
> |
sprintf(errmsg, "itsy bitsy teeny weeny photon search radius %e", |
370 |
> |
sqrt(pmap -> maxDist)); |
371 |
> |
error(WARNING, errmsg); |
372 |
> |
} |
373 |
> |
#endif |
374 |
> |
|
375 |
|
if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) { |
376 |
|
/* Short lookup; too few photons found */ |
377 |
|
if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) { |
379 |
|
* PMAP_SHORT_LOOKUP_THRESH photons under the assumption there |
380 |
|
* really are no photons in the vicinity, and increasing the max |
381 |
|
* search radius therefore won't help */ |
382 |
< |
#ifdef PMAP_LOOKUP_WARN |
382 |
> |
#ifdef PMAP_LOOKUP_WARN |
383 |
|
sprintf(errmsg, |
384 |
|
"%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s", |
385 |
|
pmap -> squeueEnd, pmap -> squeueSize, |
386 |
|
pmapName [pmap -> type], pos [0], pos [1], pos [2], |
387 |
|
ray -> ro ? ray -> ro -> oname : "<null>"); |
388 |
|
error(WARNING, errmsg); |
389 |
< |
#endif |
389 |
> |
#endif |
390 |
|
|
391 |
+ |
/* Bail out after warning if maxDist is fixed */ |
392 |
+ |
if (maxDistFix > 0) |
393 |
+ |
return; |
394 |
+ |
|
395 |
|
if (pmap -> maxDist0 < pmap -> maxDistLimit) { |
396 |
|
/* Increase max search radius if below limit & redo search */ |
397 |
|
pmap -> maxDist0 *= PMAP_MAXDIST_INC; |
398 |
< |
#ifdef PMAP_LOOKUP_REDO |
398 |
> |
#ifdef PMAP_LOOKUP_REDO |
399 |
|
redo = 1; |
400 |
< |
#endif |
401 |
< |
|
389 |
< |
#ifdef PMAP_LOOKUP_WARN |
400 |
> |
#endif |
401 |
> |
#ifdef PMAP_LOOKUP_WARN |
402 |
|
sprintf(errmsg, |
403 |
|
redo ? "restarting photon lookup with max radius %.1e" |
404 |
|
: "max photon lookup radius adjusted to %.1e", |
405 |
< |
pmap -> maxDist0); |
405 |
> |
sqrt(pmap -> maxDist0)); |
406 |
|
error(WARNING, errmsg); |
407 |
< |
#endif |
407 |
> |
#endif |
408 |
|
} |
409 |
< |
#ifdef PMAP_LOOKUP_REDO |
409 |
> |
#ifdef PMAP_LOOKUP_REDO |
410 |
|
else { |
411 |
|
sprintf(errmsg, "max photon lookup radius clamped to %.1e", |
412 |
< |
pmap -> maxDist0); |
412 |
> |
sqrt(pmap -> maxDist0)); |
413 |
|
error(WARNING, errmsg); |
414 |
|
} |
415 |
< |
#endif |
415 |
> |
#endif |
416 |
|
} |
417 |
|
|
418 |
|
/* Reset successful lookup counter */ |
419 |
|
pmap -> numLookups = 0; |
420 |
|
} |
421 |
|
else { |
422 |
+ |
/* Bail out after warning if maxDist is fixed */ |
423 |
+ |
if (maxDistFix > 0) |
424 |
+ |
return; |
425 |
+ |
|
426 |
|
/* Increment successful lookup counter and reduce max search radius if |
427 |
|
* wraparound */ |
428 |
|
pmap -> numLookups = (pmap -> numLookups + 1) % PMAP_MAXDIST_CNT; |
431 |
|
|
432 |
|
redo = 0; |
433 |
|
} |
434 |
< |
#endif |
434 |
> |
|
435 |
|
} while (redo); |
436 |
|
} |
437 |
|
|
471 |
|
dv [2] = pos [2] - p -> pos [2]; |
472 |
|
d2 = DOT(dv, dv); |
473 |
|
|
474 |
< |
if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0) { |
474 |
> |
if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0.5 * frandom()) { |
475 |
|
/* Closest photon so far with similar normal */ |
476 |
|
pmap -> maxDist = d2; |
477 |
|
*photon = p; |