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.11 by greg, Tue Aug 18 18:45:55 2015 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map data structures and kd-tree handling
7  
8     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
9     (c) Fraunhofer Institute for Solar Energy Systems,
10 <       Lucerne University of Applied Sciences & Arts
10 >   (c) Lucerne University of Applied Sciences and Arts,
11 >   supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================  
13    
14     $Id$
# Line 18 | Line 22
22   #include "otypes.h"
23   #include "source.h"
24   #include "rcontrib.h"
25 + #include "random.h"
26  
27  
28  
# Line 65 | Line 70 | void initPhotonMap (PhotonMap *pmap, PhotonMapType t)
70   const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap, const RAY *ray)
71   {
72     PhotonPrimary *prim = NULL;
73 +   FVECT dvec;
74    
75     if (!pmap || !ray)
76        return NULL;
# Line 97 | Line 103 | const PhotonPrimary* addPhotonPrimary (PhotonMap *pmap
103     prim -> srcIdx = -1;
104        
105     /* Reverse incident direction to point to light source */
106 <   prim -> dir [0] = -ray -> rdir [0];
107 <   prim -> dir [1] = -ray -> rdir [1];
108 <   prim -> dir [2] = -ray -> rdir [2];
106 >   dvec [0] = -ray -> rdir [0];
107 >   dvec [1] = -ray -> rdir [1];
108 >   dvec [2] = -ray -> rdir [2];
109 >   prim -> dir = encodedir(dvec);
110  
111 <   VCOPY(prim -> org, ray -> rorg);
111 >   VCOPY(prim -> pos, ray -> rop);
112    
113     return prim;
114   }
# Line 226 | Line 233 | static void nearestNeighbours (PhotonMap* pmap, const
233     }
234  
235     /* Reject photon if normal faces away (ignored for volume photons) */
236 <   if (norm && DOT(norm, p -> norm) <= 0)
236 >   if (norm && DOT(norm, p -> norm) <= 0.5 * frandom())
237        return;
238        
239     if (isContribPmap(pmap) && pmap -> srcContrib) {
# Line 237 | Line 244 | static void nearestNeighbours (PhotonMap* pmap, const
244        if (srcIdx < 0 || srcIdx >= nsources)
245           error(INTERNAL, "invalid light source index in photon map");
246        
247 <      srcMod = objptr(source [srcIdx].so -> omod);
247 >      srcMod = findmaterial(source [srcIdx].so);
248  
249        /* Reject photon if contributions from light source which emitted it
250         * are not sought */
# Line 308 | Line 315 | static void nearestNeighbours (PhotonMap* pmap, const
315   /* Threshold below which we assume increasing max radius won't help */
316   #define PMAP_SHORT_LOOKUP_THRESH 1
317  
318 + /* Coefficient for adaptive maximum search radius */
319 + #define PMAP_MAXDIST_COEFF 100
320 +
321 +
322   void findPhotons (PhotonMap* pmap, const RAY* ray)
323   {
324     float pos [3], norm [3];
# Line 329 | Line 340 | void findPhotons (PhotonMap* pmap, const RAY* ray)
340        pmap -> minError = FHUGE;
341        pmap -> maxError = -FHUGE;
342        pmap -> rmsError = 0;
343 <      /* Maximum search radius limit based on avg photon distance to
344 <       * centre of gravity */
343 >      /* SQUARED max search radius limit is based on avg photon distance to
344 >       * centre of gravity, unless fixed by user (maxDistFix > 0) */
345        pmap -> maxDist0 = pmap -> maxDistLimit =
346 <         maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist /
347 <         pmap -> heapSize;
346 >         maxDistFix > 0 ? maxDistFix * maxDistFix
347 >                        : PMAP_MAXDIST_COEFF * pmap -> squeueSize *
348 >                          pmap -> CoGdist / pmap -> heapSize;
349     }
350  
351     do {
# Line 352 | Line 364 | void findPhotons (PhotonMap* pmap, const RAY* ray)
364           VCOPY(norm, ray -> ron);
365           nearestNeighbours(pmap, pos, norm, 1);
366        }
367 <      
367 >
368 >      if (pmap -> maxDist < FTINY) {
369 >         sprintf(errmsg, "itsy bitsy teeny weeny photon search radius %e",
370 >                 sqrt(pmap -> maxDist));
371 >         error(WARNING, errmsg);
372 >      }
373 >
374        if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) {
375           /* Short lookup; too few photons found */
376           if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) {
# Line 368 | Line 386 | void findPhotons (PhotonMap* pmap, const RAY* ray)
386                      ray -> ro ? ray -> ro -> oname : "<null>");
387              error(WARNING, errmsg);        
388   #endif            
389 <            
389 >
390 >            /* Bail out after warning if maxDist is fixed */
391 >            if (maxDistFix > 0)
392 >               return;
393 >            
394              if (pmap -> maxDist0 < pmap -> maxDistLimit) {
395                 /* Increase max search radius if below limit & redo search */
396                 pmap -> maxDist0 *= PMAP_MAXDIST_INC;
397   #ifdef PMAP_LOOKUP_REDO
398                 redo = 1;
399   #endif              
378
400   #ifdef PMAP_LOOKUP_WARN
401                 sprintf(errmsg,
402                         redo ? "restarting photon lookup with max radius %.1e"
403                              : "max photon lookup radius adjusted to %.1e",
404 <                       pmap -> maxDist0);
404 >                       sqrt(pmap -> maxDist0));
405                 error(WARNING, errmsg);
406   #endif
407              }
408   #ifdef PMAP_LOOKUP_REDO
409              else {
410                 sprintf(errmsg, "max photon lookup radius clamped to %.1e",
411 <                       pmap -> maxDist0);
411 >                       sqrt(pmap -> maxDist0));
412                 error(WARNING, errmsg);
413              }
414   #endif
# Line 395 | Line 416 | void findPhotons (PhotonMap* pmap, const RAY* ray)
416          
417           /* Reset successful lookup counter */
418           pmap -> numLookups = 0;
419 <      }  
419 >      }
420        else {
421 +         /* Bail out after warning if maxDist is fixed */
422 +         if (maxDistFix > 0)
423 +            return;
424 +            
425           /* Increment successful lookup counter and reduce max search radius if
426            * wraparound */
427           pmap -> numLookups = (pmap -> numLookups + 1) % PMAP_MAXDIST_CNT;
# Line 405 | Line 430 | void findPhotons (PhotonMap* pmap, const RAY* ray)
430              
431           redo = 0;
432        }
433 +      
434     } while (redo);
435   }
436  
# Line 444 | Line 470 | static void nearest1Neighbour (PhotonMap *pmap, const
470     dv [2] = pos [2] - p -> pos [2];
471     d2 = DOT(dv, dv);
472    
473 <   if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0) {
473 >   if (d2 < pmap -> maxDist && DOT(norm, p -> norm) > 0.5 * frandom()) {
474        /* Closest photon so far with similar normal */
475        pmap -> maxDist = d2;
476        *photon = p;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines