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.1 by greg, Mon Oct 21 12:57:13 1991 UTC vs.
Revision 2.6 by greg, Wed Jul 20 12:48:44 1994 UTC

# Line 8 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   * Source sampling routines
9   */
10  
11 < #include  "standard.h"
11 > #include  "ray.h"
12  
13 #include  "object.h"
14
13   #include  "source.h"
14  
15   #include  "random.h"
16  
17  
18 < extern int  dimlist[];          /* dimension list for distribution */
21 < extern int  ndims;              /* number of dimensions so far */
22 < extern int  samplendx;          /* index for this sample */
18 > static int  cyl_partit(), flt_partit();
19  
20  
21   double
22 < nextssamp(org, dir, si)         /* compute sample for source, rtn. distance */
23 < FVECT  org, dir;                /* origin is read only, direction is set */
22 > nextssamp(r, si)                /* compute sample for source, rtn. distance */
23 > register RAY  *r;               /* origin is read, direction is set */
24   register SRCINDEX  *si;         /* source index (modified to current) */
25   {
26          int  cent[3], size[3], parr[2];
27          FVECT  vpos;
28          double  d;
29          register int  i;
30 < tryagain:
30 > nextsample:
31          while (++si->sp >= si->np) {    /* get next sample */
32                  if (++si->sn >= nsources)
33                          return(0.0);    /* no more */
34 <                if (srcsizerat <= FTINY)
35 <                        nopart(si, org);
34 >                if (source[si->sn].sflags & SSKIP)
35 >                        si->np = 0;
36 >                else if (srcsizerat <= FTINY)
37 >                        nopart(si, r);
38                  else {
39                          for (i = si->sn; source[i].sflags & SVIRTUAL;
40                                          i = source[i].sa.sv.sn)
41                                  ;               /* partition source */
42 <                        (*sfun[source[i].so->otype].of->partit)(si, org);
42 >                        (*sfun[source[i].so->otype].of->partit)(si, r);
43                  }
44                  si->sp = -1;
45          }
# Line 71 | Line 69 | tryagain:
69                  vpos[i] += (double)cent[i]/MAXSPART;
70                                          /* compute direction */
71          for (i = 0; i < 3; i++)
72 <                dir[i] = source[si->sn].sloc[i] +
72 >                r->rdir[i] = source[si->sn].sloc[i] +
73                                  vpos[SU]*source[si->sn].ss[SU][i] +
74                                  vpos[SV]*source[si->sn].ss[SV][i] +
75                                  vpos[SW]*source[si->sn].ss[SW][i];
76  
77          if (!(source[si->sn].sflags & SDISTANT))
78                  for (i = 0; i < 3; i++)
79 <                        dir[i] -= org[i];
79 >                        r->rdir[i] -= r->rorg[i];
80                                          /* compute distance */
81 <        if ((d = normalize(dir)) == 0.0)
82 <                goto tryagain;  /* at source! */
81 >        if ((d = normalize(r->rdir)) == 0.0)
82 >                goto nextsample;                /* at source! */
83  
84                                          /* compute sample size */
87        si->dom  = source[si->sn].ss2;
85          if (source[si->sn].sflags & SFLAT) {
86 <                si->dom *= sflatform(si->sn, dir);
87 <                if (si->dom <= FTINY) {         /* behind source */
91 <                        si->sp = si->np;
92 <                        goto tryagain;
93 <                }
94 <                si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
86 >                si->dom = sflatform(si->sn, r->rdir);
87 >                si->dom *= size[SU]*size[SV]/(MAXSPART*(double)MAXSPART);
88          } else if (source[si->sn].sflags & SCYL) {
89 <                si->dom *= scylform(si->sn, dir);
90 <                si->dom *= (double)size[SU]/MAXSPART;
89 >                si->dom = scylform(si->sn, r->rdir);
90 >                si->dom *= size[SU]/(double)MAXSPART;
91          } else {
92 <                si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
93 <                                (MAXSPART*MAXSPART*MAXSPART) ;
92 >                si->dom = size[SU]*size[SV]*(double)size[SW] /
93 >                                (MAXSPART*MAXSPART*(double)MAXSPART) ;
94          }
95 <        if (source[si->sn].sflags & SDISTANT)
95 >        if (source[si->sn].sflags & SDISTANT) {
96 >                si->dom *= source[si->sn].ss2;
97                  return(FHUGE);
98 <        si->dom /= d*d;
98 >        }
99 >        if (si->dom <= 1e-4)
100 >                goto nextsample;                /* behind source? */
101 >        si->dom *= source[si->sn].ss2/(d*d);
102          return(d);              /* sample OK, return distance */
103   }
104  
# Line 137 | Line 134 | unsigned char  *pt;            /* partition array */
134   }
135  
136  
137 < nopart(si, ro)                  /* single source partition */
137 > nopart(si, r)                   /* single source partition */
138   register SRCINDEX  *si;
139 < FVECT  ro;
139 > RAY  *r;
140   {
141          clrpart(si->spt);
142          setpart(si->spt, 0, S0);
# Line 147 | Line 144 | FVECT  ro;
144   }
145  
146  
147 < cylpart(si, ro)                 /* partition a cylinder */
147 > cylpart(si, r)                  /* partition a cylinder */
148   SRCINDEX  *si;
149 < FVECT  ro;
149 > register RAY  *r;
150   {
151          double  dist2, safedist2, dist2cent, rad2;
152          FVECT  v;
# Line 157 | Line 154 | FVECT  ro;
154          int  pi;
155                                          /* first check point location */
156          clrpart(si->spt);
157 <        sp = &source[si->sn];
158 <        rad2 = 1.273 * DOT(sp->ss[SV],sp->ss[SV]);
159 <        v[0] = ro[0] - sp->sloc[0];
160 <        v[1] = ro[1] - sp->sloc[1];
161 <        v[2] = ro[2] - sp->sloc[2];
157 >        sp = source + si->sn;
158 >        rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]);
159 >        v[0] = r->rorg[0] - sp->sloc[0];
160 >        v[1] = r->rorg[1] - sp->sloc[1];
161 >        v[2] = r->rorg[2] - sp->sloc[2];
162          dist2 = DOT(v,sp->ss[SU]);
163          safedist2 = DOT(sp->ss[SU],sp->ss[SU]);
164          dist2 *= dist2 / safedist2;
# Line 171 | Line 168 | FVECT  ro;
168                  si->np = 0;
169                  return;
170          }
171 <        safedist2 *= 4./(srcsizerat*srcsizerat);
172 <        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
173 <                        dist2cent >= safedist2) {
171 >        safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
172 >        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide */
173 >                        dist2cent >= safedist2) {       /* or too far */
174                  setpart(si->spt, 0, S0);
175                  si->np = 1;
176                  return;
177          }
178          pi = 0;
179 <        si->np = cyl_partit(ro, si->spt, &pi, MAXSPART,
179 >        si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART,
180                          sp->sloc, sp->ss[SU], safedist2);
181   }
182  
# Line 212 | Line 209 | double  d2;
209          newct[0] = cent[0] - newax[0];
210          newct[1] = cent[1] - newax[1];
211          newct[2] = cent[2] - newax[2];
212 <        npl = cyl_partit(ro, pt, pi, mp*3/4, newct, newax, d2);
212 >        npl = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2);
213                                          /* upper half */
214          newct[0] = cent[0] + newax[0];
215          newct[1] = cent[1] + newax[1];
216          newct[2] = cent[2] + newax[2];
217 <        npu = cyl_partit(ro, pt, pi, mp-npl, newct, newax, d2);
217 >        npu = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2);
218                                          /* return total */
219          return(npl + npu);
220   }
221  
222  
223 < flatpart(si, ro)                        /* partition a flat source */
223 > flatpart(si, r)                         /* partition a flat source */
224   register SRCINDEX  *si;
225 < FVECT  ro;
225 > register RAY  *r;
226   {
227 <        register double  *vp;
227 >        register FLOAT  *vp;
228 >        FVECT  v;
229          double  du2, dv2;
230          int  pi;
231  
232 +        clrpart(si->spt);
233 +        vp = source[si->sn].sloc;
234 +        v[0] = r->rorg[0] - vp[0];
235 +        v[1] = r->rorg[1] - vp[1];
236 +        v[2] = r->rorg[2] - vp[2];
237 +        vp = source[si->sn].snorm;
238 +        if (DOT(v,vp) <= FTINY) {       /* behind source */
239 +                si->np = 0;
240 +                return;
241 +        }
242 +        dv2 = 2.*r->rweight/srcsizerat;
243 +        dv2 *= dv2;
244          vp = source[si->sn].ss[SU];
245 <        du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
245 >        du2 = dv2 * DOT(vp,vp);
246          vp = source[si->sn].ss[SV];
247 <        dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
238 <        clrpart(si->spt);
247 >        dv2 *= DOT(vp,vp);
248          pi = 0;
249 <        si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc,
249 >        si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
250 >                source[si->sn].sloc,
251                  source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2);
252   }
253  
# Line 282 | Line 292 | double  du2, dv2;
292          newct[0] = cent[0] - newax[0];
293          newct[1] = cent[1] - newax[1];
294          newct[2] = cent[2] - newax[2];
295 <        npl = flt_partit(ro, pt, pi, mp*3/4, newct, u, v, du2, dv2);
295 >        npl = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2);
296                                          /* upper half */
297          newct[0] = cent[0] + newax[0];
298          newct[1] = cent[1] + newax[1];
299          newct[2] = cent[2] + newax[2];
300 <        npu = flt_partit(ro, pt, pi, mp-npl, newct, u, v, du2, dv2);
300 >        npu = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2);
301                                  /* return total */
302          return(npl + npu);
303   }
# Line 298 | Line 308 | scylform(sn, dir)              /* compute cosine for cylinder's pr
308   int  sn;
309   register FVECT  dir;            /* assume normalized */
310   {
311 <        register double  *dv;
311 >        register FLOAT  *dv;
312          double  d;
313  
314          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines