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

Comparing ray/src/rt/srcsamp.c (file contents):
Revision 1.4 by greg, Tue Oct 22 15:45:21 1991 UTC vs.
Revision 2.11 by greg, Sat Sep 13 17:31:35 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Source sampling routines
6 + *
7 + *  External symbols declared in source.h
8   */
9  
10 + #include "copyright.h"
11 +
12   #include  "ray.h"
13  
14   #include  "source.h"
# Line 15 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   #include  "random.h"
17  
18  
19 + static int  cyl_partit(), flt_partit();
20 +
21 +
22   double
23   nextssamp(r, si)                /* compute sample for source, rtn. distance */
24   register RAY  *r;               /* origin is read, direction is set */
# Line 24 | Line 28 | register SRCINDEX  *si;                /* source index (modified to
28          FVECT  vpos;
29          double  d;
30          register int  i;
31 < tryagain:
31 > nextsample:
32          while (++si->sp >= si->np) {    /* get next sample */
33                  if (++si->sn >= nsources)
34                          return(0.0);    /* no more */
35 <                if (srcsizerat <= FTINY)
35 >                if (source[si->sn].sflags & SSKIP)
36 >                        si->np = 0;
37 >                else if (srcsizerat <= FTINY)
38                          nopart(si, r);
39                  else {
40                          for (i = si->sn; source[i].sflags & SVIRTUAL;
# Line 74 | Line 80 | tryagain:
80                          r->rdir[i] -= r->rorg[i];
81                                          /* compute distance */
82          if ((d = normalize(r->rdir)) == 0.0)
83 <                goto tryagain;  /* at source! */
83 >                goto nextsample;                /* at source! */
84  
85                                          /* compute sample size */
80        si->dom  = source[si->sn].ss2;
86          if (source[si->sn].sflags & SFLAT) {
87 <                si->dom *= sflatform(si->sn, r->rdir);
88 <                if (si->dom <= FTINY) {         /* behind source */
84 <                        si->np = 0;
85 <                        goto tryagain;
86 <                }
87 <                si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
87 >                si->dom = sflatform(si->sn, r->rdir);
88 >                si->dom *= size[SU]*size[SV]/(MAXSPART*(double)MAXSPART);
89          } else if (source[si->sn].sflags & SCYL) {
90 <                si->dom *= scylform(si->sn, r->rdir);
91 <                si->dom *= (double)size[SU]/MAXSPART;
90 >                si->dom = scylform(si->sn, r->rdir);
91 >                si->dom *= size[SU]/(double)MAXSPART;
92          } else {
93 <                si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
94 <                                (MAXSPART*MAXSPART*MAXSPART) ;
93 >                si->dom = size[SU]*size[SV]*(double)size[SW] /
94 >                                (MAXSPART*MAXSPART*(double)MAXSPART) ;
95          }
96 <        if (source[si->sn].sflags & SDISTANT)
96 >        if (source[si->sn].sflags & SDISTANT) {
97 >                si->dom *= source[si->sn].ss2;
98                  return(FHUGE);
99 <        si->dom /= d*d;
99 >        }
100 >        if (si->dom <= 1e-4)
101 >                goto nextsample;                /* behind source? */
102 >        si->dom *= source[si->sn].ss2/(d*d);
103          return(d);              /* sample OK, return distance */
104   }
105  
106  
107 + int
108   skipparts(ct, sz, pp, pt)               /* skip to requested partition */
109   int  ct[3], sz[3];              /* center and size of partition (returned) */
110   register int  pp[2];            /* current index, number to skip (modified) */
# Line 108 | Line 114 | unsigned char  *pt;            /* partition array */
114                                          /* check this partition */
115          p = spart(pt, pp[0]);
116          pp[0]++;
117 <        if (p == S0)                    /* leaf partition */
117 >        if (p == S0) {                  /* leaf partition */
118                  if (pp[1]) {
119                          pp[1]--;
120                          return(0);      /* not there yet */
121                  } else
122                          return(1);      /* we've arrived */
123 +        }
124                                  /* else check lower */
125          sz[p] >>= 1;
126          ct[p] -= sz[p];
# Line 130 | Line 137 | unsigned char  *pt;            /* partition array */
137   }
138  
139  
140 + void
141   nopart(si, r)                   /* single source partition */
142   register SRCINDEX  *si;
143   RAY  *r;
# Line 140 | Line 148 | RAY  *r;
148   }
149  
150  
151 + void
152   cylpart(si, r)                  /* partition a cylinder */
153   SRCINDEX  *si;
154   register RAY  *r;
# Line 165 | Line 174 | register RAY  *r;
174                  return;
175          }
176          safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
177 <        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
178 <                        dist2cent >= safedist2) {       /* too far? */
177 >        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide */
178 >                        dist2cent >= safedist2) {       /* or too far */
179                  setpart(si->spt, 0, S0);
180                  si->np = 1;
181                  return;
# Line 216 | Line 225 | double  d2;
225   }
226  
227  
228 + void
229   flatpart(si, r)                         /* partition a flat source */
230   register SRCINDEX  *si;
231 < RAY  *r;
231 > register RAY  *r;
232   {
233 <        register double  *vp;
233 >        register RREAL  *vp;
234 >        FVECT  v;
235          double  du2, dv2;
236          int  pi;
237  
238 +        clrpart(si->spt);
239 +        vp = source[si->sn].sloc;
240 +        v[0] = r->rorg[0] - vp[0];
241 +        v[1] = r->rorg[1] - vp[1];
242 +        v[2] = r->rorg[2] - vp[2];
243 +        vp = source[si->sn].snorm;
244 +        if (DOT(v,vp) <= 0.) {          /* behind source */
245 +                si->np = 0;
246 +                return;
247 +        }
248          dv2 = 2.*r->rweight/srcsizerat;
249          dv2 *= dv2;
250          vp = source[si->sn].ss[SU];
251          du2 = dv2 * DOT(vp,vp);
252          vp = source[si->sn].ss[SV];
253          dv2 *= DOT(vp,vp);
233        clrpart(si->spt);
254          pi = 0;
255          si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
256                  source[si->sn].sloc,
# Line 294 | Line 314 | scylform(sn, dir)              /* compute cosine for cylinder's pr
314   int  sn;
315   register FVECT  dir;            /* assume normalized */
316   {
317 <        register double  *dv;
317 >        register RREAL  *dv;
318          double  d;
319  
320          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines