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.4 by rschregle, Thu Apr 23 20:02:04 2015 UTC vs.
Revision 2.10 by greg, Tue Sep 1 16:27:52 2015 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map main module
# Line 8 | Line 11
11     supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================
13    
11   $Id$
14   */
15  
16  
# Line 101 | Line 103 | void savePmaps (const PhotonMap **pmaps, int argc, cha
103    
104     for (t = 0; t < NUM_PMAP_TYPES; t++) {
105        if (pmaps [t])
106 <         savePhotonMap(pmaps [t], pmaps [t] -> fileName, t, argc, argv);
106 >         savePhotonMap(pmaps [t], pmaps [t] -> fileName, argc, argv);
107     }
108   }                  
109  
# Line 206 | Line 208 | void tracePhoton (RAY *ray)
208     OBJREC* mat;
209  
210     if (ray -> rlvl > photonMaxBounce) {
211 + #ifdef PMAP_RUNAWAY_WARN  
212        error(WARNING, "runaway photon!");
213 + #endif      
214        return;
215     }
216 <  
216 >  
217     if (colorAvg(ray -> cext) > FTINY && !photonParticipate(ray))
218        return;
219        
# Line 322 | Line 326 | void distribPhotons (PhotonMap **pmaps)
326     double totalFlux = 0;
327     PhotonMap *pm;
328    
329 <   for (t = 0; t < NUM_PMAP_TYPES && !photonMaps [t]; t++);
329 >   for (t = 0; t < NUM_PMAP_TYPES && !pmaps [t]; t++);
330     if (t >= NUM_PMAP_TYPES)
331        error(USER, "no photon maps defined");
332        
# Line 340 | Line 344 | void distribPhotons (PhotonMap **pmaps)
344        
345     /* Initialise all defined photon maps */
346     for (t = 0; t < NUM_PMAP_TYPES; t++)
347 <      initPhotonMap(photonMaps [t], t);
347 >      initPhotonMap(pmaps [t], t);
348  
349     initPhotonEmissionFuncs();
350     initPhotonScatterFuncs();
# Line 432 | Line 436 | void distribPhotons (PhotonMap **pmaps)
436              sprintf(errmsg, "too many prepasses");
437  
438              for (t = 0; t < NUM_PMAP_TYPES; t++)
439 <               if (photonMaps [t] && !photonMaps [t] -> heapEnd) {
439 >               if (pmaps [t] && !pmaps [t] -> heapEnd) {
440                    sprintf(errmsg2, ", no %s photons stored", pmapName [t]);
441                    strcat(errmsg, errmsg2);
442                 }
# Line 445 | Line 449 | void distribPhotons (PhotonMap **pmaps)
449           numEmit = FHUGE;
450          
451           for (t = 0; t < NUM_PMAP_TYPES; t++)
452 <            if (photonMaps [t])
453 <               numEmit = min(photonMaps [t] -> distribTarget, numEmit);
452 >            if (pmaps [t])
453 >               numEmit = min(pmaps [t] -> distribTarget, numEmit);
454                
455           numEmit *= preDistrib;
456        }
# Line 467 | Line 471 | void distribPhotons (PhotonMap **pmaps)
471            * Since this biases the photon density, addPhoton() promotes the
472            * flux of stored photons to compensate. */
473           for (t = 0; t < NUM_PMAP_TYPES; t++)
474 <            if ((pm = photonMaps [t])) {
474 >            if ((pm = pmaps [t])) {
475                 pm -> distribRatio = (double)pm -> distribTarget /
476                                      pm -> heapEnd - 1;
477  
# Line 492 | Line 496 | void distribPhotons (PhotonMap **pmaps)
496           /* Normalise distribution ratios and calculate number of photons to
497            * emit in main pass */
498           for (t = 0; t < NUM_PMAP_TYPES; t++)
499 <            if ((pm = photonMaps [t]))
499 >            if ((pm = pmaps [t]))
500                 pm -> distribRatio /= maxDistribRatio;
501                
502           if ((numEmit = repProgress * maxDistribRatio) < FTINY)
# Line 507 | Line 511 | void distribPhotons (PhotonMap **pmaps)
511        for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
512           unsigned portCnt = 0;
513           emap.src = source + srcIdx;
514 <                  
514 >
515           do {
516              emap.port = emap.src -> sflags & SDISTANT ? photonPorts + portCnt
517                                                        : NULL;
# Line 579 | Line 583 | void distribPhotons (PhotonMap **pmaps)
583        }
584        
585        for (t = 0; t < NUM_PMAP_TYPES; t++)
586 <         if (photonMaps [t] && !photonMaps [t] -> heapEnd) {
586 >         if (pmaps [t] && !pmaps [t] -> heapEnd) {
587              /* Double preDistrib in case a photon map is empty and redo
588               * pass 1 --> possibility of infinite loop for pathological
589               * scenes (e.g. absorbing materials) */
# Line 607 | Line 611 | void distribPhotons (PhotonMap **pmaps)
611     totalFlux /= repProgress;
612    
613     for (t = 0; t < NUM_PMAP_TYPES; t++)
614 <      if (photonMaps [t]) {
614 >      if (pmaps [t]) {
615           if (photonRepTime) {
616              sprintf(errmsg, "\nBuilding %s photon map...\n", pmapName [t]);
617              eputs(errmsg);
618              fflush(stderr);
619           }
620        
621 <         balancePhotons(photonMaps [t], &totalFlux);
621 >         balancePhotons(pmaps [t], &totalFlux);
622        }
623        
624     /* Precompute photon irradiance if necessary */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines