1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* mx_data.c - routine for stored mixtures. |
6 |
*/ |
7 |
|
8 |
#include "copyright.h" |
9 |
|
10 |
#include "ray.h" |
11 |
|
12 |
#include "data.h" |
13 |
|
14 |
#include "func.h" |
15 |
|
16 |
/* |
17 |
* A stored mixture is specified: |
18 |
* |
19 |
* modifier mixdata name |
20 |
* 6+ foremod backmod func dfname vfname v0 v1 .. xf |
21 |
* 0 |
22 |
* n A1 A2 .. |
23 |
* |
24 |
* A picture mixture is specified as: |
25 |
* |
26 |
* modifier mixpict name |
27 |
* 7+ foremod backmod func pfname vfname vx vy xf |
28 |
* 0 |
29 |
* n A1 A2 .. |
30 |
* |
31 |
* |
32 |
* Vfname is the name of the file where the variable definitions |
33 |
* can be found. The list of real arguments can be accessed by |
34 |
* definitions in the file. Dfname is the data file. |
35 |
* (Pfname is a picture file.) |
36 |
* The dimensions of the data files and the number |
37 |
* of variables must match. The func is a single argument |
38 |
* function in the case of mixdata (three argument in the case |
39 |
* of mixpict), which returns the corrected data value given the |
40 |
* interpolated value from the file. The xf is a transformation |
41 |
* to get from the original coordinates to the current coordinates. |
42 |
*/ |
43 |
|
44 |
|
45 |
mx_data(m, r) /* interpolate mixture data */ |
46 |
register OBJREC *m; |
47 |
RAY *r; |
48 |
{ |
49 |
OBJECT obj; |
50 |
double coef; |
51 |
double pt[MAXDIM]; |
52 |
DATARRAY *dp; |
53 |
OBJECT mod[2]; |
54 |
register MFUNC *mf; |
55 |
register int i; |
56 |
|
57 |
if (m->oargs.nsargs < 6) |
58 |
objerror(m, USER, "bad # arguments"); |
59 |
obj = objndx(m); |
60 |
for (i = 0; i < 2; i++) |
61 |
if (!strcmp(m->oargs.sarg[i], VOIDID)) |
62 |
mod[i] = OVOID; |
63 |
else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { |
64 |
sprintf(errmsg, "undefined modifier \"%s\"", |
65 |
m->oargs.sarg[i]); |
66 |
objerror(m, USER, errmsg); |
67 |
} |
68 |
dp = getdata(m->oargs.sarg[3]); |
69 |
i = (1 << dp->nd) - 1; |
70 |
mf = getfunc(m, 4, i<<5, 0); |
71 |
setfunc(m, r); |
72 |
errno = 0; |
73 |
for (i = 0; i < dp->nd; i++) { |
74 |
pt[i] = evalue(mf->ep[i]); |
75 |
if (errno) |
76 |
goto computerr; |
77 |
} |
78 |
coef = datavalue(dp, pt); |
79 |
errno = 0; |
80 |
coef = funvalue(m->oargs.sarg[2], 1, &coef); |
81 |
if (errno) |
82 |
goto computerr; |
83 |
if (raymixture(r, mod[0], mod[1], coef)) { |
84 |
if (m->omod != OVOID) |
85 |
objerror(m, USER, "inappropriate modifier"); |
86 |
return(1); |
87 |
} |
88 |
return(0); |
89 |
computerr: |
90 |
objerror(m, WARNING, "compute error"); |
91 |
return(0); |
92 |
} |
93 |
|
94 |
|
95 |
mx_pdata(m, r) /* interpolate mixture picture */ |
96 |
register OBJREC *m; |
97 |
RAY *r; |
98 |
{ |
99 |
OBJECT obj; |
100 |
double col[3], coef; |
101 |
double pt[MAXDIM]; |
102 |
DATARRAY *dp; |
103 |
OBJECT mod[2]; |
104 |
register MFUNC *mf; |
105 |
register int i; |
106 |
|
107 |
if (m->oargs.nsargs < 7) |
108 |
objerror(m, USER, "bad # arguments"); |
109 |
obj = objndx(m); |
110 |
for (i = 0; i < 2; i++) |
111 |
if (!strcmp(m->oargs.sarg[i], VOIDID)) |
112 |
mod[i] = OVOID; |
113 |
else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) { |
114 |
sprintf(errmsg, "undefined modifier \"%s\"", |
115 |
m->oargs.sarg[i]); |
116 |
objerror(m, USER, errmsg); |
117 |
} |
118 |
dp = getpict(m->oargs.sarg[3]); |
119 |
mf = getfunc(m, 4, 0x3<<5, 0); |
120 |
setfunc(m, r); |
121 |
errno = 0; |
122 |
pt[1] = evalue(mf->ep[0]); /* y major ordering */ |
123 |
pt[0] = evalue(mf->ep[1]); |
124 |
if (errno) |
125 |
goto computerr; |
126 |
for (i = 0; i < 3; i++) /* get pixel from picture */ |
127 |
col[i] = datavalue(dp+i, pt); |
128 |
errno = 0; /* evaluate function on pixel */ |
129 |
coef = funvalue(m->oargs.sarg[2], 3, col); |
130 |
if (errno) |
131 |
goto computerr; |
132 |
if (raymixture(r, mod[0], mod[1], coef)) { |
133 |
if (m->omod != OVOID) |
134 |
objerror(m, USER, "inappropriate modifier"); |
135 |
return(1); |
136 |
} |
137 |
return(0); |
138 |
computerr: |
139 |
objerror(m, WARNING, "compute error"); |
140 |
return(0); |
141 |
} |