ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmap.c
(Generate patch)

Comparing ray/src/rt/pmap.c (file contents):
Revision 2.3 by rschregle, Wed Apr 22 20:28:16 2015 UTC vs.
Revision 2.9 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 main module
7  
8     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
9     (c) Fraunhofer Institute for Solar Energy Systems,
10 <       Lucerne University of Applied Sciences & Arts  
10 >   (c) Lucerne University of Applied Sciences and Arts,
11 >   supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================
13    
14     $Id$
# Line 64 | Line 68 | void loadPmaps (PhotonMap **pmaps, const PhotonMapPara
68     for (t = 0; t < NUM_PMAP_TYPES; t++)
69        if (setPmapParam(&pm, parm + t)) {        
70           /* Check if photon map newer than octree */
71 <         if (!stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) &&
71 >         if (pm -> fileName && octname &&
72 >             !stat(pm -> fileName, &pmstat) && !stat(octname, &octstat) &&
73               octstat.st_mtime > pmstat.st_mtime) {
74              sprintf(errmsg, "photon map in file %s may be stale",
75                      pm -> fileName);
# Line 99 | Line 104 | void savePmaps (const PhotonMap **pmaps, int argc, cha
104    
105     for (t = 0; t < NUM_PMAP_TYPES; t++) {
106        if (pmaps [t])
107 <         savePhotonMap(pmaps [t], pmaps [t] -> fileName, t, argc, argv);
107 >         savePhotonMap(pmaps [t], pmaps [t] -> fileName, argc, argv);
108     }
109   }                  
110  
# Line 204 | Line 209 | void tracePhoton (RAY *ray)
209     OBJREC* mat;
210  
211     if (ray -> rlvl > photonMaxBounce) {
212 + #ifdef PMAP_RUNAWAY_WARN  
213        error(WARNING, "runaway photon!");
214 + #endif      
215        return;
216     }
217 <  
217 >  
218     if (colorAvg(ray -> cext) > FTINY && !photonParticipate(ray))
219        return;
220        
# Line 320 | Line 327 | void distribPhotons (PhotonMap **pmaps)
327     double totalFlux = 0;
328     PhotonMap *pm;
329    
330 <   for (t = 0; t < NUM_PMAP_TYPES && !photonMaps [t]; t++);
330 >   for (t = 0; t < NUM_PMAP_TYPES && !pmaps [t]; t++);
331     if (t >= NUM_PMAP_TYPES)
332        error(USER, "no photon maps defined");
333        
# Line 338 | Line 345 | void distribPhotons (PhotonMap **pmaps)
345        
346     /* Initialise all defined photon maps */
347     for (t = 0; t < NUM_PMAP_TYPES; t++)
348 <      initPhotonMap(photonMaps [t], t);
348 >      initPhotonMap(pmaps [t], t);
349  
350     initPhotonEmissionFuncs();
351     initPhotonScatterFuncs();
# Line 430 | Line 437 | void distribPhotons (PhotonMap **pmaps)
437              sprintf(errmsg, "too many prepasses");
438  
439              for (t = 0; t < NUM_PMAP_TYPES; t++)
440 <               if (photonMaps [t] && !photonMaps [t] -> heapEnd) {
440 >               if (pmaps [t] && !pmaps [t] -> heapEnd) {
441                    sprintf(errmsg2, ", no %s photons stored", pmapName [t]);
442                    strcat(errmsg, errmsg2);
443                 }
# Line 443 | Line 450 | void distribPhotons (PhotonMap **pmaps)
450           numEmit = FHUGE;
451          
452           for (t = 0; t < NUM_PMAP_TYPES; t++)
453 <            if (photonMaps [t])
454 <               numEmit = min(photonMaps [t] -> distribTarget, numEmit);
453 >            if (pmaps [t])
454 >               numEmit = min(pmaps [t] -> distribTarget, numEmit);
455                
456           numEmit *= preDistrib;
457        }
# Line 465 | Line 472 | void distribPhotons (PhotonMap **pmaps)
472            * Since this biases the photon density, addPhoton() promotes the
473            * flux of stored photons to compensate. */
474           for (t = 0; t < NUM_PMAP_TYPES; t++)
475 <            if ((pm = photonMaps [t])) {
475 >            if ((pm = pmaps [t])) {
476                 pm -> distribRatio = (double)pm -> distribTarget /
477                                      pm -> heapEnd - 1;
478  
# Line 490 | Line 497 | void distribPhotons (PhotonMap **pmaps)
497           /* Normalise distribution ratios and calculate number of photons to
498            * emit in main pass */
499           for (t = 0; t < NUM_PMAP_TYPES; t++)
500 <            if ((pm = photonMaps [t]))
500 >            if ((pm = pmaps [t]))
501                 pm -> distribRatio /= maxDistribRatio;
502                
503           if ((numEmit = repProgress * maxDistribRatio) < FTINY)
# Line 505 | Line 512 | void distribPhotons (PhotonMap **pmaps)
512        for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
513           unsigned portCnt = 0;
514           emap.src = source + srcIdx;
515 <                  
515 >
516           do {
517              emap.port = emap.src -> sflags & SDISTANT ? photonPorts + portCnt
518                                                        : NULL;
# Line 577 | Line 584 | void distribPhotons (PhotonMap **pmaps)
584        }
585        
586        for (t = 0; t < NUM_PMAP_TYPES; t++)
587 <         if (photonMaps [t] && !photonMaps [t] -> heapEnd) {
587 >         if (pmaps [t] && !pmaps [t] -> heapEnd) {
588              /* Double preDistrib in case a photon map is empty and redo
589               * pass 1 --> possibility of infinite loop for pathological
590               * scenes (e.g. absorbing materials) */
# Line 605 | Line 612 | void distribPhotons (PhotonMap **pmaps)
612     totalFlux /= repProgress;
613    
614     for (t = 0; t < NUM_PMAP_TYPES; t++)
615 <      if (photonMaps [t]) {
615 >      if (pmaps [t]) {
616           if (photonRepTime) {
617              sprintf(errmsg, "\nBuilding %s photon map...\n", pmapName [t]);
618              eputs(errmsg);
619              fflush(stderr);
620           }
621        
622 <         balancePhotons(photonMaps [t], &totalFlux);
622 >         balancePhotons(pmaps [t], &totalFlux);
623        }
624        
625     /* Precompute photon irradiance if necessary */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines