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

Comparing ray/src/rt/pmapsrc.c (file contents):
Revision 2.1 by greg, Tue Feb 24 19:39:27 2015 UTC vs.
Revision 2.13 by rschregle, Tue May 17 17:39:47 2016 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map support routines for emission from light sources
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 <  
10 <   $Id$
13 >
14   */
15  
16  
# Line 46 | Line 49 | static int flatPhotonPartition2 (EmissionMap* emap, un
49        if (!emap -> partitions)
50           error(USER, "can't allocate source partitions");
51  
52 <      bzero(emap -> partitions + (emap -> maxPartitions >> 2),
53 <            emap -> maxPartitions >> 2);
52 >      memset(emap -> partitions + (emap -> maxPartitions >> 2), 0,
53 >             emap -> maxPartitions >> 2);
54     }
55    
56     if (du2 * dv2 <= 1) {                /* hit limit? */
# Line 100 | Line 103 | static void flatPhotonPartition (EmissionMap* emap)
103     RREAL    *vp;
104     double   du2, dv2;
105  
106 <   bzero(emap -> partitions, emap -> maxPartitions >> 1);
106 >   memset(emap -> partitions, 0, emap -> maxPartitions >> 1);
107     emap -> partArea = srcsizerat * thescene.cusize;
108     emap -> partArea *= emap -> partArea;
109     vp = emap -> src -> ss [SU];
# Line 132 | Line 135 | static void sourcePhotonPartition (EmissionMap* emap)
135    
136     else {
137        /* No photon ports defined, so partition scene cube faces */
138 <      bzero(emap -> partitions, emap -> maxPartitions >> 1);
138 >      memset(emap -> partitions, 0, emap -> maxPartitions >> 1);
139        setpart(emap -> partitions, 0, S0);
140        emap -> partitionCnt = 0;
141        emap -> numPartitions = 1 / srcsizerat;
# Line 150 | Line 153 | static void spherePhotonPartition (EmissionMap* emap)
153   {
154     unsigned numTheta, numPhi;
155    
156 <   bzero(emap -> partitions, emap -> maxPartitions >> 1);
156 >   memset(emap -> partitions, 0, emap -> maxPartitions >> 1);
157     setpart(emap -> partitions, 0, S0);
158     emap -> partArea = 4 * PI * sqr(emap -> src -> srad);
159     emap -> numPartitions = emap -> partArea /
# Line 180 | Line 183 | static int cylPhotonPartition2 (EmissionMap* emap, uns
183                                                     emap -> maxPartitions >> 1);
184        if (!emap -> partitions)
185           error(USER, "can't allocate source partitions");
186 <      bzero(emap -> partitions + (emap -> maxPartitions >> 2),
186 >        
187 >      memset(emap -> partitions + (emap -> maxPartitions >> 2), 0,
188              emap -> maxPartitions >> 2);
189     }
190    
# Line 222 | Line 226 | static void cylPhotonPartition (EmissionMap* emap)
226   {
227     double d2;
228  
229 <   bzero(emap -> partitions, emap -> maxPartitions >> 1);
229 >   memset(emap -> partitions, 0, emap -> maxPartitions >> 1);
230     d2 = srcsizerat * thescene.cusize;
231     d2 = PI * emap -> src -> ss2 / (2 * emap -> src -> srad * sqr(d2));
232     d2 *= d2 * DOT(emap -> src -> ss [SU], emap -> src -> ss [SU]);
# Line 521 | Line 525 | void getPhotonPorts ()
525   /* Find geometry declared as photon ports */
526   {
527     OBJECT i;
528 <   OBJREC* obj;
528 >   OBJREC *obj, *mat;
529    
530     /* Check for missing port modifiers */
531     if (!ambset [0])
532 <      error(USER, "no photon ports found");
532 >      error(USER, "no photon ports");
533    
534     for (i = 0; i < nobjects; i++) {
535        obj = objptr(i);
536 +      mat = findmaterial(obj);
537        
538 <      if (inset(ambset, obj -> omod)) {
538 >      /* Check if object is a surface and NOT a light source (duh) and
539 >       * resolve its material via any aliases, then check for inclusion in
540 >       * port modifier list */
541 >      if (issurface(obj -> otype) && mat && !islight(mat -> otype) &&
542 >          inset(ambset, objndx(mat))) {
543           /* Add photon port */
544           photonPorts = (SRCREC*)realloc(photonPorts,
545                                          (numPhotonPorts + 1) *
# Line 548 | Line 557 | void getPhotonPorts ()
557           numPhotonPorts++;
558        }
559     }
560 +  
561 +   if (!numPhotonPorts)
562 +      error(USER, "no valid photon ports found");
563   }
564  
565  
# Line 590 | Line 602 | void initPhotonEmission (EmissionMap *emap, float numP
602     unsigned i, t, p;
603     double phi, cosTheta, sinTheta, du, dv, dOmega, thetaScale;
604     EmissionSample* sample;
605 <   const OBJREC* mod =  objptr(emap -> src -> so -> omod);
605 >   const OBJREC* mod =  findmaterial(emap -> src -> so);
606     static RAY r;
607   #if 0  
608     static double lastCosNorm = FHUGE;
609     static SRCREC *lastSrc = NULL, *lastPort = NULL;
610   #endif  
611  
612 +   setcolor(emap -> partFlux, 0, 0, 0);
613 +
614     photonOrigin [emap -> src -> so -> otype] (emap);
615     cosTheta = DOT(emap -> ws, emap -> wh);
616  
# Line 619 | Line 633 | void initPhotonEmission (EmissionMap *emap, float numP
633   #endif
634          
635     /* Need to recompute flux & PDF */
622   setcolor(emap -> partFlux, 0, 0, 0);
636     emap -> cdf = 0;
637     emap -> numSamples = 0;
638    
# Line 668 | Line 681 | void initPhotonEmission (EmissionMap *emap, float numP
681          
682        VCOPY(r.rorg, emap -> photonOrg);
683        VCOPY(r.rop, emap -> photonOrg);
684 <      r.rmax = FHUGE;
684 >      r.rmax = 0;
685        
686        for (t = 0; t < emap -> numTheta; t++) {
687           for (p = 0; p < emap -> numPhi; p++) {
# Line 738 | Line 751 | void emitPhoton (const EmissionMap* emap, RAY* ray)
751     unsigned long i, lo, hi;
752     const EmissionSample* sample = emap -> samples;
753     RREAL du, dv, cosTheta, cosThetaSqr, sinTheta, phi;  
754 <   const OBJREC* mod = objptr(emap -> src -> so -> omod);
754 >   const OBJREC* mod = findmaterial(emap -> src -> so);
755    
756     /* Choose a new origin within current partition for every
757        emitted photon to break up clustering artifacts */
758     photonOrigin [emap -> src -> so -> otype] ((EmissionMap*)emap);
759 +   /* If we have a local glow source with a maximum radius, then
760 +      restrict our photon to the specified distance (otherwise no limit) */
761 +   if (mod -> otype == MAT_GLOW && !(emap -> src -> sflags & SDISTANT)
762 +                && mod -> oargs.farg[3] > FTINY)
763 +      ray -> rmax = mod -> oargs.farg[3];
764 +   else
765 +      ray -> rmax = 0;
766     rayorigin(ray, PRIMARY, NULL, NULL);
747   ray -> rmax = FHUGE;
767    
768     if (!emap -> numSamples) {
769        /* Source is unmodified and has no port, and either local with

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines