--- ray/src/rt/RcontribSimulManager.cpp 2024/11/01 23:05:01 2.5 +++ ray/src/rt/RcontribSimulManager.cpp 2024/11/07 18:07:43 2.8 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: RcontribSimulManager.cpp,v 2.5 2024/11/01 23:05:01 greg Exp $"; +static const char RCSid[] = "$Id: RcontribSimulManager.cpp,v 2.8 2024/11/07 18:07:43 greg Exp $"; #endif /* * RcontribSimulManager.cpp @@ -24,11 +24,6 @@ extern const char HDRSTR[]; extern const char BIGEND[]; extern const char FMTSTR[]; -int contrib = 0; // computing contributions? - -int xres = 0; // horizontal (scan) size -int yres = 0; // vertical resolution - // new/exclusive, overwrite if exists, or recover data int RSDOflags[] = {RDSwrite|RDSexcl|RDSextend, RDSwrite|RDSextend, RDSread|RDSwrite}; @@ -68,17 +63,17 @@ defDataShare(const char *name, RCOutputOp op, size_t s RcontribMod * NewRcMod(const char *prms, const char *binexpr, int ncbins) { - if (ncbins <= 0) return NULL; if (!prms) prms = ""; if (!binexpr & (ncbins > 1)) { - error(INTERNAL, "missing bin expression"); + error(USER, "missing bin expression"); return NULL; } - if (ncbins == 1) { // shouldn't have bin expression? + if (ncbins <= 1) { // shouldn't have bin expression? if (binexpr && strcmp(binexpr, "0")) error(WARNING, "ignoring non-zero expression for single bin"); prms = ""; binexpr = NULL; + ncbins = 1; } RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + sizeof(DCOLORV)*(NCSAMP*ncbins-1) + @@ -163,7 +158,7 @@ RcontribSimulManager::RctCall(RAY *r, void *cd) } SCOLOR contr; raycontrib(contr, r, PRIMARY); // compute coefficient - if (contrib) + if (rcp->HasFlag(RCcontrib)) smultscolor(contr, r->rcol); // -> value contribution for (int i = 0; i < NCSAMP; i++) *dvp++ += contr[i]; // accumulate color/spectrum @@ -193,16 +188,20 @@ bool RcontribSimulManager::AddModifier(const char *modn, const char *outspec, const char *prms, const char *binval, int bincnt) { - if (!modn | !outspec | (bincnt <= 0) || !*modn | !*outspec) { + if (!modn | !outspec || !*modn | !*outspec) { error(WARNING, "ignoring bad call to AddModifier()"); return false; } if (!nChan) { // initial call? + if ((xres < 0) | (yres <= 0)) { + error(USER, "xres, yres must be set before first modifier"); + return false; + } if (!SetDataFormat(dtyp)) return false; nChan = NCSAMP; } else if (nChan != NCSAMP) { - error(INTERNAL, "number of spectral channels must be fixed"); + error(USER, "number of spectral channels must be fixed"); return false; } if (Ready()) { @@ -225,7 +224,7 @@ RcontribSimulManager::AddModifier(const char *modn, co const int binndx = hasFormat(outspec, "diouxX"); int bin0 = 0; char fnbuf[512]; - if (!modndx | (modndx > binndx)) + if (!modndx || (binndx > 0) & (modndx > binndx)) sprintf(fnbuf, outspec, bin0, modn); else sprintf(fnbuf, outspec, modn, bin0); @@ -254,11 +253,11 @@ RcontribSimulManager::AddModifier(const char *modn, co mp->opl = op; // first (maybe only) output channel if (modndx) // remember modifier if part of name op->omod = lp->key; - if (binndx > 0) { // append output image/bin list + if (binndx) { // append output image/bin list op->rowBytes += dsiz; op->obin = bin0; for (bincnt = 1; bincnt < mp->nbins; bincnt++) { - if (!modndx | (modndx > binndx)) + if (!modndx || (binndx > 0) & (modndx > binndx)) sprintf(fnbuf, outspec, bin0+bincnt, modn); else sprintf(fnbuf, outspec, modn, bin0+bincnt); @@ -277,7 +276,7 @@ RcontribSimulManager::AddModifier(const char *modn, co op->rowBytes += dsiz; } } else // else send all results to this channel - op->rowBytes += bincnt*dsiz; + op->rowBytes += mp->nbins*dsiz; return true; } @@ -392,7 +391,7 @@ RcontribOutput::NewHeader(const RcontribSimulManager * strcpy(hdr+begData, ROWZEROSTR); rowCountPos = begData+LNROWSTR; begData += sizeof(ROWZEROSTR)-1; - if (!xres | (rowBytes > esiz)) { + if (!rcp->xres | (rowBytes > esiz)) { sprintf(hdr+begData, "NCOLS=%d\n", int(rowBytes/esiz)); begData += strlen(hdr+begData); } @@ -430,8 +429,8 @@ RcontribOutput::NewHeader(const RcontribSimulManager * hdr[begData++] = ' '; hdr[begData++] = '\n'; // EOL for data format hdr[begData++] = '\n'; // end of nominal header - if ((xres > 0) & (rowBytes == esiz)) { // tack on resolution string? - sprintf(hdr+begData, PIXSTDFMT, yres, xres); + if ((rcp->xres > 0) & (rowBytes == esiz)) { // tack on resolution string? + sprintf(hdr+begData, PIXSTDFMT, rcp->yres, rcp->xres); begData += strlen(hdr+begData); } return rData->ReleaseMemory(hdr, RDSwrite); @@ -485,7 +484,7 @@ RcontribOutput::CheckHeader(const RcontribSimulManager } // check #columns if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) || - !xres | (rowBytes > esiz)) { + !rcp->xres | (rowBytes > esiz)) { sprintf(errmsg, "expected NCOLS=%d in '%s'", int(rowBytes/esiz), GetName()); error(USER, errmsg); @@ -500,9 +499,9 @@ RcontribOutput::CheckHeader(const RcontribSimulManager rowCountPos = cp - hdr; int rlast = atoi(cp); begData++; // advance past closing EOL - if ((xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? + if ((rcp->xres > 0) & (rowBytes == esiz)) { // check/skip resolution string? char rbuf[64]; - sprintf(rbuf, PIXSTDFMT, yres, xres); + sprintf(rbuf, PIXSTDFMT, rcp->yres, rcp->xres); int rlen = strlen(rbuf); if (strncmp(rbuf, hdr+begData, rlen)) { sprintf(errmsg, "bad resolution string in '%s'", GetName()); @@ -800,7 +799,7 @@ RcontribSimulManager::SetThreadCount(int nt) return 0; } if (nt < 0) - return nkids; + return NThreads(); if (!nt) nt = GetNCores(); int status = 0; if (nt == 1) @@ -813,5 +812,5 @@ RcontribSimulManager::SetThreadCount(int nt) sprintf(errmsg, "non-zero (%d) status from child", status); error(WARNING, errmsg); } - return nkids; + return NThreads(); }