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.5 by greg, Mon Mar 8 12:37:39 1993 UTC vs.
Revision 2.14 by greg, Wed Dec 10 07:07:07 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 56 | 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 67 | 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) && (si->np > 1 || dstrsrc > 0.7)) {
73 +                FVECT   trim;
74 +                if (source[si->sn].sflags & (SFLAT|SDISTANT)) {
75 +                        d = 1.12837917;         /* correct setflatss() */
76 +                        trim[SU] = d*sqrt(1.0 - 0.5*vpos[SV]*vpos[SV]);
77 +                        trim[SV] = d*sqrt(1.0 - 0.5*vpos[SU]*vpos[SU]);
78 +                        trim[SW] = 0.0;
79 +                } else {
80 +                        trim[SW] = trim[SU] = vpos[SU]*vpos[SU];
81 +                        d = vpos[SV]*vpos[SV];
82 +                        if (d > trim[SW]) trim[SW] = d;
83 +                        trim[SU] += d;
84 +                        d = vpos[SW]*vpos[SW];
85 +                        if (d > trim[SW]) trim[SW] = d;
86 +                        trim[SU] += d;
87 +                        d = 1.0/0.7236;         /* correct sphsetsrc() */
88 +                        trim[SW] = trim[SV] = trim[SU] =
89 +                                        d*sqrt(trim[SW]/trim[SU]);
90 +                }
91 +                for (i = 0; i < 3; i++)
92 +                        vpos[i] *= trim[i];
93 +        }
94                                          /* compute direction */
95          for (i = 0; i < 3; i++)
96                  r->rdir[i] = source[si->sn].sloc[i] +
# Line 82 | Line 106 | nextsample:
106                  goto nextsample;                /* at source! */
107  
108                                          /* compute sample size */
85        si->dom  = source[si->sn].ss2;
109          if (source[si->sn].sflags & SFLAT) {
110 <                si->dom *= sflatform(si->sn, r->rdir);
110 >                si->dom = sflatform(si->sn, r->rdir);
111                  si->dom *= size[SU]*size[SV]/(MAXSPART*(double)MAXSPART);
112          } else if (source[si->sn].sflags & SCYL) {
113 <                si->dom *= scylform(si->sn, r->rdir);
113 >                si->dom = scylform(si->sn, r->rdir);
114                  si->dom *= size[SU]/(double)MAXSPART;
115          } else {
116 <                si->dom *= size[SU]*size[SV]*(double)size[SW] /
116 >                si->dom = size[SU]*size[SV]*(double)size[SW] /
117                                  (MAXSPART*MAXSPART*(double)MAXSPART) ;
118          }
119 <        if (source[si->sn].sflags & SDISTANT)
119 >        if (source[si->sn].sflags & SDISTANT) {
120 >                si->dom *= source[si->sn].ss2;
121                  return(FHUGE);
122 +        }
123          if (si->dom <= 1e-4)
124                  goto nextsample;                /* behind source? */
125 <        si->dom /= d*d;
125 >        si->dom *= source[si->sn].ss2/(d*d);
126          return(d);              /* sample OK, return distance */
127   }
128  
129  
130 + int
131   skipparts(ct, sz, pp, pt)               /* skip to requested partition */
132   int  ct[3], sz[3];              /* center and size of partition (returned) */
133   register int  pp[2];            /* current index, number to skip (modified) */
# Line 111 | Line 137 | unsigned char  *pt;            /* partition array */
137                                          /* check this partition */
138          p = spart(pt, pp[0]);
139          pp[0]++;
140 <        if (p == S0)                    /* leaf partition */
140 >        if (p == S0) {                  /* leaf partition */
141                  if (pp[1]) {
142                          pp[1]--;
143                          return(0);      /* not there yet */
144                  } else
145                          return(1);      /* we've arrived */
146 +        }
147                                  /* else check lower */
148          sz[p] >>= 1;
149          ct[p] -= sz[p];
# Line 133 | Line 160 | unsigned char  *pt;            /* partition array */
160   }
161  
162  
163 + void
164   nopart(si, r)                   /* single source partition */
165   register SRCINDEX  *si;
166   RAY  *r;
# Line 143 | Line 171 | RAY  *r;
171   }
172  
173  
174 + void
175   cylpart(si, r)                  /* partition a cylinder */
176   SRCINDEX  *si;
177   register RAY  *r;
# Line 219 | Line 248 | double  d2;
248   }
249  
250  
251 + void
252   flatpart(si, r)                         /* partition a flat source */
253   register SRCINDEX  *si;
254   register RAY  *r;
255   {
256 <        register FLOAT  *vp;
256 >        register RREAL  *vp;
257          FVECT  v;
258          double  du2, dv2;
259          int  pi;
# Line 234 | Line 264 | register RAY  *r;
264          v[1] = r->rorg[1] - vp[1];
265          v[2] = r->rorg[2] - vp[2];
266          vp = source[si->sn].snorm;
267 <        if (DOT(v,vp) <= FTINY) {       /* behind source */
267 >        if (DOT(v,vp) <= 0.) {          /* behind source */
268                  si->np = 0;
269                  return;
270          }
# Line 307 | Line 337 | scylform(sn, dir)              /* compute cosine for cylinder's pr
337   int  sn;
338   register FVECT  dir;            /* assume normalized */
339   {
340 <        register FLOAT  *dv;
340 >        register RREAL  *dv;
341          double  d;
342  
343          dv = source[sn].ss[SU];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines