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 2.3 by greg, Tue Jul 21 12:47:12 1992 UTC vs.
Revision 2.12 by greg, Sat Dec 6 01:08:53 2008 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 "copyright.h"
11 +
12   #include  "ray.h"
13  
14   #include  "source.h"
# Line 15 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   #include  "random.h"
17  
18  
19 + static int  cyl_partit(), flt_partit();
20 +
21 +
22   double
23   nextssamp(r, si)                /* compute sample for source, rtn. distance */
24   register RAY  *r;               /* origin is read, direction is set */
# Line 53 | Line 57 | nextsample:
57                  d = urand(ilhash(dimlist,ndims+2)+samplendx);
58                  if (source[si->sn].sflags & SFLAT) {
59                          multisamp(vpos, 2, d);
60 <                        vpos[2] = 0.5;
60 >                        vpos[SW] = 0.5;
61                  } else
62                          multisamp(vpos, 3, d);
63                  for (i = 0; i < 3; i++)
# Line 64 | Line 68 | nextsample:
68  
69          for (i = 0; i < 3; i++)
70                  vpos[i] += (double)cent[i]/MAXSPART;
71 +                                        /* avoid circular aiming failures */
72 +        if (source[si->sn].sflags & SCIR) {
73 +                FVECT   trim;
74 +                double  d;
75 +                if (source[si->sn].sflags & (SFLAT|SDISTANT)) {
76 +                        d = 1.12837917;         /* correct setflatss() */
77 +                        trim[SU] = d*sqrt(1.0 - 0.5*vpos[SV]*vpos[SV]);
78 +                        trim[SV] = d*sqrt(1.0 - 0.5*vpos[SU]*vpos[SU]);
79 +                        trim[SW] = 0.0;
80 +                } else {
81 +                        trim[SW] = trim[SU] = vpos[SU]*vpos[SU];
82 +                        d = vpos[SV]*vpos[SV];
83 +                        if (d > trim[SW]) trim[SW] = d;
84 +                        trim[SU] += d;
85 +                        d = vpos[SW]*vpos[SW];
86 +                        if (d > trim[SW]) trim[SW] = d;
87 +                        trim[SU] += d;
88 +                        d = 1.0/0.7236;         /* correct sphsetsrc() */
89 +                        trim[SW] = trim[SV] = trim[SU] =
90 +                                        d*sqrt(trim[SW]/trim[SU]);
91 +                }
92 +                for (i = 0; i < 3; i++)
93 +                        vpos[i] *= trim[i];
94 +        }
95                                          /* compute direction */
96          for (i = 0; i < 3; i++)
97                  r->rdir[i] = source[si->sn].sloc[i] +
# Line 79 | Line 107 | nextsample:
107                  goto nextsample;                /* at source! */
108  
109                                          /* compute sample size */
82        si->dom  = source[si->sn].ss2;
110          if (source[si->sn].sflags & SFLAT) {
111 <                si->dom *= sflatform(si->sn, r->rdir);
112 <                si->dom *= (double)(size[SU]*size[SV])/(MAXSPART*MAXSPART);
111 >                si->dom = sflatform(si->sn, r->rdir);
112 >                si->dom *= size[SU]*size[SV]/(MAXSPART*(double)MAXSPART);
113          } else if (source[si->sn].sflags & SCYL) {
114 <                si->dom *= scylform(si->sn, r->rdir);
115 <                si->dom *= (double)size[SU]/MAXSPART;
114 >                si->dom = scylform(si->sn, r->rdir);
115 >                si->dom *= size[SU]/(double)MAXSPART;
116          } else {
117 <                si->dom *= (double)(size[SU]*size[SV]*size[SW]) /
118 <                                (MAXSPART*MAXSPART*MAXSPART) ;
117 >                si->dom = size[SU]*size[SV]*(double)size[SW] /
118 >                                (MAXSPART*MAXSPART*(double)MAXSPART) ;
119          }
120 <        if (source[si->sn].sflags & SDISTANT)
120 >        if (source[si->sn].sflags & SDISTANT) {
121 >                si->dom *= source[si->sn].ss2;
122                  return(FHUGE);
123 +        }
124          if (si->dom <= 1e-4)
125                  goto nextsample;                /* behind source? */
126 <        si->dom /= d*d;
126 >        si->dom *= source[si->sn].ss2/(d*d);
127          return(d);              /* sample OK, return distance */
128   }
129  
130  
131 + int
132   skipparts(ct, sz, pp, pt)               /* skip to requested partition */
133   int  ct[3], sz[3];              /* center and size of partition (returned) */
134   register int  pp[2];            /* current index, number to skip (modified) */
# Line 108 | Line 138 | unsigned char  *pt;            /* partition array */
138                                          /* check this partition */
139          p = spart(pt, pp[0]);
140          pp[0]++;
141 <        if (p == S0)                    /* leaf partition */
141 >        if (p == S0) {                  /* leaf partition */
142                  if (pp[1]) {
143                          pp[1]--;
144                          return(0);      /* not there yet */
145                  } else
146                          return(1);      /* we've arrived */
147 +        }
148                                  /* else check lower */
149          sz[p] >>= 1;
150          ct[p] -= sz[p];
# Line 130 | Line 161 | unsigned char  *pt;            /* partition array */
161   }
162  
163  
164 + void
165   nopart(si, r)                   /* single source partition */
166   register SRCINDEX  *si;
167   RAY  *r;
# Line 140 | Line 172 | RAY  *r;
172   }
173  
174  
175 + void
176   cylpart(si, r)                  /* partition a cylinder */
177   SRCINDEX  *si;
178   register RAY  *r;
# Line 216 | Line 249 | double  d2;
249   }
250  
251  
252 + void
253   flatpart(si, r)                         /* partition a flat source */
254   register SRCINDEX  *si;
255   register RAY  *r;
256   {
257 <        register FLOAT  *vp;
257 >        register RREAL  *vp;
258          FVECT  v;
259          double  du2, dv2;
260          int  pi;
# Line 231 | Line 265 | register RAY  *r;
265          v[1] = r->rorg[1] - vp[1];
266          v[2] = r->rorg[2] - vp[2];
267          vp = source[si->sn].snorm;
268 <        if (DOT(v,vp) <= FTINY) {       /* behind source */
268 >        if (DOT(v,vp) <= 0.) {          /* behind source */
269                  si->np = 0;
270                  return;
271          }
# Line 304 | Line 338 | scylform(sn, dir)              /* compute cosine for cylinder's pr
338   int  sn;
339   register FVECT  dir;            /* assume normalized */
340   {
341 <        register FLOAT  *dv;
341 >        register RREAL  *dv;
342          double  d;
343  
344          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines