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 |
|
* Routines to do the actual calculation for mkillum |
6 |
|
*/ |
23 |
|
sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", |
24 |
|
nm, ofun[ob->otype].funame, ob->oname); |
25 |
|
error(WARNING, errmsg); |
26 |
< |
if (!(il->flags & IL_LIGHT)) |
30 |
< |
printobj(il->altmat, ob); |
26 |
> |
printobj(il->altmat, ob); |
27 |
|
} |
28 |
|
|
29 |
|
|
52 |
|
return; |
53 |
|
} |
54 |
|
/* set up sampling */ |
55 |
< |
n = PI * il->sampdens; |
56 |
< |
nalt = sqrt(n/PI) + .5; |
57 |
< |
nazi = PI*nalt + .5; |
55 |
> |
if (il->sampdens <= 0) |
56 |
> |
nalt = nazi = 1; |
57 |
> |
else { |
58 |
> |
n = PI * il->sampdens; |
59 |
> |
nalt = sqrt(n/PI) + .5; |
60 |
> |
nazi = PI*nalt + .5; |
61 |
> |
} |
62 |
|
n = nalt*nazi; |
63 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
64 |
|
if (distarr == NULL) |
65 |
|
error(SYSTEM, "out of memory in o_face"); |
66 |
< |
mkaxes(u, v, fa->norm); |
66 |
> |
/* take first edge longer than sqrt(area) */ |
67 |
> |
for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { |
68 |
> |
u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; |
69 |
> |
u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; |
70 |
> |
u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2]; |
71 |
> |
if ((r1 = DOT(u,u)) >= fa->area-FTINY) |
72 |
> |
break; |
73 |
> |
} |
74 |
> |
if (i < fa->nv) { /* got one! -- let's align our axes */ |
75 |
> |
r2 = 1.0/sqrt(r1); |
76 |
> |
u[0] *= r2; u[1] *= r2; u[2] *= r2; |
77 |
> |
fcross(v, fa->norm, u); |
78 |
> |
} else /* oh well, we'll just have to wing it */ |
79 |
> |
mkaxes(u, v, fa->norm); |
80 |
> |
/* now, find limits in (u,v) coordinates */ |
81 |
|
ur[0] = vr[0] = FHUGE; |
82 |
|
ur[1] = vr[1] = -FHUGE; |
83 |
|
for (i = 0; i < fa->nv; i++) { |
96 |
|
for (i = 0; i < il->nsamps; i++) { |
97 |
|
/* random direction */ |
98 |
|
h = ilhash(dim, 3) + i; |
99 |
< |
peano(sp, 2, urand(h), .02); |
99 |
> |
multisamp(sp, 2, urand(h)); |
100 |
|
r1 = (dim[1] + sp[0])/nalt; |
101 |
< |
r2 = (dim[2] + sp[1])/nazi; |
101 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
102 |
|
flatdir(dn, r1, r2); |
103 |
|
for (j = 0; j < 3; j++) |
104 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*fa->norm[j]; |
105 |
|
/* random location */ |
106 |
|
do { |
107 |
< |
peano(sp, 2, urand(h+nmisses), .01); |
107 |
> |
multisamp(sp, 2, urand(h+4862+nmisses)); |
108 |
|
r1 = ur[0] + (ur[1]-ur[0]) * sp[0]; |
109 |
|
r2 = vr[0] + (vr[1]-vr[0]) * sp[1]; |
110 |
|
for (j = 0; j < 3; j++) |
115 |
|
objerror(ob, WARNING, "bad aspect"); |
116 |
|
rt->nrays = 0; |
117 |
|
freeface(ob); |
118 |
< |
free((char *)distarr); |
118 |
> |
free((void *)distarr); |
119 |
|
o_default(ob, il, rt, nm); |
120 |
|
return; |
121 |
|
} |
125 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
126 |
|
} |
127 |
|
rayflush(rt); |
128 |
< |
/* write out the face w/ distribution */ |
129 |
< |
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
130 |
< |
illumout(il, ob); |
128 |
> |
/* write out the face and its distribution */ |
129 |
> |
if (average(il, distarr, nalt*nazi)) { |
130 |
> |
if (il->sampdens > 0) |
131 |
> |
flatout(il, distarr, nalt, nazi, u, v, fa->norm); |
132 |
> |
illumout(il, ob); |
133 |
> |
} else |
134 |
> |
printobj(il->altmat, ob); |
135 |
|
/* clean up */ |
136 |
|
freeface(ob); |
137 |
< |
free((char *)distarr); |
137 |
> |
free((void *)distarr); |
138 |
|
#undef MAXMISS |
139 |
|
} |
140 |
|
|
156 |
|
if (ob->oargs.nfargs != 4) |
157 |
|
objerror(ob, USER, "bad # of arguments"); |
158 |
|
/* set up sampling */ |
159 |
< |
n = 4.*PI * il->sampdens; |
160 |
< |
nalt = sqrt(n/PI) + .5; |
161 |
< |
nazi = PI*nalt + .5; |
159 |
> |
if (il->sampdens <= 0) |
160 |
> |
nalt = nazi = 1; |
161 |
> |
else { |
162 |
> |
n = 4.*PI * il->sampdens; |
163 |
> |
nalt = sqrt(2./PI*n) + .5; |
164 |
> |
nazi = PI/2.*nalt + .5; |
165 |
> |
} |
166 |
|
n = nalt*nazi; |
167 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
168 |
|
if (distarr == NULL) |
173 |
|
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
174 |
|
for (i = 0; i < il->nsamps; i++) { |
175 |
|
/* next sample point */ |
176 |
< |
peano(sp, 4, urand(ilhash(dim,3)+i), .02); |
176 |
> |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
177 |
|
/* random direction */ |
178 |
|
r1 = (dim[1] + sp[0])/nalt; |
179 |
< |
r2 = (dim[2] + sp[1])/nazi; |
179 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
180 |
|
rounddir(dir, r1, r2); |
181 |
|
/* random location */ |
182 |
|
mkaxes(u, v, dir); /* yuck! */ |
194 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
195 |
|
} |
196 |
|
rayflush(rt); |
197 |
< |
/* write out the sphere w/ distribution */ |
198 |
< |
roundout(il, distarr, nalt, nazi); |
199 |
< |
illumout(il, ob); |
197 |
> |
/* write out the sphere and its distribution */ |
198 |
> |
if (average(il, distarr, nalt*nazi)) { |
199 |
> |
if (il->sampdens > 0) |
200 |
> |
roundout(il, distarr, nalt, nazi); |
201 |
> |
else |
202 |
> |
objerror(ob, WARNING, "diffuse distribution"); |
203 |
> |
illumout(il, ob); |
204 |
> |
} else |
205 |
> |
printobj(il->altmat, ob); |
206 |
|
/* clean up */ |
207 |
< |
free((char *)distarr); |
207 |
> |
free((void *)distarr); |
208 |
|
} |
209 |
|
|
210 |
|
|
225 |
|
/* get/check arguments */ |
226 |
|
co = getcone(ob, 0); |
227 |
|
/* set up sampling */ |
228 |
< |
n = PI * il->sampdens; |
229 |
< |
nalt = sqrt(n/PI) + .5; |
230 |
< |
nazi = PI*nalt + .5; |
228 |
> |
if (il->sampdens <= 0) |
229 |
> |
nalt = nazi = 1; |
230 |
> |
else { |
231 |
> |
n = PI * il->sampdens; |
232 |
> |
nalt = sqrt(n/PI) + .5; |
233 |
> |
nazi = PI*nalt + .5; |
234 |
> |
} |
235 |
|
n = nalt*nazi; |
236 |
|
distarr = (float *)calloc(n, 3*sizeof(float)); |
237 |
|
if (distarr == NULL) |
243 |
|
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
244 |
|
for (i = 0; i < il->nsamps; i++) { |
245 |
|
/* next sample point */ |
246 |
< |
peano(sp, 4, urand(ilhash(dim,3)+i), .02); |
246 |
> |
multisamp(sp, 4, urand(ilhash(dim,3)+i)); |
247 |
|
/* random direction */ |
248 |
|
r1 = (dim[1] + sp[0])/nalt; |
249 |
< |
r2 = (dim[2] + sp[1])/nalt; |
249 |
> |
r2 = (dim[2] + sp[1] - .5)/nazi; |
250 |
|
flatdir(dn, r1, r2); |
251 |
|
for (j = 0; j < 3; j++) |
252 |
|
dir[j] = -dn[0]*u[j] - dn[1]*v[j] - dn[2]*co->ad[j]; |
257 |
|
r1 = r3*cos(r2); |
258 |
|
r2 = r3*sin(r2); |
259 |
|
for (j = 0; j < 3; j++) |
260 |
< |
org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] + |
260 |
> |
org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] + |
261 |
|
.001*co->ad[j]; |
262 |
|
|
263 |
|
/* send sample */ |
264 |
|
raysamp(distarr+3*(dim[1]*nazi+dim[2]), org, dir, rt); |
265 |
|
} |
266 |
|
rayflush(rt); |
267 |
< |
/* write out the ring w/ distribution */ |
268 |
< |
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
269 |
< |
illumout(il, ob); |
267 |
> |
/* write out the ring and its distribution */ |
268 |
> |
if (average(il, distarr, nalt*nazi)) { |
269 |
> |
if (il->sampdens > 0) |
270 |
> |
flatout(il, distarr, nalt, nazi, u, v, co->ad); |
271 |
> |
illumout(il, ob); |
272 |
> |
} else |
273 |
> |
printobj(il->altmat, ob); |
274 |
|
/* clean up */ |
275 |
|
freecone(ob); |
276 |
< |
free((char *)distarr); |
276 |
> |
free((void *)distarr); |
277 |
|
} |
278 |
|
|
279 |
|
|
301 |
|
if (rt->nrays <= 0) |
302 |
|
return; |
303 |
|
bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); |
304 |
+ |
errno = 0; |
305 |
|
if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, |
306 |
< |
3*sizeof(float)*rt->nrays, |
306 |
> |
3*sizeof(float)*(rt->nrays+1), |
307 |
|
6*sizeof(float)*(rt->nrays+1)) < |
308 |
< |
3*sizeof(float)*rt->nrays ) |
308 |
> |
3*sizeof(float)*(rt->nrays+1) ) |
309 |
|
error(SYSTEM, "error reading from rtrace process"); |
310 |
|
i = rt->nrays; |
311 |
|
while (i--) { |