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.1 by greg, Tue Oct 29 00:36:54 2024 UTC vs.
Revision 2.7 by greg, Wed Nov 6 19:45:59 2024 UTC

# Line 24 | Line 24 | extern const char      HDRSTR[];
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};
# Line 38 | 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 49 | Line 46 | struct RcontribMod {
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
# Line 68 | Line 65 | NewRcMod(const char *prms, const char *binexpr, int nc
65   {
66          if (ncbins <= 0) return NULL;
67          if (!prms) prms = "";
68 <        if (!binexpr | (ncbins == 1))
69 <                binexpr = "0";
70 <
68 >        if (!binexpr & (ncbins > 1)) {
69 >                error(INTERNAL, "missing bin expression");
70 >                return NULL;
71 >        }
72 >        if (ncbins == 1) {              // shouldn't have bin expression?
73 >                if (binexpr && strcmp(binexpr, "0"))
74 >                        error(WARNING, "ignoring non-zero expression for single bin");
75 >                prms = "";
76 >                binexpr = NULL;
77 >        }
78          RcontribMod *   mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) +
79                                                  sizeof(DCOLORV)*(NCSAMP*ncbins-1) +
80                                                  strlen(prms)+1);
81  
82          mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms);
83 <        mp->binv = eparse(const_cast<char *>(binexpr));
83 >        if (binexpr) {
84 >                mp->binv = eparse(const_cast<char *>(binexpr));
85 >                CHECK(mp->binv->type==NUM, WARNING, "constant bin expression");
86 >        }
87          mp->nbins = ncbins;
88          return mp;
89   }
# Line 86 | Line 93 | void
93   FreeRcMod(void *p)
94   {
95          if (!p) return;
96 <        epfree((*(RcontribMod *)p).binv, true);
96 >        EPNODE *        bep = (*(RcontribMod *)p).binv;
97 >        if (bep) epfree(bep, true);
98          efree(p);
99   }
100  
# Line 133 | Line 141 | RcontribSimulManager::RctCall(RAY *r, void *cd)
141          if (!mp)
142                  return 0;               // not in our modifier list
143  
144 <        worldfunc(RCCONTEXT, r);        // compute bin #
145 <        set_eparams(mp->params);
146 <        double          bval = evalue(mp->binv);
147 <        if (bval <= -.5)
148 <                return 0;       // silently ignore negative bin index
149 <        DCOLORV *       dvp = (*mp)[int(bval + .5)];
144 >        int                     bi = 0; // get bin index
145 >        if (mp->binv) {
146 >                worldfunc(RCCONTEXT, r);
147 >                set_eparams(mp->params);
148 >                double          bval = evalue(mp->binv);
149 >                if (bval <= -.5)
150 >                        return 0;       // silently ignore negative bin index
151 >                bi = int(bval + .5);
152 >        }
153 >        DCOLORV *       dvp = (*mp)[bi];
154          if (!dvp) {
155 <                sprintf(errmsg, "bad bin number for '%s' (%.1f ignored)", mname, bval);
155 >                sprintf(errmsg, "bad bin number for '%s' (%d ignored)", mname, bi);
156                  error(WARNING, errmsg);
157                  return 0;
158          }
159          SCOLOR          contr;
160          raycontrib(contr, r, PRIMARY);          // compute coefficient
161 <        if (contrib)
161 >        if (rcp->HasFlag(RCcontrib))
162                  smultscolor(contr, r->rcol);    // -> value contribution
163          for (int i = 0; i < NCSAMP; i++)
164                  *dvp++ += contr[i];             // accumulate color/spectrum
# Line 181 | Line 193 | RcontribSimulManager::AddModifier(const char *modn, co
193                  return false;
194          }
195          if (!nChan) {                           // initial call?
196 +                if ((xres < 0) | (yres <= 0)) {
197 +                        error(INTERNAL, "xres, yres must be set before first modifier");
198 +                        return false;
199 +                }
200                  if (!SetDataFormat(dtyp))
201                          return false;
202                  nChan = NCSAMP;
# Line 287 | Line 303 | RcontribSimulManager::AddModFile(const char *modfn, co
303          return true;
304   }
305  
306 < // Run through current list of output struct's
307 < int
308 < RcontribSimulManager::GetOutputs(RoutputShareF *osF, void *cd) const
306 > // call-back to check if modifier has been loaded
307 > static int
308 > checkModExists(const LUENT *lp, void *p)
309   {
310 <        int     cnt = 0;
310 >        if (modifier(lp->key) != OVOID)
311 >                return 1;
312  
313 <        for (const RcontribOutput *op = outList; op; op = op->next) {
314 <                int     rv = 1;
315 <                if (osF && (rv = (*osF)(op, cd)) < 0)
299 <                        return rv;
300 <                cnt += rv;
301 <        }
302 <        return cnt;
313 >        sprintf(errmsg, "tracked modifier '%s' not found in main scene", lp->key);
314 >        error(WARNING, errmsg);
315 >        return 0;
316   }
317  
318   // Prepare output channels and return # completed rows
# Line 310 | Line 323 | RcontribSimulManager::PrepOutput()
323                  error(INTERNAL, "PrepOutput() called before octree & modifiers assigned");
324                  return -1;
325          }
326 +        if (!cdsF) {
327 +                error(INTERNAL, "missing RdataShare constructor call (*cdsF)");
328 +                return -1;
329 +        }
330 +        if (lu_doall(&modLUT, checkModExists, NULL) < 0)
331 +                return -1;
332 +
333          int     remWarnings = 20;
334          for (RcontribOutput *op = outList; op; op = op->next) {
335                  if (op->rData) {
# Line 341 | Line 361 | RcontribSimulManager::PrepOutput()
361                                  !op->rData->Resize(op->begData + op->nRows*op->rowBytes))
362                          return -1;              // calls error() for us
363          }
344        if (lim_dist)                           // XXX where else to put this?
345                rtFlags |= RTlimDist;
346        else
347                rtFlags &= ~RTlimDist;
348
364          rowsDone.NewBitMap(outList->nRows);     // create row completion map
365          rowsDone.ClearBits(0, rInPos, true);
366          return rInPos;
# Line 376 | Line 391 | RcontribOutput::NewHeader(const RcontribSimulManager *
391          strcpy(hdr+begData, ROWZEROSTR);
392          rowCountPos = begData+LNROWSTR;
393          begData += sizeof(ROWZEROSTR)-1;
394 <        if (!xres | (rowBytes > esiz)) {
394 >        if (!rcp->xres | (rowBytes > esiz)) {
395                  sprintf(hdr+begData, "NCOLS=%d\n", int(rowBytes/esiz));
396                  begData += strlen(hdr+begData);
397          }
# Line 414 | Line 429 | RcontribOutput::NewHeader(const RcontribSimulManager *
429                          hdr[begData++] = ' ';
430          hdr[begData++] = '\n';          // EOL for data format
431          hdr[begData++] = '\n';          // end of nominal header
432 <        if ((xres > 0) & (rowBytes == esiz)) {  // tack on resolution string?
433 <                sprintf(hdr+begData, PIXSTDFMT, yres, xres);
432 >        if ((rcp->xres > 0) & (rowBytes == esiz)) {     // tack on resolution string?
433 >                sprintf(hdr+begData, PIXSTDFMT, rcp->yres, rcp->xres);
434                  begData += strlen(hdr+begData);
435          }
436          return rData->ReleaseMemory(hdr, RDSwrite);
# Line 461 | Line 476 | RcontribOutput::CheckHeader(const RcontribSimulManager
476                  return -1;
477          }
478                                                  // check format
479 <        if (!(cp = findArgs(hdr, FMTSTR, begData)) || strcmp(cp, formstr(etyp))) {
479 >        if (!(cp = findArgs(hdr, FMTSTR, begData)) ||
480 >                                strncmp(cp, formstr(etyp), strlen(formstr(etyp)))) {
481                  sprintf(errmsg, "expected %s%s in '%s'", FMTSTR, formstr(etyp), GetName());
482                  error(USER, errmsg);
483                  return -1;
484          }
485                                                  // check #columns
486          if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) ||
487 <                        !xres | (rowBytes > esiz)) {
487 >                        !rcp->xres | (rowBytes > esiz)) {
488                  sprintf(errmsg, "expected NCOLS=%d in '%s'",
489                                  int(rowBytes/esiz), GetName());
490                  error(USER, errmsg);
# Line 483 | Line 499 | RcontribOutput::CheckHeader(const RcontribSimulManager
499          rowCountPos = cp - hdr;
500          int     rlast = atoi(cp);
501          begData++;                              // advance past closing EOL
502 <        if ((xres > 0) & (rowBytes == esiz)) {  // check/skip resolution string?
502 >        if ((rcp->xres > 0) & (rowBytes == esiz)) {     // check/skip resolution string?
503                  char    rbuf[64];
504 <                sprintf(rbuf, PIXSTDFMT, yres, xres);
504 >                sprintf(rbuf, PIXSTDFMT, rcp->yres, rcp->xres);
505                  int     rlen = strlen(rbuf);
506                  if (strncmp(rbuf, hdr+begData, rlen)) {
507                          sprintf(errmsg, "bad resolution string in '%s'", GetName());
# Line 650 | Line 666 | RcontribSimulManager::GetChild(bool forceWait)
666                                  FD_ISSET(kid[n].w, &writeset) |
667                                  FD_ISSET(kid[n].w, &errset)) {
668                                                  // update output row counts
669 <                        UpdateRowsDone(kidRow[n]);
669 >                        if (!FD_ISSET(kid[n].w, &errset))
670 >                                UpdateRowsDone(kidRow[n]);
671                          kidRow[n] = -1;         // flag it available
672                          pn = n;
673                  }
# Line 734 | Line 751 | RcontribSimulManager::StartKids(int n2go)
751                                  close(kid[nkids].w);
752                          free(kid); free(kidRow);
753                          kid = NULL; kidRow = NULL;
737                        rowsDone.NewBitMap(0);
754                          RunChild();             // should never return
755                          _exit(1);
756                  }
# Line 783 | Line 799 | RcontribSimulManager::SetThreadCount(int nt)
799                  return 0;
800          }
801          if (nt < 0)
802 <                return nkids;
802 >                return NThreads();
803          if (!nt) nt = GetNCores();
804          int     status = 0;
805          if (nt == 1)
# Line 796 | Line 812 | RcontribSimulManager::SetThreadCount(int nt)
812                  sprintf(errmsg, "non-zero (%d) status from child", status);
813                  error(WARNING, errmsg);
814          }
815 <        return nkids;
815 >        return NThreads();
816   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines