--- ray/src/rt/rtrace.c 2009/12/13 19:13:04 2.59 +++ ray/src/rt/rtrace.c 2012/06/27 15:32:58 2.67 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtrace.c,v 2.59 2009/12/13 19:13:04 greg Exp $"; +static const char RCSid[] = "$Id: rtrace.c,v 2.67 2012/06/27 15:32:58 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); @@ -114,8 +114,8 @@ rtrace( /* trace rays from file */ ) { unsigned long vcount = (hresolu > 1) ? (unsigned long)hresolu*vresolu - : vresolu; - long nextflush = hresolu; + : (unsigned long)vresolu; + 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; } @@ -338,24 +344,22 @@ rtcompute( /* compute and print ray value(s) */ double dmax ) { - if (imm_irrad) { /* set up ray */ + /* set up ray */ + rayorigin(&thisray, PRIMARY, NULL, NULL); + if (imm_irrad) { VSUM(thisray.rorg, org, dir, 1.1e-4); thisray.rdir[0] = -dir[0]; thisray.rdir[1] = -dir[1]; thisray.rdir[2] = -dir[2]; thisray.rmax = 0.0; + thisray.revf = rayirrad; } else { VCOPY(thisray.rorg, org); VCOPY(thisray.rdir, dir); thisray.rmax = dmax; + if (castonly) + thisray.revf = raycast; } - rayorigin(&thisray, PRIMARY, NULL, NULL); - /* special case evaluators */ - if (castonly) - thisray.revf = raycast; - else if (imm_irrad) - thisray.revf = rayirrad; - if (ray_pnprocs > 1) { /* multiprocessing FIFO? */ if (ray_fifo_in(&thisray) < 0) error(USER, "lost children"); @@ -490,9 +494,7 @@ oputo( /* print origin */ RAY *r ) { - (*putreal)(r->rorg[0]); - (*putreal)(r->rorg[1]); - (*putreal)(r->rorg[2]); + (*putreal)(r->rorg, 3); } @@ -501,9 +503,7 @@ oputd( /* print direction */ RAY *r ) { - (*putreal)(r->rdir[0]); - (*putreal)(r->rdir[1]); - (*putreal)(r->rdir[2]); + (*putreal)(r->rdir, 3); } @@ -512,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); } @@ -531,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); } @@ -546,7 +547,7 @@ oputl( /* print effective distance */ RAY *r ) { - (*putreal)(r->rt); + (*putreal)(&r->rt, 1); } @@ -555,7 +556,7 @@ oputL( /* print single ray length */ RAY *r ) { - (*putreal)(r->rot); + (*putreal)(&r->rot, 1); } @@ -564,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); } @@ -591,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); } @@ -611,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); } @@ -641,7 +630,9 @@ oputw( /* print weight */ RAY *r ) { - (*putreal)(r->rweight); + RREAL rwt = r->rweight; + + (*putreal)(&rwt, 1); } @@ -650,12 +641,14 @@ oputW( /* print coefficient */ RAY *r ) { - double contr[3]; + RREAL contr[3]; + /* shadow ray not on source? */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + setcolor(contr, 0.0, 0.0, 0.0); + else + raycontrib(contr, r, PRIMARY); - raycontrib(contr, r, PRIMARY); - (*putreal)(contr[RED]); - (*putreal)(contr[GRN]); - (*putreal)(contr[BLU]); + (*putreal)(contr, 3); } @@ -703,27 +696,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); }