--- ray/src/rt/rcontrib.c 2012/06/16 17:30:13 2.9 +++ ray/src/rt/rcontrib.c 2014/07/19 20:03:03 2.22 @@ -1,15 +1,17 @@ #ifndef lint -static const char RCSid[] = "$Id: rcontrib.c,v 2.9 2012/06/16 17:30:13 greg Exp $"; +static const char RCSid[] = "$Id: rcontrib.c,v 2.22 2014/07/19 20:03:03 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials * Initialization and calculation routines */ +#include "copyright.h" + +#include #include "rcontrib.h" -#include "source.h" #include "otypes.h" -#include "platform.h" +#include "source.h" char *shm_boundary = NULL; /* boundary of shared memory */ @@ -89,7 +91,7 @@ formstr( /* return format identifier */ /* Add modifier to our list to track */ MODCONT * -addmodifier(char *modn, char *outf, char *binv, int bincnt) +addmodifier(char *modn, char *outf, char *prms, char *binv, int bincnt) { LUENT *lep = lu_find(&modconttab,modn); MODCONT *mp; @@ -126,6 +128,7 @@ addmodifier(char *modn, char *outf, char *binv, int bi error(SYSTEM, "out of memory in addmodifier"); mp->outspec = outf; /* XXX assumes static string */ mp->modname = modn; /* XXX assumes static string */ + mp->params = prms; mp->binv = ebinv; mp->nbins = bincnt; memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt); @@ -137,9 +140,9 @@ addmodifier(char *modn, char *outf, char *binv, int bi } -/* add modifiers from a file list */ +/* Add modifiers from a file list */ void -addmodfile(char *fname, char *outf, char *binv, int bincnt) +addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt) { char *mname[MAXMODLIST]; int i; @@ -149,7 +152,7 @@ addmodfile(char *fname, char *outf, char *binv, int bi error(SYSTEM, errmsg); } for (i = 0; mname[i]; i++) /* add each one */ - addmodifier(mname[i], outf, binv, bincnt); + addmodifier(mname[i], outf, prms, binv, bincnt); } @@ -159,7 +162,7 @@ quit( /* quit program */ ) { if (nchild > 0) /* close children if any */ - end_children(); + end_children(code != 0); exit(code); } @@ -178,6 +181,8 @@ rcinit() /* set shared memory boundary */ shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY"); } + for (i = 0; i < nsources; i++) /* tracing to sources as well */ + source[i].sflags |= SFOLLOW; if (yres > 0) { /* set up flushing & ray counts */ if (xres > 0) raysleft = (RNUMBER)xres*yres; @@ -188,9 +193,6 @@ rcinit() if ((account = accumulate) > 1) raysleft *= accumulate; waitflush = (yres > 0) & (xres > 1) ? 0 : xres; - /* tracing to sources as well */ - for (i = 0; i < nsources; i++) - source[i].sflags |= SFOLLOW; if (nproc > 1 && in_rchild()) /* forked child? */ return; /* return to main processing loop */ @@ -213,31 +215,83 @@ rcinit() /************************** MAIN CALCULATION PROCESS ***********************/ +/* Set parameters for current bin evaluation */ +void +set_eparams(char *prms) +{ + static char *last_params = NULL; + char vname[RMAXWORD]; + double value; + char *cpd; + /* check if already set */ + if ((prms == NULL) | (prms == last_params)) + return; + if (last_params != NULL && !strcmp(prms, last_params)) + return; + last_params = prms; /* assign each variable */ + while (*prms) { + if (isspace(*prms)) { + ++prms; continue; + } + if (!isalpha(*prms)) + goto bad_params; + cpd = vname; + while (*prms && (*prms != '=') & !isspace(*prms)) { + if (!isid(*prms)) + goto bad_params; + *cpd++ = *prms++; + } + if (cpd == vname) + goto bad_params; + *cpd = '\0'; + while (isspace(*prms)) prms++; + if (*prms++ != '=') + goto bad_params; + value = atof(prms); + if ((prms = fskip(prms)) == NULL) + goto bad_params; + while (isspace(*prms)) prms++; + prms += (*prms == ',') | (*prms == ';'); + varset(vname, '=', value); + } + return; +bad_params: + sprintf(errmsg, "bad parameter list '%s'", last_params); + error(USER, errmsg); +} + + /* Our trace call to sum contributions */ static void trace_contrib(RAY *r) { MODCONT *mp; + double bval; int bn; RREAL contr[3]; if (r->ro == NULL || r->ro->omod == OVOID) return; + /* shadow ray not on source? */ + if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) + return; mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data; if (mp == NULL) /* not in our list? */ return; - worldfunc(RCCONTEXT, r); /* get bin number */ - bn = (int)(evalue(mp->binv) + .5); - if ((bn < 0) | (bn >= mp->nbins)) { + worldfunc(RCCONTEXT, r); /* else set context */ + set_eparams((char *)mp->params); + if ((bval = evalue(mp->binv)) <= -.5) /* and get bin number */ + return; /* silently ignore negatives */ + if ((bn = (int)(bval + .5)) >= mp->nbins) { error(WARNING, "bad bin number (ignored)"); return; } - raycontrib(contr, r, PRIMARY); + raycontrib(contr, r, PRIMARY); /* compute coefficient */ if (contrib) - multcolor(contr, r->rcol); + multcolor(contr, r->rcol); /* -> contribution */ addcolor(mp->cbin[bn], contr); } @@ -254,8 +308,10 @@ eval_irrad(FVECT org, FVECT dir) thisray.rdir[2] = -dir[2]; thisray.rmax = 0.0; rayorigin(&thisray, PRIMARY, NULL, NULL); - thisray.rot = 1e-5; /* pretend we hit surface */ + /* pretend we hit surface */ + thisray.rt = thisray.rot = 1e-5; thisray.rod = 1.0; + VCOPY(thisray.ron, dir); VSUM(thisray.rop, org, dir, 1e-4); samplendx++; /* compute result */ (*ofun[Lamb.otype].funp)(&Lamb, &thisray); @@ -313,7 +369,7 @@ rcontrib() #endif while (getvec(orig) == 0 && getvec(direc) == 0) { d = normalize(direc); - if (nchild != -1 && (d == 0.0) & (accumulate != 1)) { + if (nchild != -1 && (d == 0.0) & (accumulate == 0)) { if (!ignore_warning_given++) error(WARNING, "dummy ray(s) ignored during accumulation\n"); @@ -323,9 +379,10 @@ rcontrib() lastray = lastdone = 0; ++lastray; if (d == 0.0) { /* zero ==> flush */ - if ((yres <= 0) | (xres <= 0)) - waitflush = 1; /* flush right after */ - account = 1; + if ((yres <= 0) | (xres <= 1)) + waitflush = 1; /* flush after */ + if (nchild == -1) + account = 1; } else if (imm_irrad) { /* else compute */ eval_irrad(orig, direc); } else { @@ -336,7 +393,7 @@ rcontrib() if (raysleft && !--raysleft) break; /* preemptive EOI */ } - if ((accumulate <= 0) | (account < accumulate)) { + if (nchild != -1 && (accumulate <= 0) | (account < accumulate)) { if (account < accumulate) { error(WARNING, "partial accumulation in final record"); accumulate -= account;