--- ray/src/util/findglare.c 2003/02/22 02:07:30 2.9 +++ ray/src/util/findglare.c 2023/01/15 16:38:10 2.17 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: findglare.c,v 2.9 2003/02/22 02:07:30 greg Exp $"; +static const char RCSid[] = "$Id: findglare.c,v 2.17 2023/01/15 16:38:10 greg Exp $"; #endif /* * Find glare sources in a scene or image. @@ -9,10 +9,6 @@ static const char RCSid[] = "$Id: findglare.c,v 2.9 20 #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; @@ -39,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; @@ -56,7 +61,7 @@ char *argv[]; while ((rval = expandarg(&argc, &argv, i)) > 0) ; if (rval < 0) { - fprintf(stderr, "%s: cannot expand '%s'", + fprintf(stderr, "%s: cannot expand '%s'\n", argv[0], argv[i]); exit(1); } @@ -120,10 +125,13 @@ char *argv[]; /* 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': @@ -134,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; } @@ -174,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); @@ -221,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; + 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); @@ -238,10 +256,11 @@ ANGLE *ap1, *ap2; } -init() /* initialize global variables */ +static void +init(void) /* initialize global variables */ { double d; - register int i; + int i; if (verbose) fprintf(stderr, "%s: initializing data structures...\n", @@ -269,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); @@ -314,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); @@ -328,9 +348,12 @@ cleanup() /* close files, wait for children */ } -compdir(vd, x, y) /* compute direction for x,y */ -FVECT vd; -int x, y; +int +compdir( /* compute direction for x,y */ + FVECT vd, + int x, + int y +) { int hl; FVECT org; /* dummy variable */ @@ -359,10 +382,12 @@ int x, y; double -pixsize(x, y) /* return the solid angle of pixel at (x,y) */ -int x, y; +pixsize( /* return the solid angle of pixel at (x,y) */ + int x, + int y +) { - register int hl, xo; + int hl, xo; double disc; hl = hlim(y); @@ -379,30 +404,34 @@ int x, y; } -memerr(s) /* malloc failure */ -char *s; +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; + struct source *sp; printf("BEGIN glare source\n"); for (sp = donelist; sp != NULL; sp = sp->next) - printf("\t%f %f %f\t%f\t%f\n", + printf("\t%f %f %f\t%e\t%e\n", sp->dir[0], sp->dir[1], sp->dir[2], sp->dom, sp->brt); printf("END glare source\n"); } -printillum() /* print out indirect illuminances */ +static void +printillum(void) /* print out indirect illuminances */ { - register int i; + int i; printf("BEGIN indirect illuminance\n"); for (i = 0; i < nglardirs; i++)