1 |
– |
/* Copyright (c) 1992 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" |
16 |
– |
|
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 |
|
{ |
69 |
|
double bval; |
70 |
< |
double pt[MAXDIM]; |
70 |
> |
double pt[MAXDDIM]; |
71 |
|
DATARRAY *dp; |
72 |
< |
register MFUNC *mf; |
73 |
< |
register int i; |
72 |
> |
MFUNC *mf; |
73 |
> |
int i; |
74 |
|
|
75 |
|
if (m->oargs.nsargs < 4) |
76 |
|
objerror(m, USER, "bad # arguments"); |
81 |
|
errno = 0; |
82 |
|
for (i = dp->nd; i-- > 0; ) { |
83 |
|
pt[i] = evalue(mf->ep[i]); |
84 |
< |
if (errno) |
84 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
85 |
|
goto computerr; |
86 |
|
} |
87 |
|
bval = datavalue(dp, pt); |
88 |
|
errno = 0; |
89 |
|
bval = funvalue(m->oargs.sarg[0], 1, &bval); |
90 |
< |
if (errno) |
90 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
91 |
|
goto computerr; |
92 |
< |
scalecolor(r->pcol, bval); |
92 |
> |
scalescolor(r->pcol, bval); |
93 |
|
return(0); |
94 |
|
computerr: |
95 |
|
objerror(m, WARNING, "compute error"); |
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 |
|
{ |
106 |
|
double col[3]; |
107 |
|
COLOR cval; |
108 |
< |
double pt[MAXDIM]; |
108 |
> |
double pt[MAXDDIM]; |
109 |
|
int nv; |
110 |
|
DATARRAY *dp; |
111 |
< |
register MFUNC *mf; |
112 |
< |
register int i; |
111 |
> |
MFUNC *mf; |
112 |
> |
int i; |
113 |
|
|
114 |
|
if (m->oargs.nsargs < 8) |
115 |
|
objerror(m, USER, "bad # arguments"); |
120 |
|
errno = 0; |
121 |
|
for (i = 0; i < nv; i++) { |
122 |
|
pt[i] = evalue(mf->ep[i]); |
123 |
< |
if (errno) |
123 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
124 |
|
goto computerr; |
125 |
|
} |
126 |
|
col[0] = datavalue(dp, pt); |
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) |
139 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
140 |
|
goto computerr; |
141 |
< |
multcolor(r->pcol, cval); |
141 |
> |
smultcolor(r->pcol, cval); |
142 |
|
return(0); |
143 |
|
computerr: |
144 |
|
objerror(m, WARNING, "compute error"); |
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 |
|
{ |
155 |
|
double col[3]; |
156 |
|
COLOR cval; |
157 |
|
double pt[2]; |
158 |
|
DATARRAY *dp; |
159 |
< |
register MFUNC *mf; |
160 |
< |
register int i; |
159 |
> |
MFUNC *mf; |
160 |
> |
int i; |
161 |
|
|
162 |
|
if (m->oargs.nsargs < 7) |
163 |
|
objerror(m, USER, "bad # arguments"); |
166 |
|
errno = 0; |
167 |
|
pt[1] = evalue(mf->ep[0]); /* y major ordering */ |
168 |
|
pt[0] = evalue(mf->ep[1]); |
169 |
< |
if (errno) |
169 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
170 |
|
goto computerr; |
171 |
|
dp = getpict(m->oargs.sarg[3]); |
172 |
|
for (i = 0; i < 3; i++) |
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) |
180 |
> |
if ((errno == EDOM) | (errno == ERANGE)) |
181 |
|
goto computerr; |
182 |
< |
multcolor(r->pcol, cval); |
182 |
> |
smultcolor(r->pcol, cval); |
183 |
|
return(0); |
184 |
|
|
185 |
|
computerr: |
186 |
|
objerror(m, WARNING, "compute error"); |
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 |
|
} |