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.11 by greg, Wed Dec 13 23:26:16 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 +        if (dp->dim[dp->nd-1].ne > MAXCSAMP)
299 +                objerror(m, USER, "too many spectral samples in data file");
300 +        i = (1 << (dp->nd-1)) - 1;
301 +        mf = getfunc(m, 2, i<<3, 0);
302 +        setfunc(m, r);
303 +        errno = 0;
304 +        for (i = dp->nd-1; i-- > 0; ) {
305 +                pt[i] = evalue(mf->ep[i]);
306 +                if ((errno == EDOM) | (errno == ERANGE))
307 +                        goto computerr;
308 +        }
309 +        step = dp->dim[dp->nd-1].siz / (dp->dim[dp->nd-1].ne - 1.0);
310 +        scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[dp->nd-1].ne);
311 +        if (scdat == NULL)
312 +                objerror(m, SYSTEM, "out of memory");
313 +        for (i = dp->dim[dp->nd-1].ne; i-- > 0; ) {
314 +                double  bval[2];
315 +                pt[dp->nd-1] = dp->dim[dp->nd-1].org + i*step;
316 +                bval[0] = datavalue(dp, pt);
317 +                bval[1] = pt[dp->nd-1];
318 +                errno = 0;
319 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
320 +                if ((errno == EDOM) | (errno == ERANGE))
321 +                        goto computerr;
322 +        }
323 +        convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
324 +                        scdat, dp->dim[dp->nd-1].ne,
325 +                        dp->dim[dp->nd-1].org-.5*step,
326 +                        dp->dim[dp->nd-1].org+dp->dim[dp->nd-1].siz+.5*step);
327 +        free(scdat);
328 +        smultscolor(r->pcol, scval);
329 +        return(0);
330 + computerr:
331 +        objerror(m, WARNING, "compute error");
332 +        return(0);
333 + }
334 +
335 +
336 + int
337 + p_specpict(                     /* interpolate hyperspectral image data */
338 +        OBJREC  *m,
339 +        RAY  *r
340 + )
341 + {
342 +        SCOLOR          scdat, scval;
343 +        double          pt[3];
344 +        DATARRAY        *dp;
345 +        MFUNC           *mf;
346 +        double          step;
347 +        int             i;
348 +
349 +        if (m->oargs.nsargs < 5)
350 +                objerror(m, USER, "bad # arguments");
351 +        mf = getfunc(m, 2, 0x3<<3, 0);
352 +        setfunc(m, r);
353 +        errno = 0;
354 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
355 +        pt[0] = evalue(mf->ep[1]);
356 +        if ((errno == EDOM) | (errno == ERANGE))
357 +                goto computerr;
358 +        dp = getspec(m->oargs.sarg[1]);
359 +        step = dp->dim[2].siz / (dp->dim[2].ne - 1.0);
360 +        for (i = dp->dim[2].ne; i-- > 0; ) {
361 +                double  bval[2];
362 +                pt[2] = dp->dim[2].org + i*step;
363 +                bval[0] = datavalue(dp, pt);
364 +                bval[1] = pt[2];
365 +                errno = 0;
366 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
367 +                if ((errno == EDOM) | (errno == ERANGE))
368 +                        goto computerr;
369 +        }
370 +        convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
371 +                        scdat, dp->dim[2].ne,
372 +                        dp->dim[2].org-.5*step,
373 +                        dp->dim[2].org+dp->dim[2].siz+.5*step);
374 +        smultscolor(r->pcol, scval);
375 +        return(0);
376 + computerr:
377 +        objerror(m, WARNING, "compute error");
378          return(0);
379   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines