--- ray/src/rt/pmutil.c 2018/02/09 14:57:42 2.3 +++ ray/src/rt/pmutil.c 2021/03/23 00:07:13 2.6 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pmutil.c,v 2.3 2018/02/09 14:57:42 rschregle Exp $"; +static const char RCSid[] = "$Id: pmutil.c,v 2.6 2021/03/23 00:07:13 rschregle Exp $"; #endif /* @@ -12,7 +12,7 @@ static const char RCSid[] = "$Id: pmutil.c,v 2.3 2018/ supported by the Swiss National Science Foundation (SNSF, #147053) ====================================================================== - $Id: pmutil.c,v 2.3 2018/02/09 14:57:42 rschregle Exp $ + $Id: pmutil.c,v 2.6 2021/03/23 00:07:13 rschregle Exp $ */ #include "pmap.h" @@ -56,9 +56,9 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapPara struct stat octstat, pmstat; PhotonMap *pm; PhotonMapType type; - + for (t = 0; t < NUM_PMAP_TYPES; t++) - if (setPmapParam(&pm, parm + t)) { + if (setPmapParam(&pm, parm + t)) { /* Check if photon map newer than octree */ if (pm -> fileName && octname && !stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) && @@ -67,7 +67,7 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapPara 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"); @@ -75,15 +75,44 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapPara /* 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 invalid density estimate bandwidth */ + + /* 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; + /* 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; } } } @@ -181,8 +210,11 @@ void photonPreCompDensity (PhotonMap *pmap, RAY *r, CO if (r -> ro && islight(objptr(r -> ro -> omod) -> otype)) return; - find1Photon(preCompPmap, r, &p); - getPhotonFlux(&p, irrad); + if (find1Photon(preCompPmap, r, &p)) + /* p contains a found photon, so get its irradiance, otherwise it + * remains zero under the assumption all photons are too distant + * to contribute significantly */ + getPhotonFlux(&p, irrad); }