--- ray/src/util/findglare.c 1993/02/03 17:55:34 2.5 +++ ray/src/util/findglare.c 2004/03/26 23:34:23 2.12 @@ -1,9 +1,6 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: findglare.c,v 2.12 2004/03/26 23:34:23 schorsch Exp $"; #endif - /* * Find glare sources in a scene or image. * @@ -16,8 +13,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ &&FEQ((v1)[2],(v2)[2])) -char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; -int rtargc = 4; +char *rtargv[64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}; +int rtargc = 7; VIEW ourview = STDVIEW; /* our view */ VIEW pictview = STDVIEW; /* picture view */ @@ -42,10 +39,19 @@ struct illum *indirect; /* array of indirect illumina long npixinvw; /* number of pixels in view */ long npixmiss; /* number of pixels missed */ +static int angcmp(const void *ap1, const void *ap2); +static void init(void); +static void cleanup(void); +static void printsources(void); +static void printillum(void); -main(argc, argv) -int argc; -char *argv[]; + + +int +main( + int argc, + char *argv[] +) { int combine = 1; int gotview = 0; @@ -55,6 +61,14 @@ char *argv[]; progname = argv[0]; /* process options */ for (i = 1; i < argc && argv[i][0] == '-'; i++) { + /* expand arguments */ + while ((rval = expandarg(&argc, &argv, i)) > 0) + ; + if (rval < 0) { + fprintf(stderr, "%s: cannot expand '%s'", + argv[0], argv[i]); + exit(1); + } rval = getviewopt(&ourview, argc-i, argv+i); if (rval >= 0) { i += rval; @@ -105,12 +119,14 @@ char *argv[]; combine = !combine; break; case 'd': - if (argv[i][2] == 'v') { - rtargv[rtargc++] = argv[i]; + rtargv[rtargc++] = argv[i]; + if (argv[i][2] != 'v') + rtargv[rtargc++] = argv[++i]; + break; + case 'l': + if (argv[i][2] == 'd') break; - } /* FALL THROUGH */ - case 'l': case 's': case 'P': rtargv[rtargc++] = argv[i]; @@ -167,7 +183,7 @@ char *argv[]; progname); exit(1); } - copystruct(&ourview, &pictview); + ourview = pictview; } else if (picture != NULL && !VEQ(ourview.vp, pictview.vp)) { fprintf(stderr, "%s: picture must have same viewpoint\n", progname); @@ -196,6 +212,7 @@ char *argv[]; absorb_specks(); /* eliminate tiny sources */ cleanup(); /* tidy up */ /* print header */ + newheader("RADIANCE", stdout); printargs(argc, argv, stdout); fputs(VIEWSTR, stdout); fprintview(&ourview, stdout); @@ -213,14 +230,16 @@ userr: } -int -angcmp(ap1, ap2) /* compare two angles */ -ANGLE *ap1, *ap2; +static int +angcmp( /* compare two angles */ + const void *ap1, + const void *ap2 +) { register int a1, a2; - a1 = *ap1; - a2 = *ap2; + a1 = *(ANGLE *)ap1; + a2 = *(ANGLE *)ap2; if (a1 == a2) { fprintf(stderr, "%s: duplicate glare angle (%d)\n", progname, a1); @@ -230,7 +249,8 @@ ANGLE *ap1, *ap2; } -init() /* initialize global variables */ +static void +init(void) /* initialize global variables */ { double d; register int i; @@ -261,8 +281,8 @@ init() /* initialize global variables */ if (indirect == NULL) memerr("indirect illuminances"); npixinvw = npixmiss = 0L; - copystruct(&leftview, &ourview); - copystruct(&rightview, &ourview); + leftview = ourview; + rightview = ourview; spinvector(leftview.vdir, ourview.vdir, ourview.vup, maxtheta); spinvector(rightview.vdir, ourview.vdir, ourview.vup, -maxtheta); setview(&leftview); @@ -306,7 +326,8 @@ init() /* initialize global variables */ } -cleanup() /* close files, wait for children */ +static void +cleanup(void) /* close files, wait for children */ { if (verbose) fprintf(stderr, "%s: cleaning up... \n", progname); @@ -320,9 +341,12 @@ cleanup() /* close files, wait for children */ } -compdir(vd, x, y) /* compute direction for x,y */ -FVECT vd; -int x, y; +extern int +compdir( /* compute direction for x,y */ + FVECT vd, + int x, + int y +) { int hl; FVECT org; /* dummy variable */ @@ -350,9 +374,11 @@ int x, y; } -double -pixsize(x, y) /* return the solid angle of pixel at (x,y) */ -int x, y; +extern double +pixsize( /* return the solid angle of pixel at (x,y) */ + int x, + int y +) { register int hl, xo; double disc; @@ -364,22 +390,25 @@ int x, y; xo = x-hl; else xo = 0; - disc = 1. - (double)(xo*xo + y*y)/(sampdens*sampdens); - if (disc <= FTINY) + disc = 1. - (double)((long)xo*xo + (long)y*y)/((long)sampdens*sampdens); + if (disc <= FTINY*FTINY) return(0.); return(1./(sampdens*sampdens*sqrt(disc))); } -memerr(s) /* malloc failure */ -char *s; +extern void +memerr( /* malloc failure */ + char *s +) { fprintf(stderr, "%s: out of memory for %s\n", progname, s); exit(1); } -printsources() /* print out glare sources */ +static void +printsources(void) /* print out glare sources */ { register struct source *sp; @@ -392,7 +421,8 @@ printsources() /* print out glare sources */ } -printillum() /* print out indirect illuminances */ +static void +printillum(void) /* print out indirect illuminances */ { register int i;