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 |
|
* Vfname is the name of the file where the variable definitions |
53 |
|
* can be found. The list of real arguments can be accessed by |
54 |
|
* definitions in the file. The dfnames are the data file |
55 |
|
* names. The dimensions of the data files and the number |
56 |
|
* of variables must match. The funcs take a single argument |
57 |
|
* for brightdata, and three for colordata and colorpict to produce |
58 |
< |
* interpolated values from the file. The xf is a transformation |
58 |
> |
* interpolated values from the file. The xf is a transform spec |
59 |
|
* to get from the original coordinates to the current coordinates. |
60 |
|
*/ |
61 |
|
|
62 |
|
|
63 |
< |
p_bdata(m, r) /* interpolate brightness data */ |
64 |
< |
register OBJREC *m; |
65 |
< |
RAY *r; |
63 |
> |
int |
64 |
> |
p_bdata( /* interpolate brightness data */ |
65 |
> |
OBJREC *m, |
66 |
> |
RAY *r |
67 |
> |
) |
68 |
|
{ |
55 |
– |
extern double varvalue(), funvalue(), datavalue(); |
56 |
– |
extern int errno; |
57 |
– |
int nv; |
69 |
|
double bval; |
70 |
< |
double pt[MAXDIM]; |
70 |
> |
double pt[MAXDDIM]; |
71 |
|
DATARRAY *dp; |
72 |
< |
register char **sa; |
72 |
> |
MFUNC *mf; |
73 |
> |
int i; |
74 |
|
|
63 |
– |
setfunc(m, r); |
64 |
– |
|
65 |
– |
sa = m->oargs.sarg; |
66 |
– |
|
75 |
|
if (m->oargs.nsargs < 4) |
76 |
|
objerror(m, USER, "bad # arguments"); |
77 |
< |
if (!vardefined(sa[3])) |
78 |
< |
loadfunc(sa[2]); |
77 |
> |
dp = getdata(m->oargs.sarg[1]); |
78 |
> |
i = (1 << dp->nd) - 1; |
79 |
> |
mf = getfunc(m, 2, i<<3, 0); |
80 |
> |
setfunc(m, r); |
81 |
|
errno = 0; |
82 |
< |
for (nv = 0; nv+3 < m->oargs.nsargs && |
83 |
< |
sa[nv+3][0] != '-'; nv++) { |
84 |
< |
if (nv >= MAXDIM) |
85 |
< |
goto dimerr; |
76 |
< |
pt[nv] = varvalue(sa[nv+3]); |
82 |
> |
for (i = dp->nd; i-- > 0; ) { |
83 |
> |
pt[i] = evalue(mf->ep[i]); |
84 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
85 |
> |
goto computerr; |
86 |
|
} |
78 |
– |
if (errno) |
79 |
– |
goto computerr; |
80 |
– |
dp = getdata(sa[1]); |
81 |
– |
if (dp->nd != nv) |
82 |
– |
goto dimerr; |
87 |
|
bval = datavalue(dp, pt); |
88 |
|
errno = 0; |
89 |
< |
bval = funvalue(sa[0], 1, &bval); |
90 |
< |
if (errno) |
89 |
> |
bval = funvalue(m->oargs.sarg[0], 1, &bval); |
90 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
91 |
|
goto computerr; |
92 |
< |
scalecolor(r->pcol, bval); |
93 |
< |
return; |
90 |
< |
|
91 |
< |
dimerr: |
92 |
< |
objerror(m, USER, "dimension error"); |
93 |
< |
|
92 |
> |
scalescolor(r->pcol, bval); |
93 |
> |
return(0); |
94 |
|
computerr: |
95 |
|
objerror(m, WARNING, "compute error"); |
96 |
< |
return; |
96 |
> |
return(0); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
< |
p_cdata(m, r) /* interpolate color data */ |
101 |
< |
register OBJREC *m; |
102 |
< |
RAY *r; |
100 |
> |
int |
101 |
> |
p_cdata( /* interpolate color data */ |
102 |
> |
OBJREC *m, |
103 |
> |
RAY *r |
104 |
> |
) |
105 |
|
{ |
104 |
– |
extern double varvalue(), funvalue(), datavalue(); |
105 |
– |
extern int errno; |
106 |
– |
int i, nv; |
106 |
|
double col[3]; |
107 |
|
COLOR cval; |
108 |
< |
double pt[MAXDIM]; |
108 |
> |
double pt[MAXDDIM]; |
109 |
> |
int nv; |
110 |
|
DATARRAY *dp; |
111 |
< |
register char **sa; |
111 |
> |
MFUNC *mf; |
112 |
> |
int i; |
113 |
|
|
113 |
– |
setfunc(m, r); |
114 |
– |
|
115 |
– |
sa = m->oargs.sarg; |
116 |
– |
|
114 |
|
if (m->oargs.nsargs < 8) |
115 |
|
objerror(m, USER, "bad # arguments"); |
116 |
< |
if (!vardefined(sa[7])) |
117 |
< |
loadfunc(sa[6]); |
118 |
< |
for (nv = 0; nv+7 < m->oargs.nsargs && |
119 |
< |
sa[nv+7][0] != '-'; nv++) { |
120 |
< |
if (nv >= MAXDIM) |
121 |
< |
goto dimerr; |
122 |
< |
errno = 0; |
123 |
< |
pt[nv] = varvalue(sa[nv+7]); |
127 |
< |
if (errno) |
116 |
> |
dp = getdata(m->oargs.sarg[3]); |
117 |
> |
i = (1 << (nv = dp->nd)) - 1; |
118 |
> |
mf = getfunc(m, 6, i<<7, 0); |
119 |
> |
setfunc(m, r); |
120 |
> |
errno = 0; |
121 |
> |
for (i = 0; i < nv; i++) { |
122 |
> |
pt[i] = evalue(mf->ep[i]); |
123 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
124 |
|
goto computerr; |
125 |
|
} |
126 |
< |
for (i = 0; i < 3; i++) { |
127 |
< |
dp = getdata(sa[i+3]); |
126 |
> |
col[0] = datavalue(dp, pt); |
127 |
> |
for (i = 1; i < 3; i++) { |
128 |
> |
dp = getdata(m->oargs.sarg[i+3]); |
129 |
|
if (dp->nd != nv) |
130 |
< |
goto dimerr; |
130 |
> |
objerror(m, USER, "dimension error"); |
131 |
|
col[i] = datavalue(dp, pt); |
132 |
|
} |
133 |
|
errno = 0; |
134 |
< |
setcolor(cval, funvalue(sa[0], 3, col), |
135 |
< |
funvalue(sa[1], 3, col), |
136 |
< |
funvalue(sa[2], 3, col)); |
137 |
< |
if (errno) |
134 |
> |
for (i = 0; i < 3; i++) |
135 |
> |
if (fundefined(m->oargs.sarg[i]) < 3) |
136 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i); |
137 |
> |
else |
138 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col); |
139 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
140 |
|
goto computerr; |
141 |
< |
multcolor(r->pcol, cval); |
142 |
< |
return; |
144 |
< |
|
145 |
< |
dimerr: |
146 |
< |
objerror(m, USER, "dimension error"); |
147 |
< |
|
141 |
> |
smultcolor(r->pcol, cval); |
142 |
> |
return(0); |
143 |
|
computerr: |
144 |
|
objerror(m, WARNING, "compute error"); |
145 |
< |
return; |
145 |
> |
return(0); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
< |
p_pdata(m, r) /* interpolate picture data */ |
150 |
< |
register OBJREC *m; |
151 |
< |
RAY *r; |
149 |
> |
int |
150 |
> |
p_pdata( /* interpolate picture data */ |
151 |
> |
OBJREC *m, |
152 |
> |
RAY *r |
153 |
> |
) |
154 |
|
{ |
158 |
– |
extern double varvalue(), funvalue(), datavalue(); |
159 |
– |
extern int errno; |
160 |
– |
int i; |
155 |
|
double col[3]; |
156 |
|
COLOR cval; |
157 |
|
double pt[2]; |
158 |
|
DATARRAY *dp; |
159 |
< |
register char **sa; |
159 |
> |
MFUNC *mf; |
160 |
> |
int i; |
161 |
|
|
167 |
– |
setfunc(m, r); |
168 |
– |
|
169 |
– |
sa = m->oargs.sarg; |
170 |
– |
|
162 |
|
if (m->oargs.nsargs < 7) |
163 |
|
objerror(m, USER, "bad # arguments"); |
164 |
< |
if (!vardefined(sa[5])) |
165 |
< |
loadfunc(sa[4]); |
166 |
< |
for (i = 0; i < 2; i++) { |
167 |
< |
errno = 0; |
168 |
< |
pt[1-i] = varvalue(sa[i+5]); /* y major ordering */ |
169 |
< |
if (errno) |
170 |
< |
goto computerr; |
171 |
< |
} |
181 |
< |
dp = getpict(sa[3]); |
164 |
> |
mf = getfunc(m, 4, 0x3<<5, 0); |
165 |
> |
setfunc(m, r); |
166 |
> |
errno = 0; |
167 |
> |
pt[1] = evalue(mf->ep[0]); /* y major ordering */ |
168 |
> |
pt[0] = evalue(mf->ep[1]); |
169 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
170 |
> |
goto computerr; |
171 |
> |
dp = getpict(m->oargs.sarg[3]); |
172 |
|
for (i = 0; i < 3; i++) |
173 |
|
col[i] = datavalue(dp+i, pt); |
174 |
|
errno = 0; |
175 |
< |
setcolor(cval, funvalue(sa[0], 3, col), |
176 |
< |
funvalue(sa[1], 3, col), |
177 |
< |
funvalue(sa[2], 3, col)); |
178 |
< |
if (errno) |
175 |
> |
for (i = 0; i < 3; i++) |
176 |
> |
if (fundefined(m->oargs.sarg[i]) < 3) |
177 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i); |
178 |
> |
else |
179 |
> |
colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col); |
180 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
181 |
|
goto computerr; |
182 |
< |
multcolor(r->pcol, cval); |
183 |
< |
return; |
182 |
> |
smultcolor(r->pcol, cval); |
183 |
> |
return(0); |
184 |
|
|
185 |
|
computerr: |
186 |
|
objerror(m, WARNING, "compute error"); |
187 |
< |
return; |
187 |
> |
return(0); |
188 |
> |
} |
189 |
> |
|
190 |
> |
|
191 |
> |
int |
192 |
> |
p_spectrum( /* simple constant spectrum */ |
193 |
> |
OBJREC *m, |
194 |
> |
RAY *r |
195 |
> |
) |
196 |
> |
{ |
197 |
> |
COLORV *scval; |
198 |
> |
|
199 |
> |
if ((scval = (COLORV *)m->os) == NULL) { |
200 |
> |
COLORV *sinp; |
201 |
> |
double hstep; |
202 |
> |
int i; |
203 |
> |
if (m->oargs.nfargs < 5) |
204 |
> |
objerror(m, USER, "bad # arguments"); |
205 |
> |
sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2)); |
206 |
> |
scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP); |
207 |
> |
if ((sinp == NULL) | (scval == NULL)) |
208 |
> |
objerror(m, SYSTEM, "out of memory"); |
209 |
> |
for (i = m->oargs.nfargs-2; i--; ) |
210 |
> |
sinp[i] = (COLORV)m->oargs.farg[i+2]; |
211 |
> |
hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) / |
212 |
> |
(m->oargs.nfargs-3.0); |
213 |
> |
convertscolor(scval, NCSAMP, WLPART[0], WLPART[3], |
214 |
> |
sinp, m->oargs.nfargs-2, |
215 |
> |
m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep); |
216 |
> |
free(sinp); |
217 |
> |
m->os = (void *)scval; |
218 |
> |
} |
219 |
> |
smultscolor(r->pcol, scval); |
220 |
> |
return(0); |
221 |
> |
} |
222 |
> |
|
223 |
> |
|
224 |
> |
int |
225 |
> |
p_specfile( /* constant spectrum from 1-D data file */ |
226 |
> |
OBJREC *m, |
227 |
> |
RAY *r |
228 |
> |
) |
229 |
> |
{ |
230 |
> |
COLORV *scval; |
231 |
> |
|
232 |
> |
if ((scval = (COLORV *)m->os) == NULL) { |
233 |
> |
DATARRAY *dp; |
234 |
> |
COLORV *sinp; |
235 |
> |
double step; |
236 |
> |
int i; |
237 |
> |
if (m->oargs.nsargs != 1) |
238 |
> |
objerror(m, USER, "bad # arguments"); |
239 |
> |
dp = getdata(m->oargs.sarg[0]); |
240 |
> |
if (dp->nd != 1) |
241 |
> |
objerror(m, USER, "data file must be 1-dimensional"); |
242 |
> |
|
243 |
> |
sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne); |
244 |
> |
scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP); |
245 |
> |
if ((sinp == NULL) | (scval == NULL)) |
246 |
> |
objerror(m, SYSTEM, "out of memory"); |
247 |
> |
step = dp->dim[0].siz / (dp->dim[0].ne - 1.0); |
248 |
> |
for (i = dp->dim[0].ne; i-- > 0; ) { |
249 |
> |
double wl = dp->dim[0].org + i*step; |
250 |
> |
sinp[i] = (COLORV)datavalue(dp, &wl); |
251 |
> |
} |
252 |
> |
convertscolor(scval, NCSAMP, WLPART[0], WLPART[3], |
253 |
> |
sinp, dp->dim[0].ne, dp->dim[0].org-.5*step, |
254 |
> |
dp->dim[0].org+dp->dim[0].siz+.5*step); |
255 |
> |
free(sinp); |
256 |
> |
m->os = (void *)scval; |
257 |
> |
} |
258 |
> |
smultscolor(r->pcol, scval); |
259 |
> |
return(0); |
260 |
|
} |