12 |
|
|
13 |
|
#include "glare.h" |
14 |
|
|
15 |
< |
#define FEQ(a,b) ((a)-(b)<=FTINY&&(a)-(b)<=FTINY) |
15 |
> |
#define FEQ(a,b) ((a)-(b)<=FTINY&&(b)-(a)<=FTINY) |
16 |
|
#define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ |
17 |
|
&&FEQ((v1)[2],(v2)[2])) |
18 |
|
|
19 |
< |
char *rtargv[32] = {"rtrace", "-h", "-ov", "-fff"}; |
19 |
> |
char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; |
20 |
|
int rtargc = 4; |
21 |
|
|
22 |
|
VIEW ourview = STDVIEW; /* our view */ |
36 |
|
int nglarangs = 0; |
37 |
|
double maxtheta; /* maximum angle (in radians) */ |
38 |
|
int hsize; /* horizontal size */ |
39 |
– |
int hlim; /* central limit of horizontal */ |
39 |
|
|
40 |
|
struct illum *indirect; /* array of indirect illuminances */ |
41 |
|
|
189 |
|
printargs(argc, argv, stdout); |
190 |
|
fputs(VIEWSTR, stdout); |
191 |
|
fprintview(&ourview, stdout); |
192 |
< |
printf("\n\n"); |
192 |
> |
printf("\n"); |
193 |
> |
fputformat("ascii", stdout); |
194 |
> |
printf("\n"); |
195 |
|
printsources(); /* print glare sources */ |
196 |
|
printillum(); /* print illuminances */ |
197 |
|
exit(0); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
+ |
int |
207 |
+ |
angcmp(ap1, ap2) /* compare two angles */ |
208 |
+ |
ANGLE *ap1, *ap2; |
209 |
+ |
{ |
210 |
+ |
register int a1, a2; |
211 |
+ |
|
212 |
+ |
a1 = *ap1; |
213 |
+ |
a2 = *ap2; |
214 |
+ |
if (a1 == a2) { |
215 |
+ |
fprintf(stderr, "%s: duplicate glare angle (%d)\n", |
216 |
+ |
progname, a1); |
217 |
+ |
exit(1); |
218 |
+ |
} |
219 |
+ |
return(a1-a2); |
220 |
+ |
} |
221 |
+ |
|
222 |
+ |
|
223 |
|
init() /* initialize global variables */ |
224 |
|
{ |
225 |
|
double d; |
231 |
|
/* set direction vectors */ |
232 |
|
for (i = 0; glarang[i] != AEND; i++) |
233 |
|
; |
234 |
< |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
235 |
< |
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
234 |
> |
qsort(glarang, i, sizeof(ANGLE), angcmp); |
235 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) { |
236 |
> |
fprintf(stderr, "%s: glare angles must be between 1 and 180\n", |
237 |
|
progname); |
238 |
|
exit(1); |
239 |
|
} |
244 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
245 |
|
else |
246 |
|
maxtheta = 0.0; |
247 |
< |
hlim = sampdens*maxtheta; |
229 |
< |
hsize = hlim + sampdens - 1; |
247 |
> |
hsize = hlim(0) + sampdens - 1; |
248 |
|
if (hsize > (int)(PI*sampdens)) |
249 |
|
hsize = PI*sampdens; |
250 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
299 |
|
cleanup() /* close files, wait for children */ |
300 |
|
{ |
301 |
|
if (verbose) |
302 |
< |
fprintf(stderr, "%s: cleaning up...\n", progname); |
302 |
> |
fprintf(stderr, "%s: cleaning up... \n", progname); |
303 |
|
if (picture != NULL) |
304 |
|
close_pict(); |
305 |
|
if (octree != NULL) |
314 |
|
FVECT vd; |
315 |
|
int x, y; |
316 |
|
{ |
317 |
< |
static int cury = 10000; |
300 |
< |
static double err, cmpval; |
301 |
< |
long t; |
317 |
> |
int hl; |
318 |
|
FVECT org; /* dummy variable */ |
319 |
|
|
320 |
< |
if (x <= -hlim) /* left region */ |
320 |
> |
hl = hlim(y); |
321 |
> |
if (x <= -hl) { /* left region */ |
322 |
> |
if (x <= -hl-sampdens) |
323 |
> |
return(-1); |
324 |
|
return(viewray(org, vd, &leftview, |
325 |
< |
(double)(x+hlim)/(2*sampdens)+.5, |
325 |
> |
(double)(x+hl)/(2*sampdens)+.5, |
326 |
|
(double)y/(2*sampdens)+.5)); |
327 |
< |
if (x >= hlim) /* right region */ |
327 |
> |
} |
328 |
> |
if (x >= hl) { /* right region */ |
329 |
> |
if (x >= hl+sampdens) |
330 |
> |
return(-1); |
331 |
|
return(viewray(org, vd, &rightview, |
332 |
< |
(double)(x-hlim)/(2*sampdens)+.5, |
332 |
> |
(double)(x-hl)/(2*sampdens)+.5, |
333 |
|
(double)y/(2*sampdens)+.5)); |
312 |
– |
/* central region */ |
313 |
– |
/* avoid over-counting of poles */ |
314 |
– |
if (cury != y) { |
315 |
– |
err = 0.0; |
316 |
– |
cmpval = sqrt(1.0 - (double)((long)y*y)/((long)vsize*vsize)); |
317 |
– |
cury = y; |
334 |
|
} |
335 |
< |
err += cmpval; |
320 |
< |
if (err <= 0.5) |
321 |
< |
return(-1); |
322 |
< |
err -= 1.0; |
335 |
> |
/* central region */ |
336 |
|
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
337 |
|
return(-1); |
338 |
< |
spinvector(vd, vd, ourview.vup, h_theta(x)); |
338 |
> |
spinvector(vd, vd, ourview.vup, h_theta(x,y)); |
339 |
|
return(0); |
340 |
+ |
} |
341 |
+ |
|
342 |
+ |
|
343 |
+ |
double |
344 |
+ |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
345 |
+ |
int x, y; |
346 |
+ |
{ |
347 |
+ |
register int hl, xo; |
348 |
+ |
double disc; |
349 |
+ |
|
350 |
+ |
hl = hlim(y); |
351 |
+ |
if (x < -hl) |
352 |
+ |
xo = x+hl; |
353 |
+ |
else if (x > hl) |
354 |
+ |
xo = x-hl; |
355 |
+ |
else |
356 |
+ |
xo = 0; |
357 |
+ |
disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); |
358 |
+ |
if (disc <= FTINY) |
359 |
+ |
return(0.); |
360 |
+ |
return(1./(sampdens*sampdens*sqrt(disc))); |
361 |
|
} |
362 |
|
|
363 |
|
|