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.3 by greg, Tue Oct 22 11:23:55 1991 UTC vs.
Revision 2.1 by greg, Tue Nov 12 17:10:39 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);
31 >                if (source[si->sn].sflags & SSKIP)
32 >                        si->np = 0;
33 >                else if (srcsizerat <= FTINY)
34 >                        nopart(si, r);
35                  else {
36                          for (i = si->sn; source[i].sflags & SVIRTUAL;
37                                          i = source[i].sa.sv.sn)
38                                  ;               /* partition source */
39 <                        (*sfun[source[i].so->otype].of->partit)(si, org);
39 >                        (*sfun[source[i].so->otype].of->partit)(si, r);
40                  }
41                  si->sp = -1;
42          }
# Line 71 | Line 66 | tryagain:
66                  vpos[i] += (double)cent[i]/MAXSPART;
67                                          /* compute direction */
68          for (i = 0; i < 3; i++)
69 <                dir[i] = source[si->sn].sloc[i] +
69 >                r->rdir[i] = source[si->sn].sloc[i] +
70                                  vpos[SU]*source[si->sn].ss[SU][i] +
71                                  vpos[SV]*source[si->sn].ss[SV][i] +
72                                  vpos[SW]*source[si->sn].ss[SW][i];
73  
74          if (!(source[si->sn].sflags & SDISTANT))
75                  for (i = 0; i < 3; i++)
76 <                        dir[i] -= org[i];
76 >                        r->rdir[i] -= r->rorg[i];
77                                          /* compute distance */
78 <        if ((d = normalize(dir)) == 0.0)
79 <                goto tryagain;  /* at source! */
78 >        if ((d = normalize(r->rdir)) == 0.0)
79 >                return(nextssamp(r, si));       /* at source! */
80  
81                                          /* compute sample size */
82          si->dom  = source[si->sn].ss2;
83          if (source[si->sn].sflags & SFLAT) {
84 <                si->dom *= sflatform(si->sn, dir);
90 <                if (si->dom <= FTINY) {         /* behind source */
91 <                        si->np = 0;
92 <                        goto tryagain;
93 <                }
84 >                si->dom *= sflatform(si->sn, r->rdir);
85                  si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
86          } else if (source[si->sn].sflags & SCYL) {
87 <                si->dom *= scylform(si->sn, dir);
87 >                si->dom *= scylform(si->sn, r->rdir);
88                  si->dom *= (double)size[SU]/MAXSPART;
89          } else {
90                  si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
# Line 137 | Line 128 | unsigned char  *pt;            /* partition array */
128   }
129  
130  
131 < nopart(si, ro)                  /* single source partition */
131 > nopart(si, r)                   /* single source partition */
132   register SRCINDEX  *si;
133 < FVECT  ro;
133 > RAY  *r;
134   {
135          clrpart(si->spt);
136          setpart(si->spt, 0, S0);
# Line 147 | Line 138 | FVECT  ro;
138   }
139  
140  
141 < cylpart(si, ro)                 /* partition a cylinder */
141 > cylpart(si, r)                  /* partition a cylinder */
142   SRCINDEX  *si;
143 < FVECT  ro;
143 > register RAY  *r;
144   {
145          double  dist2, safedist2, dist2cent, rad2;
146          FVECT  v;
# Line 157 | Line 148 | FVECT  ro;
148          int  pi;
149                                          /* first check point location */
150          clrpart(si->spt);
151 <        sp = &source[si->sn];
151 >        sp = source + si->sn;
152          rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]);
153 <        v[0] = ro[0] - sp->sloc[0];
154 <        v[1] = ro[1] - sp->sloc[1];
155 <        v[2] = ro[2] - sp->sloc[2];
153 >        v[0] = r->rorg[0] - sp->sloc[0];
154 >        v[1] = r->rorg[1] - sp->sloc[1];
155 >        v[2] = r->rorg[2] - sp->sloc[2];
156          dist2 = DOT(v,sp->ss[SU]);
157          safedist2 = DOT(sp->ss[SU],sp->ss[SU]);
158          dist2 *= dist2 / safedist2;
# Line 171 | Line 162 | FVECT  ro;
162                  si->np = 0;
163                  return;
164          }
165 <        safedist2 *= 4./(srcsizerat*srcsizerat);
166 <        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
167 <                        dist2cent >= safedist2) {
165 >        safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
166 >        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide */
167 >                        dist2cent >= safedist2) {       /* or too far */
168                  setpart(si->spt, 0, S0);
169                  si->np = 1;
170                  return;
171          }
172          pi = 0;
173 <        si->np = cyl_partit(ro, si->spt, &pi, MAXSPART,
173 >        si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART,
174                          sp->sloc, sp->ss[SU], safedist2);
175   }
176  
# Line 223 | Line 214 | double  d2;
214   }
215  
216  
217 < flatpart(si, ro)                        /* partition a flat source */
217 > flatpart(si, r)                         /* partition a flat source */
218   register SRCINDEX  *si;
219 < FVECT  ro;
219 > register RAY  *r;
220   {
221 <        register double  *vp;
221 >        register FLOAT  *vp;
222 >        FVECT  v;
223          double  du2, dv2;
224          int  pi;
225  
226 +        clrpart(si->spt);
227 +        vp = source[si->sn].sloc;
228 +        v[0] = r->rorg[0] - vp[0];
229 +        v[1] = r->rorg[1] - vp[1];
230 +        v[2] = r->rorg[2] - vp[2];
231 +        vp = source[si->sn].snorm;
232 +        if (DOT(v,vp) <= FTINY) {       /* behind source */
233 +                si->np = 0;
234 +                return;
235 +        }
236 +        dv2 = 2.*r->rweight/srcsizerat;
237 +        dv2 *= dv2;
238          vp = source[si->sn].ss[SU];
239 <        du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
239 >        du2 = dv2 * DOT(vp,vp);
240          vp = source[si->sn].ss[SV];
241 <        dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
238 <        clrpart(si->spt);
241 >        dv2 *= DOT(vp,vp);
242          pi = 0;
243 <        si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc,
243 >        si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
244 >                source[si->sn].sloc,
245                  source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2);
246   }
247  
# Line 298 | Line 302 | scylform(sn, dir)              /* compute cosine for cylinder's pr
302   int  sn;
303   register FVECT  dir;            /* assume normalized */
304   {
305 <        register double  *dv;
305 >        register FLOAT  *dv;
306          double  d;
307  
308          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines