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.4 by greg, Fri Nov 1 16:17:33 2024 UTC

# Line 40 | Line 40 | static const char      ROWZEROSTR[] = "NROWS=00000000000000
40   struct RcontribMod {
41          RcontribOutput *        opl;            // pointer to first output channel
42          char *                  params;         // parameters string
43 <        EPNODE *                binv;           // bin expression
43 >        EPNODE *                binv;           // bin expression (NULL if 1 bin)
44          int                     nbins;          // bin count this modifier
45          int                     coffset;        // column offset in bytes
46          DCOLORV                 cbin[1];        // bin accumulator (extends struct)
# Line 70 | Line 70 | NewRcMod(const char *prms, const char *binexpr, int nc
70   {
71          if (ncbins <= 0) return NULL;
72          if (!prms) prms = "";
73 <        if (!binexpr | (ncbins == 1))
74 <                binexpr = "0";
75 <
73 >        if (!binexpr & (ncbins > 1)) {
74 >                error(INTERNAL, "missing bin expression");
75 >                return NULL;
76 >        }
77 >        if (ncbins == 1) {              // shouldn't have bin expression?
78 >                if (binexpr && strcmp(binexpr, "0"))
79 >                        error(WARNING, "ignoring non-zero expression for single bin");
80 >                prms = "";
81 >                binexpr = NULL;
82 >        }
83          RcontribMod *   mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) +
84                                                  sizeof(DCOLORV)*(NCSAMP*ncbins-1) +
85                                                  strlen(prms)+1);
86  
87          mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms);
88 <        mp->binv = eparse(const_cast<char *>(binexpr));
88 >        if (binexpr) {
89 >                mp->binv = eparse(const_cast<char *>(binexpr));
90 >                CHECK(mp->binv->type==NUM, WARNING, "constant bin expression");
91 >        }
92          mp->nbins = ncbins;
93          return mp;
94   }
# Line 88 | Line 98 | void
98   FreeRcMod(void *p)
99   {
100          if (!p) return;
101 <        epfree((*(RcontribMod *)p).binv, true);
101 >        EPNODE *        bep = (*(RcontribMod *)p).binv;
102 >        if (bep) epfree(bep, true);
103          efree(p);
104   }
105  
# Line 135 | Line 146 | RcontribSimulManager::RctCall(RAY *r, void *cd)
146          if (!mp)
147                  return 0;               // not in our modifier list
148  
149 <        worldfunc(RCCONTEXT, r);        // compute bin #
150 <        set_eparams(mp->params);
151 <        double          bval = evalue(mp->binv);
152 <        if (bval <= -.5)
153 <                return 0;       // silently ignore negative bin index
154 <        DCOLORV *       dvp = (*mp)[int(bval + .5)];
149 >        int                     bi = 0; // get bin index
150 >        if (mp->binv) {
151 >                worldfunc(RCCONTEXT, r);        // compute bin #
152 >                set_eparams(mp->params);
153 >                double          bval = evalue(mp->binv);
154 >                if (bval <= -.5)
155 >                        return 0;       // silently ignore negative bin index
156 >                bi = int(bval + .5);
157 >        }
158 >        DCOLORV *       dvp = (*mp)[bi];
159          if (!dvp) {
160 <                sprintf(errmsg, "bad bin number for '%s' (%.1f ignored)", mname, bval);
160 >                sprintf(errmsg, "bad bin number for '%s' (%d ignored)", mname, bi);
161                  error(WARNING, errmsg);
162                  return 0;
163          }
# Line 289 | Line 304 | RcontribSimulManager::AddModFile(const char *modfn, co
304          return true;
305   }
306  
307 + // call-back to check if modifier has been loaded
308 + static int
309 + checkModExists(const LUENT *lp, void *p)
310 + {
311 +        if (modifier(lp->key) != OVOID)
312 +                return 1;
313 +
314 +        sprintf(errmsg, "tracked modifier '%s' not found in main scene", lp->key);
315 +        error(WARNING, errmsg);
316 +        return 0;
317 + }
318 +
319   // Prepare output channels and return # completed rows
320   int
321   RcontribSimulManager::PrepOutput()
# Line 297 | Line 324 | RcontribSimulManager::PrepOutput()
324                  error(INTERNAL, "PrepOutput() called before octree & modifiers assigned");
325                  return -1;
326          }
327 +        if (lu_doall(&modLUT, checkModExists, NULL) < 0)
328 +                return -1;
329 +
330          int     remWarnings = 20;
331          for (RcontribOutput *op = outList; op; op = op->next) {
332                  if (op->rData) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines