| 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 |
+ |
#include "otspecial.h" |
| 19 |
+ |
#include "random.h" |
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 200 |
|
error(SYSTEM, "failed in-core heap allocation in kdT_BuildPhotonMap"); |
| 201 |
|
|
| 202 |
|
rewind(pmap -> heap); |
| 203 |
< |
if (fread(nodes, sizeof(Photon), pmap -> numPhotons, pmap -> heap) != |
| 203 |
> |
i = fread(nodes, sizeof(Photon), pmap -> numPhotons, pmap -> heap); |
| 204 |
> |
if (i != |
| 205 |
|
pmap -> numPhotons) |
| 206 |
|
error(SYSTEM, "failed loading photon heap in kdT_BuildPhotonMap"); |
| 207 |
|
|
| 348 |
|
if (norm && DOT(norm, p -> norm) <= PMAP_NORM_TOL * 127 * frandom()) |
| 349 |
|
return; |
| 350 |
|
|
| 351 |
< |
if (isContribPmap(pmap) && pmap -> srcContrib) { |
| 352 |
< |
/* Lookup in contribution photon map */ |
| 353 |
< |
OBJREC *srcMod; |
| 354 |
< |
const int srcIdx = photonSrcIdx(pmap, p); |
| 355 |
< |
|
| 356 |
< |
if (srcIdx < 0 || srcIdx >= nsources) |
| 357 |
< |
error(INTERNAL, "invalid light source index in photon map"); |
| 358 |
< |
|
| 359 |
< |
srcMod = findmaterial(source [srcIdx].so); |
| 351 |
> |
if (isContribPmap(pmap)) { |
| 352 |
> |
/* Lookup in contribution photon map; filter according to emitting |
| 353 |
> |
* light source if contrib list set, else accept all */ |
| 354 |
> |
|
| 355 |
> |
if (pmap -> srcContrib) { |
| 356 |
> |
OBJREC *srcMod; |
| 357 |
> |
const int srcIdx = photonSrcIdx(pmap, p); |
| 358 |
> |
|
| 359 |
> |
if (srcIdx < 0 || srcIdx >= nsources) |
| 360 |
> |
error(INTERNAL, "invalid light source index in photon map"); |
| 361 |
> |
|
| 362 |
> |
srcMod = findmaterial(source [srcIdx].so); |
| 363 |
|
|
| 364 |
< |
/* Reject photon if contributions from light source which emitted it |
| 365 |
< |
* are not sought */ |
| 366 |
< |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
| 367 |
< |
return; |
| 364 |
> |
/* Reject photon if contributions from light source which emitted it |
| 365 |
> |
* are not sought */ |
| 366 |
> |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
| 367 |
> |
return; |
| 368 |
> |
} |
| 369 |
|
|
| 370 |
|
/* Reject non-caustic photon if lookup for caustic contribs */ |
| 371 |
|
if (pmap -> lookupCaustic & !p -> caustic) |
| 426 |
|
|
| 427 |
|
/* Photon pos & normal stored at lower precision */ |
| 428 |
|
VCOPY(p, pos); |
| 429 |
< |
VCOPY(n, norm); |
| 430 |
< |
kdT_FindNearest(pmap, p, n, 1); |
| 429 |
> |
if (norm) |
| 430 |
> |
VCOPY(n, norm); |
| 431 |
> |
kdT_FindNearest(pmap, p, norm ? n : NULL, 1); |
| 432 |
|
} |
| 433 |
|
|
| 434 |
|
|
| 467 |
|
d2 = DOT(dv, dv); |
| 468 |
|
|
| 469 |
|
if (d2 < pmap -> maxDist2 && |
| 470 |
< |
DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom()) { |
| 470 |
> |
(!norm || DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom())) { |
| 471 |
|
/* Closest photon so far with similar normal. We allow for tolerance |
| 472 |
|
* to account for perturbation in the latter; note the photon normal |
| 473 |
|
* is coded in the range [-127,127], hence we factor this in */ |
| 486 |
|
|
| 487 |
|
/* Photon pos & normal stored at lower precision */ |
| 488 |
|
VCOPY(p, pos); |
| 489 |
< |
VCOPY(n, norm); |
| 490 |
< |
kdT_Find1Nearest(pmap, p, n, &pnn, 1); |
| 489 |
> |
if (norm) |
| 490 |
> |
VCOPY(n, norm); |
| 491 |
> |
kdT_Find1Nearest(pmap, p, norm ? n : NULL, &pnn, 1); |
| 492 |
|
memcpy(photon, pnn, sizeof(Photon)); |
| 493 |
|
} |
| 494 |
|
|