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.8 by rschregle, Tue May 26 13:31:19 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 >      /* Maximum 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
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  
366 #ifndef PMAP_MAXDIST_ABS      
365        if (pmap -> squeueEnd < pmap -> squeueSize * pmap -> gatherTolerance) {
366           /* Short lookup; too few photons found */
367           if (pmap -> squeueEnd > PMAP_SHORT_LOOKUP_THRESH) {
# Line 371 | Line 369 | void findPhotons (PhotonMap* pmap, const RAY* ray)
369               * PMAP_SHORT_LOOKUP_THRESH photons under the assumption there
370               * really are no photons in the vicinity, and increasing the max
371               * search radius therefore won't help */
372 <   #ifdef PMAP_LOOKUP_WARN
372 > #ifdef PMAP_LOOKUP_WARN
373              sprintf(errmsg,
374                      "%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s",
375                      pmap -> squeueEnd, pmap -> squeueSize,
376                      pmapName [pmap -> type], pos [0], pos [1], pos [2],
377                      ray -> ro ? ray -> ro -> oname : "<null>");
378              error(WARNING, errmsg);        
379 <   #endif            
379 > #endif            
380  
381 +            /* Bail out after warning if maxDist is fixed */
382 +            if (maxDistFix > 0)
383 +               return;
384 +            
385              if (pmap -> maxDist0 < pmap -> maxDistLimit) {
386                 /* Increase max search radius if below limit & redo search */
387                 pmap -> maxDist0 *= PMAP_MAXDIST_INC;
388 <   #ifdef PMAP_LOOKUP_REDO
388 > #ifdef PMAP_LOOKUP_REDO
389                 redo = 1;
390 <   #endif              
391 <
390 <   #ifdef PMAP_LOOKUP_WARN
390 > #endif              
391 > #ifdef PMAP_LOOKUP_WARN
392                 sprintf(errmsg,
393                         redo ? "restarting photon lookup with max radius %.1e"
394                              : "max photon lookup radius adjusted to %.1e",
395                         pmap -> maxDist0);
396                 error(WARNING, errmsg);
397 <   #endif
397 > #endif
398              }
399 <   #ifdef PMAP_LOOKUP_REDO
399 > #ifdef PMAP_LOOKUP_REDO
400              else {
401                 sprintf(errmsg, "max photon lookup radius clamped to %.1e",
402                         pmap -> maxDist0);
403                 error(WARNING, errmsg);
404              }
405 <   #endif
405 > #endif
406           }
407          
408           /* Reset successful lookup counter */
409           pmap -> numLookups = 0;
410        }
411        else {
412 +         /* Bail out after warning if maxDist is fixed */
413 +         if (maxDistFix > 0)
414 +            return;
415 +            
416           /* Increment successful lookup counter and reduce max search radius if
417            * wraparound */
418           pmap -> numLookups = (pmap -> numLookups + 1) % PMAP_MAXDIST_CNT;
# Line 416 | Line 421 | void findPhotons (PhotonMap* pmap, const RAY* ray)
421              
422           redo = 0;
423        }
424 < #endif
424 >      
425     } while (redo);
426   }
427  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines