77 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
78 |
|
{ |
79 |
|
if (!prms) prms = ""; |
80 |
< |
if (!binexpr & (ncbins > 1)) { |
80 |
> |
if ((ncbins > 1) & !binexpr) { |
81 |
|
error(USER, "missing bin expression"); |
82 |
|
return NULL; |
83 |
|
} |
84 |
< |
if (ncbins <= 1) { // shouldn't have bin expression? |
85 |
< |
if (binexpr && strcmp(binexpr, "0")) |
86 |
< |
error(WARNING, "ignoring non-zero expression for single bin"); |
87 |
< |
prms = ""; |
88 |
< |
binexpr = NULL; |
89 |
< |
ncbins = 1; |
90 |
< |
} |
84 |
> |
if (ncbins < 1) ncbins = 1; |
85 |
> |
|
86 |
|
RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + |
87 |
|
sizeof(DCOLORV)*(NCSAMP*ncbins-1) + |
88 |
|
strlen(prms)+1); |
89 |
|
|
90 |
< |
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
96 |
< |
if (binexpr) { |
90 |
> |
if (binexpr) { // get/check bin expression |
91 |
|
mp->binv = eparse(const_cast<char *>(binexpr)); |
92 |
< |
CHECK(mp->binv->type==NUM, WARNING, "constant bin expression"); |
92 |
> |
if (mp->binv->type == NUM) { // constant expression (0)? |
93 |
> |
if ((int)evalue(mp->binv) != 0) { |
94 |
> |
sprintf(errmsg, "illegal non-zero constant for bin (%s)", |
95 |
> |
binexpr); |
96 |
> |
error(USER, errmsg); |
97 |
> |
} |
98 |
> |
if (ncbins > 1) { |
99 |
> |
sprintf(errmsg, "bad bin count (%d should be 1)", ncbins); |
100 |
> |
error(USER, errmsg); |
101 |
> |
} |
102 |
> |
epfree(mp->binv, true); |
103 |
> |
mp->binv = NULL; |
104 |
> |
prms = ""; |
105 |
> |
ncbins = 1; |
106 |
> |
} |
107 |
|
} |
108 |
+ |
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
109 |
|
mp->nbins = ncbins; |
110 |
|
return mp; |
111 |
|
} |
182 |
|
raycontrib(contr, r, PRIMARY); // compute coefficient |
183 |
|
if (rcp->HasFlag(RCcontrib)) |
184 |
|
smultscolor(contr, r->rcol); // -> value contribution |
185 |
+ |
|
186 |
|
for (int i = 0; i < NCSAMP; i++) |
187 |
|
*dvp++ += contr[i]; // accumulate color/spectrum |
188 |
|
return 1; |
215 |
|
error(WARNING, "ignoring bad call to AddModifier()"); |
216 |
|
return false; |
217 |
|
} |
218 |
+ |
if (*outspec == '!') { |
219 |
+ |
error(USER, "command output not supported by RcontribSimulManager"); |
220 |
+ |
return false; |
221 |
+ |
} |
222 |
|
if (!nChan) { // initial call? |
223 |
|
if ((xres < 0) | (yres <= 0)) { |
224 |
|
error(USER, "xres, yres must be set before first modifier"); |
228 |
|
return false; |
229 |
|
nChan = NCSAMP; |
230 |
|
} else if (nChan != NCSAMP) { |
231 |
< |
error(USER, "number of spectral channels must be fixed"); |
231 |
> |
error(USER, "# spectral channels must be fixed in AddModifier()"); |
232 |
|
return false; |
233 |
|
} |
234 |
|
if (Ready()) { |
324 |
|
} |
325 |
|
char mod[MAXSTR]; |
326 |
|
while (fgetword(mod, sizeof(mod), fp)) |
327 |
< |
if (!AddModifier(mod, outspec, prms, binval, bincnt)) |
327 |
> |
if (!AddModifier(mod, outspec, prms, binval, bincnt)) { |
328 |
> |
fclose(fp); |
329 |
|
return false; |
330 |
+ |
} |
331 |
|
fclose(fp); |
332 |
|
return true; |
333 |
|
} |
336 |
|
static int |
337 |
|
checkModExists(const LUENT *lp, void *p) |
338 |
|
{ |
339 |
< |
if (modifier(lp->key) != OVOID) |
339 |
> |
OBJECT mod = modifier(lp->key); |
340 |
> |
|
341 |
> |
if ((mod != OVOID) & (mod < nsceneobjs)) |
342 |
|
return 1; |
343 |
|
|
344 |
|
sprintf(errmsg, "tracked modifier '%s' not found in main scene", lp->key); |
351 |
|
RcontribSimulManager::PrepOutput() |
352 |
|
{ |
353 |
|
if (!outList || !RtraceSimulManager::Ready()) { |
354 |
< |
error(INTERNAL, "PrepOutput() called before octree & modifiers assigned"); |
354 |
> |
error(INTERNAL, "PrepOutput() called before octree & modifiers set"); |
355 |
|
return -1; |
356 |
|
} |
357 |
|
if (!cdsF) { |
358 |
< |
error(INTERNAL, "missing RdataShare constructor call (*cdsF)"); |
358 |
> |
error(INTERNAL, "missing RdataShare constructor call (cdsF)"); |
359 |
|
return -1; |
360 |
|
} |
361 |
|
if (lu_doall(&modLUT, checkModExists, NULL) < 0) |
362 |
|
return -1; |
363 |
|
|
364 |
+ |
outList->nRows = yres * (xres + !xres); // all outputs have same #rows |
365 |
|
int remWarnings = 20; |
366 |
|
for (RcontribOutput *op = outList; op; op = op->next) { |
367 |
|
if (op->rData) { |
368 |
|
error(INTERNAL, "output channel already open in PrepOutput()"); |
369 |
|
return -1; |
370 |
|
} |
371 |
< |
op->nRows = yres * (xres + !xres); |
371 |
> |
op->nRows = outList->nRows; |
372 |
|
op->rData = (*cdsF)(op->ofname, outOp, |
373 |
|
GetHeadLen()+1024 + op->nRows*op->rowBytes); |
374 |
|
freeqstr(op->ofname); op->ofname = NULL; |
378 |
|
return -1; |
379 |
|
if (rd >= op->nRows) { |
380 |
|
if (remWarnings >= 0) { |
381 |
< |
sprintf(errmsg, "recovered output '%s' already done", |
381 |
> |
sprintf(errmsg, "recovered output '%s' is complete", |
382 |
|
op->GetName()); |
383 |
< |
error(WARNING, remWarnings ? errmsg : "etc..."); |
365 |
< |
remWarnings--; |
383 |
> |
error(WARNING, --remWarnings ? errmsg : "etc..."); |
384 |
|
} |
385 |
|
rd = op->nRows; |
386 |
|
} |