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$ |
65 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
66 |
|
if (setPmapParam(&pm, parm + t)) { |
67 |
|
/* Check if photon map newer than octree */ |
68 |
< |
if (!stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) && |
68 |
> |
if (pm -> fileName && octname && |
69 |
> |
!stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) && |
70 |
|
octstat.st_mtime > pmstat.st_mtime) { |
71 |
|
sprintf(errmsg, "photon map in file %s may be stale", |
72 |
|
pm -> fileName); |
101 |
|
|
102 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) { |
103 |
|
if (pmaps [t]) |
104 |
< |
savePhotonMap(pmaps [t], pmaps [t] -> fileName, t, argc, argv); |
104 |
> |
savePhotonMap(pmaps [t], pmaps [t] -> fileName, argc, argv); |
105 |
|
} |
106 |
|
} |
107 |
|
|
206 |
|
OBJREC* mat; |
207 |
|
|
208 |
|
if (ray -> rlvl > photonMaxBounce) { |
209 |
+ |
#ifdef PMAP_RUNAWAY_WARN |
210 |
|
error(WARNING, "runaway photon!"); |
211 |
+ |
#endif |
212 |
|
return; |
213 |
|
} |
214 |
< |
|
214 |
> |
|
215 |
|
if (colorAvg(ray -> cext) > FTINY && !photonParticipate(ray)) |
216 |
|
return; |
217 |
|
|
267 |
|
|
268 |
|
/* Record start time, baby */ |
269 |
|
repStartTime = time(NULL); |
270 |
< |
signal(SIGCONT, pmapPreCompReport); |
270 |
> |
#ifdef SIGCONT |
271 |
> |
signal(SIGCONT, pmapPreCompReport); |
272 |
> |
#endif |
273 |
|
repProgress = 0; |
274 |
|
memcpy(nuHeap, pmap -> heap, nuHeapSize * sizeof(Photon)); |
275 |
|
|
290 |
|
|
291 |
|
if (photonRepTime > 0 && time(NULL) >= repLastTime + photonRepTime) |
292 |
|
pmapPreCompReport(); |
293 |
< |
#ifndef BSD |
294 |
< |
else signal(SIGCONT, pmapPreCompReport); |
295 |
< |
#endif |
293 |
> |
#ifdef SIGCONT |
294 |
> |
else signal(SIGCONT, pmapPreCompReport); |
295 |
> |
#endif |
296 |
|
} |
297 |
|
|
298 |
< |
signal(SIGCONT, SIG_DFL); |
298 |
> |
#ifdef SIGCONT |
299 |
> |
signal(SIGCONT, SIG_DFL); |
300 |
> |
#endif |
301 |
|
|
302 |
|
/* Replace & rebuild heap */ |
303 |
|
free(pmap -> heap); |
324 |
|
double totalFlux = 0; |
325 |
|
PhotonMap *pm; |
326 |
|
|
327 |
< |
for (t = 0; t < NUM_PMAP_TYPES && !photonMaps [t]; t++); |
327 |
> |
for (t = 0; t < NUM_PMAP_TYPES && !pmaps [t]; t++); |
328 |
|
if (t >= NUM_PMAP_TYPES) |
329 |
|
error(USER, "no photon maps defined"); |
330 |
|
|
342 |
|
|
343 |
|
/* Initialise all defined photon maps */ |
344 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
345 |
< |
initPhotonMap(photonMaps [t], t); |
345 |
> |
initPhotonMap(pmaps [t], t); |
346 |
|
|
347 |
|
initPhotonEmissionFuncs(); |
348 |
|
initPhotonScatterFuncs(); |
408 |
|
|
409 |
|
/* Record start time and enable progress report signal handler */ |
410 |
|
repStartTime = time(NULL); |
411 |
< |
signal(SIGCONT, pmapDistribReport); |
411 |
> |
#ifdef SIGCONT |
412 |
> |
signal(SIGCONT, pmapDistribReport); |
413 |
> |
#endif |
414 |
|
repProgress = prePassCnt = 0; |
415 |
|
|
416 |
|
if (photonRepTime) |
434 |
|
sprintf(errmsg, "too many prepasses"); |
435 |
|
|
436 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
437 |
< |
if (photonMaps [t] && !photonMaps [t] -> heapEnd) { |
437 |
> |
if (pmaps [t] && !pmaps [t] -> heapEnd) { |
438 |
|
sprintf(errmsg2, ", no %s photons stored", pmapName [t]); |
439 |
|
strcat(errmsg, errmsg2); |
440 |
|
} |
447 |
|
numEmit = FHUGE; |
448 |
|
|
449 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
450 |
< |
if (photonMaps [t]) |
451 |
< |
numEmit = min(photonMaps [t] -> distribTarget, numEmit); |
450 |
> |
if (pmaps [t]) |
451 |
> |
numEmit = min(pmaps [t] -> distribTarget, numEmit); |
452 |
|
|
453 |
|
numEmit *= preDistrib; |
454 |
|
} |
469 |
|
* Since this biases the photon density, addPhoton() promotes the |
470 |
|
* flux of stored photons to compensate. */ |
471 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
472 |
< |
if ((pm = photonMaps [t])) { |
472 |
> |
if ((pm = pmaps [t])) { |
473 |
|
pm -> distribRatio = (double)pm -> distribTarget / |
474 |
|
pm -> heapEnd - 1; |
475 |
|
|
494 |
|
/* Normalise distribution ratios and calculate number of photons to |
495 |
|
* emit in main pass */ |
496 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
497 |
< |
if ((pm = photonMaps [t])) |
497 |
> |
if ((pm = pmaps [t])) |
498 |
|
pm -> distribRatio /= maxDistribRatio; |
499 |
|
|
500 |
|
if ((numEmit = repProgress * maxDistribRatio) < FTINY) |
509 |
|
for (srcIdx = 0; srcIdx < nsources; srcIdx++) { |
510 |
|
unsigned portCnt = 0; |
511 |
|
emap.src = source + srcIdx; |
512 |
< |
|
512 |
> |
|
513 |
|
do { |
514 |
|
emap.port = emap.src -> sflags & SDISTANT ? photonPorts + portCnt |
515 |
|
: NULL; |
570 |
|
if (photonRepTime > 0 && |
571 |
|
time(NULL) >= repLastTime + photonRepTime) |
572 |
|
pmapDistribReport(); |
573 |
< |
#ifndef BSD |
573 |
> |
#ifdef SIGCONT |
574 |
|
else signal(SIGCONT, pmapDistribReport); |
575 |
|
#endif |
576 |
|
} |
581 |
|
} |
582 |
|
|
583 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
584 |
< |
if (photonMaps [t] && !photonMaps [t] -> heapEnd) { |
584 |
> |
if (pmaps [t] && !pmaps [t] -> heapEnd) { |
585 |
|
/* Double preDistrib in case a photon map is empty and redo |
586 |
|
* pass 1 --> possibility of infinite loop for pathological |
587 |
|
* scenes (e.g. absorbing materials) */ |
600 |
|
/* =================================================================== |
601 |
|
* POST-DISTRIBUTION - Set photon flux and build kd-tree, etc. |
602 |
|
* =================================================================== */ |
603 |
< |
signal(SIGCONT, SIG_DFL); |
603 |
> |
#ifdef SIGCONT |
604 |
> |
signal(SIGCONT, SIG_DFL); |
605 |
> |
#endif |
606 |
|
free(emap.samples); |
607 |
|
|
608 |
|
/* Set photon flux (repProgress is total num emitted) */ |
609 |
|
totalFlux /= repProgress; |
610 |
|
|
611 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
612 |
< |
if (photonMaps [t]) { |
612 |
> |
if (pmaps [t]) { |
613 |
|
if (photonRepTime) { |
614 |
|
sprintf(errmsg, "\nBuilding %s photon map...\n", pmapName [t]); |
615 |
|
eputs(errmsg); |
616 |
|
fflush(stderr); |
617 |
|
} |
618 |
|
|
619 |
< |
balancePhotons(photonMaps [t], &totalFlux); |
619 |
> |
balancePhotons(pmaps [t], &totalFlux); |
620 |
|
} |
621 |
|
|
622 |
|
/* Precompute photon irradiance if necessary */ |