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.14 by greg, Thu Feb 22 20:11:54 2024 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 >                if (!strcmp(m->oargs.sarg[3+i], m->oargs.sarg[3])) {
145 >                        col[i] = col[0];        /* same data */
146 >                        continue;
147 >                }
148 >                dp = getdata(m->oargs.sarg[3+i]);
149                  if (dp->nd != nv)
150                          objerror(m, USER, "dimension error");
151                  col[i] = datavalue(dp, pt);
152          }
153          errno = 0;
154          for (i = 0; i < 3; i++)
155 <                if (fundefined(m->oargs.sarg[i]) < 3)
155 >                if (i && fundefined(m->oargs.sarg[i]) < 3)
156                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
157                  else
158                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
# Line 173 | Line 193 | p_pdata(                       /* interpolate picture data */
193                  col[i] = datavalue(dp+i, pt);
194          errno = 0;
195          for (i = 0; i < 3; i++)
196 <                if (fundefined(m->oargs.sarg[i]) < 3)
196 >                if (i && fundefined(m->oargs.sarg[i]) < 3)
197                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
198                  else
199                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
# Line 210 | Line 230 | p_spectrum(                    /* simple constant spectrum */
230                          sinp[i] = (COLORV)m->oargs.farg[i+2];
231                  hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) /
232                                  (m->oargs.nfargs-3.0);
233 <                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
214 <                                sinp, m->oargs.nfargs-2,
233 >                convertscolorcol(scval, sinp, m->oargs.nfargs-2,
234                                  m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep);
235                  free(sinp);
236                  m->os = (void *)scval;
# Line 249 | Line 268 | p_specfile(                    /* constant spectrum from 1-D data file
268                          double  wl = dp->dim[0].org + i*step;
269                          sinp[i] = (COLORV)datavalue(dp, &wl);
270                  }
271 <                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
272 <                                sinp, dp->dim[0].ne, dp->dim[0].org-.5*step,
271 >                convertscolorcol(scval, sinp, dp->dim[0].ne,
272 >                                dp->dim[0].org-.5*step,
273                                  dp->dim[0].org+dp->dim[0].siz+.5*step);
274                  free(sinp);
275                  m->os = (void *)scval;
276          }
277          smultscolor(r->pcol, scval);
278 +        return(0);
279 + }
280 +
281 +
282 + int
283 + p_specdata(                     /* varied spectrum from (N+1)-D file */
284 +        OBJREC  *m,
285 +        RAY  *r
286 + )
287 + {
288 +        SCOLOR          scval;
289 +        COLORV          *scdat;
290 +        double          pt[MAXDDIM];
291 +        DATARRAY        *dp;
292 +        MFUNC           *mf;
293 +        double          step;
294 +        int             i;
295 +
296 +        if (m->oargs.nsargs < 4)
297 +                objerror(m, USER, "bad # arguments");
298 +        dp = getdata(m->oargs.sarg[1]);
299 +        if (dp->nd < 2)
300 +                objerror(m, USER, "need at least 2-dimensional data");
301 +        i = (1 << (dp->nd-1)) - 1;
302 +        mf = getfunc(m, 2, i<<3, 0);
303 +        setfunc(m, r);
304 +        errno = 0;
305 +        for (i = dp->nd-1; i-- > 0; ) {
306 +                pt[i] = evalue(mf->ep[i]);
307 +                if ((errno == EDOM) | (errno == ERANGE))
308 +                        goto computerr;
309 +        }
310 +        step = dp->dim[dp->nd-1].siz / (dp->dim[dp->nd-1].ne - 1.0);
311 +        scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[dp->nd-1].ne);
312 +        if (scdat == NULL)
313 +                objerror(m, SYSTEM, "out of memory");
314 +        for (i = dp->dim[dp->nd-1].ne; i-- > 0; ) {
315 +                double  bval[2];
316 +                pt[dp->nd-1] = dp->dim[dp->nd-1].org + i*step;
317 +                bval[0] = datavalue(dp, pt);
318 +                bval[1] = pt[dp->nd-1];
319 +                errno = 0;
320 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, bval);
321 +                if ((errno == EDOM) | (errno == ERANGE))
322 +                        goto computerr;
323 +        }
324 +        convertscolorcol(scval, 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 +        convertscolorcol(scval, scdat, dp->dim[2].ne,
371 +                        dp->dim[2].org-.5*step,
372 +                        dp->dim[2].org+dp->dim[2].siz+.5*step);
373 +        smultscolor(r->pcol, scval);
374 +        return(0);
375 + computerr:
376 +        objerror(m, WARNING, "compute error");
377          return(0);
378   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines