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.2 by greg, Mon Oct 21 14:27:36 1991 UTC vs.
Revision 1.5 by greg, Wed Oct 23 08:50:06 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];
24          FVECT  vpos;
25          double  d;
26          register int  i;
27 < tryagain:
27 >
28          while (++si->sp >= si->np) {    /* get next sample */
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)
77 <                goto tryagain;  /* at source! */
76 >        if ((d = normalize(r->rdir)) == 0.0)
77 >                return(nextssamp(r, si));       /* 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);
90 <                if (si->dom <= FTINY) {         /* behind source */
91 <                        si->sp = si->np;
92 <                        goto tryagain;
93 <                }
82 >                si->dom *= sflatform(si->sn, r->rdir);
83                  si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
84          } else if (source[si->sn].sflags & SCYL) {
85 <                si->dom *= scylform(si->sn, dir);
85 >                si->dom *= scylform(si->sn, r->rdir);
86                  si->dom *= (double)size[SU]/MAXSPART;
87          } else {
88                  si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
# Line 137 | Line 126 | unsigned char  *pt;            /* partition array */
126   }
127  
128  
129 < nopart(si, ro)                  /* single source partition */
129 > nopart(si, r)                   /* single source partition */
130   register SRCINDEX  *si;
131 < FVECT  ro;
131 > RAY  *r;
132   {
133          clrpart(si->spt);
134          setpart(si->spt, 0, S0);
# Line 147 | Line 136 | FVECT  ro;
136   }
137  
138  
139 < cylpart(si, ro)                 /* partition a cylinder */
139 > cylpart(si, r)                  /* partition a cylinder */
140   SRCINDEX  *si;
141 < FVECT  ro;
141 > register RAY  *r;
142   {
143          double  dist2, safedist2, dist2cent, rad2;
144          FVECT  v;
# Line 157 | Line 146 | FVECT  ro;
146          int  pi;
147                                          /* first check point location */
148          clrpart(si->spt);
149 <        sp = &source[si->sn];
150 <        rad2 = 1.273 * DOT(sp->ss[SV],sp->ss[SV]);
151 <        v[0] = ro[0] - sp->sloc[0];
152 <        v[1] = ro[1] - sp->sloc[1];
153 <        v[2] = ro[2] - sp->sloc[2];
149 >        sp = source + si->sn;
150 >        rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]);
151 >        v[0] = r->rorg[0] - sp->sloc[0];
152 >        v[1] = r->rorg[1] - sp->sloc[1];
153 >        v[2] = r->rorg[2] - sp->sloc[2];
154          dist2 = DOT(v,sp->ss[SU]);
155          safedist2 = DOT(sp->ss[SU],sp->ss[SU]);
156          dist2 *= dist2 / safedist2;
# Line 171 | Line 160 | FVECT  ro;
160                  si->np = 0;
161                  return;
162          }
163 <        safedist2 *= 4./(srcsizerat*srcsizerat);
164 <        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
165 <                        dist2cent >= safedist2) {
163 >        safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
164 >        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide */
165 >                        dist2cent >= safedist2) {       /* or too far */
166                  setpart(si->spt, 0, S0);
167                  si->np = 1;
168                  return;
169          }
170          pi = 0;
171 <        si->np = cyl_partit(ro, si->spt, &pi, MAXSPART,
171 >        si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART,
172                          sp->sloc, sp->ss[SU], safedist2);
173   }
174  
# Line 223 | Line 212 | double  d2;
212   }
213  
214  
215 < flatpart(si, ro)                        /* partition a flat source */
215 > flatpart(si, r)                         /* partition a flat source */
216   register SRCINDEX  *si;
217 < FVECT  ro;
217 > register RAY  *r;
218   {
219          register double  *vp;
220 +        FVECT  v;
221          double  du2, dv2;
222          int  pi;
223  
224 +        clrpart(si->spt);
225 +        vp = source[si->sn].sloc;
226 +        v[0] = r->rorg[0] - vp[0];
227 +        v[1] = r->rorg[1] - vp[1];
228 +        v[2] = r->rorg[2] - vp[2];
229 +        vp = source[si->sn].snorm;
230 +        if (DOT(v,vp) <= FTINY) {       /* behind source */
231 +                si->np = 0;
232 +                return;
233 +        }
234 +        dv2 = 2.*r->rweight/srcsizerat;
235 +        dv2 *= dv2;
236          vp = source[si->sn].ss[SU];
237 <        du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
237 >        du2 = dv2 * DOT(vp,vp);
238          vp = source[si->sn].ss[SV];
239 <        dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
238 <        clrpart(si->spt);
239 >        dv2 *= DOT(vp,vp);
240          pi = 0;
241 <        si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc,
241 >        si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
242 >                source[si->sn].sloc,
243                  source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2);
244   }
245  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines