Skip to content

Commit

Permalink
Fixed off-by-one bug in photon density estimate bandwidth clamping if
Browse files Browse the repository at this point in the history
exceeds number of photons.
  • Loading branch information
rschregle committed Mar 23, 2021
1 parent bc6813a commit fab87ba
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/rt/pmutil.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $";
static const char RCSid[] = "$Id: pmutil.c,v 2.6 2021/03/23 00:07:13 rschregle Exp $";
#endif

/*
Expand All @@ -12,7 +12,7 @@ static const char RCSid[] = "$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle E
supported by the Swiss National Science Foundation (SNSF, #147053)
======================================================================
$Id: pmutil.c,v 2.5 2020/04/08 15:14:21 rschregle Exp $
$Id: pmutil.c,v 2.6 2021/03/23 00:07:13 rschregle Exp $
*/

#include "pmap.h"
Expand Down Expand Up @@ -56,9 +56,9 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapParams *parm)
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) &&
Expand All @@ -67,7 +67,7 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapParams *parm)
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");
Expand All @@ -82,15 +82,15 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapParams *parm)
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)
Expand All @@ -102,11 +102,18 @@ void loadPmaps (PhotonMap **pmaps, const PhotonMapParams *parm)
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;
}
}
}

Expand Down

0 comments on commit fab87ba

Please sign in to comment.