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 |
|
* Find glare sources in a scene or image. |
6 |
|
* |
13 |
|
#define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ |
14 |
|
&&FEQ((v1)[2],(v2)[2])) |
15 |
|
|
16 |
< |
char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; |
17 |
< |
int rtargc = 4; |
16 |
> |
char *rtargv[64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}; |
17 |
> |
int rtargc = 7; |
18 |
|
|
19 |
|
VIEW ourview = STDVIEW; /* our view */ |
20 |
|
VIEW pictview = STDVIEW; /* picture view */ |
39 |
|
long npixinvw; /* number of pixels in view */ |
40 |
|
long npixmiss; /* number of pixels missed */ |
41 |
|
|
42 |
+ |
static int angcmp(const void *ap1, const void *ap2); |
43 |
+ |
static void init(void); |
44 |
+ |
static void cleanup(void); |
45 |
+ |
static void printsources(void); |
46 |
+ |
static void printillum(void); |
47 |
|
|
48 |
< |
main(argc, argv) |
49 |
< |
int argc; |
50 |
< |
char *argv[]; |
48 |
> |
|
49 |
> |
|
50 |
> |
int |
51 |
> |
main( |
52 |
> |
int argc, |
53 |
> |
char *argv[] |
54 |
> |
) |
55 |
|
{ |
56 |
|
int combine = 1; |
57 |
|
int gotview = 0; |
61 |
|
progname = argv[0]; |
62 |
|
/* process options */ |
63 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
64 |
+ |
/* expand arguments */ |
65 |
+ |
while ((rval = expandarg(&argc, &argv, i)) > 0) |
66 |
+ |
; |
67 |
+ |
if (rval < 0) { |
68 |
+ |
fprintf(stderr, "%s: cannot expand '%s'", |
69 |
+ |
argv[0], argv[i]); |
70 |
+ |
exit(1); |
71 |
+ |
} |
72 |
|
rval = getviewopt(&ourview, argc-i, argv+i); |
73 |
|
if (rval >= 0) { |
74 |
|
i += rval; |
89 |
|
} |
90 |
|
if (argv[i][2] != 'f') |
91 |
|
goto userr; |
92 |
< |
rval = viewfile(argv[++i], &ourview, 0, 0); |
92 |
> |
rval = viewfile(argv[++i], &ourview, NULL); |
93 |
|
if (rval < 0) { |
94 |
|
fprintf(stderr, |
95 |
|
"%s: cannot open view file \"%s\"\n", |
119 |
|
combine = !combine; |
120 |
|
break; |
121 |
|
case 'd': |
122 |
+ |
rtargv[rtargc++] = argv[i]; |
123 |
+ |
if (argv[i][2] != 'v') |
124 |
+ |
rtargv[rtargc++] = argv[++i]; |
125 |
+ |
break; |
126 |
|
case 'l': |
127 |
+ |
if (argv[i][2] == 'd') |
128 |
+ |
break; |
129 |
+ |
/* FALL THROUGH */ |
130 |
+ |
case 's': |
131 |
+ |
case 'P': |
132 |
|
rtargv[rtargc++] = argv[i]; |
133 |
|
rtargv[rtargc++] = argv[++i]; |
134 |
|
break; |
135 |
+ |
case 'w': |
136 |
+ |
rtargv[rtargc++] = argv[i]; |
137 |
+ |
break; |
138 |
|
case 'a': |
139 |
|
rtargv[rtargc++] = argv[i]; |
140 |
|
if (argv[i][2] == 'v') { |
156 |
|
} |
157 |
|
/* get view */ |
158 |
|
if (picture != NULL) { |
159 |
< |
rval = viewfile(picture, &pictview, 0, 0); |
159 |
> |
rval = viewfile(picture, &pictview, NULL); |
160 |
|
if (rval < 0) { |
161 |
|
fprintf(stderr, "%s: cannot open picture file \"%s\"\n", |
162 |
|
progname, picture); |
183 |
|
progname); |
184 |
|
exit(1); |
185 |
|
} |
186 |
< |
copystruct(&ourview, &pictview); |
186 |
> |
ourview = pictview; |
187 |
|
} else if (picture != NULL && !VEQ(ourview.vp, pictview.vp)) { |
188 |
|
fprintf(stderr, "%s: picture must have same viewpoint\n", |
189 |
|
progname); |
212 |
|
absorb_specks(); /* eliminate tiny sources */ |
213 |
|
cleanup(); /* tidy up */ |
214 |
|
/* print header */ |
215 |
+ |
newheader("RADIANCE", stdout); |
216 |
|
printargs(argc, argv, stdout); |
217 |
|
fputs(VIEWSTR, stdout); |
218 |
|
fprintview(&ourview, stdout); |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
< |
int |
234 |
< |
angcmp(ap1, ap2) /* compare two angles */ |
235 |
< |
ANGLE *ap1, *ap2; |
233 |
> |
static int |
234 |
> |
angcmp( /* compare two angles */ |
235 |
> |
const void *ap1, |
236 |
> |
const void *ap2 |
237 |
> |
) |
238 |
|
{ |
239 |
|
register int a1, a2; |
240 |
|
|
241 |
< |
a1 = *ap1; |
242 |
< |
a2 = *ap2; |
241 |
> |
a1 = *(ANGLE *)ap1; |
242 |
> |
a2 = *(ANGLE *)ap2; |
243 |
|
if (a1 == a2) { |
244 |
|
fprintf(stderr, "%s: duplicate glare angle (%d)\n", |
245 |
|
progname, a1); |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
< |
init() /* initialize global variables */ |
252 |
> |
static void |
253 |
> |
init(void) /* initialize global variables */ |
254 |
|
{ |
255 |
|
double d; |
256 |
|
register int i; |
281 |
|
if (indirect == NULL) |
282 |
|
memerr("indirect illuminances"); |
283 |
|
npixinvw = npixmiss = 0L; |
284 |
< |
copystruct(&leftview, &ourview); |
285 |
< |
copystruct(&rightview, &ourview); |
284 |
> |
leftview = ourview; |
285 |
> |
rightview = ourview; |
286 |
|
spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); |
287 |
|
spinvector(rightview.vdir, ourview.vdir, ourview.vup, -maxtheta); |
288 |
|
setview(&leftview); |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
< |
cleanup() /* close files, wait for children */ |
329 |
> |
static void |
330 |
> |
cleanup(void) /* close files, wait for children */ |
331 |
|
{ |
332 |
|
if (verbose) |
333 |
|
fprintf(stderr, "%s: cleaning up... \n", progname); |
336 |
|
if (octree != NULL) |
337 |
|
done_rtrace(); |
338 |
|
if (npixinvw < 100*npixmiss) |
339 |
< |
fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", |
340 |
< |
progname, 100L*npixmiss/npixinvw); |
339 |
> |
fprintf(stderr, "%s: warning -- missing %d%% of samples\n", |
340 |
> |
progname, (int)(100L*npixmiss/npixinvw)); |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
< |
compdir(vd, x, y) /* compute direction for x,y */ |
345 |
< |
FVECT vd; |
346 |
< |
int x, y; |
344 |
> |
extern int |
345 |
> |
compdir( /* compute direction for x,y */ |
346 |
> |
FVECT vd, |
347 |
> |
int x, |
348 |
> |
int y |
349 |
> |
) |
350 |
|
{ |
351 |
|
int hl; |
352 |
|
FVECT org; /* dummy variable */ |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
< |
double |
378 |
< |
pixsize(x, y) /* return the solid angle of pixel at (x,y) */ |
379 |
< |
int x, y; |
377 |
> |
extern double |
378 |
> |
pixsize( /* return the solid angle of pixel at (x,y) */ |
379 |
> |
int x, |
380 |
> |
int y |
381 |
> |
) |
382 |
|
{ |
383 |
|
register int hl, xo; |
384 |
|
double disc; |
390 |
|
xo = x-hl; |
391 |
|
else |
392 |
|
xo = 0; |
393 |
< |
disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); |
394 |
< |
if (disc <= FTINY) |
393 |
> |
disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens); |
394 |
> |
if (disc <= FTINY*FTINY) |
395 |
|
return(0.); |
396 |
|
return(1./(sampdens*sampdens*sqrt(disc))); |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
< |
memerr(s) /* malloc failure */ |
401 |
< |
char *s; |
400 |
> |
extern void |
401 |
> |
memerr( /* malloc failure */ |
402 |
> |
char *s |
403 |
> |
) |
404 |
|
{ |
405 |
|
fprintf(stderr, "%s: out of memory for %s\n", progname, s); |
406 |
|
exit(1); |
407 |
|
} |
408 |
|
|
409 |
|
|
410 |
< |
printsources() /* print out glare sources */ |
410 |
> |
static void |
411 |
> |
printsources(void) /* print out glare sources */ |
412 |
|
{ |
413 |
|
register struct source *sp; |
414 |
|
|
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
< |
printillum() /* print out indirect illuminances */ |
424 |
> |
static void |
425 |
> |
printillum(void) /* print out indirect illuminances */ |
426 |
|
{ |
427 |
|
register int i; |
428 |
|
|