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

Comparing ray/src/rt/rcontrib.c (file contents):
Revision 2.14 by greg, Wed Jun 27 15:32:58 2012 UTC vs.
Revision 2.23 by greg, Mon Aug 25 13:18:30 2014 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   * Initialization and calculation routines
7   */
8  
9 + #include "copyright.h"
10 +
11 + #include <ctype.h>
12   #include "rcontrib.h"
13   #include "otypes.h"
14   #include "source.h"
# Line 88 | Line 91 | formstr(                               /* return format identifier */
91  
92   /* Add modifier to our list to track */
93   MODCONT *
94 < addmodifier(char *modn, char *outf, char *binv, int bincnt)
94 > addmodifier(char *modn, char *outf, char *prms, char *binv, int bincnt)
95   {
96          LUENT   *lep = lu_find(&modconttab,modn);
97          MODCONT *mp;
# Line 125 | Line 128 | addmodifier(char *modn, char *outf, char *binv, int bi
128                  error(SYSTEM, "out of memory in addmodifier");
129          mp->outspec = outf;             /* XXX assumes static string */
130          mp->modname = modn;             /* XXX assumes static string */
131 +        mp->params = prms;
132          mp->binv = ebinv;
133          mp->nbins = bincnt;
134          memset(mp->cbin, 0, sizeof(DCOLOR)*bincnt);
# Line 138 | Line 142 | addmodifier(char *modn, char *outf, char *binv, int bi
142  
143   /* Add modifiers from a file list */
144   void
145 < addmodfile(char *fname, char *outf, char *binv, int bincnt)
145 > addmodfile(char *fname, char *outf, char *prms, char *binv, int bincnt)
146   {
147          char    *mname[MAXMODLIST];
148          int     i;
# Line 148 | Line 152 | addmodfile(char *fname, char *outf, char *binv, int bi
152                  error(SYSTEM, errmsg);
153          }
154          for (i = 0; mname[i]; i++)      /* add each one */
155 <                addmodifier(mname[i], outf, binv, bincnt);
155 >                addmodifier(mname[i], outf, prms, binv, bincnt);
156   }
157  
158  
# Line 211 | Line 215 | rcinit()
215  
216   /************************** MAIN CALCULATION PROCESS ***********************/
217  
218 + /* Set parameters for current bin evaluation */
219 + void
220 + set_eparams(char *prms)
221 + {
222 +        static char     *last_params = NULL;
223 +        char            vname[RMAXWORD];
224 +        double          value;
225 +        char            *cpd;
226 +                                        /* check if already set */
227 +        if ((prms == NULL) | (prms == last_params))
228 +                return;
229 +        if (last_params != NULL && !strcmp(prms, last_params))
230 +                return;
231 +        last_params = prms;             /* assign each variable */
232 +        while (*prms) {
233 +                if (isspace(*prms)) {
234 +                        ++prms; continue;
235 +                }
236 +                if (!isalpha(*prms))
237 +                        goto bad_params;
238 +                cpd = vname;
239 +                while (*prms && (*prms != '=') & !isspace(*prms)) {
240 +                        if (!isid(*prms))
241 +                                goto bad_params;
242 +                        *cpd++ = *prms++;
243 +                }
244 +                if (cpd == vname)
245 +                        goto bad_params;
246 +                *cpd = '\0';
247 +                while (isspace(*prms)) prms++;
248 +                if (*prms++ != '=')
249 +                        goto bad_params;
250 +                value = atof(prms);
251 +                if ((prms = fskip(prms)) == NULL)
252 +                        goto bad_params;
253 +                while (isspace(*prms)) prms++;
254 +                prms += (*prms == ',') | (*prms == ';');
255 +                varset(vname, '=', value);
256 +        }
257 +        return;
258 + bad_params:
259 +        sprintf(errmsg, "bad parameter list '%s'", last_params);
260 +        error(USER, errmsg);
261 + }
262 +
263 +
264   /* Our trace call to sum contributions */
265   static void
266   trace_contrib(RAY *r)
267   {
268          MODCONT *mp;
269 +        double  bval;
270          int     bn;
271          RREAL   contr[3];
272  
273          if (r->ro == NULL || r->ro->omod == OVOID)
274                  return;
275 +                                                /* shadow ray not on source? */
276 +        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
277 +                return;
278  
279          mp = (MODCONT *)lu_find(&modconttab,objptr(r->ro->omod)->oname)->data;
280  
281          if (mp == NULL)                         /* not in our list? */
282                  return;
229                                                /* shadow ray not on source? */
230        if (r->rsrc >= 0 && source[r->rsrc].so != r->ro)
231                return;
283  
284 <        worldfunc(RCCONTEXT, r);                /* else get bin number */
285 <        bn = (int)(evalue(mp->binv) + .5);
286 <        if ((bn < 0) | (bn >= mp->nbins)) {
287 <                error(WARNING, "bad bin number (ignored)");
284 >        worldfunc(RCCONTEXT, r);                /* else set context */
285 >        set_eparams((char *)mp->params);
286 >        if ((bval = evalue(mp->binv)) <= -.5)   /* and get bin number */
287 >                return;                         /* silently ignore negatives */
288 >        if ((bn = (int)(bval + .5)) >= mp->nbins) {
289 >                sprintf(errmsg, "bad bin number (%d ignored)", bn);
290 >                error(WARNING, errmsg);
291                  return;
292          }
293          raycontrib(contr, r, PRIMARY);          /* compute coefficient */
# Line 255 | Line 309 | eval_irrad(FVECT org, FVECT dir)
309          thisray.rdir[2] = -dir[2];
310          thisray.rmax = 0.0;
311          rayorigin(&thisray, PRIMARY, NULL, NULL);
312 <        thisray.rot = 1e-5;             /* pretend we hit surface */
312 >                                        /* pretend we hit surface */
313 >        thisray.rt = thisray.rot = 1e-5;
314          thisray.rod = 1.0;
315 +        VCOPY(thisray.ron, dir);
316          VSUM(thisray.rop, org, dir, 1e-4);
317          samplendx++;                    /* compute result */
318          (*ofun[Lamb.otype].funp)(&Lamb, &thisray);
# Line 314 | Line 370 | rcontrib()
370   #endif
371          while (getvec(orig) == 0 && getvec(direc) == 0) {
372                  d = normalize(direc);
373 <                if (nchild != -1 && (d == 0.0) & (accumulate != 1)) {
373 >                if (nchild != -1 && (d == 0.0) & (accumulate == 0)) {
374                          if (!ignore_warning_given++)
375                                  error(WARNING,
376                                  "dummy ray(s) ignored during accumulation\n");
# Line 324 | Line 380 | rcontrib()
380                          lastray = lastdone = 0;
381                  ++lastray;
382                  if (d == 0.0) {                         /* zero ==> flush */
383 <                        if ((yres <= 0) | (xres <= 0))
384 <                                waitflush = 1;          /* flush right after */
385 <                        account = 1;
383 >                        if ((yres <= 0) | (xres <= 1))
384 >                                waitflush = 1;          /* flush after */
385 >                        if (nchild == -1)
386 >                                account = 1;
387                  } else if (imm_irrad) {                 /* else compute */
388                          eval_irrad(orig, direc);
389                  } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines