ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
Revision: 2.6
Committed: Tue Feb 25 02:47:23 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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