ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/mx_data.c
Revision: 2.9
Committed: Tue Mar 30 16:13:01 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 2.8: +12 -9 lines
Log Message:
Continued ANSIfication. There are only bits and pieces left now.

File Contents

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