ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
Revision: 1.4
Committed: Wed Jan 2 18:22:40 1991 UTC (33 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +6 -7 lines
Log Message:
eliminated unnecessary loopy

File Contents

# User Rev Content
1 greg 1.4 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * p_data.c - routine for stored patterns.
9     *
10     * 6/4/86
11     */
12    
13     #include "ray.h"
14    
15     #include "data.h"
16    
17     /*
18     * A stored pattern can either be brightness or
19     * color data. Brightness data is specified as:
20     *
21     * modifier brightdata name
22     * 4+ func dfname vfname v0 v1 .. xf
23     * 0
24     * n A1 A2 ..
25     *
26     * Color data is specified as:
27     *
28     * modifier colordata name
29     * 8+ rfunc gfunc bfunc rdfname gdfname bdfname vfname v0 v1 .. xf
30     * 0
31     * n A1 A2 ..
32     *
33     * Color picture data is specified as:
34     *
35     * modifier colorpict name
36     * 7+ rfunc gfunc bfunc pfname vfname vx vy xf
37     * 0
38     * n A1 A2 ..
39     *
40     * Vfname is the name of the file where the variable definitions
41     * can be found. The list of real arguments can be accessed by
42     * definitions in the file. The dfnames are the data file
43     * names. The dimensions of the data files and the number
44     * of variables must match. The funcs take a single argument
45     * for brightdata, and three for colordata and colorpict to produce
46     * interpolated values from the file. The xf is a transformation
47     * to get from the original coordinates to the current coordinates.
48     */
49    
50    
51     p_bdata(m, r) /* interpolate brightness data */
52     register OBJREC *m;
53     RAY *r;
54     {
55     extern double varvalue(), funvalue(), datavalue();
56     extern int errno;
57     int nv;
58     double bval;
59     double pt[MAXDIM];
60     DATARRAY *dp;
61     register char **sa;
62    
63     setfunc(m, r);
64    
65     sa = m->oargs.sarg;
66    
67     if (m->oargs.nsargs < 4)
68     objerror(m, USER, "bad # arguments");
69     if (!vardefined(sa[3]))
70     loadfunc(sa[2]);
71 greg 1.2 errno = 0;
72 greg 1.1 for (nv = 0; nv+3 < m->oargs.nsargs &&
73     sa[nv+3][0] != '-'; nv++) {
74     if (nv >= MAXDIM)
75     goto dimerr;
76     pt[nv] = varvalue(sa[nv+3]);
77     }
78 greg 1.2 if (errno)
79     goto computerr;
80 greg 1.1 dp = getdata(sa[1]);
81     if (dp->nd != nv)
82     goto dimerr;
83     bval = datavalue(dp, pt);
84     errno = 0;
85     bval = funvalue(sa[0], 1, &bval);
86     if (errno)
87     goto computerr;
88     scalecolor(r->pcol, bval);
89     return;
90    
91     dimerr:
92     objerror(m, USER, "dimension error");
93    
94     computerr:
95     objerror(m, WARNING, "compute error");
96     return;
97     }
98    
99    
100     p_cdata(m, r) /* interpolate color data */
101     register OBJREC *m;
102     RAY *r;
103     {
104     extern double varvalue(), funvalue(), datavalue();
105     extern int errno;
106     int i, nv;
107     double col[3];
108     COLOR cval;
109     double pt[MAXDIM];
110     DATARRAY *dp;
111     register char **sa;
112    
113     setfunc(m, r);
114    
115     sa = m->oargs.sarg;
116    
117     if (m->oargs.nsargs < 8)
118     objerror(m, USER, "bad # arguments");
119     if (!vardefined(sa[7]))
120     loadfunc(sa[6]);
121     for (nv = 0; nv+7 < m->oargs.nsargs &&
122     sa[nv+7][0] != '-'; nv++) {
123     if (nv >= MAXDIM)
124     goto dimerr;
125     errno = 0;
126     pt[nv] = varvalue(sa[nv+7]);
127     if (errno)
128     goto computerr;
129     }
130     for (i = 0; i < 3; i++) {
131     dp = getdata(sa[i+3]);
132     if (dp->nd != nv)
133     goto dimerr;
134     col[i] = datavalue(dp, pt);
135     }
136     errno = 0;
137     setcolor(cval, funvalue(sa[0], 3, col),
138     funvalue(sa[1], 3, col),
139     funvalue(sa[2], 3, col));
140     if (errno)
141     goto computerr;
142     multcolor(r->pcol, cval);
143     return;
144    
145     dimerr:
146     objerror(m, USER, "dimension error");
147    
148     computerr:
149     objerror(m, WARNING, "compute error");
150     return;
151     }
152    
153    
154     p_pdata(m, r) /* interpolate picture data */
155     register OBJREC *m;
156     RAY *r;
157     {
158     extern double varvalue(), funvalue(), datavalue();
159     extern int errno;
160     int i;
161     double col[3];
162     COLOR cval;
163     double pt[2];
164     DATARRAY *dp;
165     register char **sa;
166    
167     setfunc(m, r);
168    
169     sa = m->oargs.sarg;
170    
171     if (m->oargs.nsargs < 7)
172     objerror(m, USER, "bad # arguments");
173     if (!vardefined(sa[5]))
174     loadfunc(sa[4]);
175 greg 1.4 errno = 0;
176     pt[1] = varvalue(sa[5]); /* y major ordering */
177     pt[0] = varvalue(sa[6]);
178     if (errno)
179     goto computerr;
180 greg 1.1 dp = getpict(sa[3]);
181     for (i = 0; i < 3; i++)
182     col[i] = datavalue(dp+i, pt);
183     errno = 0;
184     setcolor(cval, funvalue(sa[0], 3, col),
185     funvalue(sa[1], 3, col),
186     funvalue(sa[2], 3, col));
187     if (errno)
188     goto computerr;
189     multcolor(r->pcol, cval);
190     return;
191    
192     computerr:
193     objerror(m, WARNING, "compute error");
194     return;
195     }