Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77506547
pmutil.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 14, 21:25
Size
3 KB
Mime Type
text/x-c
Expires
Fri, Aug 16, 21:25 (2 d)
Engine
blob
Format
Raw Data
Handle
19862860
Attached To
R10977 RADIANCE Photon Map
pmutil.c
View Options
#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) {
/* Clamp lookup bandwidth to total number of photons (minus one,
since density estimate gets extra photon to obtain averaged
radius) */
sprintf(
errmsg, "clamping density estimate bandwidth to %ld",
pm -> numPhotons
);
error(WARNING, errmsg);
pm -> minGather = pm -> maxGather = pm -> numPhotons - 1;
}
}
}
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
Log In to Comment