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 |
|
|
75 |
|
} |
76 |
|
if (argv[i][2] != 'f') |
77 |
|
goto userr; |
78 |
< |
rval = viewfile(argv[++i], &ourview, 0, 0); |
78 |
> |
rval = viewfile(argv[++i], &ourview, NULL); |
79 |
|
if (rval < 0) { |
80 |
|
fprintf(stderr, |
81 |
|
"%s: cannot open view file \"%s\"\n", |
105 |
|
combine = !combine; |
106 |
|
break; |
107 |
|
case 'd': |
108 |
+ |
if (argv[i][2] == 'v') { |
109 |
+ |
rtargv[rtargc++] = argv[i]; |
110 |
+ |
break; |
111 |
+ |
} |
112 |
+ |
/* FALL THROUGH */ |
113 |
|
case 'l': |
114 |
+ |
case 's': |
115 |
|
rtargv[rtargc++] = argv[i]; |
116 |
|
rtargv[rtargc++] = argv[++i]; |
117 |
|
break; |
118 |
+ |
case 'w': |
119 |
+ |
rtargv[rtargc++] = argv[i]; |
120 |
+ |
break; |
121 |
|
case 'a': |
122 |
|
rtargv[rtargc++] = argv[i]; |
123 |
|
if (argv[i][2] == 'v') { |
139 |
|
} |
140 |
|
/* get view */ |
141 |
|
if (picture != NULL) { |
142 |
< |
rval = viewfile(picture, &pictview, 0, 0); |
142 |
> |
rval = viewfile(picture, &pictview, NULL); |
143 |
|
if (rval < 0) { |
144 |
|
fprintf(stderr, "%s: cannot open picture file \"%s\"\n", |
145 |
|
progname, picture); |
198 |
|
printargs(argc, argv, stdout); |
199 |
|
fputs(VIEWSTR, stdout); |
200 |
|
fprintview(&ourview, stdout); |
201 |
< |
printf("\n\n"); |
201 |
> |
printf("\n"); |
202 |
> |
fputformat("ascii", stdout); |
203 |
> |
printf("\n"); |
204 |
|
printsources(); /* print glare sources */ |
205 |
|
printillum(); /* print illuminances */ |
206 |
|
exit(0); |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
+ |
int |
216 |
+ |
angcmp(ap1, ap2) /* compare two angles */ |
217 |
+ |
ANGLE *ap1, *ap2; |
218 |
+ |
{ |
219 |
+ |
register int a1, a2; |
220 |
+ |
|
221 |
+ |
a1 = *ap1; |
222 |
+ |
a2 = *ap2; |
223 |
+ |
if (a1 == a2) { |
224 |
+ |
fprintf(stderr, "%s: duplicate glare angle (%d)\n", |
225 |
+ |
progname, a1); |
226 |
+ |
exit(1); |
227 |
+ |
} |
228 |
+ |
return(a1-a2); |
229 |
+ |
} |
230 |
+ |
|
231 |
+ |
|
232 |
|
init() /* initialize global variables */ |
233 |
|
{ |
234 |
|
double d; |
240 |
|
/* set direction vectors */ |
241 |
|
for (i = 0; glarang[i] != AEND; i++) |
242 |
|
; |
243 |
< |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] >= 180)) { |
244 |
< |
fprintf(stderr, "%s: glare angles must be between 1 and 179\n", |
243 |
> |
qsort(glarang, i, sizeof(ANGLE), angcmp); |
244 |
> |
if (i > 0 && (glarang[0] <= 0 || glarang[i-1] > 180)) { |
245 |
> |
fprintf(stderr, "%s: glare angles must be between 1 and 180\n", |
246 |
|
progname); |
247 |
|
exit(1); |
248 |
|
} |
253 |
|
maxtheta = (PI/180.)*glarang[nglarangs-1]; |
254 |
|
else |
255 |
|
maxtheta = 0.0; |
256 |
< |
hlim = sampdens*maxtheta; |
229 |
< |
hsize = hlim + sampdens - 1; |
256 |
> |
hsize = hlim(0) + sampdens - 1; |
257 |
|
if (hsize > (int)(PI*sampdens)) |
258 |
|
hsize = PI*sampdens; |
259 |
|
indirect = (struct illum *)calloc(nglardirs, sizeof(struct illum)); |
308 |
|
cleanup() /* close files, wait for children */ |
309 |
|
{ |
310 |
|
if (verbose) |
311 |
< |
fprintf(stderr, "%s: cleaning up...\n", progname); |
311 |
> |
fprintf(stderr, "%s: cleaning up... \n", progname); |
312 |
|
if (picture != NULL) |
313 |
|
close_pict(); |
314 |
|
if (octree != NULL) |
315 |
|
done_rtrace(); |
316 |
|
if (npixinvw < 100*npixmiss) |
317 |
< |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
318 |
< |
progname, 100L*npixmiss/npixinvw); |
317 |
> |
fprintf(stderr, "%s: warning -- missing %d%% of samples\n", |
318 |
> |
progname, (int)(100L*npixmiss/npixinvw)); |
319 |
|
} |
320 |
|
|
321 |
|
|
323 |
|
FVECT vd; |
324 |
|
int x, y; |
325 |
|
{ |
326 |
< |
static int cury = 10000; |
300 |
< |
static double err, cmpval; |
301 |
< |
long t; |
326 |
> |
int hl; |
327 |
|
FVECT org; /* dummy variable */ |
328 |
|
|
329 |
< |
if (x <= -hlim) /* left region */ |
329 |
> |
hl = hlim(y); |
330 |
> |
if (x <= -hl) { /* left region */ |
331 |
> |
if (x <= -hl-sampdens) |
332 |
> |
return(-1); |
333 |
|
return(viewray(org, vd, &leftview, |
334 |
< |
(double)(x+hlim)/(2*sampdens)+.5, |
334 |
> |
(double)(x+hl)/(2*sampdens)+.5, |
335 |
|
(double)y/(2*sampdens)+.5)); |
336 |
< |
if (x >= hlim) /* right region */ |
336 |
> |
} |
337 |
> |
if (x >= hl) { /* right region */ |
338 |
> |
if (x >= hl+sampdens) |
339 |
> |
return(-1); |
340 |
|
return(viewray(org, vd, &rightview, |
341 |
< |
(double)(x-hlim)/(2*sampdens)+.5, |
341 |
> |
(double)(x-hl)/(2*sampdens)+.5, |
342 |
|
(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; |
343 |
|
} |
344 |
< |
err += cmpval; |
320 |
< |
if (err <= 0.5) |
321 |
< |
return(-1); |
322 |
< |
err -= 1.0; |
344 |
> |
/* central region */ |
345 |
|
if (viewray(org, vd, &ourview, .5, (double)y/(2*sampdens)+.5) < 0) |
346 |
|
return(-1); |
347 |
< |
spinvector(vd, vd, ourview.vup, h_theta(x)); |
347 |
> |
spinvector(vd, vd, ourview.vup, h_theta(x,y)); |
348 |
|
return(0); |
349 |
+ |
} |
350 |
+ |
|
351 |
+ |
|
352 |
+ |
double |
353 |
+ |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
354 |
+ |
int x, y; |
355 |
+ |
{ |
356 |
+ |
register int hl, xo; |
357 |
+ |
double disc; |
358 |
+ |
|
359 |
+ |
hl = hlim(y); |
360 |
+ |
if (x < -hl) |
361 |
+ |
xo = x+hl; |
362 |
+ |
else if (x > hl) |
363 |
+ |
xo = x-hl; |
364 |
+ |
else |
365 |
+ |
xo = 0; |
366 |
+ |
disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); |
367 |
+ |
if (disc <= FTINY) |
368 |
+ |
return(0.); |
369 |
+ |
return(1./(sampdens*sampdens*sqrt(disc))); |
370 |
|
} |
371 |
|
|
372 |
|
|