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

Comparing ray/src/rt/pmutil.c (file contents):
Revision 2.2 by rschregle, Wed Jan 24 19:39:05 2018 UTC vs.
Revision 2.4 by rschregle, Thu Jan 23 18:27:02 2020 UTC

# Line 75 | Line 75 | void loadPmaps (PhotonMap **pmaps, const PhotonMapPara
75           /* Assign to appropriate photon map type (deleting previously
76            * loaded photon map of same type if necessary) */
77           if (pmaps [type]) {
78 +            sprintf(errmsg, "multiple %s photon maps, dropping previous",
79 +                    pmapName [type]);
80 +            error(WARNING, errmsg);
81              deletePhotons(pmaps [type]);
82              free(pmaps [type]);
83           }
84           pmaps [type] = pm;
85          
86 <         /* Check for invalid density estimate bandwidth */                            
86 >         /* Check for valid density estimate bandwidths */
87 >         if ((pm -> minGather > 1 || pm -> maxGather > 1) &&
88 >             (type == PMAP_TYPE_PRECOMP)) {
89 >            /* Force bwidth to 1 for precomputed pmap */
90 >            error(WARNING, "ignoring bandwidth for precomp photon map");
91 >            pm -> minGather = pm -> maxGather = 1;
92 >         }
93 >                    
94 >         if ((pm -> maxGather > pm -> minGather) &&
95 >             (type == PMAP_TYPE_VOLUME)) {            
96 >            /* Biascomp for volume pmaps (see volumePhotonDensity() below)
97 >               is considered redundant, and there's probably no point in
98 >               recovering by using the lower bandwidth, since it's probably
99 >               not what the user wants, so bail out. */
100 >            sprintf(errmsg,
101 >                    "bias compensation is not available with %s photon maps",
102 >                    pmapName [type]);
103 >            error(USER, errmsg);
104 >         }
105 >        
106           if (pm -> maxGather > pm -> numPhotons) {
107              error(WARNING, "adjusting density estimate bandwidth");
108              pm -> minGather = pm -> maxGather = pm -> numPhotons;
109 <         }
109 >         }            
110        }
111   }
112  
# Line 109 | Line 131 | void photonDensity (PhotonMap *pmap, RAY *ray, COLOR i
131   /* Photon density estimate. Returns irradiance at ray -> rop. */
132   {
133     unsigned                      i;
134 <   float                         r;
134 >   float                         r2;
135     COLOR                         flux;
136     Photon                        *photon;
137     const PhotonSearchQueueNode   *sqn;
# Line 141 | Line 163 | void photonDensity (PhotonMap *pmap, RAY *ray, COLOR i
163        /* No bias compensation. Just do a plain vanilla estimate */
164        sqn = pmap -> squeue.node + 1;
165        
166 <      /* Average radius between furthest two photons to improve accuracy */      
167 <      r = max(sqn -> dist2, (sqn + 1) -> dist2);
168 <      r = 0.25 * (pmap -> maxDist2 + r + 2 * sqrt(pmap -> maxDist2 * r));  
166 >      /* Average radius^2 between furthest two photons to improve accuracy */
167 >      r2 = max(sqn -> dist2, (sqn + 1) -> dist2);
168 >      r2 = 0.25 * (pmap -> maxDist2 + r2 + 2 * sqrt(pmap -> maxDist2 * r2));
169        
170        /* Skip the extra photon */
171        for (i = 1 ; i < pmap -> squeue.tail; i++, sqn++) {
# Line 151 | Line 173 | void photonDensity (PhotonMap *pmap, RAY *ray, COLOR i
173           getPhotonFlux(photon, flux);        
174   #ifdef PMAP_EPANECHNIKOV
175           /* Apply Epanechnikov kernel to photon flux based on photon dist */
176 <         scalecolor(flux, 2 * (1 - sqn -> dist2 / r));
176 >         scalecolor(flux, 2 * (1 - sqn -> dist2 / r2));
177   #endif  
178           addcolor(irrad, flux);
179        }
180        
181        /* Divide by search area PI * r^2, 1 / PI required as ambient
182           normalisation factor */        
183 <      scalecolor(irrad, 1 / (PI * PI * r));
183 >      scalecolor(irrad, 1 / (PI * PI * r2));
184        
185        return;
186     }
# Line 192 | Line 214 | void volumePhotonDensity (PhotonMap *pmap, RAY *ray, C
214   /* Photon volume density estimate. Returns irradiance at ray -> rop. */
215   {
216     unsigned                      i;
217 <   float                         r, gecc2, ph;
217 >   float                         r2, gecc2, ph;
218     COLOR                         flux;
219     Photon                        *photon;
220     const PhotonSearchQueueNode   *sqn;
# Line 217 | Line 239 | void volumePhotonDensity (PhotonMap *pmap, RAY *ray, C
239        gecc2 = ray -> gecc * ray -> gecc;
240        sqn = pmap -> squeue.node + 1;
241        
242 <      /* Average radius between furthest two photons to improve accuracy */      
243 <      r = max(sqn -> dist2, (sqn + 1) -> dist2);
244 <      r = 0.25 * (pmap -> maxDist2 + r + 2 * sqrt(pmap -> maxDist2 * r));  
242 >      /* Average radius^2 between furthest two photons to improve accuracy */      
243 >      r2 = max(sqn -> dist2, (sqn + 1) -> dist2);
244 >      r2 = 0.25 * (pmap -> maxDist2 + r2 + 2 * sqrt(pmap -> maxDist2 * r2));
245        
246        /* Skip the extra photon */
247        for (i = 1; i < pmap -> squeue.tail; i++, sqn++) {
# Line 241 | Line 263 | void volumePhotonDensity (PhotonMap *pmap, RAY *ray, C
263        
264        /* Divide by search volume 4 / 3 * PI * r^3 and phase function
265           normalization factor 1 / (4 * PI) */
266 <      scalecolor(irrad, 3 / (16 * PI * PI * r * sqrt(r)));
266 >      scalecolor(irrad, 3 / (16 * PI * PI * r2 * sqrt(r2)));
267        return;
268     }
269   #if 0

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines