ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/p_data.c
(Generate patch)

Comparing ray/src/rt/p_data.c (file contents):
Revision 2.8 by schorsch, Tue Mar 30 16:13:01 2004 UTC vs.
Revision 2.13 by greg, Wed Jan 17 17:35:35 2024 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
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
# Line 35 | Line 35 | static const char      RCSid[] = "$Id$";
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 + *  A spectral data file is given as:
53 + *
54 + *      modifier specdata name
55 + *      4+ sfunc dfname vfname v0 .. xf
56 + *      0
57 + *      n A1 A2 ..
58 + *
59 + *  A spectral image is given as:
60 + *
61 + *      modifier specpict name
62 + *      5+ sfunc sfname vfname vx vy xf
63 + *      0
64 + *      n A1 A2 ..
65 + *
66   *  Vfname is the name of the file where the variable definitions
67   *  can be found.  The list of real arguments can be accessed by
68   *  definitions in the file.  The dfnames are the data file
69   *  names.  The dimensions of the data files and the number
70 < *  of variables must match.  The funcs take a single argument
71 < *  for brightdata, and three for colordata and colorpict to produce
72 < *  interpolated values from the file.  The xf is a transformation
73 < *  to get from the original coordinates to the current coordinates.
70 > *  of variables must match, except for specdata, which has a "hidden"
71 > *  last variable for the wavelength.  The funcs take a single argument
72 > *  for brightdata, three for colordata and colorpict, and two for
73 > *  specdata and specpict to modify interpolated values from the file.
74 > *  The xf is a transform spec to get from the original coordinates to
75 > *  the current coordinates.
76   */
77  
78  
79 < extern int
79 > int
80   p_bdata(                        /* interpolate brightness data */
81 <        register OBJREC  *m,
81 >        OBJREC  *m,
82          RAY  *r
83   )
84   {
85          double  bval;
86 <        double  pt[MAXDIM];
86 >        double  pt[MAXDDIM];
87          DATARRAY  *dp;
88 <        register MFUNC  *mf;
89 <        register int  i;
88 >        MFUNC  *mf;
89 >        int  i;
90  
91          if (m->oargs.nsargs < 4)
92                  objerror(m, USER, "bad # arguments");
# Line 67 | Line 97 | p_bdata(                       /* interpolate brightness data */
97          errno = 0;
98          for (i = dp->nd; i-- > 0; ) {
99                  pt[i] = evalue(mf->ep[i]);
100 <                if (errno == EDOM || errno == ERANGE)
100 >                if ((errno == EDOM) | (errno == ERANGE))
101                          goto computerr;
102          }
103          bval = datavalue(dp, pt);
104          errno = 0;
105          bval = funvalue(m->oargs.sarg[0], 1, &bval);
106 <        if (errno == EDOM || errno == ERANGE)
106 >        if ((errno == EDOM) | (errno == ERANGE))
107                  goto computerr;
108 <        scalecolor(r->pcol, bval);
108 >        scalescolor(r->pcol, bval);
109          return(0);
110   computerr:
111          objerror(m, WARNING, "compute error");
# Line 83 | Line 113 | computerr:
113   }
114  
115  
116 < extern int
116 > int
117   p_cdata(                        /* interpolate color data */
118 <        register OBJREC  *m,
118 >        OBJREC  *m,
119          RAY  *r
120   )
121   {
122          double  col[3];
123          COLOR  cval;
124 <        double  pt[MAXDIM];
124 >        double  pt[MAXDDIM];
125          int  nv;
126          DATARRAY  *dp;
127 <        register MFUNC  *mf;
128 <        register int  i;
127 >        MFUNC  *mf;
128 >        int  i;
129  
130          if (m->oargs.nsargs < 8)
131                  objerror(m, USER, "bad # arguments");
# Line 106 | Line 136 | p_cdata(                       /* interpolate color data */
136          errno = 0;
137          for (i = 0; i < nv; i++) {
138                  pt[i] = evalue(mf->ep[i]);
139 <                if (errno == EDOM || errno == ERANGE)
139 >                if ((errno == EDOM) | (errno == ERANGE))
140                          goto computerr;
141          }
142          col[0] = datavalue(dp, pt);
143          for (i = 1; i < 3; i++) {
144 <                dp = getdata(m->oargs.sarg[i+3]);
144 >                dp = getdata(m->oargs.sarg[3+i]);
145                  if (dp->nd != nv)
146                          objerror(m, USER, "dimension error");
147                  col[i] = datavalue(dp, pt);
148          }
149          errno = 0;
150          for (i = 0; i < 3; i++)
151 <                if (fundefined(m->oargs.sarg[i]) < 3)
151 >                if (i && fundefined(m->oargs.sarg[i]) < 3)
152                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
153                  else
154                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
155 <        if (errno == EDOM || errno == ERANGE)
155 >        if ((errno == EDOM) | (errno == ERANGE))
156                  goto computerr;
157 <        multcolor(r->pcol, cval);
157 >        smultcolor(r->pcol, cval);
158          return(0);
159   computerr:
160          objerror(m, WARNING, "compute error");
# Line 132 | Line 162 | computerr:
162   }
163  
164  
165 < extern int
165 > int
166   p_pdata(                        /* interpolate picture data */
167 <        register OBJREC  *m,
167 >        OBJREC  *m,
168          RAY  *r
169   )
170   {
# Line 142 | Line 172 | p_pdata(                       /* interpolate picture data */
172          COLOR  cval;
173          double  pt[2];
174          DATARRAY  *dp;
175 <        register MFUNC  *mf;
176 <        register int  i;
175 >        MFUNC  *mf;
176 >        int  i;
177  
178          if (m->oargs.nsargs < 7)
179                  objerror(m, USER, "bad # arguments");
# Line 152 | Line 182 | p_pdata(                       /* interpolate picture data */
182          errno = 0;
183          pt[1] = evalue(mf->ep[0]);      /* y major ordering */
184          pt[0] = evalue(mf->ep[1]);
185 <        if (errno == EDOM || errno == ERANGE)
185 >        if ((errno == EDOM) | (errno == ERANGE))
186                  goto computerr;
187          dp = getpict(m->oargs.sarg[3]);
188          for (i = 0; i < 3; i++)
189                  col[i] = datavalue(dp+i, pt);
190          errno = 0;
191          for (i = 0; i < 3; i++)
192 <                if (fundefined(m->oargs.sarg[i]) < 3)
192 >                if (i && fundefined(m->oargs.sarg[i]) < 3)
193                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
194                  else
195                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
196 <        if (errno == EDOM || errno == ERANGE)
196 >        if ((errno == EDOM) | (errno == ERANGE))
197                  goto computerr;
198 <        multcolor(r->pcol, cval);
198 >        smultcolor(r->pcol, cval);
199          return(0);
200  
201 + computerr:
202 +        objerror(m, WARNING, "compute error");
203 +        return(0);
204 + }
205 +
206 +
207 + int
208 + p_spectrum(                     /* simple constant spectrum */
209 +        OBJREC  *m,
210 +        RAY  *r
211 + )
212 + {
213 +        COLORV  *scval;
214 +
215 +        if ((scval = (COLORV *)m->os) == NULL) {
216 +                COLORV  *sinp;
217 +                double  hstep;
218 +                int     i;
219 +                if (m->oargs.nfargs < 5)
220 +                        objerror(m, USER, "bad # arguments");
221 +                sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2));
222 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
223 +                if ((sinp == NULL) | (scval == NULL))
224 +                        objerror(m, SYSTEM, "out of memory");
225 +                for (i = m->oargs.nfargs-2; i--; )
226 +                        sinp[i] = (COLORV)m->oargs.farg[i+2];
227 +                hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) /
228 +                                (m->oargs.nfargs-3.0);
229 +                convertscolorcol(scval, sinp, m->oargs.nfargs-2,
230 +                                m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep);
231 +                free(sinp);
232 +                m->os = (void *)scval;
233 +        }
234 +        smultscolor(r->pcol, scval);
235 +        return(0);
236 + }
237 +
238 +
239 + int
240 + p_specfile(                     /* constant spectrum from 1-D data file */
241 +        OBJREC  *m,
242 +        RAY  *r
243 + )
244 + {
245 +        COLORV  *scval;
246 +
247 +        if ((scval = (COLORV *)m->os) == NULL) {
248 +                DATARRAY        *dp;
249 +                COLORV          *sinp;
250 +                double          step;
251 +                int             i;
252 +                if (m->oargs.nsargs != 1)
253 +                        objerror(m, USER, "bad # arguments");
254 +                dp = getdata(m->oargs.sarg[0]);
255 +                if (dp->nd != 1)
256 +                        objerror(m, USER, "data file must be 1-dimensional");
257 +
258 +                sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
259 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
260 +                if ((sinp == NULL) | (scval == NULL))
261 +                        objerror(m, SYSTEM, "out of memory");
262 +                step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
263 +                for (i = dp->dim[0].ne; i-- > 0; ) {
264 +                        double  wl = dp->dim[0].org + i*step;
265 +                        sinp[i] = (COLORV)datavalue(dp, &wl);
266 +                }
267 +                convertscolorcol(scval, sinp, dp->dim[0].ne,
268 +                                dp->dim[0].org-.5*step,
269 +                                dp->dim[0].org+dp->dim[0].siz+.5*step);
270 +                free(sinp);
271 +                m->os = (void *)scval;
272 +        }
273 +        smultscolor(r->pcol, scval);
274 +        return(0);
275 + }
276 +
277 +
278 + int
279 + p_specdata(                     /* varied spectrum from (N+1)-D file */
280 +        OBJREC  *m,
281 +        RAY  *r
282 + )
283 + {
284 +        SCOLOR          scval;
285 +        COLORV          *scdat;
286 +        double          pt[MAXDDIM];
287 +        DATARRAY        *dp;
288 +        MFUNC           *mf;
289 +        double          step;
290 +        int             i;
291 +
292 +        if (m->oargs.nsargs < 4)
293 +                objerror(m, USER, "bad # arguments");
294 +        dp = getdata(m->oargs.sarg[1]);
295 +        if (dp->nd < 2)
296 +                objerror(m, USER, "need at least 2-dimensional data");
297 +        i = (1 << (dp->nd-1)) - 1;
298 +        mf = getfunc(m, 2, i<<3, 0);
299 +        setfunc(m, r);
300 +        errno = 0;
301 +        for (i = dp->nd-1; i-- > 0; ) {
302 +                pt[i] = evalue(mf->ep[i]);
303 +                if ((errno == EDOM) | (errno == ERANGE))
304 +                        goto computerr;
305 +        }
306 +        step = dp->dim[dp->nd-1].siz / (dp->dim[dp->nd-1].ne - 1.0);
307 +        scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[dp->nd-1].ne);
308 +        if (scdat == NULL)
309 +                objerror(m, SYSTEM, "out of memory");
310 +        for (i = dp->dim[dp->nd-1].ne; i-- > 0; ) {
311 +                double  bval[2];
312 +                pt[dp->nd-1] = dp->dim[dp->nd-1].org + i*step;
313 +                bval[0] = datavalue(dp, pt);
314 +                bval[1] = pt[dp->nd-1];
315 +                errno = 0;
316 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
317 +                if ((errno == EDOM) | (errno == ERANGE))
318 +                        goto computerr;
319 +        }
320 +        convertscolorcol(scval, scdat, dp->dim[dp->nd-1].ne,
321 +                        dp->dim[dp->nd-1].org-.5*step,
322 +                        dp->dim[dp->nd-1].org+dp->dim[dp->nd-1].siz+.5*step);
323 +        free(scdat);
324 +        smultscolor(r->pcol, scval);
325 +        return(0);
326 + computerr:
327 +        objerror(m, WARNING, "compute error");
328 +        return(0);
329 + }
330 +
331 +
332 + int
333 + p_specpict(                     /* interpolate hyperspectral image data */
334 +        OBJREC  *m,
335 +        RAY  *r
336 + )
337 + {
338 +        SCOLOR          scdat, scval;
339 +        double          pt[3];
340 +        DATARRAY        *dp;
341 +        MFUNC           *mf;
342 +        double          step;
343 +        int             i;
344 +
345 +        if (m->oargs.nsargs < 5)
346 +                objerror(m, USER, "bad # arguments");
347 +        mf = getfunc(m, 2, 0x3<<3, 0);
348 +        setfunc(m, r);
349 +        errno = 0;
350 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
351 +        pt[0] = evalue(mf->ep[1]);
352 +        if ((errno == EDOM) | (errno == ERANGE))
353 +                goto computerr;
354 +        dp = getspec(m->oargs.sarg[1]);
355 +        step = dp->dim[2].siz / (dp->dim[2].ne - 1.0);
356 +        for (i = dp->dim[2].ne; i-- > 0; ) {
357 +                double  bval[2];
358 +                pt[2] = dp->dim[2].org + i*step;
359 +                bval[0] = datavalue(dp, pt);
360 +                bval[1] = pt[2];
361 +                errno = 0;
362 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
363 +                if ((errno == EDOM) | (errno == ERANGE))
364 +                        goto computerr;
365 +        }
366 +        convertscolorcol(scval, scdat, dp->dim[2].ne,
367 +                        dp->dim[2].org-.5*step,
368 +                        dp->dim[2].org+dp->dim[2].siz+.5*step);
369 +        smultscolor(r->pcol, scval);
370 +        return(0);
371   computerr:
372          objerror(m, WARNING, "compute error");
373          return(0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines