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.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
# Line 312 | 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 333 | Line 340 | void findPhotons (PhotonMap* pmap, const RAY* ray)
340        pmap -> minError = FHUGE;
341        pmap -> maxError = -FHUGE;
342        pmap -> rmsError = 0;
343 < #ifdef PMAP_MAXDIST_ABS
344 <      /* 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 >      /* 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;
348 < #endif      
346 >         maxDistFix > 0 ? maxDistFix * maxDistFix
347 >                        : PMAP_MAXDIST_COEFF * pmap -> squeueSize *
348 >                          pmap -> CoGdist / pmap -> heapSize;
349     }
350  
351     do {
# Line 363 | Line 365 | void findPhotons (PhotonMap* pmap, const RAY* ray)
365           nearestNeighbours(pmap, pos, norm, 1);
366        }
367  
368 < #ifndef PMAP_MAXDIST_ABS      
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 371 | Line 378 | void findPhotons (PhotonMap* pmap, const RAY* ray)
378               * PMAP_SHORT_LOOKUP_THRESH photons under the assumption there
379               * really are no photons in the vicinity, and increasing the max
380               * search radius therefore won't help */
381 <   #ifdef PMAP_LOOKUP_WARN
381 > #ifdef PMAP_LOOKUP_WARN
382              sprintf(errmsg,
383                      "%d/%d %s photons found at (%.2f,%.2f,%.2f) on %s",
384                      pmap -> squeueEnd, pmap -> squeueSize,
385                      pmapName [pmap -> type], pos [0], pos [1], pos [2],
386                      ray -> ro ? ray -> ro -> oname : "<null>");
387              error(WARNING, errmsg);        
388 <   #endif            
388 > #endif            
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
397 > #ifdef PMAP_LOOKUP_REDO
398                 redo = 1;
399 <   #endif              
400 <
390 <   #ifdef PMAP_LOOKUP_WARN
399 > #endif              
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
406 > #endif
407              }
408 <   #ifdef PMAP_LOOKUP_REDO
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
414 > #endif
415           }
416          
417           /* Reset successful lookup counter */
418           pmap -> numLookups = 0;
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 416 | Line 430 | void findPhotons (PhotonMap* pmap, const RAY* ray)
430              
431           redo = 0;
432        }
433 < #endif
433 >      
434     } while (redo);
435   }
436  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines