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.10 by greg, Wed Nov 15 18:02:53 2023 UTC vs.
Revision 2.12 by greg, Thu Dec 14 00:51:12 2023 UTC

# Line 49 | Line 49 | static const char      RCSid[] = "$Id$";
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 transform spec
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  
# Line 125 | Line 141 | p_cdata(                       /* interpolate color data */
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);
# Line 173 | Line 189 | p_pdata(                       /* interpolate picture data */
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);
# Line 256 | Line 272 | p_specfile(                    /* constant spectrum from 1-D data file
272                  m->os = (void *)scval;
273          }
274          smultscolor(r->pcol, scval);
275 +        return(0);
276 + }
277 +
278 +
279 + int
280 + p_specdata(                     /* varied spectrum from (N+1)-D file */
281 +        OBJREC  *m,
282 +        RAY  *r
283 + )
284 + {
285 +        SCOLOR          scval;
286 +        COLORV          *scdat;
287 +        double          pt[MAXDDIM];
288 +        DATARRAY        *dp;
289 +        MFUNC           *mf;
290 +        double          step;
291 +        int             i;
292 +
293 +        if (m->oargs.nsargs < 4)
294 +                objerror(m, USER, "bad # arguments");
295 +        dp = getdata(m->oargs.sarg[1]);
296 +        if (dp->nd < 2)
297 +                objerror(m, USER, "need at least 2-dimensional data");
298 +        i = (1 << (dp->nd-1)) - 1;
299 +        mf = getfunc(m, 2, i<<3, 0);
300 +        setfunc(m, r);
301 +        errno = 0;
302 +        for (i = dp->nd-1; i-- > 0; ) {
303 +                pt[i] = evalue(mf->ep[i]);
304 +                if ((errno == EDOM) | (errno == ERANGE))
305 +                        goto computerr;
306 +        }
307 +        step = dp->dim[dp->nd-1].siz / (dp->dim[dp->nd-1].ne - 1.0);
308 +        scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[dp->nd-1].ne);
309 +        if (scdat == NULL)
310 +                objerror(m, SYSTEM, "out of memory");
311 +        for (i = dp->dim[dp->nd-1].ne; i-- > 0; ) {
312 +                double  bval[2];
313 +                pt[dp->nd-1] = dp->dim[dp->nd-1].org + i*step;
314 +                bval[0] = datavalue(dp, pt);
315 +                bval[1] = pt[dp->nd-1];
316 +                errno = 0;
317 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
318 +                if ((errno == EDOM) | (errno == ERANGE))
319 +                        goto computerr;
320 +        }
321 +        convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
322 +                        scdat, dp->dim[dp->nd-1].ne,
323 +                        dp->dim[dp->nd-1].org-.5*step,
324 +                        dp->dim[dp->nd-1].org+dp->dim[dp->nd-1].siz+.5*step);
325 +        free(scdat);
326 +        smultscolor(r->pcol, scval);
327 +        return(0);
328 + computerr:
329 +        objerror(m, WARNING, "compute error");
330 +        return(0);
331 + }
332 +
333 +
334 + int
335 + p_specpict(                     /* interpolate hyperspectral image data */
336 +        OBJREC  *m,
337 +        RAY  *r
338 + )
339 + {
340 +        SCOLOR          scdat, scval;
341 +        double          pt[3];
342 +        DATARRAY        *dp;
343 +        MFUNC           *mf;
344 +        double          step;
345 +        int             i;
346 +
347 +        if (m->oargs.nsargs < 5)
348 +                objerror(m, USER, "bad # arguments");
349 +        mf = getfunc(m, 2, 0x3<<3, 0);
350 +        setfunc(m, r);
351 +        errno = 0;
352 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
353 +        pt[0] = evalue(mf->ep[1]);
354 +        if ((errno == EDOM) | (errno == ERANGE))
355 +                goto computerr;
356 +        dp = getspec(m->oargs.sarg[1]);
357 +        step = dp->dim[2].siz / (dp->dim[2].ne - 1.0);
358 +        for (i = dp->dim[2].ne; i-- > 0; ) {
359 +                double  bval[2];
360 +                pt[2] = dp->dim[2].org + i*step;
361 +                bval[0] = datavalue(dp, pt);
362 +                bval[1] = pt[2];
363 +                errno = 0;
364 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
365 +                if ((errno == EDOM) | (errno == ERANGE))
366 +                        goto computerr;
367 +        }
368 +        convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
369 +                        scdat, dp->dim[2].ne,
370 +                        dp->dim[2].org-.5*step,
371 +                        dp->dim[2].org+dp->dim[2].siz+.5*step);
372 +        smultscolor(r->pcol, scval);
373 +        return(0);
374 + computerr:
375 +        objerror(m, WARNING, "compute error");
376          return(0);
377   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines