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

Comparing ray/src/rt/func.c (file contents):
Revision 2.27 by greg, Wed Jun 27 16:29:26 2012 UTC vs.
Revision 2.42 by greg, Tue Oct 29 00:36:54 2024 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  "paths.h"
12   #include  "otypes.h"
13   #include  "func.h"
14 + #include <ctype.h>
15  
16  
17   #define  INITFILE       "rayinit.cal"
# Line 36 | Line 37 | static double  l_erf(char *), l_erfc(char *), l_arg(ch
37  
38  
39   void
40 < initfunc()      /* initialize function evaluation */
40 > initfunc(void)  /* initialize function evaluation */
41   {
42          if (!rayinitcal[0])     /* already done? */
43                  return;
44          esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW;
45          esupport &= ~(E_OUTCHAN);
46 <        setcontext("");
46 >        calcontext("");
47          scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
48          scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0);
49          scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0);
# Line 62 | Line 63 | initfunc()     /* initialize function evaluation */
63   }
64  
65  
66 + /* Set parameters for current evaluation */
67 + void
68 + set_eparams(const char *prms)
69 + {
70 +        static const char       *last_params = NULL;
71 +        char                    vname[RMAXWORD];
72 +        double                  value;
73 +        char                    *cpd;
74 +                                        /* check if already set */
75 +        if (prms == NULL || !*prms)
76 +                return;
77 +        if (prms == last_params || (last_params != NULL &&
78 +                                        !strcmp(prms, last_params)))
79 +                return;
80 +        last_params = prms;             /* XXX assumes static string */
81 +                                        /* assign each variable */
82 +        while (*prms) {
83 +                if (isspace(*prms)) {
84 +                        ++prms; continue;
85 +                }
86 +                if (!isalpha(*prms))
87 +                        goto bad_params;
88 +                cpd = vname;
89 +                while (*prms && (*prms != '=') & !isspace(*prms)) {
90 +                        if (!isid(*prms) | (cpd-vname >= RMAXWORD-1))
91 +                                goto bad_params;
92 +                        *cpd++ = *prms++;
93 +                }
94 +                *cpd = '\0';
95 +                while (isspace(*prms)) prms++;
96 +                if (*prms++ != '=')
97 +                        goto bad_params;
98 +                value = atof(prms);
99 +                if ((prms = fskip((char *)prms)) == NULL)
100 +                        goto bad_params;
101 +                while (isspace(*prms)) prms++;
102 +                prms += (*prms == ',') | (*prms == ';') | (*prms == ':');
103 +                varset(vname, '=', value);
104 +        }
105 +        eclock++;               /* notify expression evaluator */
106 +        return;
107 + bad_params:
108 +        sprintf(errmsg, "bad parameter list '%s'", last_params);
109 +        error(USER, errmsg);
110 + }
111 +
112 +
113   MFUNC *
114   getfunc(        /* get function for this modifier */
115          OBJREC  *m,
# Line 88 | Line 136 | getfunc(       /* get function for this modifier */
136                  goto memerr;
137          i = strlen(arg[ff]);                    /* set up context */
138          if (i == 1 && arg[ff][0] == '.') {
139 <                setcontext(f->ctx = "");        /* "." means no file */
139 >                calcontext(f->ctx = "");        /* "." means no file */
140          } else {
141                  strcpy(sbuf,arg[ff]);           /* file name is context */
142                  if (i > LCALSUF && !strcmp(sbuf+i-LCALSUF, CALSUF))
143                          sbuf[i-LCALSUF] = '\0'; /* remove suffix */
144 <                setcontext(f->ctx = savestr(sbuf));
144 >                calcontext(f->ctx = savestr(sbuf));
145                  if (!vardefined(REFVNAME)) {    /* file loaded? */
146                          loadfunc(arg[ff]);
147                          varset(REFVNAME, '=', 1.0);
148                  } else                          /* reference_count++ */
149                          varset(REFVNAME, '=', varvalue(REFVNAME)+1.0);
150          }
151 <        curfunc = NULL;                 /* parse expressions */
151 >        ecurfunc = NULL;                        /* parse expressions */
152          sprintf(sbuf, "%s \"%s\"", ofun[m->otype].funame, m->oname);
153          for (i=0, ne=0; ef && i < na; i++, ef>>=1)
154                  if (ef & 1) {                   /* flagged as an expression? */
# Line 109 | Line 157 | getfunc(       /* get function for this modifier */
157                          initstr(arg[i], sbuf, 0);
158                          f->ep[ne++] = getE1();
159                          if (nextc != EOF)
160 <                                syntax("unexpected character");
160 >                                esyntax("unexpected character");
161                  }
162          if (ef)
163                  goto toofew;
# Line 155 | Line 203 | freefunc(                      /* free memory associated with modifier */
203          if ((f = (MFUNC *)m->os) == NULL)
204                  return;
205          for (i = 0; f->ep[i] != NULL; i++)
206 <                epfree(f->ep[i]);
206 >                epfree(f->ep[i],1);
207          if (f->ctx[0]) {                        /* done with definitions */
208 <                setcontext(f->ctx);
208 >                calcontext(f->ctx);
209                  i = varvalue(REFVNAME)-.5;      /* reference_count-- */
210                  if (i > 0)
211                          varset(REFVNAME, '=', (double)i);
# Line 186 | Line 234 | setfunc(                       /* set channels for function call */
234          if ((f = (MFUNC *)m->os) == NULL)
235                  objerror(m, CONSISTENCY, "setfunc called before getfunc");
236                  
237 <        setcontext(f->ctx);             /* set evaluator context */
237 >        calcontext(f->ctx);             /* set evaluator context */
238                                          /* check to see if matrix set */
239          if ((m == fobj) & (r->rno == lastrno))
240                  return(0);
# Line 208 | Line 256 | setfunc(                       /* set channels for function call */
256  
257   int
258   worldfunc(                      /* special function context sans object */
259 <        char    *ctx,
259 >        const char      *ctx,
260          RAY     *r
261   )
262   {
# Line 217 | Line 265 | worldfunc(                     /* special function context sans object *
265          if (rayinitcal[0])              /* initialize on first call */
266                  initfunc();
267                                          /* set evaluator context */
268 <        setcontext(ctx);
268 >        calcontext((char *)ctx);
269                                          /* check if ray already set */
270          if ((fobj == NULL) & (r->rno == lastrno))
271                  return(0);
# Line 239 | Line 287 | loadfunc(                      /* load definition file */
287  
288          if ((ffname = getpath(fname, getrlibpath(), R_OK)) == NULL) {
289                  sprintf(errmsg, "cannot find function file \"%s\"", fname);
290 <                error(USER, errmsg);
290 >                error(SYSTEM, errmsg);
291          }
292          fcompile(ffname);
293 +        doptimize(1);           /* optimize definitions */
294   }
295  
296  
# Line 251 | Line 300 | l_arg(char *nm)                        /* return nth real argument */
300          int  n;
301  
302          if (fobj == NULL)
303 <                error(USER, "arg(n) called without a context");
303 >                error(USER,
304 >                        "bad call to arg(n) - illegal constant in .cal file?");
305  
306          n = argument(1) + .5;           /* round to integer */
307  
# Line 286 | Line 336 | chanvalue(                     /* return channel n to calcomp */
336   )
337   {
338          if (fray == NULL)
339 <                syntax("ray parameter used in constant expression");
339 >                esyntax("ray parameter used in constant expression");
340  
341          if (--n < 0)
342                  goto badchan;
# Line 305 | Line 355 | chanvalue(                     /* return channel n to calcomp */
355                                  fray->ron[2]*funcxf.xfm[2][n-3] )
356                           / funcxf.sca );
357  
358 <        if (n <= 8)                     /* intersection */
358 >        if (n <= 8) {                   /* intersection point */
359 >                if (fray->rot >= FHUGE*.99)
360 >                        return(0.0);    /* XXX should be runtime error? */
361  
362                  return( fray->rop[0]*funcxf.xfm[0][n-6] +
363                                  fray->rop[1]*funcxf.xfm[1][n-6] +
364                                  fray->rop[2]*funcxf.xfm[2][n-6] +
365                                               funcxf.xfm[3][n-6] );
366 +        }
367  
368          if (n == 9)                     /* total distance */
369                  return(raydist(fray,PRIMARY) * funcxf.sca);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines