ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
Revision: 2.12
Committed: Thu Dec 14 00:51:12 2023 UTC (5 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.11: +1 -3 lines
Log Message:
fix: Removed spurious error

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: p_data.c,v 2.11 2023/12/13 23:26:16 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,
17 * color, or spectral 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 * A simple spectrum is specified as:
39 *
40 * modifier spectrum name
41 * 0
42 * 0
43 * 5+ nmA nmB s1 s2 s3 ..
44 *
45 * A constant spectrum from a data file is given as:
46 *
47 * modifier specfile name
48 * 1 dfname
49 * 0
50 * 0
51 *
52 * A spectral data file is given as:
53 *
54 * modifier specdata name
55 * 4+ sfunc dfname vfname v0 .. xf
56 * 0
57 * n A1 A2 ..
58 *
59 * A spectral image is given as:
60 *
61 * modifier specpict name
62 * 5+ sfunc sfname vfname vx vy xf
63 * 0
64 * n A1 A2 ..
65 *
66 * Vfname is the name of the file where the variable definitions
67 * can be found. The list of real arguments can be accessed by
68 * definitions in the file. The dfnames are the data file
69 * names. The dimensions of the data files and the number
70 * of variables must match, except for specdata, which has a "hidden"
71 * last variable for the wavelength. The funcs take a single argument
72 * for brightdata, three for colordata and colorpict, and two for
73 * specdata and specpict to modify interpolated values from the file.
74 * The xf is a transform spec to get from the original coordinates to
75 * the current coordinates.
76 */
77
78
79 int
80 p_bdata( /* interpolate brightness data */
81 OBJREC *m,
82 RAY *r
83 )
84 {
85 double bval;
86 double pt[MAXDDIM];
87 DATARRAY *dp;
88 MFUNC *mf;
89 int i;
90
91 if (m->oargs.nsargs < 4)
92 objerror(m, USER, "bad # arguments");
93 dp = getdata(m->oargs.sarg[1]);
94 i = (1 << dp->nd) - 1;
95 mf = getfunc(m, 2, i<<3, 0);
96 setfunc(m, r);
97 errno = 0;
98 for (i = dp->nd; i-- > 0; ) {
99 pt[i] = evalue(mf->ep[i]);
100 if ((errno == EDOM) | (errno == ERANGE))
101 goto computerr;
102 }
103 bval = datavalue(dp, pt);
104 errno = 0;
105 bval = funvalue(m->oargs.sarg[0], 1, &bval);
106 if ((errno == EDOM) | (errno == ERANGE))
107 goto computerr;
108 scalescolor(r->pcol, bval);
109 return(0);
110 computerr:
111 objerror(m, WARNING, "compute error");
112 return(0);
113 }
114
115
116 int
117 p_cdata( /* interpolate color data */
118 OBJREC *m,
119 RAY *r
120 )
121 {
122 double col[3];
123 COLOR cval;
124 double pt[MAXDDIM];
125 int nv;
126 DATARRAY *dp;
127 MFUNC *mf;
128 int i;
129
130 if (m->oargs.nsargs < 8)
131 objerror(m, USER, "bad # arguments");
132 dp = getdata(m->oargs.sarg[3]);
133 i = (1 << (nv = dp->nd)) - 1;
134 mf = getfunc(m, 6, i<<7, 0);
135 setfunc(m, r);
136 errno = 0;
137 for (i = 0; i < nv; i++) {
138 pt[i] = evalue(mf->ep[i]);
139 if ((errno == EDOM) | (errno == ERANGE))
140 goto computerr;
141 }
142 col[0] = datavalue(dp, pt);
143 for (i = 1; i < 3; i++) {
144 dp = getdata(m->oargs.sarg[3+i]);
145 if (dp->nd != nv)
146 objerror(m, USER, "dimension error");
147 col[i] = datavalue(dp, pt);
148 }
149 errno = 0;
150 for (i = 0; i < 3; i++)
151 if (i && fundefined(m->oargs.sarg[i]) < 3)
152 colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
153 else
154 colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
155 if ((errno == EDOM) | (errno == ERANGE))
156 goto computerr;
157 smultcolor(r->pcol, cval);
158 return(0);
159 computerr:
160 objerror(m, WARNING, "compute error");
161 return(0);
162 }
163
164
165 int
166 p_pdata( /* interpolate picture data */
167 OBJREC *m,
168 RAY *r
169 )
170 {
171 double col[3];
172 COLOR cval;
173 double pt[2];
174 DATARRAY *dp;
175 MFUNC *mf;
176 int i;
177
178 if (m->oargs.nsargs < 7)
179 objerror(m, USER, "bad # arguments");
180 mf = getfunc(m, 4, 0x3<<5, 0);
181 setfunc(m, r);
182 errno = 0;
183 pt[1] = evalue(mf->ep[0]); /* y major ordering */
184 pt[0] = evalue(mf->ep[1]);
185 if ((errno == EDOM) | (errno == ERANGE))
186 goto computerr;
187 dp = getpict(m->oargs.sarg[3]);
188 for (i = 0; i < 3; i++)
189 col[i] = datavalue(dp+i, pt);
190 errno = 0;
191 for (i = 0; i < 3; i++)
192 if (i && fundefined(m->oargs.sarg[i]) < 3)
193 colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
194 else
195 colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
196 if ((errno == EDOM) | (errno == ERANGE))
197 goto computerr;
198 smultcolor(r->pcol, cval);
199 return(0);
200
201 computerr:
202 objerror(m, WARNING, "compute error");
203 return(0);
204 }
205
206
207 int
208 p_spectrum( /* simple constant spectrum */
209 OBJREC *m,
210 RAY *r
211 )
212 {
213 COLORV *scval;
214
215 if ((scval = (COLORV *)m->os) == NULL) {
216 COLORV *sinp;
217 double hstep;
218 int i;
219 if (m->oargs.nfargs < 5)
220 objerror(m, USER, "bad # arguments");
221 sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2));
222 scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
223 if ((sinp == NULL) | (scval == NULL))
224 objerror(m, SYSTEM, "out of memory");
225 for (i = m->oargs.nfargs-2; i--; )
226 sinp[i] = (COLORV)m->oargs.farg[i+2];
227 hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) /
228 (m->oargs.nfargs-3.0);
229 convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
230 sinp, m->oargs.nfargs-2,
231 m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep);
232 free(sinp);
233 m->os = (void *)scval;
234 }
235 smultscolor(r->pcol, scval);
236 return(0);
237 }
238
239
240 int
241 p_specfile( /* constant spectrum from 1-D data file */
242 OBJREC *m,
243 RAY *r
244 )
245 {
246 COLORV *scval;
247
248 if ((scval = (COLORV *)m->os) == NULL) {
249 DATARRAY *dp;
250 COLORV *sinp;
251 double step;
252 int i;
253 if (m->oargs.nsargs != 1)
254 objerror(m, USER, "bad # arguments");
255 dp = getdata(m->oargs.sarg[0]);
256 if (dp->nd != 1)
257 objerror(m, USER, "data file must be 1-dimensional");
258
259 sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
260 scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
261 if ((sinp == NULL) | (scval == NULL))
262 objerror(m, SYSTEM, "out of memory");
263 step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
264 for (i = dp->dim[0].ne; i-- > 0; ) {
265 double wl = dp->dim[0].org + i*step;
266 sinp[i] = (COLORV)datavalue(dp, &wl);
267 }
268 convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
269 sinp, dp->dim[0].ne, dp->dim[0].org-.5*step,
270 dp->dim[0].org+dp->dim[0].siz+.5*step);
271 free(sinp);
272 m->os = (void *)scval;
273 }
274 smultscolor(r->pcol, scval);
275 return(0);
276 }
277
278
279 int
280 p_specdata( /* varied spectrum from (N+1)-D file */
281 OBJREC *m,
282 RAY *r
283 )
284 {
285 SCOLOR scval;
286 COLORV *scdat;
287 double pt[MAXDDIM];
288 DATARRAY *dp;
289 MFUNC *mf;
290 double step;
291 int i;
292
293 if (m->oargs.nsargs < 4)
294 objerror(m, USER, "bad # arguments");
295 dp = getdata(m->oargs.sarg[1]);
296 if (dp->nd < 2)
297 objerror(m, USER, "need at least 2-dimensional data");
298 i = (1 << (dp->nd-1)) - 1;
299 mf = getfunc(m, 2, i<<3, 0);
300 setfunc(m, r);
301 errno = 0;
302 for (i = dp->nd-1; i-- > 0; ) {
303 pt[i] = evalue(mf->ep[i]);
304 if ((errno == EDOM) | (errno == ERANGE))
305 goto computerr;
306 }
307 step = dp->dim[dp->nd-1].siz / (dp->dim[dp->nd-1].ne - 1.0);
308 scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[dp->nd-1].ne);
309 if (scdat == NULL)
310 objerror(m, SYSTEM, "out of memory");
311 for (i = dp->dim[dp->nd-1].ne; i-- > 0; ) {
312 double bval[2];
313 pt[dp->nd-1] = dp->dim[dp->nd-1].org + i*step;
314 bval[0] = datavalue(dp, pt);
315 bval[1] = pt[dp->nd-1];
316 errno = 0;
317 scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
318 if ((errno == EDOM) | (errno == ERANGE))
319 goto computerr;
320 }
321 convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
322 scdat, dp->dim[dp->nd-1].ne,
323 dp->dim[dp->nd-1].org-.5*step,
324 dp->dim[dp->nd-1].org+dp->dim[dp->nd-1].siz+.5*step);
325 free(scdat);
326 smultscolor(r->pcol, scval);
327 return(0);
328 computerr:
329 objerror(m, WARNING, "compute error");
330 return(0);
331 }
332
333
334 int
335 p_specpict( /* interpolate hyperspectral image data */
336 OBJREC *m,
337 RAY *r
338 )
339 {
340 SCOLOR scdat, scval;
341 double pt[3];
342 DATARRAY *dp;
343 MFUNC *mf;
344 double step;
345 int i;
346
347 if (m->oargs.nsargs < 5)
348 objerror(m, USER, "bad # arguments");
349 mf = getfunc(m, 2, 0x3<<3, 0);
350 setfunc(m, r);
351 errno = 0;
352 pt[1] = evalue(mf->ep[0]); /* y major ordering */
353 pt[0] = evalue(mf->ep[1]);
354 if ((errno == EDOM) | (errno == ERANGE))
355 goto computerr;
356 dp = getspec(m->oargs.sarg[1]);
357 step = dp->dim[2].siz / (dp->dim[2].ne - 1.0);
358 for (i = dp->dim[2].ne; i-- > 0; ) {
359 double bval[2];
360 pt[2] = dp->dim[2].org + i*step;
361 bval[0] = datavalue(dp, pt);
362 bval[1] = pt[2];
363 errno = 0;
364 scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
365 if ((errno == EDOM) | (errno == ERANGE))
366 goto computerr;
367 }
368 convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
369 scdat, dp->dim[2].ne,
370 dp->dim[2].org-.5*step,
371 dp->dim[2].org+dp->dim[2].siz+.5*step);
372 smultscolor(r->pcol, scval);
373 return(0);
374 computerr:
375 objerror(m, WARNING, "compute error");
376 return(0);
377 }