--- ray/src/gen/mkillum2.c 1992/08/12 14:44:15 2.3 +++ ray/src/gen/mkillum2.c 2004/03/28 20:33:12 2.14 @@ -1,40 +1,52 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mkillum2.c,v 2.14 2004/03/28 20:33:12 schorsch Exp $"; #endif - /* * Routines to do the actual calculation for mkillum */ -#include "mkillum.h" +#include +#include "mkillum.h" #include "face.h" - #include "cone.h" - #include "random.h" -o_default(ob, il, rt, nm) /* default illum action */ -OBJREC *ob; -struct illum_args *il; -struct rtproc *rt; -char *nm; +int o_default(FUN_ARGLIST); +int o_face(FUN_ARGLIST); +int o_sphere(FUN_ARGLIST); +int o_ring(FUN_ARGLIST); +void raysamp(float res[3], FVECT org, FVECT dir, struct rtproc *rt); +void rayflush(struct rtproc *rt); +void mkaxes(FVECT u, FVECT v, FVECT n); +void rounddir(FVECT dv, double alt, double azi); +void flatdir(FVECT dv, double alt, double azi); + + +int /* XXX type conflict with otypes.h */ +o_default( /* default illum action */ + OBJREC *ob, + struct illum_args *il, + struct rtproc *rt, + char *nm +) { sprintf(errmsg, "(%s): cannot make illum for %s \"%s\"", nm, ofun[ob->otype].funame, ob->oname); error(WARNING, errmsg); printobj(il->altmat, ob); + return(1); } -o_face(ob, il, rt, nm) /* make an illum face */ -OBJREC *ob; -struct illum_args *il; -struct rtproc *rt; -char *nm; +int +o_face( /* make an illum face */ + OBJREC *ob, + struct illum_args *il, + struct rtproc *rt, + char *nm +) { #define MAXMISS (5*n*il->nsamps) int dim[3]; @@ -51,8 +63,7 @@ char *nm; fa = getface(ob); if (fa->area == 0.0) { freeface(ob); - o_default(ob, il, rt, nm); - return; + return(o_default(ob, il, rt, nm)); } /* set up sampling */ if (il->sampdens <= 0) @@ -67,14 +78,16 @@ char *nm; if (distarr == NULL) error(SYSTEM, "out of memory in o_face"); /* take first edge longer than sqrt(area) */ - for (i = 1; i < fa->nv; i++) { - for (j = 0; j < 3; j++) - u[j] = VERTEX(fa,i)[j] - VERTEX(fa,i-1)[j]; - if (DOT(u,u) >= fa->area-FTINY) + for (j = fa->nv-1, i = 0; i < fa->nv; j = i++) { + u[0] = VERTEX(fa,i)[0] - VERTEX(fa,j)[0]; + u[1] = VERTEX(fa,i)[1] - VERTEX(fa,j)[1]; + u[2] = VERTEX(fa,i)[2] - VERTEX(fa,j)[2]; + if ((r1 = DOT(u,u)) >= fa->area-FTINY) break; } if (i < fa->nv) { /* got one! -- let's align our axes */ - normalize(u); + r2 = 1.0/sqrt(r1); + u[0] *= r2; u[1] *= r2; u[2] *= r2; fcross(v, fa->norm, u); } else /* oh well, we'll just have to wing it */ mkaxes(u, v, fa->norm); @@ -116,9 +129,8 @@ char *nm; objerror(ob, WARNING, "bad aspect"); rt->nrays = 0; freeface(ob); - free((char *)distarr); - o_default(ob, il, rt, nm); - return; + free((void *)distarr); + return(o_default(ob, il, rt, nm)); } for (j = 0; j < 3; j++) org[j] += .001*fa->norm[j]; @@ -135,16 +147,19 @@ char *nm; printobj(il->altmat, ob); /* clean up */ freeface(ob); - free((char *)distarr); + free((void *)distarr); #undef MAXMISS + /* XXX we need to return something here. what is it? */ } -o_sphere(ob, il, rt, nm) /* make an illum sphere */ -register OBJREC *ob; -struct illum_args *il; -struct rtproc *rt; -char *nm; +int +o_sphere( /* make an illum sphere */ + register OBJREC *ob, + struct illum_args *il, + struct rtproc *rt, + char *nm +) { int dim[3]; int n, nalt, nazi; @@ -161,8 +176,8 @@ char *nm; nalt = nazi = 1; else { n = 4.*PI * il->sampdens; - nalt = sqrt(n/PI) + .5; - nazi = PI*nalt + .5; + nalt = sqrt(2./PI*n) + .5; + nazi = PI/2.*nalt + .5; } n = nalt*nazi; distarr = (float *)calloc(n, 3*sizeof(float)); @@ -205,15 +220,18 @@ char *nm; } else printobj(il->altmat, ob); /* clean up */ - free((char *)distarr); + free((void *)distarr); + return(1); } -o_ring(ob, il, rt, nm) /* make an illum ring */ -OBJREC *ob; -struct illum_args *il; -struct rtproc *rt; -char *nm; +int +o_ring( /* make an illum ring */ + OBJREC *ob, + struct illum_args *il, + struct rtproc *rt, + char *nm +) { int dim[3]; int n, nalt, nazi; @@ -258,7 +276,7 @@ char *nm; r1 = r3*cos(r2); r2 = r3*sin(r2); for (j = 0; j < 3; j++) - org[j] = CO_P0(co)[j] + r1*u[j] + r1*v[j] + + org[j] = CO_P0(co)[j] + r1*u[j] + r2*v[j] + .001*co->ad[j]; /* send sample */ @@ -274,14 +292,18 @@ char *nm; printobj(il->altmat, ob); /* clean up */ freecone(ob); - free((char *)distarr); + free((void *)distarr); + return(1); } -raysamp(res, org, dir, rt) /* compute a ray sample */ -float res[3]; -FVECT org, dir; -register struct rtproc *rt; +void +raysamp( /* compute a ray sample */ + float res[3], + FVECT org, + FVECT dir, + register struct rtproc *rt +) { register float *fp; @@ -294,19 +316,21 @@ register struct rtproc *rt; } -rayflush(rt) /* flush buffered rays */ -register struct rtproc *rt; +void +rayflush( /* flush buffered rays */ + register struct rtproc *rt +) { register int i; if (rt->nrays <= 0) return; - bzero(rt->buf+6*rt->nrays, 6*sizeof(float)); + memset(rt->buf+6*rt->nrays, '\0', 6*sizeof(float)); errno = 0; - if ( process(rt->pd, (char *)rt->buf, (char *)rt->buf, - 3*sizeof(float)*rt->nrays, + if ( process(&(rt->pd), (char *)rt->buf, (char *)rt->buf, + 3*sizeof(float)*(rt->nrays+1), 6*sizeof(float)*(rt->nrays+1)) < - 3*sizeof(float)*rt->nrays ) + 3*sizeof(float)*(rt->nrays+1) ) error(SYSTEM, "error reading from rtrace process"); i = rt->nrays; while (i--) { @@ -318,8 +342,12 @@ register struct rtproc *rt; } -mkaxes(u, v, n) /* compute u and v to go with n */ -FVECT u, v, n; +void +mkaxes( /* compute u and v to go with n */ + FVECT u, + FVECT v, + FVECT n +) { register int i; @@ -334,9 +362,12 @@ FVECT u, v, n; } -rounddir(dv, alt, azi) /* compute uniform spherical direction */ -register FVECT dv; -double alt, azi; +void +rounddir( /* compute uniform spherical direction */ + register FVECT dv, + double alt, + double azi +) { double d1, d2; @@ -348,9 +379,12 @@ double alt, azi; } -flatdir(dv, alt, azi) /* compute uniform hemispherical direction */ -register FVECT dv; -double alt, azi; +void +flatdir( /* compute uniform hemispherical direction */ + register FVECT dv, + double alt, + double azi +) { double d1, d2;