--- ray/src/rt/rtrace.c 2009/12/14 03:15:45 2.60 +++ ray/src/rt/rtrace.c 2011/04/06 00:14:26 2.65 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtrace.c,v 2.60 2009/12/14 03:15:45 greg Exp $"; +static const char RCSid[] = "$Id: rtrace.c,v 2.65 2011/04/06 00:14:26 greg Exp $"; #endif /* * rtrace.c - program and variables for individual ray tracing. @@ -53,7 +53,7 @@ OBJECT traset[MAXTSET+1]={0}; /* trace include/exclud static RAY thisray; /* for our convenience */ -typedef void putf_t(double v); +typedef void putf_t(RREAL *v, int n); static putf_t puta, putd, putf; typedef void oputf_t(RAY *r); @@ -115,7 +115,7 @@ rtrace( /* trace rays from file */ { unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu : vresolu; - long nextflush = hresolu; + long nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : hresolu; FILE *fp; double d; FVECT orig, direc; @@ -160,13 +160,15 @@ rtrace( /* trace rays from file */ d = normalize(direc); if (d == 0.0) { /* zero ==> flush */ - if (nproc > 1 && ray_fifo_flush() < 0) - error(USER, "lost children"); - bogusray(); if (--nextflush <= 0 || !vcount) { + if (nproc > 1 && ray_fifo_flush() < 0) + error(USER, "lost children"); + bogusray(); fflush(stdout); - nextflush = hresolu; - } + nextflush = (vresolu > 0) & (hresolu > 1) ? 0 : + hresolu; + } else + bogusray(); } else { /* compute and print */ rtcompute(orig, direc, lim_dist ? d : 0.0); /* flush if time */ @@ -320,6 +322,8 @@ rayirrad( /* compute irradiance rather than radiance RAY *r ) { + void (*old_revf)(RAY *) = r->revf; + r->rot = 1e-5; /* pretend we hit surface */ VSUM(r->rop, r->rorg, r->rdir, r->rot); r->ron[0] = -r->rdir[0]; @@ -327,7 +331,9 @@ rayirrad( /* compute irradiance rather than radiance r->ron[2] = -r->rdir[2]; r->rod = 1.0; /* compute result */ + r->revf = raytrace; (*ofun[Lamb.otype].funp)(&Lamb, r); + r->revf = old_revf; } @@ -488,9 +494,7 @@ oputo( /* print origin */ RAY *r ) { - (*putreal)(r->rorg[0]); - (*putreal)(r->rorg[1]); - (*putreal)(r->rorg[2]); + (*putreal)(r->rorg, 3); } @@ -499,9 +503,7 @@ oputd( /* print direction */ RAY *r ) { - (*putreal)(r->rdir[0]); - (*putreal)(r->rdir[1]); - (*putreal)(r->rdir[2]); + (*putreal)(r->rdir, 3); } @@ -510,17 +512,20 @@ oputv( /* print value */ RAY *r ) { + RREAL cval[3]; + if (outform == 'c') { COLR cout; setcolr(cout, colval(r->rcol,RED), colval(r->rcol,GRN), colval(r->rcol,BLU)); - fwrite((char *)cout, sizeof(cout), 1, stdout); + fwrite(cout, sizeof(cout), 1, stdout); return; } - (*putreal)(colval(r->rcol,RED)); - (*putreal)(colval(r->rcol,GRN)); - (*putreal)(colval(r->rcol,BLU)); + cval[0] = colval(r->rcol,RED); + cval[1] = colval(r->rcol,GRN); + cval[2] = colval(r->rcol,BLU); + (*putreal)(cval, 3); } @@ -529,13 +534,11 @@ oputV( /* print value contribution */ RAY *r ) { - double contr[3]; + RREAL contr[3]; raycontrib(contr, r, PRIMARY); multcolor(contr, r->rcol); - (*putreal)(contr[RED]); - (*putreal)(contr[GRN]); - (*putreal)(contr[BLU]); + (*putreal)(contr, 3); } @@ -544,7 +547,7 @@ oputl( /* print effective distance */ RAY *r ) { - (*putreal)(r->rt); + (*putreal)(&r->rt, 1); } @@ -553,7 +556,7 @@ oputL( /* print single ray length */ RAY *r ) { - (*putreal)(r->rot); + (*putreal)(&r->rot, 1); } @@ -562,25 +565,22 @@ oputc( /* print local coordinates */ RAY *r ) { - (*putreal)(r->uv[0]); - (*putreal)(r->uv[1]); + (*putreal)(r->uv, 2); } +static RREAL vdummy[3] = {0.0, 0.0, 0.0}; + + static void oputp( /* print point */ RAY *r ) { - if (r->rot < FHUGE) { - (*putreal)(r->rop[0]); - (*putreal)(r->rop[1]); - (*putreal)(r->rop[2]); - } else { - (*putreal)(0.0); - (*putreal)(0.0); - (*putreal)(0.0); - } + if (r->rot < FHUGE) + (*putreal)(r->rop, 3); + else + (*putreal)(vdummy, 3); } @@ -589,15 +589,10 @@ oputN( /* print unperturbed normal */ RAY *r ) { - if (r->rot < FHUGE) { - (*putreal)(r->ron[0]); - (*putreal)(r->ron[1]); - (*putreal)(r->ron[2]); - } else { - (*putreal)(0.0); - (*putreal)(0.0); - (*putreal)(0.0); - } + if (r->rot < FHUGE) + (*putreal)(r->ron, 3); + else + (*putreal)(vdummy, 3); } @@ -609,15 +604,11 @@ oputn( /* print perturbed normal */ FVECT pnorm; if (r->rot >= FHUGE) { - (*putreal)(0.0); - (*putreal)(0.0); - (*putreal)(0.0); + (*putreal)(vdummy, 3); return; } raynormal(pnorm, r); - (*putreal)(pnorm[0]); - (*putreal)(pnorm[1]); - (*putreal)(pnorm[2]); + (*putreal)(pnorm, 3); } @@ -639,7 +630,9 @@ oputw( /* print weight */ RAY *r ) { - (*putreal)(r->rweight); + RREAL rwt = r->rweight; + + (*putreal)(&rwt, 1); } @@ -648,12 +641,10 @@ oputW( /* print coefficient */ RAY *r ) { - double contr[3]; + RREAL contr[3]; raycontrib(contr, r, PRIMARY); - (*putreal)(contr[RED]); - (*putreal)(contr[GRN]); - (*putreal)(contr[BLU]); + (*putreal)(contr, 3); } @@ -701,27 +692,37 @@ oputtilde( /* output tilde (spacer) */ static void -puta( /* print ascii value */ - double v +puta( /* print ascii value(s) */ + RREAL *v, int n ) { - printf("%e\t", v); + if (n == 3) { + printf("%e\t%e\t%e\t", v[0], v[1], v[2]); + return; + } + while (n--) + printf("%e\t", *v++); } static void -putd(v) /* print binary double */ -double v; +putd(RREAL *v, int n) /* print binary double(s) */ { - fwrite((char *)&v, sizeof(v), 1, stdout); + if (sizeof(RREAL) != sizeof(double)) + error(INTERNAL, "code error in putd()"); + fwrite(v, sizeof(RREAL), n, stdout); } static void -putf(v) /* print binary float */ -double v; +putf(RREAL *v, int n) /* print binary float(s) */ { - float f = v; + float fa[3]; + int i; - fwrite((char *)&f, sizeof(f), 1, stdout); + if (n > 3) + error(INTERNAL, "code error in putf()"); + for (i = n; i--; ) + fa[i] = v[i]; + fwrite(fa, sizeof(float), n, stdout); }