--- ray/src/util/findglare.c 1991/11/12 17:19:13 2.1 +++ ray/src/util/findglare.c 2021/02/12 00:53:56 2.15 @@ -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.15 2021/02/12 00:53:56 greg Exp $"; #endif - /* * Find glare sources in a scene or image. * @@ -12,13 +9,9 @@ static char SCCSid[] = "$SunId$ LBL"; #include "glare.h" -#define FEQ(a,b) ((a)-(b)<=FTINY&&(b)-(a)<=FTINY) -#define VEQ(v1,v2) (FEQ((v1)[0],(v2)[0])&&FEQ((v1)[1],(v2)[1]) \ - &&FEQ((v1)[2],(v2)[2])) +char *rtargv[64] = {"rtrace", "-h-", "-ov", "-fff", "-ld-", "-i-", "-I-"}; +int rtargc = 7; -char *rtargv[32] = {"rtrace", "-h-", "-ov", "-fff"}; -int rtargc = 4; - VIEW ourview = STDVIEW; /* our view */ VIEW pictview = STDVIEW; /* picture view */ VIEW leftview, rightview; /* leftmost and rightmost views */ @@ -42,10 +35,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 +57,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'\n", + argv[0], argv[i]); + exit(1); + } rval = getviewopt(&ourview, argc-i, argv+i); if (rval >= 0) { i += rval; @@ -75,7 +85,7 @@ char *argv[]; } if (argv[i][2] != 'f') goto userr; - rval = viewfile(argv[++i], &ourview, 0, 0); + rval = viewfile(argv[++i], &ourview, NULL); if (rval < 0) { fprintf(stderr, "%s: cannot open view file \"%s\"\n", @@ -105,10 +115,25 @@ char *argv[]; combine = !combine; break; case 'd': + 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 's': + case 'P': + case 'n': rtargv[rtargc++] = argv[i]; rtargv[rtargc++] = argv[++i]; break; + case 'w': + case 'u': + case 'b': + rtargv[rtargc++] = argv[i]; + break; case 'a': rtargv[rtargc++] = argv[i]; if (argv[i][2] == 'v') { @@ -117,6 +142,14 @@ char *argv[]; } rtargv[rtargc++] = argv[++i]; break; + case 'm': + rtargv[rtargc++] = argv[i]; + if ((argv[i][2] == 'e') | (argv[i][2] == 'a')) { + rtargv[rtargc++] = argv[++i]; + rtargv[rtargc++] = argv[++i]; + } + rtargv[rtargc++] = argv[++i]; + break; default: goto userr; } @@ -130,7 +163,7 @@ char *argv[]; } /* get view */ if (picture != NULL) { - rval = viewfile(picture, &pictview, 0, 0); + rval = viewfile(picture, &pictview, NULL); if (rval < 0) { fprintf(stderr, "%s: cannot open picture file \"%s\"\n", progname, picture); @@ -157,8 +190,8 @@ char *argv[]; progname); exit(1); } - copystruct(&ourview, &pictview); - } else if (picture != NULL && !VEQ(ourview.vp, pictview.vp)) { + ourview = pictview; + } else if (picture != NULL && !VABSEQ(ourview.vp, pictview.vp)) { fprintf(stderr, "%s: picture must have same viewpoint\n", progname); exit(1); @@ -186,6 +219,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); @@ -203,14 +237,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); @@ -220,7 +256,8 @@ ANGLE *ap1, *ap2; } -init() /* initialize global variables */ +static void +init(void) /* initialize global variables */ { double d; register int i; @@ -251,8 +288,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); @@ -296,7 +333,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); @@ -305,14 +343,17 @@ cleanup() /* close files, wait for children */ if (octree != NULL) done_rtrace(); if (npixinvw < 100*npixmiss) - fprintf(stderr, "%s: warning -- missing %ld%% of samples\n", - progname, 100L*npixmiss/npixinvw); + fprintf(stderr, "%s: warning -- missing %d%% of samples\n", + progname, (int)(100L*npixmiss/npixinvw)); } -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 */ @@ -340,9 +381,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; @@ -354,22 +397,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; @@ -382,7 +428,8 @@ printsources() /* print out glare sources */ } -printillum() /* print out indirect illuminances */ +static void +printillum(void) /* print out indirect illuminances */ { register int i;