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 2.8 by greg, Tue Feb 25 02:47:23 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  "standard.h"
10 > #include "copyright.h"
11  
12 < #include  "object.h"
12 > #include  "ray.h"
13  
14   #include  "source.h"
15  
16   #include  "random.h"
17  
18  
19 < extern int  dimlist[];          /* dimension list for distribution */
21 < extern int  ndims;              /* number of dimensions so far */
22 < extern int  samplendx;          /* index for this sample */
19 > static int  cyl_partit(), flt_partit();
20  
21  
22   double
23 < nextssamp(org, dir, si)         /* compute sample for source, rtn. distance */
24 < FVECT  org, dir;                /* origin is read only, direction is set */
23 > nextssamp(r, si)                /* compute sample for source, rtn. distance */
24 > register RAY  *r;               /* origin is read, direction is set */
25   register SRCINDEX  *si;         /* source index (modified to current) */
26   {
27          int  cent[3], size[3], parr[2];
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)
36 <                        nopart(si, org);
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;
41                                          i = source[i].sa.sv.sn)
42                                  ;               /* partition source */
43 <                        (*sfun[source[i].so->otype].of->partit)(si, org);
43 >                        (*sfun[source[i].so->otype].of->partit)(si, r);
44                  }
45                  si->sp = -1;
46          }
# Line 71 | Line 70 | tryagain:
70                  vpos[i] += (double)cent[i]/MAXSPART;
71                                          /* compute direction */
72          for (i = 0; i < 3; i++)
73 <                dir[i] = source[si->sn].sloc[i] +
73 >                r->rdir[i] = source[si->sn].sloc[i] +
74                                  vpos[SU]*source[si->sn].ss[SU][i] +
75                                  vpos[SV]*source[si->sn].ss[SV][i] +
76                                  vpos[SW]*source[si->sn].ss[SW][i];
77  
78          if (!(source[si->sn].sflags & SDISTANT))
79                  for (i = 0; i < 3; i++)
80 <                        dir[i] -= org[i];
80 >                        r->rdir[i] -= r->rorg[i];
81                                          /* compute distance */
82 <        if ((d = normalize(dir)) == 0.0)
83 <                goto tryagain;  /* at source! */
82 >        if ((d = normalize(r->rdir)) == 0.0)
83 >                goto nextsample;                /* at source! */
84  
85                                          /* compute sample size */
87        si->dom  = source[si->sn].ss2;
86          if (source[si->sn].sflags & SFLAT) {
87 <                si->dom *= sflatform(si->sn, dir);
88 <                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);
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, dir);
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 137 | Line 136 | unsigned char  *pt;            /* partition array */
136   }
137  
138  
139 < nopart(si, ro)                  /* single source partition */
139 > void
140 > nopart(si, r)                   /* single source partition */
141   register SRCINDEX  *si;
142 < FVECT  ro;
142 > RAY  *r;
143   {
144          clrpart(si->spt);
145          setpart(si->spt, 0, S0);
# Line 147 | Line 147 | FVECT  ro;
147   }
148  
149  
150 < cylpart(si, ro)                 /* partition a cylinder */
150 > void
151 > cylpart(si, r)                  /* partition a cylinder */
152   SRCINDEX  *si;
153 < FVECT  ro;
153 > register RAY  *r;
154   {
155          double  dist2, safedist2, dist2cent, rad2;
156          FVECT  v;
# Line 157 | Line 158 | FVECT  ro;
158          int  pi;
159                                          /* first check point location */
160          clrpart(si->spt);
161 <        sp = &source[si->sn];
162 <        rad2 = 1.273 * DOT(sp->ss[SV],sp->ss[SV]);
163 <        v[0] = ro[0] - sp->sloc[0];
164 <        v[1] = ro[1] - sp->sloc[1];
165 <        v[2] = ro[2] - sp->sloc[2];
161 >        sp = source + si->sn;
162 >        rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]);
163 >        v[0] = r->rorg[0] - sp->sloc[0];
164 >        v[1] = r->rorg[1] - sp->sloc[1];
165 >        v[2] = r->rorg[2] - sp->sloc[2];
166          dist2 = DOT(v,sp->ss[SU]);
167          safedist2 = DOT(sp->ss[SU],sp->ss[SU]);
168          dist2 *= dist2 / safedist2;
# Line 171 | Line 172 | FVECT  ro;
172                  si->np = 0;
173                  return;
174          }
175 <        safedist2 *= 4./(srcsizerat*srcsizerat);
176 <        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide? */
177 <                        dist2cent >= safedist2) {
175 >        safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat);
176 >        if (dist2 <= 4.*rad2 ||         /* point too close to subdivide */
177 >                        dist2cent >= safedist2) {       /* or too far */
178                  setpart(si->spt, 0, S0);
179                  si->np = 1;
180                  return;
181          }
182          pi = 0;
183 <        si->np = cyl_partit(ro, si->spt, &pi, MAXSPART,
183 >        si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART,
184                          sp->sloc, sp->ss[SU], safedist2);
185   }
186  
# Line 223 | Line 224 | double  d2;
224   }
225  
226  
227 < flatpart(si, ro)                        /* partition a flat source */
227 > void
228 > flatpart(si, r)                         /* partition a flat source */
229   register SRCINDEX  *si;
230 < FVECT  ro;
230 > register RAY  *r;
231   {
232 <        register double  *vp;
232 >        register FLOAT  *vp;
233 >        FVECT  v;
234          double  du2, dv2;
235          int  pi;
236  
237 +        clrpart(si->spt);
238 +        vp = source[si->sn].sloc;
239 +        v[0] = r->rorg[0] - vp[0];
240 +        v[1] = r->rorg[1] - vp[1];
241 +        v[2] = r->rorg[2] - vp[2];
242 +        vp = source[si->sn].snorm;
243 +        if (DOT(v,vp) <= FTINY) {       /* behind source */
244 +                si->np = 0;
245 +                return;
246 +        }
247 +        dv2 = 2.*r->rweight/srcsizerat;
248 +        dv2 *= dv2;
249          vp = source[si->sn].ss[SU];
250 <        du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
250 >        du2 = dv2 * DOT(vp,vp);
251          vp = source[si->sn].ss[SV];
252 <        dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp);
238 <        clrpart(si->spt);
252 >        dv2 *= DOT(vp,vp);
253          pi = 0;
254 <        si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc,
254 >        si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART,
255 >                source[si->sn].sloc,
256                  source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2);
257   }
258  
# Line 298 | Line 313 | scylform(sn, dir)              /* compute cosine for cylinder's pr
313   int  sn;
314   register FVECT  dir;            /* assume normalized */
315   {
316 <        register double  *dv;
316 >        register FLOAT  *dv;
317          double  d;
318  
319          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines