ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/RcontribSimulManager.cpp
(Generate patch)

Comparing ray/src/rt/RcontribSimulManager.cpp (file contents):
Revision 2.3 by greg, Wed Oct 30 01:38:21 2024 UTC vs.
Revision 2.9 by greg, Tue Dec 3 17:39:42 2024 UTC

# Line 24 | Line 24 | extern const char      HDRSTR[];
24   extern const char       BIGEND[];
25   extern const char       FMTSTR[];
26  
27 int     contrib = 0;                    // computing contributions?
28
29 int     xres = 0;                       // horizontal (scan) size
30 int     yres = 0;                       // vertical resolution
31
27   // new/exclusive, overwrite if exists, or recover data
28   int     RSDOflags[] = {RDSwrite|RDSexcl|RDSextend, RDSwrite|RDSextend,
29                                  RDSread|RDSwrite};
# Line 40 | Line 35 | static const char      ROWZEROSTR[] = "NROWS=00000000000000
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)
# Line 57 | Line 52 | struct RowAssignment {
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)
# Line 68 | Line 76 | defDataShare(const char *name, RCOutputOp op, size_t s
76   RcontribMod *
77   NewRcMod(const char *prms, const char *binexpr, int ncbins)
78   {
71        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   }
# Line 88 | Line 106 | void
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  
# Line 135 | Line 154 | RcontribSimulManager::RctCall(RAY *r, void *cd)
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
# Line 178 | Line 201 | bool
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()) {
# Line 210 | Line 237 | RcontribSimulManager::AddModifier(const char *modn, co
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);
# Line 239 | Line 266 | RcontribSimulManager::AddModifier(const char *modn, co
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);
# Line 262 | Line 289 | RcontribSimulManager::AddModifier(const char *modn, co
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  
# Line 289 | Line 316 | RcontribSimulManager::AddModFile(const char *modfn, co
316          return true;
317   }
318  
319 + // call-back to check if modifier has been loaded
320 + static int
321 + checkModExists(const LUENT *lp, void *p)
322 + {
323 +        if (modifier(lp->key) != OVOID)
324 +                return 1;
325 +
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
332   int
333   RcontribSimulManager::PrepOutput()
# Line 297 | Line 336 | RcontribSimulManager::PrepOutput()
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) {
# Line 358 | Line 404 | RcontribOutput::NewHeader(const RcontribSimulManager *
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          }
# Line 396 | Line 442 | RcontribOutput::NewHeader(const RcontribSimulManager *
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);
# Line 451 | Line 497 | RcontribOutput::CheckHeader(const RcontribSimulManager
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);
# Line 466 | Line 512 | RcontribOutput::CheckHeader(const RcontribSimulManager
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());
# Line 766 | Line 812 | RcontribSimulManager::SetThreadCount(int nt)
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)
# Line 779 | Line 825 | RcontribSimulManager::SetThreadCount(int nt)
825                  sprintf(errmsg, "non-zero (%d) status from child", status);
826                  error(WARNING, errmsg);
827          }
828 <        return nkids;
828 >        return NThreads();
829   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines