4 |
|
|
5 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
6 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
7 |
< |
Lucerne University of Applied Sciences & Arts |
7 |
> |
(c) Lucerne University of Applied Sciences and Arts, |
8 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
9 |
|
================================================================== |
10 |
|
|
11 |
|
$Id$ |
66 |
|
const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray) |
67 |
|
{ |
68 |
|
PhotonPrimary *prim = NULL; |
69 |
+ |
FVECT dvec; |
70 |
|
|
71 |
|
if (!pmap || !ray) |
72 |
|
return NULL; |
99 |
|
prim -> srcIdx = -1; |
100 |
|
|
101 |
|
/* Reverse incident direction to point to light source */ |
102 |
< |
prim -> dir [0] = -ray -> rdir [0]; |
103 |
< |
prim -> dir [1] = -ray -> rdir [1]; |
104 |
< |
prim -> dir [2] = -ray -> rdir [2]; |
102 |
> |
dvec [0] = -ray -> rdir [0]; |
103 |
> |
dvec [1] = -ray -> rdir [1]; |
104 |
> |
dvec [2] = -ray -> rdir [2]; |
105 |
> |
prim -> dir = encodedir(dvec); |
106 |
|
|
107 |
< |
VCOPY(prim -> org, ray -> rorg); |
107 |
> |
VCOPY(prim -> pos, ray -> rop); |
108 |
|
|
109 |
|
return prim; |
110 |
|
} |
240 |
|
if (srcIdx < 0 || srcIdx >= nsources) |
241 |
|
error(INTERNAL, "invalid light source index in photon map"); |
242 |
|
|
243 |
< |
srcMod = objptr(source [srcIdx].so -> omod); |
243 |
> |
srcMod = findmaterial(source [srcIdx].so); |
244 |
|
|
245 |
|
/* Reject photon if contributions from light source which emitted it |
246 |
|
* are not sought */ |
332 |
|
pmap -> minError = FHUGE; |
333 |
|
pmap -> maxError = -FHUGE; |
334 |
|
pmap -> rmsError = 0; |
335 |
+ |
#ifdef PMAP_MAXDIST_ABS |
336 |
+ |
/* 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 |
|
pmap -> maxDist0 = pmap -> maxDistLimit = |
343 |
|
maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist / |
344 |
|
pmap -> heapSize; |
345 |
+ |
#endif |
346 |
|
} |
347 |
|
|
348 |
|
do { |
361 |
|
VCOPY(norm, ray -> ron); |
362 |
|
nearestNeighbours(pmap, pos, norm, 1); |
363 |
|
} |
364 |
< |
|
364 |
> |
|
365 |
> |
#ifndef PMAP_MAXDIST_ABS |
366 |
|
if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) { |
367 |
|
/* Short lookup; too few photons found */ |
368 |
|
if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) { |
370 |
|
* PMAP_SHORT_LOOKUP_THRESH photons under the assumption there |
371 |
|
* really are no photons in the vicinity, and increasing the max |
372 |
|
* search radius therefore won't help */ |
373 |
< |
#ifdef PMAP_LOOKUP_WARN |
373 |
> |
#ifdef PMAP_LOOKUP_WARN |
374 |
|
sprintf(errmsg, |
375 |
|
"%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s", |
376 |
|
pmap -> squeueEnd, pmap -> squeueSize, |
377 |
|
pmapName [pmap -> type], pos [0], pos [1], pos [2], |
378 |
|
ray -> ro ? ray -> ro -> oname : "<null>"); |
379 |
|
error(WARNING, errmsg); |
380 |
< |
#endif |
381 |
< |
|
380 |
> |
#endif |
381 |
> |
|
382 |
|
if (pmap -> maxDist0 < pmap -> maxDistLimit) { |
383 |
|
/* Increase max search radius if below limit & redo search */ |
384 |
|
pmap -> maxDist0 *= PMAP_MAXDIST_INC; |
385 |
< |
#ifdef PMAP_LOOKUP_REDO |
385 |
> |
#ifdef PMAP_LOOKUP_REDO |
386 |
|
redo = 1; |
387 |
< |
#endif |
387 |
> |
#endif |
388 |
|
|
389 |
< |
#ifdef PMAP_LOOKUP_WARN |
389 |
> |
#ifdef PMAP_LOOKUP_WARN |
390 |
|
sprintf(errmsg, |
391 |
|
redo ? "restarting photon lookup with max radius %.1e" |
392 |
|
: "max photon lookup radius adjusted to %.1e", |
393 |
|
pmap -> maxDist0); |
394 |
|
error(WARNING, errmsg); |
395 |
< |
#endif |
395 |
> |
#endif |
396 |
|
} |
397 |
< |
#ifdef PMAP_LOOKUP_REDO |
397 |
> |
#ifdef PMAP_LOOKUP_REDO |
398 |
|
else { |
399 |
|
sprintf(errmsg, "max photon lookup radius clamped to %.1e", |
400 |
|
pmap -> maxDist0); |
401 |
|
error(WARNING, errmsg); |
402 |
|
} |
403 |
< |
#endif |
403 |
> |
#endif |
404 |
|
} |
405 |
|
|
406 |
|
/* Reset successful lookup counter */ |
407 |
|
pmap -> numLookups = 0; |
408 |
< |
} |
408 |
> |
} |
409 |
|
else { |
410 |
|
/* Increment successful lookup counter and reduce max search radius if |
411 |
|
* wraparound */ |
415 |
|
|
416 |
|
redo = 0; |
417 |
|
} |
418 |
+ |
#endif |
419 |
|
} while (redo); |
420 |
|
} |
421 |
|
|