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.20 by rschregle, Fri Mar 8 17:25:17 2019 UTC vs.
Revision 2.23 by rschregle, Wed Apr 14 11:26:25 2021 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13  
14     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
15     (c) Fraunhofer Institute for Solar Energy Systems,
16 +       supported by the German Research Foundation
17 +       (DFG LU-204/10-2, "Fassadenintegrierte Regelsysteme" (FARESYS))
18     (c) Lucerne University of Applied Sciences and Arts,
19 <       supported by the Swiss National Science Foundation (SNSF, #147053)
19 >       supported by the Swiss National Science Foundation
20 >       (SNSF #147053, "Daylight Redirecting Components")
21     ==========================================================================
22    
23     $Id$
# Line 51 | Line 54 | PhotonMap *photonMaps [NUM_PMAP_TYPES] = {
54   #endif
55   extern OBJECT ambset [MAXASET+1];
56  
57 + /* Callback to print photon attributes acc. to user defined format */
58 + int (*printPhoton)(RAY *r, Photon *p, PhotonMap *pm);
59  
60  
61 +
62   void initPhotonMap (PhotonMap *pmap, PhotonMapType t)
63   /* Init photon map 'n' stuff... */
64   {
# Line 219 | Line 225 | int newPhoton (PhotonMap* pmap, const RAY* ray)
225         ambincl != inset(ambset, ray -> ro -> omod))
226        return -1;
227  
228 <   if (pmapNumROI && pmapROI) {      
228 >   if (pmapNumROI && pmapROI) {
229        unsigned inROI = 0;
230 +      FVECT    photonDist;
231        
232 <      /* Store photon if within a region of interest (for ze Ecksperts!) */
233 <      for (i = 0; !inROI && i < pmapNumROI; i++)
234 <         inROI = (ray -> rop [0] >= pmapROI [i].min [0] &&
235 <                  ray -> rop [0] <= pmapROI [i].max [0] &&
236 <                  ray -> rop [1] >= pmapROI [i].min [1] &&
237 <                  ray -> rop [1] <= pmapROI [i].max [1] &&
238 <                  ray -> rop [2] >= pmapROI [i].min [2] &&
239 <                  ray -> rop [2] <= pmapROI [i].max [2]);
232 >      /* Store photon if within a region of interest (for ze Ecksperts!)
233 >         Note size of spherical ROI is squared. */
234 >      for (i = 0; !inROI && i < pmapNumROI; i++) {
235 >         VSUB(photonDist, ray -> rop, pmapROI [i].pos);
236 >        
237 >         inROI = (
238 >            PMAP_ROI_ISSPHERE(pmapROI + i)
239 >            ?  DOT(photonDist, photonDist) <= pmapROI [i].siz [0]
240 >            :  fabs(photonDist [0]) <= pmapROI [i].siz [0] &&
241 >               fabs(photonDist [1]) <= pmapROI [i].siz [1] &&
242 >               fabs(photonDist [2]) <= pmapROI [i].siz [2]
243 >         );
244 >      }
245        if (!inROI)
246           return -1;
247     }
248    
249     /* Adjust flux according to distribution ratio and ray weight */
250 <   copycolor(photonFlux, ray -> rcol);  
250 >   copycolor(photonFlux, ray -> rcol);        
251 > #if 0
252 >   /* Factored out ray -> rweight as deprecated (?) for pmap, and infact
253 >      erroneously attenuates volume photon flux based on extinction,
254 >      which is already factored in by photonParticipate() */
255     scalecolor(photonFlux,
256                ray -> rweight / (pmap -> distribRatio ? pmap -> distribRatio
257                                                       : 1));
258 + #else
259 +   scalecolor(photonFlux,
260 +              1.0 / (pmap -> distribRatio ? pmap -> distribRatio : 1));
261 + #endif
262     setPhotonFlux(&photon, photonFlux);
263  
264     /* Set photon position and flags */
# Line 287 | Line 307 | int newPhoton (PhotonMap* pmap, const RAY* ray)
307        flushPhotonHeap(pmap);
308  
309     pmap -> numPhotons++;
310 +        
311 +   /* Print photon attributes */
312 +   if (printPhoton)
313 +      /* Non-const kludge */
314 +      printPhoton((RAY*)ray, &photon, pmap);
315              
316     return 0;
317   }
# Line 501 | Line 526 | void findPhotons (PhotonMap* pmap, const RAY* ray)
526          
527        /* Search position is ray -> rorg for volume photons, since we have no
528           intersection point. Normals are ignored -- these are incident
529 <         directions). */  
529 >         directions). */
530 >      /* NOTE: status returned by XXX_FindPhotons() is currently ignored;
531 >         if no photons are found, an empty queue is returned under the
532 >         assumption all photons are too distant to contribute significant
533 >         flux. */
534        if (isVolumePmap(pmap)) {
535   #ifdef PMAP_OOC
536           OOC_FindPhotons(pmap, ray -> rorg, NULL);
# Line 591 | Line 620 | void findPhotons (PhotonMap* pmap, const RAY* ray)
620  
621  
622  
623 < void find1Photon (PhotonMap *pmap, const RAY* ray, Photon *photon)
623 > Photon *find1Photon (PhotonMap *pmap, const RAY* ray, Photon *photon)
624   {
625 <   pmap -> maxDist2 = thescene.cusize;  /* ? */
625 >   /* Init (squared) search radius to avg photon dist to centre of gravity */
626 >   float maxDist2_0 = pmap -> CoGdist;  
627 >   int found = 0;  
628 > #ifdef PMAP_LOOKUP_REDO
629 >   #define REDO 1
630 > #else
631 >   #define REDO 0
632 > #endif
633    
634 +   do {
635 +      pmap -> maxDist2 = maxDist2_0;
636   #ifdef PMAP_OOC
637 <   OOC_Find1Photon(pmap, ray -> rop, ray -> ron, photon);
637 >      found = OOC_Find1Photon(pmap, ray -> rop, ray -> ron, photon);
638   #else
639 <   kdT_Find1Photon(pmap, ray -> rop, ray -> ron, photon);
640 < #endif                  
639 >      found = kdT_Find1Photon(pmap, ray -> rop, ray -> ron, photon);
640 > #endif
641 >      if (found < 0) {
642 >         /* Expand search radius to retry */
643 >         maxDist2_0 *= 2;      
644 > #ifdef PMAP_LOOKUP_WARN
645 >         sprintf(errmsg, "failed 1-NN photon lookup"
646 > #ifdef PMAP_LOOKUP_REDO
647 >            ", retrying with search radius %.2f", maxDist2_0
648 > #endif
649 >         );
650 >         error(WARNING, errmsg);
651 > #endif
652 >      }
653 >   } while (REDO && found < 0);
654 >
655 >   /* Return photon buffer containing valid photon, else NULL */
656 >   return found < 0 ? NULL : photon;
657   }
658  
659  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines