Page MenuHomec4science

pmutil.c
No OneTemporary

File Metadata

Created
Fri, May 3, 17:53

pmutil.c

#ifndef lint
static const char RCSid[] = "$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $";
#endif
/*
======================================================================
Auxiliary photon map utilities
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Fraunhofer Institute for Solar Energy Systems,
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation (SNSF, #147053)
======================================================================
$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $
*/
#include "pmap.h"
#include "pmapio.h"
#include <sys/stat.h>
extern char *octname;
void colorNorm (COLOR c)
/* Normalise colour channels to average of 1 */
{
const float avg = colorAvg(c);
if (!avg)
return;
c [0] /= avg;
c [1] /= avg;
c [2] /= avg;
}
void loadPmaps (PhotonMap **pmaps, const PhotonMapParams *parm)
{
unsigned t;
struct stat octstat, pmstat;
PhotonMap *pm;
PhotonMapType type;
for (t = 0; t < NUM_PMAP_TYPES; t++)
if (setPmapParam(&pm, parm + t)) {
/* Check if photon map newer than octree */
if (pm -> fileName && octname &&
!stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) &&
octstat.st_mtime > pmstat.st_mtime) {
sprintf(errmsg, "photon map in file %s may be stale",
pm -> fileName);
error(USER, errmsg);
}
/* Load photon map from file and get its type */
if ((type = loadPhotonMap(pm, pm -> fileName)) == PMAP_TYPE_NONE)
error(USER, "failed loading photon map");
/* Assign to appropriate photon map type (deleting previously
* loaded photon map of same type if necessary) */
if (pmaps [type]) {
sprintf(errmsg, "multiple %s photon maps, dropping previous",
pmapName [type]);
error(WARNING, errmsg);
deletePhotons(pmaps [type]);
free(pmaps [type]);
}
pmaps [type] = pm;
/* Check for valid density estimate bandwidths */
if ((pm -> minGather > 1 || pm -> maxGather > 1) &&
(type == PMAP_TYPE_PRECOMP)) {
/* Force bwidth to 1 for precomputed pmap */
error(WARNING, "ignoring bandwidth for precomp photon map");
pm -> minGather = pm -> maxGather = 1;
}
if ((pm -> maxGather > pm -> minGather) &&
(type == PMAP_TYPE_VOLUME)) {
/* Biascomp for volume pmaps (see volumePhotonDensity() below)
is considered redundant, and there's probably no point in
recovering by using the lower bandwidth, since it's probably
not what the user wants, so bail out. */
sprintf(errmsg,
"bias compensation is not available with %s photon maps",
pmapName [type]);
error(USER, errmsg);
}
if (pm -> maxGather > pm -> numPhotons) {
error(WARNING, "adjusting density estimate bandwidth");
pm -> minGather = pm -> maxGather = pm -> numPhotons;
}
}
}
void cleanUpPmaps (PhotonMap **pmaps)
{
unsigned t;
for (t = 0; t < NUM_PMAP_TYPES; t++) {
if (pmaps [t]) {
deletePhotons(pmaps [t]);
free(pmaps [t]);
}
}
}

Event Timeline