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