1 |
|
/* |
2 |
< |
================================================================== |
2 |
> |
====================================================================== |
3 |
|
In-core kd-tree for photon map |
4 |
|
|
5 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
6 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
7 |
|
(c) Lucerne University of Applied Sciences and Arts, |
8 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
9 |
< |
================================================================== |
8 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
9 |
> |
====================================================================== |
10 |
|
|
11 |
|
$Id$ |
12 |
|
*/ |
13 |
|
|
14 |
|
|
15 |
< |
#ifdef PMAP_OOC |
16 |
< |
/* Checked in pmapdata.h */ |
17 |
< |
#undef PMAP_OOC |
18 |
< |
#endif |
15 |
> |
|
16 |
|
#include "pmapdata.h" /* Includes pmapkdt.h */ |
17 |
|
#include "source.h" |
18 |
|
|
198 |
|
error(SYSTEM, "failed in-core heap allocation in kdT_BuildPhotonMap"); |
199 |
|
|
200 |
|
rewind(pmap -> heap); |
201 |
< |
if (fread(nodes, sizeof(Photon), pmap -> numPhotons, pmap -> heap) != |
201 |
> |
i = fread(nodes, sizeof(Photon), pmap -> numPhotons, pmap -> heap); |
202 |
> |
if (i != |
203 |
|
pmap -> numPhotons) |
204 |
|
error(SYSTEM, "failed loading photon heap in kdT_BuildPhotonMap"); |
205 |
|
|
346 |
|
if (norm && DOT(norm, p -> norm) <= PMAP_NORM_TOL * 127 * frandom()) |
347 |
|
return; |
348 |
|
|
349 |
< |
if (isContribPmap(pmap) && pmap -> srcContrib) { |
350 |
< |
/* Lookup in contribution photon map */ |
351 |
< |
OBJREC *srcMod; |
352 |
< |
const int srcIdx = photonSrcIdx(pmap, p); |
353 |
< |
|
354 |
< |
if (srcIdx < 0 || srcIdx >= nsources) |
355 |
< |
error(INTERNAL, "invalid light source index in photon map"); |
356 |
< |
|
357 |
< |
srcMod = findmaterial(source [srcIdx].so); |
349 |
> |
if (isContribPmap(pmap)) { |
350 |
> |
/* Lookup in contribution photon map; filter according to emitting |
351 |
> |
* light source if contrib list set, else accept all */ |
352 |
> |
|
353 |
> |
if (pmap -> srcContrib) { |
354 |
> |
OBJREC *srcMod; |
355 |
> |
const int srcIdx = photonSrcIdx(pmap, p); |
356 |
> |
|
357 |
> |
if (srcIdx < 0 || srcIdx >= nsources) |
358 |
> |
error(INTERNAL, "invalid light source index in photon map"); |
359 |
> |
|
360 |
> |
srcMod = findmaterial(source [srcIdx].so); |
361 |
|
|
362 |
< |
/* Reject photon if contributions from light source which emitted it |
363 |
< |
* are not sought */ |
364 |
< |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
365 |
< |
return; |
362 |
> |
/* Reject photon if contributions from light source which emitted it |
363 |
> |
* are not sought */ |
364 |
> |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
365 |
> |
return; |
366 |
> |
} |
367 |
|
|
368 |
|
/* Reject non-caustic photon if lookup for caustic contribs */ |
369 |
|
if (pmap -> lookupCaustic & !p -> caustic) |
424 |
|
|
425 |
|
/* Photon pos & normal stored at lower precision */ |
426 |
|
VCOPY(p, pos); |
427 |
< |
VCOPY(n, norm); |
428 |
< |
kdT_FindNearest(pmap, p, n, 1); |
427 |
> |
if (norm) |
428 |
> |
VCOPY(n, norm); |
429 |
> |
kdT_FindNearest(pmap, p, norm ? n : NULL, 1); |
430 |
|
} |
431 |
|
|
432 |
|
|
465 |
|
d2 = DOT(dv, dv); |
466 |
|
|
467 |
|
if (d2 < pmap -> maxDist2 && |
468 |
< |
DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom()) { |
468 |
> |
(!norm || DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom())) { |
469 |
|
/* Closest photon so far with similar normal. We allow for tolerance |
470 |
|
* to account for perturbation in the latter; note the photon normal |
471 |
|
* is coded in the range [-127,127], hence we factor this in */ |
484 |
|
|
485 |
|
/* Photon pos & normal stored at lower precision */ |
486 |
|
VCOPY(p, pos); |
487 |
< |
VCOPY(n, norm); |
488 |
< |
kdT_Find1Nearest(pmap, p, n, &pnn, 1); |
487 |
> |
if (norm) |
488 |
> |
VCOPY(n, norm); |
489 |
> |
kdT_Find1Nearest(pmap, p, norm ? n : NULL, &pnn, 1); |
490 |
|
memcpy(photon, pnn, sizeof(Photon)); |
491 |
|
} |
492 |
|
|