24 |
|
extern const char BIGEND[]; |
25 |
|
extern const char FMTSTR[]; |
26 |
|
|
27 |
– |
extern int contrib; /* computing contributions? */ |
28 |
– |
extern int lim_dist; /* limit distance? */ |
29 |
– |
|
27 |
|
// new/exclusive, overwrite if exists, or recover data |
28 |
|
int RSDOflags[] = {RDSwrite|RDSexcl|RDSextend, RDSwrite|RDSextend, |
29 |
|
RDSread|RDSwrite}; |
35 |
|
struct RcontribMod { |
36 |
|
RcontribOutput * opl; // pointer to first output channel |
37 |
|
char * params; // parameters string |
38 |
< |
EPNODE * binv; // bin expression |
38 |
> |
EPNODE * binv; // bin expression (NULL if 1 bin) |
39 |
|
int nbins; // bin count this modifier |
40 |
|
int coffset; // column offset in bytes |
41 |
|
DCOLORV cbin[1]; // bin accumulator (extends struct) |
46 |
|
} |
47 |
|
}; |
48 |
|
|
49 |
< |
// used to assign record calc to child |
49 |
> |
// Struct used to assign record calculation to child |
50 |
|
struct RowAssignment { |
51 |
|
uint32 row; // row to do |
52 |
|
uint32 ac; // accumulation count |
53 |
|
}; |
54 |
|
|
55 |
+ |
// Get format identifier |
56 |
+ |
const char * |
57 |
+ |
formstr(int f) |
58 |
+ |
{ |
59 |
+ |
switch (f) { |
60 |
+ |
case 'a': return("ascii"); |
61 |
+ |
case 'f': return("float"); |
62 |
+ |
case 'd': return("double"); |
63 |
+ |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
64 |
+ |
} |
65 |
+ |
return("unknown"); |
66 |
+ |
} |
67 |
+ |
|
68 |
|
// Our default data share function |
69 |
|
RdataShare * |
70 |
|
defDataShare(const char *name, RCOutputOp op, size_t siz) |
76 |
|
RcontribMod * |
77 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
78 |
|
{ |
69 |
– |
if (ncbins <= 0) return NULL; |
79 |
|
if (!prms) prms = ""; |
80 |
< |
if (!binexpr | (ncbins == 1)) |
81 |
< |
binexpr = "0"; |
82 |
< |
|
80 |
> |
if (!binexpr & (ncbins > 1)) { |
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 |
> |
} |
91 |
|
RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + |
92 |
|
sizeof(DCOLORV)*(NCSAMP*ncbins-1) + |
93 |
|
strlen(prms)+1); |
94 |
|
|
95 |
|
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
96 |
< |
mp->binv = eparse(const_cast<char *>(binexpr)); |
96 |
> |
if (binexpr) { |
97 |
> |
mp->binv = eparse(const_cast<char *>(binexpr)); |
98 |
> |
CHECK(mp->binv->type==NUM, WARNING, "constant bin expression"); |
99 |
> |
} |
100 |
|
mp->nbins = ncbins; |
101 |
|
return mp; |
102 |
|
} |
106 |
|
FreeRcMod(void *p) |
107 |
|
{ |
108 |
|
if (!p) return; |
109 |
< |
epfree((*(RcontribMod *)p).binv, true); |
109 |
> |
EPNODE * bep = (*(RcontribMod *)p).binv; |
110 |
> |
if (bep) epfree(bep, true); |
111 |
|
efree(p); |
112 |
|
} |
113 |
|
|
154 |
|
if (!mp) |
155 |
|
return 0; // not in our modifier list |
156 |
|
|
157 |
< |
worldfunc(RCCONTEXT, r); // compute bin # |
158 |
< |
set_eparams(mp->params); |
159 |
< |
double bval = evalue(mp->binv); |
160 |
< |
if (bval <= -.5) |
161 |
< |
return 0; // silently ignore negative bin index |
162 |
< |
DCOLORV * dvp = (*mp)[int(bval + .5)]; |
157 |
> |
int bi = 0; // get bin index |
158 |
> |
if (mp->binv) { |
159 |
> |
worldfunc(RCCONTEXT, r); |
160 |
> |
set_eparams(mp->params); |
161 |
> |
double bval = evalue(mp->binv); |
162 |
> |
if (bval <= -.5) |
163 |
> |
return 0; // silently ignore negative bin index |
164 |
> |
bi = int(bval + .5); |
165 |
> |
} |
166 |
> |
DCOLORV * dvp = (*mp)[bi]; |
167 |
|
if (!dvp) { |
168 |
< |
sprintf(errmsg, "bad bin number for '%s' (%.1f ignored)", mname, bval); |
168 |
> |
sprintf(errmsg, "bad bin number for '%s' (%d ignored)", mname, bi); |
169 |
|
error(WARNING, errmsg); |
170 |
|
return 0; |
171 |
|
} |
172 |
|
SCOLOR contr; |
173 |
|
raycontrib(contr, r, PRIMARY); // compute coefficient |
174 |
< |
if (contrib) |
174 |
> |
if (rcp->HasFlag(RCcontrib)) |
175 |
|
smultscolor(contr, r->rcol); // -> value contribution |
176 |
|
for (int i = 0; i < NCSAMP; i++) |
177 |
|
*dvp++ += contr[i]; // accumulate color/spectrum |
201 |
|
RcontribSimulManager::AddModifier(const char *modn, const char *outspec, |
202 |
|
const char *prms, const char *binval, int bincnt) |
203 |
|
{ |
204 |
< |
if (!modn | !outspec | (bincnt <= 0) || !*modn | !*outspec) { |
204 |
> |
if (!modn | !outspec || !*modn | !*outspec) { |
205 |
|
error(WARNING, "ignoring bad call to AddModifier()"); |
206 |
|
return false; |
207 |
|
} |
208 |
|
if (!nChan) { // initial call? |
209 |
+ |
if ((xres < 0) | (yres <= 0)) { |
210 |
+ |
error(USER, "xres, yres must be set before first modifier"); |
211 |
+ |
return false; |
212 |
+ |
} |
213 |
|
if (!SetDataFormat(dtyp)) |
214 |
|
return false; |
215 |
|
nChan = NCSAMP; |
216 |
|
} else if (nChan != NCSAMP) { |
217 |
< |
error(INTERNAL, "number of spectral channels must be fixed"); |
217 |
> |
error(USER, "number of spectral channels must be fixed"); |
218 |
|
return false; |
219 |
|
} |
220 |
|
if (Ready()) { |
237 |
|
const int binndx = hasFormat(outspec, "diouxX"); |
238 |
|
int bin0 = 0; |
239 |
|
char fnbuf[512]; |
240 |
< |
if (!modndx | (modndx > binndx)) |
240 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
241 |
|
sprintf(fnbuf, outspec, bin0, modn); |
242 |
|
else |
243 |
|
sprintf(fnbuf, outspec, modn, bin0); |
266 |
|
mp->opl = op; // first (maybe only) output channel |
267 |
|
if (modndx) // remember modifier if part of name |
268 |
|
op->omod = lp->key; |
269 |
< |
if (binndx > 0) { // append output image/bin list |
269 |
> |
if (binndx) { // append output image/bin list |
270 |
|
op->rowBytes += dsiz; |
271 |
|
op->obin = bin0; |
272 |
|
for (bincnt = 1; bincnt < mp->nbins; bincnt++) { |
273 |
< |
if (!modndx | (modndx > binndx)) |
273 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
274 |
|
sprintf(fnbuf, outspec, bin0+bincnt, modn); |
275 |
|
else |
276 |
|
sprintf(fnbuf, outspec, modn, bin0+bincnt); |
289 |
|
op->rowBytes += dsiz; |
290 |
|
} |
291 |
|
} else // else send all results to this channel |
292 |
< |
op->rowBytes += bincnt*dsiz; |
292 |
> |
op->rowBytes += mp->nbins*dsiz; |
293 |
|
return true; |
294 |
|
} |
295 |
|
|
316 |
|
return true; |
317 |
|
} |
318 |
|
|
319 |
< |
// Run through current list of output struct's |
320 |
< |
int |
321 |
< |
RcontribSimulManager::GetOutputs(RoutputShareF *osF, void *cd) const |
319 |
> |
// call-back to check if modifier has been loaded |
320 |
> |
static int |
321 |
> |
checkModExists(const LUENT *lp, void *p) |
322 |
|
{ |
323 |
< |
int cnt = 0; |
323 |
> |
if (modifier(lp->key) != OVOID) |
324 |
> |
return 1; |
325 |
|
|
326 |
< |
for (const RcontribOutput *op = outList; op; op = op->next) { |
327 |
< |
int rv = 1; |
328 |
< |
if (osF && (rv = (*osF)(op, cd)) < 0) |
299 |
< |
return rv; |
300 |
< |
cnt += rv; |
301 |
< |
} |
302 |
< |
return cnt; |
326 |
> |
sprintf(errmsg, "tracked modifier '%s' not found in main scene", lp->key); |
327 |
> |
error(WARNING, errmsg); |
328 |
> |
return 0; |
329 |
|
} |
330 |
|
|
331 |
|
// Prepare output channels and return # completed rows |
336 |
|
error(INTERNAL, "PrepOutput() called before octree & modifiers assigned"); |
337 |
|
return -1; |
338 |
|
} |
339 |
+ |
if (!cdsF) { |
340 |
+ |
error(INTERNAL, "missing RdataShare constructor call (*cdsF)"); |
341 |
+ |
return -1; |
342 |
+ |
} |
343 |
+ |
if (lu_doall(&modLUT, checkModExists, NULL) < 0) |
344 |
+ |
return -1; |
345 |
+ |
|
346 |
|
int remWarnings = 20; |
347 |
|
for (RcontribOutput *op = outList; op; op = op->next) { |
348 |
|
if (op->rData) { |
374 |
|
!op->rData->Resize(op->begData + op->nRows*op->rowBytes)) |
375 |
|
return -1; // calls error() for us |
376 |
|
} |
344 |
– |
if (lim_dist) // XXX where else to put this? |
345 |
– |
rtFlags |= RTlimDist; |
346 |
– |
else |
347 |
– |
rtFlags &= ~RTlimDist; |
348 |
– |
|
377 |
|
rowsDone.NewBitMap(outList->nRows); // create row completion map |
378 |
|
rowsDone.ClearBits(0, rInPos, true); |
379 |
|
return rInPos; |
404 |
|
strcpy(hdr+begData, ROWZEROSTR); |
405 |
|
rowCountPos = begData+LNROWSTR; |
406 |
|
begData += sizeof(ROWZEROSTR)-1; |
407 |
< |
if (!xres | (rowBytes > esiz)) { |
407 |
> |
if (!rcp->xres | (rowBytes > esiz)) { |
408 |
|
sprintf(hdr+begData, "NCOLS=%d\n", int(rowBytes/esiz)); |
409 |
|
begData += strlen(hdr+begData); |
410 |
|
} |
442 |
|
hdr[begData++] = ' '; |
443 |
|
hdr[begData++] = '\n'; // EOL for data format |
444 |
|
hdr[begData++] = '\n'; // end of nominal header |
445 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
446 |
< |
sprintf(hdr+begData, PIXSTDFMT, yres, xres); |
445 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // tack on resolution string? |
446 |
> |
sprintf(hdr+begData, PIXSTDFMT, rcp->yres, rcp->xres); |
447 |
|
begData += strlen(hdr+begData); |
448 |
|
} |
449 |
|
return rData->ReleaseMemory(hdr, RDSwrite); |
489 |
|
return -1; |
490 |
|
} |
491 |
|
// check format |
492 |
< |
if (!(cp = findArgs(hdr, FMTSTR, begData)) || strcmp(cp, formstr(etyp))) { |
492 |
> |
if (!(cp = findArgs(hdr, FMTSTR, begData)) || |
493 |
> |
strncmp(cp, formstr(etyp), strlen(formstr(etyp)))) { |
494 |
|
sprintf(errmsg, "expected %s%s in '%s'", FMTSTR, formstr(etyp), GetName()); |
495 |
|
error(USER, errmsg); |
496 |
|
return -1; |
497 |
|
} |
498 |
|
// check #columns |
499 |
|
if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) || |
500 |
< |
!xres | (rowBytes > esiz)) { |
500 |
> |
!rcp->xres | (rowBytes > esiz)) { |
501 |
|
sprintf(errmsg, "expected NCOLS=%d in '%s'", |
502 |
|
int(rowBytes/esiz), GetName()); |
503 |
|
error(USER, errmsg); |
512 |
|
rowCountPos = cp - hdr; |
513 |
|
int rlast = atoi(cp); |
514 |
|
begData++; // advance past closing EOL |
515 |
< |
if ((xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
515 |
> |
if ((rcp->xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? |
516 |
|
char rbuf[64]; |
517 |
< |
sprintf(rbuf, PIXSTDFMT, yres, xres); |
517 |
> |
sprintf(rbuf, PIXSTDFMT, rcp->yres, rcp->xres); |
518 |
|
int rlen = strlen(rbuf); |
519 |
|
if (strncmp(rbuf, hdr+begData, rlen)) { |
520 |
|
sprintf(errmsg, "bad resolution string in '%s'", GetName()); |
679 |
|
FD_ISSET(kid[n].w, &writeset) | |
680 |
|
FD_ISSET(kid[n].w, &errset)) { |
681 |
|
// update output row counts |
682 |
< |
UpdateRowsDone(kidRow[n]); |
682 |
> |
if (!FD_ISSET(kid[n].w, &errset)) |
683 |
> |
UpdateRowsDone(kidRow[n]); |
684 |
|
kidRow[n] = -1; // flag it available |
685 |
|
pn = n; |
686 |
|
} |
764 |
|
close(kid[nkids].w); |
765 |
|
free(kid); free(kidRow); |
766 |
|
kid = NULL; kidRow = NULL; |
737 |
– |
rowsDone.NewBitMap(0); |
767 |
|
RunChild(); // should never return |
768 |
|
_exit(1); |
769 |
|
} |
812 |
|
return 0; |
813 |
|
} |
814 |
|
if (nt < 0) |
815 |
< |
return nkids; |
815 |
> |
return NThreads(); |
816 |
|
if (!nt) nt = GetNCores(); |
817 |
|
int status = 0; |
818 |
|
if (nt == 1) |
825 |
|
sprintf(errmsg, "non-zero (%d) status from child", status); |
826 |
|
error(WARNING, errmsg); |
827 |
|
} |
828 |
< |
return nkids; |
828 |
> |
return NThreads(); |
829 |
|
} |