ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapdata.c
(Generate patch)

Comparing ray/src/rt/pmapdata.c (file contents):
Revision 2.2 by rschregle, Wed Apr 22 15:44:57 2015 UTC vs.
Revision 2.7 by rschregle, Tue May 26 11:26:27 2015 UTC

# Line 4 | Line 4
4  
5     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
6     (c) Fraunhofer Institute for Solar Energy Systems,
7 <       Lucerne University of Applied Sciences & Arts
7 >   (c) Lucerne University of Applied Sciences and Arts,
8 >   supported by the Swiss National Science Foundation (SNSF, #147053)
9     ==================================================================  
10    
11     $Id$
# Line 18 | Line 19
19   #include "otypes.h"
20   #include "source.h"
21   #include "rcontrib.h"
22 + #include "random.h"
23  
24  
25  
# Line 65 | Line 67 | void initPhotonMap (PhotonMap *pmap, PhotonMapType t)
67   const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray)
68   {
69     PhotonPrimary *prim = NULL;
70 +   FVECT dvec;
71    
72     if (!pmap || !ray)
73        return NULL;
# Line 97 | Line 100 | const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap
100     prim -> srcIdx = -1;
101        
102     /* Reverse incident direction to point to light source */
103 <   prim -> dir [0] = -ray -> rdir [0];
104 <   prim -> dir [1] = -ray -> rdir [1];
105 <   prim -> dir [2] = -ray -> rdir [2];
103 >   dvec [0] = -ray -> rdir [0];
104 >   dvec [1] = -ray -> rdir [1];
105 >   dvec [2] = -ray -> rdir [2];
106 >   prim -> dir = encodedir(dvec);
107  
108 <   VCOPY(prim -> org, ray -> rorg);
108 >   VCOPY(prim -> pos, ray -> rop);
109    
110     return prim;
111   }
# Line 226 | Line 230 | static void nearestNeighbours (PhotonMap* pmap, const
230     }
231  
232     /* Reject photon if normal faces away (ignored for volume photons) */
233 <   if (norm && DOT(norm, p -> norm) <= 0)
233 >   if (norm && DOT(norm, p -> norm) <= 0.5 * frandom())
234        return;
235        
236     if (isContribPmap(pmap) && pmap -> srcContrib) {
# Line 237 | Line 241 | static void nearestNeighbours (PhotonMap* pmap, const
241        if (srcIdx < 0 || srcIdx >= nsources)
242           error(INTERNAL, "invalid light source index in photon map");
243        
244 <      srcMod = objptr(source [srcIdx].so -> omod);
244 >      srcMod = findmaterial(source [srcIdx].so);
245  
246        /* Reject photon if contributions from light source which emitted it
247         * are not sought */
# Line 329 | Line 333 | void findPhotons (PhotonMap* pmap, const RAY* ray)
333        pmap -> minError = FHUGE;
334        pmap -> maxError = -FHUGE;
335        pmap -> rmsError = 0;
336 + #ifdef PMAP_MAXDIST_ABS
337 +      /* Treat maxDistCoeff as an *absolute* and *fixed* max search radius.
338 +         Primarily intended for debugging; FOR ZE ECKSPURTZ ONLY! */
339 +      pmap -> maxDist0 = pmap -> maxDistLimit = maxDistCoeff;
340 + #else
341        /* Maximum search radius limit based on avg photon distance to
342         * centre of gravity */
343        pmap -> maxDist0 = pmap -> maxDistLimit =
344           maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist /
345           pmap -> heapSize;
346 + #endif      
347     }
348  
349     do {
# Line 352 | Line 362 | void findPhotons (PhotonMap* pmap, const RAY* ray)
362           VCOPY(norm, ray -> ron);
363           nearestNeighbours(pmap, pos, norm, 1);
364        }
365 <      
365 >
366 > #ifndef PMAP_MAXDIST_ABS      
367        if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) {
368           /* Short lookup; too few photons found */
369           if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) {
# Line 360 | Line 371 | void findPhotons (PhotonMap* pmap, const RAY* ray)
371               * PMAP_SHORT_LOOKUP_THRESH photons under the assumption there
372               * really are no photons in the vicinity, and increasing the max
373               * search radius therefore won't help */
374 < #ifdef PMAP_LOOKUP_WARN
374 >   #ifdef PMAP_LOOKUP_WARN
375              sprintf(errmsg,
376                      "%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s",
377                      pmap -> squeueEnd, pmap -> squeueSize,
378                      pmapName [pmap -> type], pos [0], pos [1], pos [2],
379                      ray -> ro ? ray -> ro -> oname : "<null>");
380              error(WARNING, errmsg);        
381 < #endif            
382 <            
381 >   #endif            
382 >
383              if (pmap -> maxDist0 < pmap -> maxDistLimit) {
384                 /* Increase max search radius if below limit & redo search */
385                 pmap -> maxDist0 *= PMAP_MAXDIST_INC;
386 < #ifdef PMAP_LOOKUP_REDO
386 >   #ifdef PMAP_LOOKUP_REDO
387                 redo = 1;
388 < #endif              
388 >   #endif              
389  
390 < #ifdef PMAP_LOOKUP_WARN
390 >   #ifdef PMAP_LOOKUP_WARN
391                 sprintf(errmsg,
392                         redo ? "restarting photon lookup with max radius %.1e"
393                              : "max photon lookup radius adjusted to %.1e",
394                         pmap -> maxDist0);
395                 error(WARNING, errmsg);
396 < #endif
396 >   #endif
397              }
398 < #ifdef PMAP_LOOKUP_REDO
398 >   #ifdef PMAP_LOOKUP_REDO
399              else {
400                 sprintf(errmsg, "max photon lookup radius clamped to %.1e",
401                         pmap -> maxDist0);
402                 error(WARNING, errmsg);
403              }
404 < #endif
404 >   #endif
405           }
406          
407           /* Reset successful lookup counter */
408           pmap -> numLookups = 0;
409 <      }  
409 >      }
410        else {
411           /* Increment successful lookup counter and reduce max search radius if
412            * wraparound */
# Line 405 | Line 416 | void findPhotons (PhotonMap* pmap, const RAY* ray)
416              
417           redo = 0;
418        }
419 + #endif
420     } while (redo);
421   }
422  
# Line 444 | Line 456 | static void nearest1Neighbour (PhotonMap *pmap, const
456     dv [2] = pos [2] - p -> pos [2];
457     d2 = DOT(dv, dv);
458    
459 <   if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0) {
459 >   if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0.5 * frandom()) {
460        /* Closest photon so far with similar normal */
461        pmap -> maxDist = d2;
462        *photon = p;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines