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

Comparing ray/src/rt/pmapkdt.c (file contents):
Revision 1.3 by rschregle, Wed Jan 24 19:39:05 2018 UTC vs.
Revision 1.6 by rschregle, Wed Apr 8 15:14:21 2020 UTC

# Line 15 | Line 15
15  
16   #include "pmapdata.h"   /* Includes pmapkdt.h */
17   #include "source.h"
18 + #include "otspecial.h"
19 + #include "random.h"
20  
21  
22  
# Line 417 | Line 419 | static void kdT_FindNearest (PhotonMap *pmap, const fl
419  
420  
421  
422 < void kdT_FindPhotons (struct PhotonMap *pmap, const FVECT pos,
423 <                      const FVECT norm)
422 > int kdT_FindPhotons (struct PhotonMap *pmap, const FVECT pos,
423 >                     const FVECT norm)
424   {
425     float p [3], n [3];
426    
427     /* Photon pos & normal stored at lower precision */
428     VCOPY(p, pos);
429 <   VCOPY(n, norm);
430 <   kdT_FindNearest(pmap, p, n, 1);
429 >   if (norm)
430 >      VCOPY(n, norm);
431 >   kdT_FindNearest(pmap, p, norm ? n : NULL, 1);
432 >  
433 >   /* Return success or failure (empty queue => none found) */
434 >   return pmap -> squeue.tail ? 0 : -1;
435   }
436  
437  
# Line 464 | Line 470 | static void kdT_Find1Nearest (PhotonMap *pmap, const f
470     d2 = DOT(dv, dv);
471    
472     if (d2 < pmap -> maxDist2 &&
473 <       DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom()) {
473 >       (!norm || DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom())) {
474        /* Closest photon so far with similar normal. We allow for tolerance
475         * to account for perturbation in the latter; note the photon normal
476         * is coded in the range [-127,127], hence we factor this in  */
# Line 475 | Line 481 | static void kdT_Find1Nearest (PhotonMap *pmap, const f
481  
482  
483  
484 < void kdT_Find1Photon (struct PhotonMap *pmap, const FVECT pos,
485 <                      const FVECT norm, Photon *photon)
484 > int kdT_Find1Photon (struct PhotonMap *pmap, const FVECT pos,
485 >                     const FVECT norm, Photon *photon)
486   {
487     float    p [3], n [3];
488 <   Photon   *pnn;
488 >   Photon   *pnn = NULL;
489    
490     /* Photon pos & normal stored at lower precision */
491     VCOPY(p, pos);
492 <   VCOPY(n, norm);
493 <   kdT_Find1Nearest(pmap, p, n, &pnn, 1);
494 <   memcpy(photon, pnn, sizeof(Photon));
492 >   if (norm)
493 >      VCOPY(n, norm);  
494 >   kdT_Find1Nearest(pmap, p, norm ? n : NULL, &pnn, 1);  
495 >   if (!pnn)
496 >      /* No photon found => failed */
497 >      return -1;
498 >   else {
499 >      /* Copy found photon => successs */
500 >      memcpy(photon, pnn, sizeof(Photon));
501 >      return 0;
502 >   }
503   }
504  
505  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines