ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
Revision: 2.8
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.7: +17 -12 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: p_data.c,v 2.7 2003/03/05 16:16:53 greg Exp $";
3 #endif
4 /*
5 * p_data.c - routine for stored patterns.
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 pattern can either be brightness or
17 * color data. Brightness data is specified as:
18 *
19 * modifier brightdata name
20 * 4+ func dfname vfname v0 v1 .. xf
21 * 0
22 * n A1 A2 ..
23 *
24 * Color data is specified as:
25 *
26 * modifier colordata name
27 * 8+ rfunc gfunc bfunc rdfname gdfname bdfname vfname v0 v1 .. xf
28 * 0
29 * n A1 A2 ..
30 *
31 * Color picture data is specified as:
32 *
33 * modifier colorpict name
34 * 7+ rfunc gfunc bfunc pfname vfname vx vy xf
35 * 0
36 * n A1 A2 ..
37 *
38 * Vfname is the name of the file where the variable definitions
39 * can be found. The list of real arguments can be accessed by
40 * definitions in the file. The dfnames are the data file
41 * names. The dimensions of the data files and the number
42 * of variables must match. The funcs take a single argument
43 * for brightdata, and three for colordata and colorpict to produce
44 * interpolated values from the file. The xf is a transformation
45 * to get from the original coordinates to the current coordinates.
46 */
47
48
49 extern int
50 p_bdata( /* interpolate brightness data */
51 register OBJREC *m,
52 RAY *r
53 )
54 {
55 double bval;
56 double pt[MAXDIM];
57 DATARRAY *dp;
58 register MFUNC *mf;
59 register int i;
60
61 if (m->oargs.nsargs < 4)
62 objerror(m, USER, "bad # arguments");
63 dp = getdata(m->oargs.sarg[1]);
64 i = (1 << dp->nd) - 1;
65 mf = getfunc(m, 2, i<<3, 0);
66 setfunc(m, r);
67 errno = 0;
68 for (i = dp->nd; i-- > 0; ) {
69 pt[i] = evalue(mf->ep[i]);
70 if (errno == EDOM || errno == ERANGE)
71 goto computerr;
72 }
73 bval = datavalue(dp, pt);
74 errno = 0;
75 bval = funvalue(m->oargs.sarg[0], 1, &bval);
76 if (errno == EDOM || errno == ERANGE)
77 goto computerr;
78 scalecolor(r->pcol, bval);
79 return(0);
80 computerr:
81 objerror(m, WARNING, "compute error");
82 return(0);
83 }
84
85
86 extern int
87 p_cdata( /* interpolate color data */
88 register OBJREC *m,
89 RAY *r
90 )
91 {
92 double col[3];
93 COLOR cval;
94 double pt[MAXDIM];
95 int nv;
96 DATARRAY *dp;
97 register MFUNC *mf;
98 register int i;
99
100 if (m->oargs.nsargs < 8)
101 objerror(m, USER, "bad # arguments");
102 dp = getdata(m->oargs.sarg[3]);
103 i = (1 << (nv = dp->nd)) - 1;
104 mf = getfunc(m, 6, i<<7, 0);
105 setfunc(m, r);
106 errno = 0;
107 for (i = 0; i < nv; i++) {
108 pt[i] = evalue(mf->ep[i]);
109 if (errno == EDOM || errno == ERANGE)
110 goto computerr;
111 }
112 col[0] = datavalue(dp, pt);
113 for (i = 1; i < 3; i++) {
114 dp = getdata(m->oargs.sarg[i+3]);
115 if (dp->nd != nv)
116 objerror(m, USER, "dimension error");
117 col[i] = datavalue(dp, pt);
118 }
119 errno = 0;
120 for (i = 0; i < 3; i++)
121 if (fundefined(m->oargs.sarg[i]) < 3)
122 colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
123 else
124 colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
125 if (errno == EDOM || errno == ERANGE)
126 goto computerr;
127 multcolor(r->pcol, cval);
128 return(0);
129 computerr:
130 objerror(m, WARNING, "compute error");
131 return(0);
132 }
133
134
135 extern int
136 p_pdata( /* interpolate picture data */
137 register OBJREC *m,
138 RAY *r
139 )
140 {
141 double col[3];
142 COLOR cval;
143 double pt[2];
144 DATARRAY *dp;
145 register MFUNC *mf;
146 register int i;
147
148 if (m->oargs.nsargs < 7)
149 objerror(m, USER, "bad # arguments");
150 mf = getfunc(m, 4, 0x3<<5, 0);
151 setfunc(m, r);
152 errno = 0;
153 pt[1] = evalue(mf->ep[0]); /* y major ordering */
154 pt[0] = evalue(mf->ep[1]);
155 if (errno == EDOM || errno == ERANGE)
156 goto computerr;
157 dp = getpict(m->oargs.sarg[3]);
158 for (i = 0; i < 3; i++)
159 col[i] = datavalue(dp+i, pt);
160 errno = 0;
161 for (i = 0; i < 3; i++)
162 if (fundefined(m->oargs.sarg[i]) < 3)
163 colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
164 else
165 colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
166 if (errno == EDOM || errno == ERANGE)
167 goto computerr;
168 multcolor(r->pcol, cval);
169 return(0);
170
171 computerr:
172 objerror(m, WARNING, "compute error");
173 return(0);
174 }