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