ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/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.16 by greg, Wed Dec 17 00:45:55 2025 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 232 | Line 251 | p_specfile(                    /* constant spectrum from 1-D data file
251          if ((scval = (COLORV *)m->os) == NULL) {
252                  DATARRAY        *dp;
253                  COLORV          *sinp;
254 +                int             n;
255                  double          step;
236                int             i;
256                  if (m->oargs.nsargs != 1)
257                          objerror(m, USER, "bad # arguments");
258                  dp = getdata(m->oargs.sarg[0]);
259                  if (dp->nd != 1)
260                          objerror(m, USER, "data file must be 1-dimensional");
261  
262 <                sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
262 >                n = (dp->dim[0].p == NULL) ? dp->dim[0].ne : 2*dp->dim[0].ne;
263 >                sinp = (COLORV *)malloc(sizeof(COLORV)*n);
264                  scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
265                  if ((sinp == NULL) | (scval == NULL))
266                          objerror(m, SYSTEM, "out of memory");
267 <                step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
268 <                for (i = dp->dim[0].ne; i-- > 0; ) {
269 <                        double  wl = dp->dim[0].org + i*step;
270 <                        sinp[i] = (COLORV)datavalue(dp, &wl);
267 >                step = dp->dim[0].siz / (n - 1.0);
268 >                while (n--) {
269 >                        double  wl = dp->dim[0].org + n*step;
270 >                        sinp[n] = (COLORV)datavalue(dp, &wl);
271                  }
272 <                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
273 <                                sinp, dp->dim[0].ne, dp->dim[0].org-.5*step,
272 >                convertscolorcol(scval, sinp, dp->dim[0].ne,
273 >                                dp->dim[0].org-.5*step,
274                                  dp->dim[0].org+dp->dim[0].siz+.5*step);
275                  free(sinp);
276                  m->os = (void *)scval;
277          }
278          smultscolor(r->pcol, scval);
279 +        return(0);
280 + }
281 +
282 +
283 + int
284 + p_specdata(                     /* varied spectrum from (N+1)-D file */
285 +        OBJREC  *m,
286 +        RAY  *r
287 + )
288 + {
289 +        SCOLOR          scval;
290 +        COLORV          *scdat;
291 +        double          pt[MAXDDIM];
292 +        DATARRAY        *dp;
293 +        MFUNC           *mf;
294 +        double          step;
295 +        int             i;
296 +
297 +        if (m->oargs.nsargs < 4)
298 +                objerror(m, USER, "bad # arguments");
299 +        dp = getdata(m->oargs.sarg[1]);
300 +        if (dp->nd < 2)
301 +                objerror(m, USER, "need at least 2-dimensional data");
302 +        i = (1 << (dp->nd-1)) - 1;
303 +        mf = getfunc(m, 2, i<<3, 0);
304 +        setfunc(m, r);
305 +        errno = 0;
306 +        for (i = dp->nd-1; i-- > 0; ) {
307 +                pt[i] = evalue(mf->ep[i]);
308 +                if ((errno == EDOM) | (errno == ERANGE))
309 +                        goto computerr;
310 +        }
311 +        dp = datavector(dp, pt);        /* interpolate spectrum */
312 +        step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
313 +        scdat = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
314 +        if (scdat == NULL)
315 +                objerror(m, SYSTEM, "out of memory");
316 +        for (i = dp->dim[0].ne; i-- > 0; ) {
317 +                pt[1] = dp->dim[0].org + i*step;
318 +                pt[0] = datavalue(dp, pt+1);
319 +                errno = 0;
320 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, pt);
321 +                if ((errno == EDOM) | (errno == ERANGE))
322 +                        goto computerr;
323 +        }
324 +        convertscolorcol(scval, scdat, dp->dim[0].ne,
325 +                        dp->dim[0].org-.5*step,
326 +                        dp->dim[0].org+dp->dim[0].siz+.5*step);
327 +        free(scdat);
328 +        free(dp);
329 +        smultscolor(r->pcol, scval);
330 +        return(0);
331 + computerr:
332 +        objerror(m, WARNING, "compute error");
333 +        return(0);
334 + }
335 +
336 +
337 + int
338 + p_specpict(                     /* interpolate hyperspectral image data */
339 +        OBJREC  *m,
340 +        RAY  *r
341 + )
342 + {
343 +        SCOLOR          scdat, scval;
344 +        double          pt[2];
345 +        DATARRAY        *dp;
346 +        MFUNC           *mf;
347 +        double          step;
348 +        int             i;
349 +
350 +        if (m->oargs.nsargs < 5)
351 +                objerror(m, USER, "bad # arguments");
352 +        mf = getfunc(m, 2, 0x3<<3, 0);
353 +        setfunc(m, r);
354 +        errno = 0;
355 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
356 +        pt[0] = evalue(mf->ep[1]);
357 +        if ((errno == EDOM) | (errno == ERANGE))
358 +                goto computerr;
359 +                                        /* interpolate spectrum */
360 +        dp = datavector(getspec(m->oargs.sarg[1]), pt);
361 +        step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
362 +        for (i = dp->dim[0].ne; i-- > 0; ) {
363 +                pt[1] = dp->dim[0].org + i*step;
364 +                pt[0] = dp->arr.d[i];   /* datavalue(dp, pt+1); */
365 +                errno = 0;
366 +                scdat[i] = funvalue(m->oargs.sarg[0], 2, pt);
367 +                if ((errno == EDOM) | (errno == ERANGE))
368 +                        goto computerr;
369 +        }
370 +        convertscolorcol(scval, scdat, dp->dim[0].ne,
371 +                        dp->dim[0].org-.5*step,
372 +                        dp->dim[0].org+dp->dim[0].siz+.5*step);
373 +        free(dp);
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 (old)
> Changed lines (new)