--- ray/src/rt/pmapdata.c 2015/04/22 15:44:57 2.2 +++ ray/src/rt/pmapdata.c 2015/05/21 13:54:59 2.6 @@ -4,10 +4,11 @@ Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) (c) Fraunhofer Institute for Solar Energy Systems, - Lucerne University of Applied Sciences & Arts + (c) Lucerne University of Applied Sciences and Arts, + supported by the Swiss National Science Foundation (SNSF, #147053) ================================================================== - $Id: pmapdata.c,v 2.2 2015/04/22 15:44:57 rschregle Exp $ + $Id: pmapdata.c,v 2.6 2015/05/21 13:54:59 greg Exp $ */ @@ -65,6 +66,7 @@ void initPhotonMap (PhotonMap *pmap, PhotonMapType t) const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray) { PhotonPrimary *prim = NULL; + FVECT dvec; if (!pmap || !ray) return NULL; @@ -97,11 +99,12 @@ const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap prim -> srcIdx = -1; /* Reverse incident direction to point to light source */ - prim -> dir [0] = -ray -> rdir [0]; - prim -> dir [1] = -ray -> rdir [1]; - prim -> dir [2] = -ray -> rdir [2]; + dvec [0] = -ray -> rdir [0]; + dvec [1] = -ray -> rdir [1]; + dvec [2] = -ray -> rdir [2]; + prim -> dir = encodedir(dvec); - VCOPY(prim -> org, ray -> rorg); + VCOPY(prim -> pos, ray -> rop); return prim; } @@ -237,7 +240,7 @@ static void nearestNeighbours (PhotonMap* pmap, const if (srcIdx < 0 || srcIdx >= nsources) error(INTERNAL, "invalid light source index in photon map"); - srcMod = objptr(source [srcIdx].so -> omod); + srcMod = findmaterial(source [srcIdx].so); /* Reject photon if contributions from light source which emitted it * are not sought */ @@ -329,11 +332,17 @@ void findPhotons (PhotonMap* pmap, const RAY* ray) pmap -> minError = FHUGE; pmap -> maxError = -FHUGE; pmap -> rmsError = 0; +#ifdef PMAP_MAXDIST_ABS + /* Treat maxDistCoeff as an *absolute* and *fixed* max search radius. + Primarily intended for debugging; FOR ZE ECKSPURTZ ONLY! */ + pmap -> maxDist0 = pmap -> maxDistLimit = maxDistCoeff; +#else /* Maximum search radius limit based on avg photon distance to * centre of gravity */ pmap -> maxDist0 = pmap -> maxDistLimit = maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist / pmap -> heapSize; +#endif } do { @@ -352,7 +361,8 @@ void findPhotons (PhotonMap* pmap, const RAY* ray) VCOPY(norm, ray -> ron); nearestNeighbours(pmap, pos, norm, 1); } - + +#ifndef PMAP_MAXDIST_ABS if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) { /* Short lookup; too few photons found */ if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) { @@ -360,42 +370,42 @@ void findPhotons (PhotonMap* pmap, const RAY* ray) * PMAP_SHORT_LOOKUP_THRESH photons under the assumption there * really are no photons in the vicinity, and increasing the max * search radius therefore won't help */ -#ifdef PMAP_LOOKUP_WARN + #ifdef PMAP_LOOKUP_WARN sprintf(errmsg, "%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s", pmap -> squeueEnd, pmap -> squeueSize, pmapName [pmap -> type], pos [0], pos [1], pos [2], ray -> ro ? ray -> ro -> oname : ""); error(WARNING, errmsg); -#endif - + #endif + if (pmap -> maxDist0 < pmap -> maxDistLimit) { /* Increase max search radius if below limit & redo search */ pmap -> maxDist0 *= PMAP_MAXDIST_INC; -#ifdef PMAP_LOOKUP_REDO + #ifdef PMAP_LOOKUP_REDO redo = 1; -#endif + #endif -#ifdef PMAP_LOOKUP_WARN + #ifdef PMAP_LOOKUP_WARN sprintf(errmsg, redo ? "restarting photon lookup with max radius %.1e" : "max photon lookup radius adjusted to %.1e", pmap -> maxDist0); error(WARNING, errmsg); -#endif + #endif } -#ifdef PMAP_LOOKUP_REDO + #ifdef PMAP_LOOKUP_REDO else { sprintf(errmsg, "max photon lookup radius clamped to %.1e", pmap -> maxDist0); error(WARNING, errmsg); } -#endif + #endif } /* Reset successful lookup counter */ pmap -> numLookups = 0; - } + } else { /* Increment successful lookup counter and reduce max search radius if * wraparound */ @@ -405,6 +415,7 @@ void findPhotons (PhotonMap* pmap, const RAY* ray) redo = 0; } +#endif } while (redo); }