6 |
|
* Initialization and calculation routines |
7 |
|
*/ |
8 |
|
|
9 |
+ |
#include "copyright.h" |
10 |
+ |
|
11 |
+ |
#include <ctype.h> |
12 |
|
#include "rcontrib.h" |
13 |
|
#include "otypes.h" |
14 |
+ |
#include "source.h" |
15 |
|
|
16 |
|
char *shm_boundary = NULL; /* boundary of shared memory */ |
17 |
|
|
91 |
|
|
92 |
|
/* Add modifier to our list to track */ |
93 |
|
MODCONT * |
94 |
< |
addmodifier(char *modn, char *outf, char *binv, int bincnt) |
94 |
> |
addmodifier(char *modn, char *outf, char *prms, char *binv, int bincnt) |
95 |
|
{ |
96 |
|
LUENT *lep = lu_find(&modconttab,modn); |
97 |
|
MODCONT *mp; |
128 |
|
error(SYSTEM, "out of memory in addmodifier"); |
129 |
|
mp->outspec = outf; /* XXX assumes static string */ |
130 |
|
mp->modname = modn; /* XXX assumes static string */ |
131 |
+ |
mp->params = prms; |
132 |
|
mp->binv = ebinv; |
133 |
|
mp->nbins = bincnt; |
134 |
|
memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt); |
142 |
|
|
143 |
|
/* Add modifiers from a file list */ |
144 |
|
void |
145 |
< |
addmodfile(char *fname, char *outf, char *binv, int bincnt) |
145 |
> |
addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt) |
146 |
|
{ |
147 |
|
char *mname[MAXMODLIST]; |
148 |
|
int i; |
152 |
|
error(SYSTEM, errmsg); |
153 |
|
} |
154 |
|
for (i = 0; mname[i]; i++) /* add each one */ |
155 |
< |
addmodifier(mname[i], outf, binv, bincnt); |
155 |
> |
addmodifier(mname[i], outf, prms, binv, bincnt); |
156 |
|
} |
157 |
|
|
158 |
|
|
181 |
|
/* set shared memory boundary */ |
182 |
|
shm_boundary = strcpy((char *)malloc(16), "SHM_BOUNDARY"); |
183 |
|
} |
184 |
+ |
for (i = 0; i < nsources; i++) /* tracing to sources as well */ |
185 |
+ |
source[i].sflags |= SFOLLOW; |
186 |
|
if (yres > 0) { /* set up flushing & ray counts */ |
187 |
|
if (xres > 0) |
188 |
|
raysleft = (RNUMBER)xres*yres; |
215 |
|
|
216 |
|
/************************** MAIN CALCULATION PROCESS ***********************/ |
217 |
|
|
218 |
+ |
/* Set parameters for current bin evaluation */ |
219 |
+ |
static void |
220 |
+ |
set_eparams(char *prms) |
221 |
+ |
{ |
222 |
+ |
char vname[64]; |
223 |
+ |
double value; |
224 |
+ |
char *cps, *cpd; |
225 |
+ |
/* assign each variable */ |
226 |
+ |
for (cps = prms; *cps; cps++) { |
227 |
+ |
if (isspace(*cps)) |
228 |
+ |
continue; |
229 |
+ |
if (!isalpha(*cps)) |
230 |
+ |
goto bad_params; |
231 |
+ |
cpd = vname; |
232 |
+ |
while (*cps && (*cps != '=') & !isspace(*cps)) { |
233 |
+ |
if (!isid(*cps)) |
234 |
+ |
goto bad_params; |
235 |
+ |
*cpd++ = *cps++; |
236 |
+ |
} |
237 |
+ |
if (cpd == vname) |
238 |
+ |
goto bad_params; |
239 |
+ |
*cpd = '\0'; |
240 |
+ |
while (isspace(*cps)) cps++; |
241 |
+ |
if (*cps++ != '=') |
242 |
+ |
goto bad_params; |
243 |
+ |
value = atof(cps); |
244 |
+ |
if ((cps = fskip(cps)) == NULL) |
245 |
+ |
goto bad_params; |
246 |
+ |
while (isspace(*cps)) cps++; |
247 |
+ |
cps += (*cps == ',') | (*cps == ';'); |
248 |
+ |
varset(vname, '=', value); |
249 |
+ |
} |
250 |
+ |
return; |
251 |
+ |
bad_params: |
252 |
+ |
sprintf(errmsg, "bad parameter list '%s'", prms); |
253 |
+ |
error(USER, errmsg); |
254 |
+ |
} |
255 |
+ |
|
256 |
|
/* Our trace call to sum contributions */ |
257 |
|
static void |
258 |
|
trace_contrib(RAY *r) |
259 |
|
{ |
260 |
+ |
static char *last_params = NULL; |
261 |
|
MODCONT *mp; |
262 |
+ |
double bval; |
263 |
|
int bn; |
264 |
|
RREAL contr[3]; |
265 |
|
|
266 |
|
if (r->ro == NULL || r->ro->omod == OVOID) |
267 |
|
return; |
268 |
+ |
/* shadow ray not on source? */ |
269 |
+ |
if (r->rsrc >= 0 && source[r->rsrc].so != r->ro) |
270 |
+ |
return; |
271 |
|
|
272 |
|
mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data; |
273 |
|
|
274 |
|
if (mp == NULL) /* not in our list? */ |
275 |
|
return; |
276 |
|
|
277 |
< |
worldfunc(RCCONTEXT, r); /* get bin number */ |
278 |
< |
bn = (int)(evalue(mp->binv) + .5); |
279 |
< |
if ((bn < 0) | (bn >= mp->nbins)) { |
277 |
> |
worldfunc(RCCONTEXT, r); /* else set context */ |
278 |
> |
if ((mp->params != NULL) & (mp->params != last_params) && |
279 |
> |
(last_params == NULL || strcmp(mp->params, last_params))) |
280 |
> |
set_eparams(last_params = (char *)mp->params); |
281 |
> |
if ((bval = evalue(mp->binv)) <= -.5) /* and get bin number */ |
282 |
> |
return; /* silently ignore negatives */ |
283 |
> |
if ((bn = (int)(bval + .5)) >= mp->nbins) { |
284 |
|
error(WARNING, "bad bin number (ignored)"); |
285 |
|
return; |
286 |
|
} |
287 |
< |
raycontrib(contr, r, PRIMARY); |
287 |
> |
raycontrib(contr, r, PRIMARY); /* compute coefficient */ |
288 |
|
if (contrib) |
289 |
< |
multcolor(contr, r->rcol); |
289 |
> |
multcolor(contr, r->rcol); /* -> contribution */ |
290 |
|
addcolor(mp->cbin[bn], contr); |
291 |
|
} |
292 |
|
|
303 |
|
thisray.rdir[2] = -dir[2]; |
304 |
|
thisray.rmax = 0.0; |
305 |
|
rayorigin(&thisray, PRIMARY, NULL, NULL); |
306 |
< |
thisray.rot = 1e-5; /* pretend we hit surface */ |
306 |
> |
/* pretend we hit surface */ |
307 |
> |
thisray.rt = thisray.rot = 1e-5; |
308 |
|
thisray.rod = 1.0; |
309 |
+ |
VCOPY(thisray.ron, dir); |
310 |
|
VSUM(thisray.rop, org, dir, 1e-4); |
311 |
|
samplendx++; /* compute result */ |
312 |
|
(*ofun[Lamb.otype].funp)(&Lamb, &thisray); |
364 |
|
#endif |
365 |
|
while (getvec(orig) == 0 && getvec(direc) == 0) { |
366 |
|
d = normalize(direc); |
367 |
< |
if (nchild != -1 && (d == 0.0) & (accumulate != 1)) { |
367 |
> |
if (nchild != -1 && (d == 0.0) & (accumulate == 0)) { |
368 |
|
if (!ignore_warning_given++) |
369 |
|
error(WARNING, |
370 |
|
"dummy ray(s) ignored during accumulation\n"); |
374 |
|
lastray = lastdone = 0; |
375 |
|
++lastray; |
376 |
|
if (d == 0.0) { /* zero ==> flush */ |
377 |
< |
if ((yres <= 0) | (xres <= 0)) |
378 |
< |
waitflush = 1; /* flush right after */ |
379 |
< |
account = 1; |
377 |
> |
if ((yres <= 0) | (xres <= 1)) |
378 |
> |
waitflush = 1; /* flush after */ |
379 |
> |
if (nchild == -1) |
380 |
> |
account = 1; |
381 |
|
} else if (imm_irrad) { /* else compute */ |
382 |
|
eval_irrad(orig, direc); |
383 |
|
} else { |