ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
Revision: 2.2
Committed: Mon Nov 25 09:50:53 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +40 -64 lines
Log Message:
changed function file calls to allow expressions instead of just vars

File Contents

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