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

Comparing ray/src/rt/mx_data.c (file contents):
Revision 1.2 by greg, Thu Aug 8 11:29:53 1991 UTC vs.
Revision 2.8 by greg, Wed Mar 5 16:16:53 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1988 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  mx_data.c - routine for stored mixtures.
9 *
10 *     11/2/88
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11  
12   #include  "data.h"
13  
14 + #include  "func.h"
15 +
16   /*
17 < *      A stored mixture is specified:
17 > *  A stored mixture is specified:
18   *
19   *      modifier mixdata name
20   *      6+ foremod backmod func dfname vfname v0 v1 .. xf
21   *      0
22   *      n A1 A2 ..
23   *
24 + *  A picture mixture is specified as:
25 + *
26 + *      modifier mixpict name
27 + *      7+ foremod backmod func pfname vfname vx vy xf
28 + *      0
29 + *      n A1 A2 ..
30 + *
31 + *
32   *  Vfname is the name of the file where the variable definitions
33   *  can be found.  The list of real arguments can be accessed by
34   *  definitions in the file.  Dfname is the data file.
35 + *  (Pfname is a picture file.)
36   *  The dimensions of the data files and the number
37   *  of variables must match.  The func is a single argument
38 < *  function which returns the corrected data value given the
38 > *  function in the case of mixdata (three argument in the case
39 > *  of mixpict), which returns the corrected data value given the
40   *  interpolated value from the file.  The xf is a transformation
41   *  to get from the original coordinates to the current coordinates.
42   */
# Line 37 | Line 46 | mx_data(m, r)                  /* interpolate mixture data */
46   register OBJREC  *m;
47   RAY  *r;
48   {
49 <        extern double  varvalue(), funvalue(), datavalue();
41 <        extern int  errno;
42 <        register int  i;
49 >        OBJECT  obj;
50          double  coef;
51          double  pt[MAXDIM];
52          DATARRAY  *dp;
53          OBJECT  mod[2];
54 <        register char  **sa;
54 >        register MFUNC  *mf;
55 >        register int  i;
56  
49        setfunc(m, r);
50
51        sa = m->oargs.sarg;
52
57          if (m->oargs.nsargs < 6)
58                  objerror(m, USER, "bad # arguments");
59 +        obj = objndx(m);
60          for (i = 0; i < 2; i++)
61 <                if (!strcmp(sa[i], VOIDID))
61 >                if (!strcmp(m->oargs.sarg[i], VOIDID))
62                          mod[i] = OVOID;
63 <                else if ((mod[i] = modifier(sa[i])) == OVOID) {
64 <                        sprintf(errmsg, "undefined modifier \"%s\"", sa[i]);
63 >                else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
64 >                        sprintf(errmsg, "undefined modifier \"%s\"",
65 >                                        m->oargs.sarg[i]);
66                          objerror(m, USER, errmsg);
67                  }
68 <        funcfile(sa[4]);
69 <        for (i = 0; i+5 < m->oargs.nsargs &&
70 <                        sa[i+5][0] != '-'; i++) {
71 <                if (i >= MAXDIM)
72 <                        objerror(m, USER, "dimension error");
73 <                errno = 0;
74 <                pt[i] = varvalue(sa[i+5]);
75 <                if (errno)
68 >        dp = getdata(m->oargs.sarg[3]);
69 >        i = (1 << dp->nd) - 1;
70 >        mf = getfunc(m, 4, i<<5, 0);
71 >        setfunc(m, r);
72 >        errno = 0;
73 >        for (i = 0; i < dp->nd; i++) {
74 >                pt[i] = evalue(mf->ep[i]);
75 >                if (errno == EDOM || errno == ERANGE)
76                          goto computerr;
77          }
72        dp = getdata(sa[3]);
73        if (dp->nd != i)
74                objerror(m, USER, "dimension error");
78          coef = datavalue(dp, pt);
79          errno = 0;
80 <        coef = funvalue(sa[2], 1, &coef);
81 <        if (errno)
80 >        coef = funvalue(m->oargs.sarg[2], 1, &coef);
81 >        if (errno == EDOM || errno == ERANGE)
82                  goto computerr;
83 <        raymixture(r, mod[0], mod[1], coef);
84 <        return;
83 >        if (raymixture(r, mod[0], mod[1], coef)) {
84 >                if (m->omod != OVOID)
85 >                        objerror(m, USER, "inappropriate modifier");
86 >                return(1);
87 >        }
88 >        return(0);
89 > computerr:
90 >        objerror(m, WARNING, "compute error");
91 >        return(0);
92 > }
93  
94 +
95 + mx_pdata(m, r)                  /* interpolate mixture picture */
96 + register OBJREC  *m;
97 + RAY  *r;
98 + {
99 +        OBJECT  obj;
100 +        double  col[3], coef;
101 +        double  pt[MAXDIM];
102 +        DATARRAY  *dp;
103 +        OBJECT  mod[2];
104 +        register MFUNC  *mf;
105 +        register int  i;
106 +
107 +        if (m->oargs.nsargs < 7)
108 +                objerror(m, USER, "bad # arguments");
109 +        obj = objndx(m);
110 +        for (i = 0; i < 2; i++)
111 +                if (!strcmp(m->oargs.sarg[i], VOIDID))
112 +                        mod[i] = OVOID;
113 +                else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
114 +                        sprintf(errmsg, "undefined modifier \"%s\"",
115 +                                        m->oargs.sarg[i]);
116 +                        objerror(m, USER, errmsg);
117 +                }
118 +        dp = getpict(m->oargs.sarg[3]);
119 +        mf = getfunc(m, 4, 0x3<<5, 0);
120 +        setfunc(m, r);
121 +        errno = 0;
122 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
123 +        pt[0] = evalue(mf->ep[1]);
124 +        if (errno == EDOM || errno == ERANGE)
125 +                goto computerr;
126 +        for (i = 0; i < 3; i++)         /* get pixel from picture */
127 +                col[i] = datavalue(dp+i, pt);
128 +        errno = 0;                      /* evaluate function on pixel */
129 +        coef = funvalue(m->oargs.sarg[2], 3, col);
130 +        if (errno == EDOM || errno == ERANGE)
131 +                goto computerr;
132 +        if (raymixture(r, mod[0], mod[1], coef)) {
133 +                if (m->omod != OVOID)
134 +                        objerror(m, USER, "inappropriate modifier");
135 +                return(1);
136 +        }
137 +        return(0);
138   computerr:
139          objerror(m, WARNING, "compute error");
140 +        return(0);
141   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines