1 |
– |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* p_data.c - routine for stored patterns. |
9 |
– |
* |
10 |
– |
* 6/4/86 |
6 |
|
*/ |
7 |
|
|
8 |
< |
#include "ray.h" |
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: |
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 |
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. The funcs take a single argument |
71 |
< |
* for brightdata, and three for colordata and colorpict to produce |
72 |
< |
* interpolated values from the file. The xf is a transformation |
73 |
< |
* to get from the original coordinates to the current coordinates. |
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 |
< |
p_bdata(m, r) /* interpolate brightness data */ |
80 |
< |
register OBJREC *m; |
81 |
< |
RAY *r; |
79 |
> |
int |
80 |
> |
p_bdata( /* interpolate brightness data */ |
81 |
> |
OBJREC *m, |
82 |
> |
RAY *r |
83 |
> |
) |
84 |
|
{ |
55 |
– |
extern double varvalue(), funvalue(), datavalue(); |
56 |
– |
extern int errno; |
57 |
– |
int nv; |
85 |
|
double bval; |
86 |
< |
double pt[MAXDIM]; |
86 |
> |
double pt[MAXDDIM]; |
87 |
|
DATARRAY *dp; |
88 |
< |
register char **sa; |
88 |
> |
MFUNC *mf; |
89 |
> |
int i; |
90 |
|
|
63 |
– |
setfunc(m, r); |
64 |
– |
|
65 |
– |
sa = m->oargs.sarg; |
66 |
– |
|
91 |
|
if (m->oargs.nsargs < 4) |
92 |
|
objerror(m, USER, "bad # arguments"); |
93 |
< |
if (!vardefined(sa[3])) |
94 |
< |
loadfunc(sa[2]); |
95 |
< |
for (nv = 0; nv+3 < m->oargs.nsargs && |
96 |
< |
sa[nv+3][0] != '-'; nv++) { |
97 |
< |
if (nv >= MAXDIM) |
98 |
< |
goto dimerr; |
99 |
< |
errno = 0; |
100 |
< |
pt[nv] = varvalue(sa[nv+3]); |
77 |
< |
if (errno) |
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 |
|
} |
80 |
– |
dp = getdata(sa[1]); |
81 |
– |
if (dp->nd != nv) |
82 |
– |
goto dimerr; |
103 |
|
bval = datavalue(dp, pt); |
104 |
|
errno = 0; |
105 |
< |
bval = funvalue(sa[0], 1, &bval); |
106 |
< |
if (errno) |
105 |
> |
bval = funvalue(m->oargs.sarg[0], 1, &bval); |
106 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
107 |
|
goto computerr; |
108 |
< |
scalecolor(r->pcol, bval); |
109 |
< |
return; |
90 |
< |
|
91 |
< |
dimerr: |
92 |
< |
objerror(m, USER, "dimension error"); |
93 |
< |
|
108 |
> |
scalescolor(r->pcol, bval); |
109 |
> |
return(0); |
110 |
|
computerr: |
111 |
|
objerror(m, WARNING, "compute error"); |
112 |
< |
return; |
112 |
> |
return(0); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
< |
p_cdata(m, r) /* interpolate color data */ |
117 |
< |
register OBJREC *m; |
118 |
< |
RAY *r; |
116 |
> |
int |
117 |
> |
p_cdata( /* interpolate color data */ |
118 |
> |
OBJREC *m, |
119 |
> |
RAY *r |
120 |
> |
) |
121 |
|
{ |
104 |
– |
extern double varvalue(), funvalue(), datavalue(); |
105 |
– |
extern int errno; |
106 |
– |
int i, nv; |
122 |
|
double col[3]; |
123 |
|
COLOR cval; |
124 |
< |
double pt[MAXDIM]; |
124 |
> |
double pt[MAXDDIM]; |
125 |
> |
int nv; |
126 |
|
DATARRAY *dp; |
127 |
< |
register char **sa; |
127 |
> |
MFUNC *mf; |
128 |
> |
int i; |
129 |
|
|
113 |
– |
setfunc(m, r); |
114 |
– |
|
115 |
– |
sa = m->oargs.sarg; |
116 |
– |
|
130 |
|
if (m->oargs.nsargs < 8) |
131 |
|
objerror(m, USER, "bad # arguments"); |
132 |
< |
if (!vardefined(sa[7])) |
133 |
< |
loadfunc(sa[6]); |
134 |
< |
for (nv = 0; nv+7 < m->oargs.nsargs && |
135 |
< |
sa[nv+7][0] != '-'; nv++) { |
136 |
< |
if (nv >= MAXDIM) |
137 |
< |
goto dimerr; |
138 |
< |
errno = 0; |
139 |
< |
pt[nv] = varvalue(sa[nv+7]); |
127 |
< |
if (errno) |
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 |
< |
for (i = 0; i < 3; i++) { |
143 |
< |
dp = getdata(sa[i+3]); |
142 |
> |
col[0] = datavalue(dp, pt); |
143 |
> |
for (i = 1; i < 3; i++) { |
144 |
> |
if (!strcmp(m->oargs.sarg[3+i], m->oargs.sarg[3])) { |
145 |
> |
col[i] = col[0]; /* same data */ |
146 |
> |
continue; |
147 |
> |
} |
148 |
> |
dp = getdata(m->oargs.sarg[3+i]); |
149 |
|
if (dp->nd != nv) |
150 |
< |
goto dimerr; |
150 |
> |
objerror(m, USER, "dimension error"); |
151 |
|
col[i] = datavalue(dp, pt); |
152 |
|
} |
153 |
|
errno = 0; |
154 |
< |
setcolor(cval, funvalue(sa[0], 3, col), |
155 |
< |
funvalue(sa[1], 3, col), |
156 |
< |
funvalue(sa[2], 3, col)); |
157 |
< |
if (errno) |
154 |
> |
for (i = 0; i < 3; i++) |
155 |
> |
if (i && fundefined(m->oargs.sarg[i]) < 3) |
156 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i); |
157 |
> |
else |
158 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col); |
159 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
160 |
|
goto computerr; |
161 |
< |
multcolor(r->pcol, cval); |
162 |
< |
return; |
144 |
< |
|
145 |
< |
dimerr: |
146 |
< |
objerror(m, USER, "dimension error"); |
147 |
< |
|
161 |
> |
smultcolor(r->pcol, cval); |
162 |
> |
return(0); |
163 |
|
computerr: |
164 |
|
objerror(m, WARNING, "compute error"); |
165 |
< |
return; |
165 |
> |
return(0); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
< |
p_pdata(m, r) /* interpolate picture data */ |
170 |
< |
register OBJREC *m; |
171 |
< |
RAY *r; |
169 |
> |
int |
170 |
> |
p_pdata( /* interpolate picture data */ |
171 |
> |
OBJREC *m, |
172 |
> |
RAY *r |
173 |
> |
) |
174 |
|
{ |
158 |
– |
extern double varvalue(), funvalue(), datavalue(); |
159 |
– |
extern int errno; |
160 |
– |
int i; |
175 |
|
double col[3]; |
176 |
|
COLOR cval; |
177 |
|
double pt[2]; |
178 |
|
DATARRAY *dp; |
179 |
< |
register char **sa; |
179 |
> |
MFUNC *mf; |
180 |
> |
int i; |
181 |
|
|
182 |
+ |
if (m->oargs.nsargs < 7) |
183 |
+ |
objerror(m, USER, "bad # arguments"); |
184 |
+ |
mf = getfunc(m, 4, 0x3<<5, 0); |
185 |
|
setfunc(m, r); |
186 |
+ |
errno = 0; |
187 |
+ |
pt[1] = evalue(mf->ep[0]); /* y major ordering */ |
188 |
+ |
pt[0] = evalue(mf->ep[1]); |
189 |
+ |
if ((errno == EDOM) | (errno == ERANGE)) |
190 |
+ |
goto computerr; |
191 |
+ |
dp = getpict(m->oargs.sarg[3]); |
192 |
+ |
for (i = 0; i < 3; i++) |
193 |
+ |
col[i] = datavalue(dp+i, pt); |
194 |
+ |
errno = 0; |
195 |
+ |
for (i = 0; i < 3; i++) |
196 |
+ |
if (i && fundefined(m->oargs.sarg[i]) < 3) |
197 |
+ |
colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i); |
198 |
+ |
else |
199 |
+ |
colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col); |
200 |
+ |
if ((errno == EDOM) | (errno == ERANGE)) |
201 |
+ |
goto computerr; |
202 |
+ |
smultcolor(r->pcol, cval); |
203 |
+ |
return(0); |
204 |
|
|
205 |
< |
sa = m->oargs.sarg; |
205 |
> |
computerr: |
206 |
> |
objerror(m, WARNING, "compute error"); |
207 |
> |
return(0); |
208 |
> |
} |
209 |
|
|
210 |
< |
if (m->oargs.nsargs < 7) |
210 |
> |
|
211 |
> |
int |
212 |
> |
p_spectrum( /* simple constant spectrum */ |
213 |
> |
OBJREC *m, |
214 |
> |
RAY *r |
215 |
> |
) |
216 |
> |
{ |
217 |
> |
COLORV *scval; |
218 |
> |
|
219 |
> |
if ((scval = (COLORV *)m->os) == NULL) { |
220 |
> |
COLORV *sinp; |
221 |
> |
double hstep; |
222 |
> |
int i; |
223 |
> |
if (m->oargs.nfargs < 5) |
224 |
> |
objerror(m, USER, "bad # arguments"); |
225 |
> |
sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2)); |
226 |
> |
scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP); |
227 |
> |
if ((sinp == NULL) | (scval == NULL)) |
228 |
> |
objerror(m, SYSTEM, "out of memory"); |
229 |
> |
for (i = m->oargs.nfargs-2; i--; ) |
230 |
> |
sinp[i] = (COLORV)m->oargs.farg[i+2]; |
231 |
> |
hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) / |
232 |
> |
(m->oargs.nfargs-3.0); |
233 |
> |
convertscolorcol(scval, sinp, m->oargs.nfargs-2, |
234 |
> |
m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep); |
235 |
> |
free(sinp); |
236 |
> |
m->os = (void *)scval; |
237 |
> |
} |
238 |
> |
smultscolor(r->pcol, scval); |
239 |
> |
return(0); |
240 |
> |
} |
241 |
> |
|
242 |
> |
|
243 |
> |
int |
244 |
> |
p_specfile( /* constant spectrum from 1-D data file */ |
245 |
> |
OBJREC *m, |
246 |
> |
RAY *r |
247 |
> |
) |
248 |
> |
{ |
249 |
> |
COLORV *scval; |
250 |
> |
|
251 |
> |
if ((scval = (COLORV *)m->os) == NULL) { |
252 |
> |
DATARRAY *dp; |
253 |
> |
COLORV *sinp; |
254 |
> |
double step; |
255 |
> |
int i; |
256 |
> |
if (m->oargs.nsargs != 1) |
257 |
> |
objerror(m, USER, "bad # arguments"); |
258 |
> |
dp = getdata(m->oargs.sarg[0]); |
259 |
> |
if (dp->nd != 1) |
260 |
> |
objerror(m, USER, "data file must be 1-dimensional"); |
261 |
> |
|
262 |
> |
sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne); |
263 |
> |
scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP); |
264 |
> |
if ((sinp == NULL) | (scval == NULL)) |
265 |
> |
objerror(m, SYSTEM, "out of memory"); |
266 |
> |
step = dp->dim[0].siz / (dp->dim[0].ne - 1.0); |
267 |
> |
for (i = dp->dim[0].ne; i-- > 0; ) { |
268 |
> |
double wl = dp->dim[0].org + i*step; |
269 |
> |
sinp[i] = (COLORV)datavalue(dp, &wl); |
270 |
> |
} |
271 |
> |
convertscolorcol(scval, sinp, dp->dim[0].ne, |
272 |
> |
dp->dim[0].org-.5*step, |
273 |
> |
dp->dim[0].org+dp->dim[0].siz+.5*step); |
274 |
> |
free(sinp); |
275 |
> |
m->os = (void *)scval; |
276 |
> |
} |
277 |
> |
smultscolor(r->pcol, scval); |
278 |
> |
return(0); |
279 |
> |
} |
280 |
> |
|
281 |
> |
|
282 |
> |
int |
283 |
> |
p_specdata( /* varied spectrum from (N+1)-D file */ |
284 |
> |
OBJREC *m, |
285 |
> |
RAY *r |
286 |
> |
) |
287 |
> |
{ |
288 |
> |
SCOLOR scval; |
289 |
> |
COLORV *scdat; |
290 |
> |
double pt[MAXDDIM]; |
291 |
> |
DATARRAY *dp; |
292 |
> |
MFUNC *mf; |
293 |
> |
double step; |
294 |
> |
int i; |
295 |
> |
|
296 |
> |
if (m->oargs.nsargs < 4) |
297 |
|
objerror(m, USER, "bad # arguments"); |
298 |
< |
if (!vardefined(sa[5])) |
299 |
< |
loadfunc(sa[4]); |
300 |
< |
for (i = 0; i < 2; i++) { |
298 |
> |
dp = getdata(m->oargs.sarg[1]); |
299 |
> |
if (dp->nd < 2) |
300 |
> |
objerror(m, USER, "need at least 2-dimensional data"); |
301 |
> |
i = (1 << (dp->nd-1)) - 1; |
302 |
> |
mf = getfunc(m, 2, i<<3, 0); |
303 |
> |
setfunc(m, r); |
304 |
> |
errno = 0; |
305 |
> |
for (i = dp->nd-1; i-- > 0; ) { |
306 |
> |
pt[i] = evalue(mf->ep[i]); |
307 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
308 |
> |
goto computerr; |
309 |
> |
} |
310 |
> |
dp = datavector(dp, pt); /* interpolate spectrum */ |
311 |
> |
step = dp->dim[0].siz / (dp->dim[0].ne - 1.0); |
312 |
> |
scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne); |
313 |
> |
if (scdat == NULL) |
314 |
> |
objerror(m, SYSTEM, "out of memory"); |
315 |
> |
for (i = dp->dim[0].ne; i-- > 0; ) { |
316 |
> |
pt[1] = dp->dim[0].org + i*step; |
317 |
> |
pt[0] = datavalue(dp, pt+1); |
318 |
|
errno = 0; |
319 |
< |
pt[i] = varvalue(sa[i+5]); |
320 |
< |
if (errno) |
319 |
> |
scdat[i] = funvalue(m->oargs.sarg[0], 2, pt); |
320 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
321 |
|
goto computerr; |
322 |
|
} |
323 |
< |
dp = getpict(sa[3]); |
324 |
< |
for (i = 0; i < 3; i++) |
325 |
< |
col[i] = datavalue(dp+i, pt); |
323 |
> |
convertscolorcol(scval, scdat, dp->dim[0].ne, |
324 |
> |
dp->dim[0].org-.5*step, |
325 |
> |
dp->dim[0].org+dp->dim[0].siz+.5*step); |
326 |
> |
free(scdat); |
327 |
> |
free(dp); |
328 |
> |
smultscolor(r->pcol, scval); |
329 |
> |
return(0); |
330 |
> |
computerr: |
331 |
> |
objerror(m, WARNING, "compute error"); |
332 |
> |
return(0); |
333 |
> |
} |
334 |
> |
|
335 |
> |
|
336 |
> |
int |
337 |
> |
p_specpict( /* interpolate hyperspectral image data */ |
338 |
> |
OBJREC *m, |
339 |
> |
RAY *r |
340 |
> |
) |
341 |
> |
{ |
342 |
> |
SCOLOR scdat, scval; |
343 |
> |
double pt[2]; |
344 |
> |
DATARRAY *dp; |
345 |
> |
MFUNC *mf; |
346 |
> |
double step; |
347 |
> |
int i; |
348 |
> |
|
349 |
> |
if (m->oargs.nsargs < 5) |
350 |
> |
objerror(m, USER, "bad # arguments"); |
351 |
> |
mf = getfunc(m, 2, 0x3<<3, 0); |
352 |
> |
setfunc(m, r); |
353 |
|
errno = 0; |
354 |
< |
setcolor(cval, funvalue(sa[0], 3, col), |
355 |
< |
funvalue(sa[1], 3, col), |
356 |
< |
funvalue(sa[2], 3, col)); |
188 |
< |
if (errno) |
354 |
> |
pt[1] = evalue(mf->ep[0]); /* y major ordering */ |
355 |
> |
pt[0] = evalue(mf->ep[1]); |
356 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
357 |
|
goto computerr; |
358 |
< |
multcolor(r->pcol, cval); |
359 |
< |
return; |
360 |
< |
|
358 |
> |
/* interpolate spectrum */ |
359 |
> |
dp = datavector(getspec(m->oargs.sarg[1]), pt); |
360 |
> |
step = dp->dim[0].siz / (dp->dim[0].ne - 1.0); |
361 |
> |
for (i = dp->dim[0].ne; i-- > 0; ) { |
362 |
> |
pt[1] = dp->dim[0].org + i*step; |
363 |
> |
pt[0] = dp->arr.d[i]; /* datavalue(dp, pt+1); */ |
364 |
> |
errno = 0; |
365 |
> |
scdat[i] = funvalue(m->oargs.sarg[0], 2, pt); |
366 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
367 |
> |
goto computerr; |
368 |
> |
} |
369 |
> |
convertscolorcol(scval, scdat, dp->dim[0].ne, |
370 |
> |
dp->dim[0].org-.5*step, |
371 |
> |
dp->dim[0].org+dp->dim[0].siz+.5*step); |
372 |
> |
free(dp); |
373 |
> |
smultscolor(r->pcol, scval); |
374 |
> |
return(0); |
375 |
|
computerr: |
376 |
|
objerror(m, WARNING, "compute error"); |
377 |
< |
return; |
377 |
> |
return(0); |
378 |
|
} |