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.7 by rschregle, Tue May 26 11:26:27 2015 UTC vs.
Revision 2.10 by rschregle, Wed Jul 29 18:54:20 2015 UTC

# Line 312 | Line 312 | static void nearestNeighbours (PhotonMap* pmap, const
312   /* Threshold below which we assume increasing max radius won't help */
313   #define PMAP_SHORT_LOOKUP_THRESH 1
314  
315 + /* Coefficient for adaptive maximum search radius */
316 + #define PMAP_MAXDIST_COEFF 100
317 +
318 +
319   void findPhotons (PhotonMap* pmap, const RAY* ray)
320   {
321     float pos [3], norm [3];
# Line 333 | Line 337 | void findPhotons (PhotonMap* pmap, const RAY* ray)
337        pmap -> minError = FHUGE;
338        pmap -> maxError = -FHUGE;
339        pmap -> rmsError = 0;
340 < #ifdef PMAP_MAXDIST_ABS
341 <      /* 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 */
340 >      /* SQUARED max search radius limit is based on avg photon distance to
341 >       * centre of gravity, unless fixed by user (maxDistFix > 0) */
342        pmap -> maxDist0 = pmap -> maxDistLimit =
343 <         maxDistCoeff * pmap -> squeueSize * pmap -> CoGdist /
344 <         pmap -> heapSize;
345 < #endif      
343 >         maxDistFix > 0 ? maxDistFix * maxDistFix
344 >                        : PMAP_MAXDIST_COEFF * pmap -> squeueSize *
345 >                          pmap -> CoGdist / pmap -> heapSize;
346     }
347  
348     do {
# Line 363 | Line 362 | void findPhotons (PhotonMap* pmap, const RAY* ray)
362           nearestNeighbours(pmap, pos, norm, 1);
363        }
364  
365 < #ifndef PMAP_MAXDIST_ABS      
365 >      if (pmap -> maxDist < FTINY) {
366 >         sprintf(errmsg, "itsy bitsy teeny weeny photon search radius %e",
367 >                 sqrt(pmap -> maxDist));
368 >         error(WARNING, errmsg);
369 >      }
370 >
371        if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) {
372           /* Short lookup; too few photons found */
373           if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) {
# Line 371 | Line 375 | void findPhotons (PhotonMap* pmap, const RAY* ray)
375               * PMAP_SHORT_LOOKUP_THRESH photons under the assumption there
376               * really are no photons in the vicinity, and increasing the max
377               * search radius therefore won't help */
378 <   #ifdef PMAP_LOOKUP_WARN
378 > #ifdef PMAP_LOOKUP_WARN
379              sprintf(errmsg,
380                      "%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s",
381                      pmap -> squeueEnd, pmap -> squeueSize,
382                      pmapName [pmap -> type], pos [0], pos [1], pos [2],
383                      ray -> ro ? ray -> ro -> oname : "<null>");
384              error(WARNING, errmsg);        
385 <   #endif            
385 > #endif            
386  
387 +            /* Bail out after warning if maxDist is fixed */
388 +            if (maxDistFix > 0)
389 +               return;
390 +            
391              if (pmap -> maxDist0 < pmap -> maxDistLimit) {
392                 /* Increase max search radius if below limit & redo search */
393                 pmap -> maxDist0 *= PMAP_MAXDIST_INC;
394 <   #ifdef PMAP_LOOKUP_REDO
394 > #ifdef PMAP_LOOKUP_REDO
395                 redo = 1;
396 <   #endif              
397 <
390 <   #ifdef PMAP_LOOKUP_WARN
396 > #endif              
397 > #ifdef PMAP_LOOKUP_WARN
398                 sprintf(errmsg,
399                         redo ? "restarting photon lookup with max radius %.1e"
400                              : "max photon lookup radius adjusted to %.1e",
401 <                       pmap -> maxDist0);
401 >                       sqrt(pmap -> maxDist0));
402                 error(WARNING, errmsg);
403 <   #endif
403 > #endif
404              }
405 <   #ifdef PMAP_LOOKUP_REDO
405 > #ifdef PMAP_LOOKUP_REDO
406              else {
407                 sprintf(errmsg, "max photon lookup radius clamped to %.1e",
408 <                       pmap -> maxDist0);
408 >                       sqrt(pmap -> maxDist0));
409                 error(WARNING, errmsg);
410              }
411 <   #endif
411 > #endif
412           }
413          
414           /* Reset successful lookup counter */
415           pmap -> numLookups = 0;
416        }
417        else {
418 +         /* Bail out after warning if maxDist is fixed */
419 +         if (maxDistFix > 0)
420 +            return;
421 +            
422           /* Increment successful lookup counter and reduce max search radius if
423            * wraparound */
424           pmap -> numLookups = (pmap -> numLookups + 1) % PMAP_MAXDIST_CNT;
# Line 416 | Line 427 | void findPhotons (PhotonMap* pmap, const RAY* ray)
427              
428           redo = 0;
429        }
430 < #endif
430 >      
431     } while (redo);
432   }
433  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines