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 1.4 by greg, Tue Oct 22 15:45:21 1991 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  
20 extern int  dimlist[];          /* dimension list for distribution */
21 extern int  ndims;              /* number of dimensions so far */
22 extern int  samplendx;          /* index for this sample */
23
24
18   double
19 < nextssamp(org, dir, si)         /* compute sample for source, rtn. distance */
20 < FVECT  org, dir;                /* origin is read only, direction is set */
19 > nextssamp(r, si)                /* compute sample for source, rtn. distance */
20 > register RAY  *r;               /* origin is read, direction is set */
21   register SRCINDEX  *si;         /* source index (modified to current) */
22   {
23          int  cent[3], size[3], parr[2];
# Line 36 | Line 29 | tryagain:
29                  if (++si->sn >= nsources)
30                          return(0.0);    /* no more */
31                  if (srcsizerat <= FTINY)
32 <                        nopart(si, org);
32 >                        nopart(si, r);
33                  else {
34                          for (i = si->sn; source[i].sflags & SVIRTUAL;
35                                          i = source[i].sa.sv.sn)
36                                  ;               /* partition source */
37 <                        (*sfun[source[i].so->otype].of->partit)(si, org);
37 >                        (*sfun[source[i].so->otype].of->partit)(si, r);
38                  }
39                  si->sp = -1;
40          }
# Line 71 | Line 64 | tryagain:
64                  vpos[i] += (double)cent[i]/MAXSPART;
65                                          /* compute direction */
66          for (i = 0; i < 3; i++)
67 <                dir[i] = source[si->sn].sloc[i] +
67 >                r->rdir[i] = source[si->sn].sloc[i] +
68                                  vpos[SU]*source[si->sn].ss[SU][i] +
69                                  vpos[SV]*source[si->sn].ss[SV][i] +
70                                  vpos[SW]*source[si->sn].ss[SW][i];
71  
72          if (!(source[si->sn].sflags & SDISTANT))
73                  for (i = 0; i < 3; i++)
74 <                        dir[i] -= org[i];
74 >                        r->rdir[i] -= r->rorg[i];
75                                          /* compute distance */
76 <        if ((d = normalize(dir)) == 0.0)
76 >        if ((d = normalize(r->rdir)) == 0.0)
77                  goto tryagain;  /* at source! */
78  
79                                          /* compute sample size */
80          si->dom  = source[si->sn].ss2;
81          if (source[si->sn].sflags & SFLAT) {
82 <                si->dom *= sflatform(si->sn, dir);
82 >                si->dom *= sflatform(si->sn, r->rdir);
83                  if (si->dom <= FTINY) {         /* behind source */
84 <                        si->sp = si->np;
84 >                        si->np = 0;
85                          goto tryagain;
86                  }
87                  si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
88          } else if (source[si->sn].sflags & SCYL) {
89 <                si->dom *= scylform(si->sn, dir);
89 >                si->dom *= scylform(si->sn, r->rdir);
90                  si->dom *= (double)size[SU]/MAXSPART;
91          } else {
92                  si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
# Line 137 | Line 130 | unsigned char  *pt;            /* partition array */
130   }
131  
132  
133 < nopart(si, ro)                  /* single source partition */
133 > nopart(si, r)                   /* single source partition */
134   register SRCINDEX  *si;
135 < FVECT  ro;
135 > RAY  *r;
136   {
137          clrpart(si->spt);
138          setpart(si->spt, 0, S0);
# Line 147 | Line 140 | FVECT  ro;
140   }
141  
142  
143 < cylpart(si, ro)                 /* partition a cylinder */
143 > cylpart(si, r)                  /* partition a cylinder */
144   SRCINDEX  *si;
145 < FVECT  ro;
145 > register RAY  *r;
146   {
147          double  dist2, safedist2, dist2cent, rad2;
148          FVECT  v;
# Line 157 | Line 150 | FVECT  ro;
150          int  pi;
151                                          /* first check point location */
152          clrpart(si->spt);
153 <        sp = &source[si->sn];
154 <        rad2 = 1.273 * DOT(sp->ss[SV],sp->ss[SV]);
155 <        v[0] = ro[0] - sp->sloc[0];
156 <        v[1] = ro[1] - sp->sloc[1];
157 <        v[2] = ro[2] - sp->sloc[2];
153 >        sp = source + si->sn;
154 >        rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]);
155 >        v[0] = r->rorg[0] - sp->sloc[0];
156 >        v[1] = r->rorg[1] - sp->sloc[1];
157 >        v[2] = r->rorg[2] - sp->sloc[2];
158          dist2 = DOT(v,sp->ss[SU]);
159          safedist2 = DOT(sp->ss[SU],sp->ss[SU]);
160          dist2 *= dist2 / safedist2;
# Line 171 | Line 164 | FVECT  ro;
164                  si->np = 0;
165                  return;
166          }
167 <        safedist2 *= 4./(srcsizerat*srcsizerat);
167 >        safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
168          if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
169 <                        dist2cent >= safedist2) {
169 >                        dist2cent >= safedist2) {       /* too far? */
170                  setpart(si->spt, 0, S0);
171                  si->np = 1;
172                  return;
173          }
174          pi = 0;
175 <        si->np = cyl_partit(ro, si->spt, &pi, MAXSPART,
175 >        si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART,
176                          sp->sloc, sp->ss[SU], safedist2);
177   }
178  
# Line 212 | Line 205 | double  d2;
205          newct[0] = cent[0] - newax[0];
206          newct[1] = cent[1] - newax[1];
207          newct[2] = cent[2] - newax[2];
208 <        npl = cyl_partit(ro, pt, pi, mp*3/4, newct, newax, d2);
208 >        npl = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2);
209                                          /* upper half */
210          newct[0] = cent[0] + newax[0];
211          newct[1] = cent[1] + newax[1];
212          newct[2] = cent[2] + newax[2];
213 <        npu = cyl_partit(ro, pt, pi, mp-npl, newct, newax, d2);
213 >        npu = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2);
214                                          /* return total */
215          return(npl + npu);
216   }
217  
218  
219 < flatpart(si, ro)                        /* partition a flat source */
219 > flatpart(si, r)                         /* partition a flat source */
220   register SRCINDEX  *si;
221 < FVECT  ro;
221 > RAY  *r;
222   {
223          register double  *vp;
224          double  du2, dv2;
225          int  pi;
226  
227 +        dv2 = 2.*r->rweight/srcsizerat;
228 +        dv2 *= dv2;
229          vp = source[si->sn].ss[SU];
230 <        du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
230 >        du2 = dv2 * DOT(vp,vp);
231          vp = source[si->sn].ss[SV];
232 <        dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
232 >        dv2 *= DOT(vp,vp);
233          clrpart(si->spt);
234          pi = 0;
235 <        si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc,
235 >        si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
236 >                source[si->sn].sloc,
237                  source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2);
238   }
239  
# Line 282 | Line 278 | double  du2, dv2;
278          newct[0] = cent[0] - newax[0];
279          newct[1] = cent[1] - newax[1];
280          newct[2] = cent[2] - newax[2];
281 <        npl = flt_partit(ro, pt, pi, mp*3/4, newct, u, v, du2, dv2);
281 >        npl = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2);
282                                          /* upper half */
283          newct[0] = cent[0] + newax[0];
284          newct[1] = cent[1] + newax[1];
285          newct[2] = cent[2] + newax[2];
286 <        npu = flt_partit(ro, pt, pi, mp-npl, newct, u, v, du2, dv2);
286 >        npu = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2);
287                                  /* return total */
288          return(npl + npu);
289   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines