64 |
|
struct rtproc *rt; |
65 |
|
char *nm; |
66 |
|
{ |
67 |
+ |
#define MAXMISS (5*n*il->nsamps) |
68 |
+ |
int dim[4]; |
69 |
+ |
int n, nalt, nazi; |
70 |
+ |
float *distarr; |
71 |
+ |
double r1, r2; |
72 |
+ |
FVECT dn, pos, dir; |
73 |
+ |
FVECT u, v; |
74 |
+ |
double ur[2], vr[2]; |
75 |
+ |
int nmisses; |
76 |
+ |
register FACE *fa; |
77 |
+ |
register int i, j; |
78 |
+ |
/* get/check arguments */ |
79 |
+ |
fa = getface(ob); |
80 |
+ |
if (fa->area == 0.0) { |
81 |
+ |
freeface(ob); |
82 |
+ |
o_default(ob, il, rt, nm); |
83 |
+ |
return; |
84 |
+ |
} |
85 |
+ |
/* set up sampling */ |
86 |
+ |
n = PI * il->sampdens; |
87 |
+ |
nalt = sqrt(n/PI) + .5; |
88 |
+ |
nazi = PI*nalt + .5; |
89 |
+ |
n = nalt*nazi; |
90 |
+ |
distarr = (float *)calloc(n, 3*sizeof(float)); |
91 |
+ |
if (distarr == NULL) |
92 |
+ |
error(SYSTEM, "out of memory in o_face"); |
93 |
+ |
mkaxes(u, v, fa->norm); |
94 |
+ |
ur[0] = vr[0] = FHUGE; |
95 |
+ |
ur[1] = vr[1] = -FHUGE; |
96 |
+ |
for (i = 0; i < fa->nv; i++) { |
97 |
+ |
r1 = DOT(VERTEX(fa,i),u); |
98 |
+ |
if (r1 < ur[0]) ur[0] = r1; |
99 |
+ |
if (r1 > ur[1]) ur[1] = r1; |
100 |
+ |
r2 = DOT(VERTEX(fa,i),v); |
101 |
+ |
if (r2 < vr[0]) vr[0] = r2; |
102 |
+ |
if (r2 > vr[1]) vr[1] = r2; |
103 |
+ |
} |
104 |
+ |
dim[0] = random(); |
105 |
+ |
/* sample polygon */ |
106 |
+ |
nmisses = 0; |
107 |
+ |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
108 |
+ |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
109 |
+ |
for (i = 0; i < il->nsamps; i++) { |
110 |
+ |
/* random direction */ |
111 |
+ |
dim[3] = 1; |
112 |
+ |
r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt; |
113 |
+ |
dim[3] = 2; |
114 |
+ |
r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt; |
115 |
+ |
flatdir(dn, r1, r2); |
116 |
+ |
for (j = 0; j < 3; j++) |
117 |
+ |
dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*fa->norm[j]; |
118 |
+ |
/* random location */ |
119 |
+ |
do { |
120 |
+ |
dim[3] = 3; |
121 |
+ |
r1 = ur[0] + |
122 |
+ |
(ur[1]-ur[0])*urand(urind(ilhash(dim,4),i)); |
123 |
+ |
dim[3] = 4; |
124 |
+ |
r2 = vr[0] + |
125 |
+ |
(vr[1]-vr[0])*urand(urind(ilhash(dim,4),i)); |
126 |
+ |
for (j = 0; j < 3; j++) |
127 |
+ |
org[j] = r1*u[j] + r2*v[j] |
128 |
+ |
+ fa->offset*fa->norm[j]; |
129 |
+ |
} while (!inface(org, fa) && nmisses++ < MAXMISS); |
130 |
+ |
if (nmisses > MAXMISS) { |
131 |
+ |
objerror(ob, WARNING, "bad aspect"); |
132 |
+ |
rt->nrays = 0; |
133 |
+ |
freeface(ob); |
134 |
+ |
free((char *)distarr); |
135 |
+ |
o_default(ob, il, rt, nm); |
136 |
+ |
return; |
137 |
+ |
} |
138 |
+ |
for (j = 0; j < 3; j++) |
139 |
+ |
org[j] += .001*fa->norm[j]; |
140 |
+ |
/* send sample */ |
141 |
+ |
raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); |
142 |
+ |
} |
143 |
+ |
rayflush(rt); |
144 |
+ |
/* write out the distribution */ |
145 |
+ |
flatdist(distarr, nalt, nazi, il, ob); |
146 |
+ |
/* clean up */ |
147 |
+ |
freeface(ob); |
148 |
+ |
free((char *)distarr); |
149 |
+ |
#undef MAXMISS |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
o_sphere(ob, il, rt, nm) /* make an illum sphere */ |
154 |
< |
OBJREC *ob; |
154 |
> |
register OBJREC *ob; |
155 |
|
struct illum_args *il; |
156 |
|
struct rtproc *rt; |
157 |
|
char *nm; |
200 |
|
raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); |
201 |
|
} |
202 |
|
rayflush(rt); |
203 |
< |
/* write out distribution */ |
203 |
> |
/* write out the distribution */ |
204 |
|
rounddist(distarr, nalt, nazi, il, ob); |
205 |
|
/* clean up */ |
206 |
|
free((char *)distarr); |
213 |
|
struct rtproc *rt; |
214 |
|
char *nm; |
215 |
|
{ |
216 |
+ |
int dim[4]; |
217 |
+ |
int n, nalt, nazi; |
218 |
+ |
float *distarr; |
219 |
+ |
double r1, r2; |
220 |
+ |
FVECT dn, pos, dir; |
221 |
+ |
FVECT u, v; |
222 |
+ |
register CONE *co; |
223 |
+ |
register int i, j; |
224 |
+ |
/* get/check arguments */ |
225 |
+ |
co = getcone(ob, 0); |
226 |
+ |
/* set up sampling */ |
227 |
+ |
n = PI * il->sampdens; |
228 |
+ |
nalt = sqrt(n/PI) + .5; |
229 |
+ |
nazi = PI*nalt + .5; |
230 |
+ |
n = nalt*nazi; |
231 |
+ |
distarr = (float *)calloc(n, 3*sizeof(float)); |
232 |
+ |
if (distarr == NULL) |
233 |
+ |
error(SYSTEM, "out of memory in o_ring"); |
234 |
+ |
mkaxes(u, v, co->ad); |
235 |
+ |
dim[0] = random(); |
236 |
+ |
/* sample disk */ |
237 |
+ |
for (dim[1] = 0; dim[1] < nalt; dim[1]++) |
238 |
+ |
for (dim[2] = 0; dim[2] < nazi; dim[2]++) |
239 |
+ |
for (i = 0; i < il->nsamps; i++) { |
240 |
+ |
/* random direction */ |
241 |
+ |
dim[3] = 1; |
242 |
+ |
r1 = (dim[1]+urand(urind(ilhash(dim,4),i)))/nalt; |
243 |
+ |
dim[3] = 2; |
244 |
+ |
r2 = (dim[2]+urand(urind(ilhash(dim,4),i)))/nalt; |
245 |
+ |
flatdir(dn, r1, r2); |
246 |
+ |
for (j = 0; j < 3; j++) |
247 |
+ |
dir[j] = dn[0]*u[j] + dn[1]*v[j] - dn[2]*co->ad[j]; |
248 |
+ |
/* random location */ |
249 |
+ |
dim[3] = 3; |
250 |
+ |
r1 = sqrt(CO_R0(co)*CO_R0(co) + |
251 |
+ |
urand(urind(ilhash(dim,4),i))* |
252 |
+ |
(CO_R1(co)*CO_R1(co) - CO_R0(co)*CO_R0(co))); |
253 |
+ |
dim[3] = 4; |
254 |
+ |
r2 = 2.*PI*urand(urind(ilhash(dim,4),i)); |
255 |
+ |
for (j = 0; j < 3; j++) |
256 |
+ |
org[j] = CO_P0(co)[j] + |
257 |
+ |
r1*cos(r2)*u[j] + r1*sin(r2)*v[j] |
258 |
+ |
+ .001*co->ad[j]; |
259 |
+ |
|
260 |
+ |
/* send sample */ |
261 |
+ |
raysamp(distarr+dim[1]*nazi+dim[2], org, dir, rt); |
262 |
+ |
} |
263 |
+ |
rayflush(rt); |
264 |
+ |
/* write out the distribution */ |
265 |
+ |
flatdist(distarr, nalt, nazi, il, ob); |
266 |
+ |
/* clean up */ |
267 |
+ |
freecone(ob); |
268 |
+ |
free((char *)distarr); |
269 |
|
} |
270 |
|
|
271 |
|
|