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

Comparing ray/src/rt/pmapooc.c (file contents):
Revision 1.1 by rschregle, Wed May 18 08:22:45 2016 UTC vs.
Revision 1.6 by rschregle, Wed Apr 8 15:14:21 2020 UTC

# Line 1 | Line 1
1   /*
2 <   ==================================================================
2 >   ======================================================================
3     Photon map interface to out-of-core octree
4  
5     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
6     (c) Lucerne University of Applied Sciences and Arts,
7 <   supported by the Swiss National Science Foundation (SNSF, #147053)
8 <   ==================================================================
7 >       supported by the Swiss National Science Foundation (SNSF, #147053)
8 >   ======================================================================
9    
10     $Id$
11   */
12  
13  
14 < #ifndef PMAP_OOC
15 <   /* Checked in pmapdata.h */
16 <   #define PMAP_OOC
17 < #endif
14 >
15   #include "pmapdata.h"   /* Includes pmapooc.h */
16   #include "source.h"
17 + #include "otspecial.h"
18   #include "oocsort.h"
19   #include "oocbuild.h"
20  
# Line 217 | Line 215 | int OOC_FilterPhoton (void *p, void *fd)
215         DOT(filtData->norm, photon->norm) <= PMAP_NORM_TOL * 127 * frandom())
216        return 0;
217        
218 <   if (isContribPmap(pmap) && pmap -> srcContrib) {
219 <      /* Lookup in contribution photon map */
220 <      OBJREC *srcMod;
221 <      const int srcIdx = photonSrcIdx(pmap, photon);
218 >   if (isContribPmap(pmap)) {
219 >      /* Lookup in contribution photon map; filter according to emitting
220 >       * light source if contrib list set, else accept all */
221 >      
222 >      if (pmap -> srcContrib) {
223 >         OBJREC *srcMod;
224 >         const int srcIdx = photonSrcIdx(pmap, photon);
225        
226 <      if (srcIdx < 0 || srcIdx >= nsources)
227 <         error(INTERNAL, "invalid light source index in photon map");
226 >         if (srcIdx < 0 || srcIdx >= nsources)
227 >            error(INTERNAL, "invalid light source index in photon map");
228        
229 <      srcMod = findmaterial(source [srcIdx].so);
229 >         srcMod = findmaterial(source [srcIdx].so);
230  
231 <      /* Reject photon if contributions from light source which emitted it
232 <       * are not sought */
233 <      if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data)
234 <         return 0;
231 >         /* Reject photon if contributions from light source which emitted
232 >          * it are not sought */
233 >         if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data)
234 >            return 0;
235 >      }
236  
237        /* Reject non-caustic photon if lookup for caustic contribs */
238        if (pmap -> lookupCaustic && !photon -> caustic)
# Line 243 | Line 245 | int OOC_FilterPhoton (void *p, void *fd)
245  
246  
247  
248 < void OOC_FindPhotons (struct PhotonMap *pmap, const FVECT pos, const FVECT norm)
248 > int OOC_FindPhotons (struct PhotonMap *pmap, const FVECT pos, const FVECT norm)
249   {
250     OOC_SearchFilter  filt;
251     OOC_FilterData    filtData;
# Line 255 | Line 257 | void OOC_FindPhotons (struct PhotonMap *pmap, const FV
257          
258     /* Set up filter callback */
259     filtData.pmap = pmap;
260 <   VCOPY(n, norm);
261 <   filtData.norm = n;
260 >   if (norm)
261 >      VCOPY(n, norm);
262 >   filtData.norm = norm ? n : NULL;
263     filt.data = &filtData;
264     filt.func = OOC_FilterPhoton;
265  
# Line 268 | Line 271 | void OOC_FindPhotons (struct PhotonMap *pmap, const FV
271  
272     if (pmap -> maxDist2 < 0)
273        error(INTERNAL, "failed k-NN photon lookup in OOC_FindPhotons");
274 +  
275 +   /* Return success or failure (empty queue => none found) */
276 +   return pmap -> squeue.tail ? 0 : -1;
277   }
278  
279  
280  
281 < void OOC_Find1Photon (struct PhotonMap* pmap, const FVECT pos,
282 <                      const FVECT norm, Photon *photon)
281 > int OOC_Find1Photon (struct PhotonMap* pmap, const FVECT pos,
282 >                     const FVECT norm, Photon *photon)
283   {
284     OOC_SearchFilter     filt;
285     OOC_FilterData       filtData;
286 <   float                n [3];
286 >   float                n [3], maxDist2;
287    
288     /* Lazily init OOC cache */
289     if (!pmap -> store.cache)
# Line 285 | Line 291 | void OOC_Find1Photon (struct PhotonMap* pmap, const FV
291    
292     /* Set up filter callback */
293     filtData.pmap = pmap;
294 <   VCOPY(n, norm);
295 <   filtData.norm = n;
294 >   if (norm)
295 >      VCOPY(n, norm);
296 >   filtData.norm = norm ? n : NULL;  
297     filt.data = &filtData;
298     filt.func = OOC_FilterPhoton;
299    
300 <   pmap -> maxDist2 = OOC_Find1Nearest(&pmap -> store,
301 <                                       OOC_ROOT(&pmap -> store), 0,
302 <                                       pmap -> store.org, pmap -> store.size,
303 <                                       pos, &filt, photon, pmap -> maxDist2);
304 <
305 <   if (pmap -> maxDist2 < 0)
306 <      error(INTERNAL, "failed 1-NN photon lookup in OOC_Find1Photon");
300 >   maxDist2 = OOC_Find1Nearest(&pmap -> store,
301 >                               OOC_ROOT(&pmap -> store), 0,
302 >                               pmap -> store.org, pmap -> store.size,
303 >                               pos, &filt, photon, pmap -> maxDist2);
304 >                              
305 >   if (maxDist2 < 0)
306 >      error(INTERNAL, "failed 1-NN photon lookup in OOC_Find1Photon");      
307 >      
308 >   if (maxDist2 >= pmap -> maxDist2)
309 >      /* No photon found => failed */
310 >      return -1;
311 >   else {
312 >      /* Set photon distance => success */
313 >      pmap -> maxDist2 = maxDist2;
314 >      return 0;
315 >   }
316   }
317  
318  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines