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 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

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: mx_data.c,v 2.8 2003/03/05 16:16:53 greg Exp $";
3 #endif
4 /*
5 * mx_data.c - routine for stored mixtures.
6 */
7
8 #include "copyright.h"
9
10 #include "ray.h"
11 #include "data.h"
12 #include "func.h"
13 #include "rtotypes.h"
14
15 /*
16 * A stored mixture is specified:
17 *
18 * modifier mixdata name
19 * 6+ foremod backmod func dfname vfname v0 v1 .. xf
20 * 0
21 * n A1 A2 ..
22 *
23 * 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 * 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 * (Pfname is a picture file.)
35 * The dimensions of the data files and the number
36 * of variables must match. The func is a single argument
37 * function in the case of mixdata (three argument in the case
38 * of mixpict), which returns the corrected data value given the
39 * 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 extern int
45 mx_data( /* interpolate mixture data */
46 register OBJREC *m,
47 RAY *r
48 )
49 {
50 OBJECT obj;
51 double coef;
52 double pt[MAXDIM];
53 DATARRAY *dp;
54 OBJECT mod[2];
55 register MFUNC *mf;
56 register int i;
57
58 if (m->oargs.nsargs < 6)
59 objerror(m, USER, "bad # arguments");
60 obj = objndx(m);
61 for (i = 0; i < 2; i++)
62 if (!strcmp(m->oargs.sarg[i], VOIDID))
63 mod[i] = OVOID;
64 else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
65 sprintf(errmsg, "undefined modifier \"%s\"",
66 m->oargs.sarg[i]);
67 objerror(m, USER, errmsg);
68 }
69 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 if (errno == EDOM || errno == ERANGE)
77 goto computerr;
78 }
79 coef = datavalue(dp, pt);
80 errno = 0;
81 coef = funvalue(m->oargs.sarg[2], 1, &coef);
82 if (errno == EDOM || errno == ERANGE)
83 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 extern int
97 mx_pdata( /* interpolate mixture picture */
98 register OBJREC *m,
99 RAY *r
100 )
101 {
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 if (errno == EDOM || errno == ERANGE)
128 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 if (errno == EDOM || errno == ERANGE)
134 goto computerr;
135 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 computerr:
142 objerror(m, WARNING, "compute error");
143 return(0);
144 }