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.3 by rschregle, Fri May 8 13:20:23 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 19 | Line 22
22   #include "otypes.h"
23   #include "source.h"
24   #include "rcontrib.h"
25 + #include "random.h"
26  
27  
28  
# Line 66 | 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 98 | 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 227 | 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 238 | 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 309 | 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 330 | 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.
335 <         Primarily intended for debugging; FOR ZE ECKSPURTZ ONLY! */
336 <      pmap -> maxDist0 = pmap -> maxDistLimit = maxDistCoeff;
337 < #else
338 <      /* Maximum search radius limit based on avg photon distance to
339 <       * 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 360 | 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 368 | 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 <
387 <   #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 413 | Line 430 | void findPhotons (PhotonMap* pmap, const RAY* ray)
430              
431           redo = 0;
432        }
433 < #endif
433 >      
434     } while (redo);
435   }
436  
# Line 453 | 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