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 |
> |
/* ==================================================================== |
11 |
> |
* The Radiance Software License, Version 1.0 |
12 |
> |
* |
13 |
> |
* Copyright (c) 1990 - 2002 The Regents of the University of California, |
14 |
> |
* through Lawrence Berkeley National Laboratory. All rights reserved. |
15 |
> |
* |
16 |
> |
* Redistribution and use in source and binary forms, with or without |
17 |
> |
* modification, are permitted provided that the following conditions |
18 |
> |
* are met: |
19 |
> |
* |
20 |
> |
* 1. Redistributions of source code must retain the above copyright |
21 |
> |
* notice, this list of conditions and the following disclaimer. |
22 |
> |
* |
23 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
24 |
> |
* notice, this list of conditions and the following disclaimer in |
25 |
> |
* the documentation and/or other materials provided with the |
26 |
> |
* distribution. |
27 |
> |
* |
28 |
> |
* 3. The end-user documentation included with the redistribution, |
29 |
> |
* if any, must include the following acknowledgment: |
30 |
> |
* "This product includes Radiance software |
31 |
> |
* (http://radsite.lbl.gov/) |
32 |
> |
* developed by the Lawrence Berkeley National Laboratory |
33 |
> |
* (http://www.lbl.gov/)." |
34 |
> |
* Alternately, this acknowledgment may appear in the software itself, |
35 |
> |
* if and wherever such third-party acknowledgments normally appear. |
36 |
> |
* |
37 |
> |
* 4. The names "Radiance," "Lawrence Berkeley National Laboratory" |
38 |
> |
* and "The Regents of the University of California" must |
39 |
> |
* not be used to endorse or promote products derived from this |
40 |
> |
* software without prior written permission. For written |
41 |
> |
* permission, please contact [email protected]. |
42 |
> |
* |
43 |
> |
* 5. Products derived from this software may not be called "Radiance", |
44 |
> |
* nor may "Radiance" appear in their name, without prior written |
45 |
> |
* permission of Lawrence Berkeley National Laboratory. |
46 |
> |
* |
47 |
> |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
48 |
> |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 |
> |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
50 |
> |
* DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR |
51 |
> |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
52 |
> |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
53 |
> |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
54 |
> |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
55 |
> |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
56 |
> |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
57 |
> |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 |
> |
* SUCH DAMAGE. |
59 |
> |
* ==================================================================== |
60 |
> |
* |
61 |
> |
* This software consists of voluntary contributions made by many |
62 |
> |
* individuals on behalf of Lawrence Berkeley National Laboratory. For more |
63 |
> |
* information on Lawrence Berkeley National Laboratory, please see |
64 |
> |
* <http://www.lbl.gov/>. |
65 |
> |
*/ |
66 |
|
|
67 |
< |
#include "object.h" |
67 |
> |
#include "ray.h" |
68 |
|
|
69 |
|
#include "source.h" |
70 |
|
|
71 |
|
#include "random.h" |
72 |
|
|
73 |
|
|
74 |
< |
extern int dimlist[]; /* dimension list for distribution */ |
21 |
< |
extern int ndims; /* number of dimensions so far */ |
22 |
< |
extern int samplendx; /* index for this sample */ |
74 |
> |
static int cyl_partit(), flt_partit(); |
75 |
|
|
76 |
|
|
77 |
|
double |
78 |
< |
nextssamp(org, dir, si) /* compute sample for source, rtn. distance */ |
79 |
< |
FVECT org, dir; /* origin is read only, direction is set */ |
78 |
> |
nextssamp(r, si) /* compute sample for source, rtn. distance */ |
79 |
> |
register RAY *r; /* origin is read, direction is set */ |
80 |
|
register SRCINDEX *si; /* source index (modified to current) */ |
81 |
|
{ |
82 |
|
int cent[3], size[3], parr[2]; |
83 |
|
FVECT vpos; |
84 |
|
double d; |
85 |
|
register int i; |
86 |
< |
tryagain: |
86 |
> |
nextsample: |
87 |
|
while (++si->sp >= si->np) { /* get next sample */ |
88 |
|
if (++si->sn >= nsources) |
89 |
|
return(0.0); /* no more */ |
90 |
< |
if (srcsizerat <= FTINY) |
91 |
< |
nopart(si, org); |
90 |
> |
if (source[si->sn].sflags & SSKIP) |
91 |
> |
si->np = 0; |
92 |
> |
else if (srcsizerat <= FTINY) |
93 |
> |
nopart(si, r); |
94 |
|
else { |
95 |
|
for (i = si->sn; source[i].sflags & SVIRTUAL; |
96 |
|
i = source[i].sa.sv.sn) |
97 |
|
; /* partition source */ |
98 |
< |
(*sfun[source[i].so->otype].of->partit)(si, org); |
98 |
> |
(*sfun[source[i].so->otype].of->partit)(si, r); |
99 |
|
} |
100 |
|
si->sp = -1; |
101 |
|
} |
125 |
|
vpos[i] += (double)cent[i]/MAXSPART; |
126 |
|
/* compute direction */ |
127 |
|
for (i = 0; i < 3; i++) |
128 |
< |
dir[i] = source[si->sn].sloc[i] + |
128 |
> |
r->rdir[i] = source[si->sn].sloc[i] + |
129 |
|
vpos[SU]*source[si->sn].ss[SU][i] + |
130 |
|
vpos[SV]*source[si->sn].ss[SV][i] + |
131 |
|
vpos[SW]*source[si->sn].ss[SW][i]; |
132 |
|
|
133 |
|
if (!(source[si->sn].sflags & SDISTANT)) |
134 |
|
for (i = 0; i < 3; i++) |
135 |
< |
dir[i] -= org[i]; |
135 |
> |
r->rdir[i] -= r->rorg[i]; |
136 |
|
/* compute distance */ |
137 |
< |
if ((d = normalize(dir)) == 0.0) |
138 |
< |
goto tryagain; /* at source! */ |
137 |
> |
if ((d = normalize(r->rdir)) == 0.0) |
138 |
> |
goto nextsample; /* at source! */ |
139 |
|
|
140 |
|
/* compute sample size */ |
87 |
– |
si->dom = source[si->sn].ss2; |
141 |
|
if (source[si->sn].sflags & SFLAT) { |
142 |
< |
si->dom *= sflatform(si->sn, dir); |
143 |
< |
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); |
142 |
> |
si->dom = sflatform(si->sn, r->rdir); |
143 |
> |
si->dom *= size[SU]*size[SV]/(MAXSPART*(double)MAXSPART); |
144 |
|
} else if (source[si->sn].sflags & SCYL) { |
145 |
< |
si->dom *= scylform(si->sn, dir); |
146 |
< |
si->dom *= (double)size[SU]/MAXSPART; |
145 |
> |
si->dom = scylform(si->sn, r->rdir); |
146 |
> |
si->dom *= size[SU]/(double)MAXSPART; |
147 |
|
} else { |
148 |
< |
si->dom *= (double)(size[SU]*size[SV]*size[SW]) / |
149 |
< |
(MAXSPART*MAXSPART*MAXSPART) ; |
148 |
> |
si->dom = size[SU]*size[SV]*(double)size[SW] / |
149 |
> |
(MAXSPART*MAXSPART*(double)MAXSPART) ; |
150 |
|
} |
151 |
< |
if (source[si->sn].sflags & SDISTANT) |
151 |
> |
if (source[si->sn].sflags & SDISTANT) { |
152 |
> |
si->dom *= source[si->sn].ss2; |
153 |
|
return(FHUGE); |
154 |
< |
si->dom /= d*d; |
154 |
> |
} |
155 |
> |
if (si->dom <= 1e-4) |
156 |
> |
goto nextsample; /* behind source? */ |
157 |
> |
si->dom *= source[si->sn].ss2/(d*d); |
158 |
|
return(d); /* sample OK, return distance */ |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
+ |
int |
163 |
|
skipparts(ct, sz, pp, pt) /* skip to requested partition */ |
164 |
|
int ct[3], sz[3]; /* center and size of partition (returned) */ |
165 |
|
register int pp[2]; /* current index, number to skip (modified) */ |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
nopart(si, ro) /* single source partition */ |
194 |
> |
void |
195 |
> |
nopart(si, r) /* single source partition */ |
196 |
|
register SRCINDEX *si; |
197 |
< |
FVECT ro; |
197 |
> |
RAY *r; |
198 |
|
{ |
199 |
|
clrpart(si->spt); |
200 |
|
setpart(si->spt, 0, S0); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
< |
cylpart(si, ro) /* partition a cylinder */ |
205 |
> |
void |
206 |
> |
cylpart(si, r) /* partition a cylinder */ |
207 |
|
SRCINDEX *si; |
208 |
< |
FVECT ro; |
208 |
> |
register RAY *r; |
209 |
|
{ |
210 |
|
double dist2, safedist2, dist2cent, rad2; |
211 |
|
FVECT v; |
213 |
|
int pi; |
214 |
|
/* first check point location */ |
215 |
|
clrpart(si->spt); |
216 |
< |
sp = &source[si->sn]; |
217 |
< |
rad2 = 1.273 * DOT(sp->ss[SV],sp->ss[SV]); |
218 |
< |
v[0] = ro[0] - sp->sloc[0]; |
219 |
< |
v[1] = ro[1] - sp->sloc[1]; |
220 |
< |
v[2] = ro[2] - sp->sloc[2]; |
216 |
> |
sp = source + si->sn; |
217 |
> |
rad2 = 1.365 * DOT(sp->ss[SV],sp->ss[SV]); |
218 |
> |
v[0] = r->rorg[0] - sp->sloc[0]; |
219 |
> |
v[1] = r->rorg[1] - sp->sloc[1]; |
220 |
> |
v[2] = r->rorg[2] - sp->sloc[2]; |
221 |
|
dist2 = DOT(v,sp->ss[SU]); |
222 |
|
safedist2 = DOT(sp->ss[SU],sp->ss[SU]); |
223 |
|
dist2 *= dist2 / safedist2; |
227 |
|
si->np = 0; |
228 |
|
return; |
229 |
|
} |
230 |
< |
safedist2 *= 4./(srcsizerat*srcsizerat); |
231 |
< |
if (dist2 <= 4.*rad2 || /* point too close to subdivide? */ |
232 |
< |
dist2cent >= safedist2) { |
230 |
> |
safedist2 *= 4.*r->rweight*r->rweight/(srcsizerat*srcsizerat); |
231 |
> |
if (dist2 <= 4.*rad2 || /* point too close to subdivide */ |
232 |
> |
dist2cent >= safedist2) { /* or too far */ |
233 |
|
setpart(si->spt, 0, S0); |
234 |
|
si->np = 1; |
235 |
|
return; |
236 |
|
} |
237 |
|
pi = 0; |
238 |
< |
si->np = cyl_partit(ro, si->spt, &pi, MAXSPART, |
238 |
> |
si->np = cyl_partit(r->rorg, si->spt, &pi, MAXSPART, |
239 |
|
sp->sloc, sp->ss[SU], safedist2); |
240 |
|
} |
241 |
|
|
268 |
|
newct[0] = cent[0] - newax[0]; |
269 |
|
newct[1] = cent[1] - newax[1]; |
270 |
|
newct[2] = cent[2] - newax[2]; |
271 |
< |
npl = cyl_partit(ro, pt, pi, mp*3/4, newct, newax, d2); |
271 |
> |
npl = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2); |
272 |
|
/* upper half */ |
273 |
|
newct[0] = cent[0] + newax[0]; |
274 |
|
newct[1] = cent[1] + newax[1]; |
275 |
|
newct[2] = cent[2] + newax[2]; |
276 |
< |
npu = cyl_partit(ro, pt, pi, mp-npl, newct, newax, d2); |
276 |
> |
npu = cyl_partit(ro, pt, pi, mp/2, newct, newax, d2); |
277 |
|
/* return total */ |
278 |
|
return(npl + npu); |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
< |
flatpart(si, ro) /* partition a flat source */ |
282 |
> |
void |
283 |
> |
flatpart(si, r) /* partition a flat source */ |
284 |
|
register SRCINDEX *si; |
285 |
< |
FVECT ro; |
285 |
> |
register RAY *r; |
286 |
|
{ |
287 |
< |
register double *vp; |
287 |
> |
register FLOAT *vp; |
288 |
> |
FVECT v; |
289 |
|
double du2, dv2; |
290 |
|
int pi; |
291 |
|
|
292 |
+ |
clrpart(si->spt); |
293 |
+ |
vp = source[si->sn].sloc; |
294 |
+ |
v[0] = r->rorg[0] - vp[0]; |
295 |
+ |
v[1] = r->rorg[1] - vp[1]; |
296 |
+ |
v[2] = r->rorg[2] - vp[2]; |
297 |
+ |
vp = source[si->sn].snorm; |
298 |
+ |
if (DOT(v,vp) <= FTINY) { /* behind source */ |
299 |
+ |
si->np = 0; |
300 |
+ |
return; |
301 |
+ |
} |
302 |
+ |
dv2 = 2.*r->rweight/srcsizerat; |
303 |
+ |
dv2 *= dv2; |
304 |
|
vp = source[si->sn].ss[SU]; |
305 |
< |
du2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp); |
305 |
> |
du2 = dv2 * DOT(vp,vp); |
306 |
|
vp = source[si->sn].ss[SV]; |
307 |
< |
dv2 = 4./(srcsizerat*srcsizerat) * DOT(vp,vp); |
238 |
< |
clrpart(si->spt); |
307 |
> |
dv2 *= DOT(vp,vp); |
308 |
|
pi = 0; |
309 |
< |
si->np = flt_partit(ro, si->spt, &pi, MAXSPART, source[si->sn].sloc, |
309 |
> |
si->np = flt_partit(r->rorg, si->spt, &pi, MAXSPART, |
310 |
> |
source[si->sn].sloc, |
311 |
|
source[si->sn].ss[SU], source[si->sn].ss[SV], du2, dv2); |
312 |
|
} |
313 |
|
|
352 |
|
newct[0] = cent[0] - newax[0]; |
353 |
|
newct[1] = cent[1] - newax[1]; |
354 |
|
newct[2] = cent[2] - newax[2]; |
355 |
< |
npl = flt_partit(ro, pt, pi, mp*3/4, newct, u, v, du2, dv2); |
355 |
> |
npl = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2); |
356 |
|
/* upper half */ |
357 |
|
newct[0] = cent[0] + newax[0]; |
358 |
|
newct[1] = cent[1] + newax[1]; |
359 |
|
newct[2] = cent[2] + newax[2]; |
360 |
< |
npu = flt_partit(ro, pt, pi, mp-npl, newct, u, v, du2, dv2); |
360 |
> |
npu = flt_partit(ro, pt, pi, mp/2, newct, u, v, du2, dv2); |
361 |
|
/* return total */ |
362 |
|
return(npl + npu); |
363 |
|
} |
368 |
|
int sn; |
369 |
|
register FVECT dir; /* assume normalized */ |
370 |
|
{ |
371 |
< |
register double *dv; |
371 |
> |
register FLOAT *dv; |
372 |
|
double d; |
373 |
|
|
374 |
|
dv = source[sn].ss[SU]; |