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.9 by greg, Tue Jul 8 18:25:00 2014 UTC vs.
Revision 2.10 by greg, Wed Nov 15 18:02:53 2023 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   *  Vfname is the name of the file where the variable definitions
53   *  can be found.  The list of real arguments can be accessed by
54   *  definitions in the file.  The dfnames are the data file
55   *  names.  The dimensions of the data files and the number
56   *  of variables must match.  The funcs take a single argument
57   *  for brightdata, and three for colordata and colorpict to produce
58 < *  interpolated values from the file.  The xf is a transformation
58 > *  interpolated values from the file.  The xf is a transform spec
59   *  to get from the original coordinates to the current coordinates.
60   */
61  
# Line 53 | Line 67 | p_bdata(                       /* interpolate brightness data */
67   )
68   {
69          double  bval;
70 <        double  pt[MAXDIM];
70 >        double  pt[MAXDDIM];
71          DATARRAY  *dp;
72          MFUNC  *mf;
73          int  i;
# Line 67 | Line 81 | p_bdata(                       /* interpolate brightness data */
81          errno = 0;
82          for (i = dp->nd; i-- > 0; ) {
83                  pt[i] = evalue(mf->ep[i]);
84 <                if (errno == EDOM || errno == ERANGE)
84 >                if ((errno == EDOM) | (errno == ERANGE))
85                          goto computerr;
86          }
87          bval = datavalue(dp, pt);
88          errno = 0;
89          bval = funvalue(m->oargs.sarg[0], 1, &bval);
90 <        if (errno == EDOM || errno == ERANGE)
90 >        if ((errno == EDOM) | (errno == ERANGE))
91                  goto computerr;
92 <        scalecolor(r->pcol, bval);
92 >        scalescolor(r->pcol, bval);
93          return(0);
94   computerr:
95          objerror(m, WARNING, "compute error");
# Line 91 | Line 105 | p_cdata(                       /* interpolate color data */
105   {
106          double  col[3];
107          COLOR  cval;
108 <        double  pt[MAXDIM];
108 >        double  pt[MAXDDIM];
109          int  nv;
110          DATARRAY  *dp;
111          MFUNC  *mf;
# Line 106 | Line 120 | p_cdata(                       /* interpolate color data */
120          errno = 0;
121          for (i = 0; i < nv; i++) {
122                  pt[i] = evalue(mf->ep[i]);
123 <                if (errno == EDOM || errno == ERANGE)
123 >                if ((errno == EDOM) | (errno == ERANGE))
124                          goto computerr;
125          }
126          col[0] = datavalue(dp, pt);
# Line 122 | Line 136 | p_cdata(                       /* interpolate color data */
136                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
137                  else
138                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
139 <        if (errno == EDOM || errno == ERANGE)
139 >        if ((errno == EDOM) | (errno == ERANGE))
140                  goto computerr;
141 <        multcolor(r->pcol, cval);
141 >        smultcolor(r->pcol, cval);
142          return(0);
143   computerr:
144          objerror(m, WARNING, "compute error");
# Line 152 | Line 166 | p_pdata(                       /* interpolate picture data */
166          errno = 0;
167          pt[1] = evalue(mf->ep[0]);      /* y major ordering */
168          pt[0] = evalue(mf->ep[1]);
169 <        if (errno == EDOM || errno == ERANGE)
169 >        if ((errno == EDOM) | (errno == ERANGE))
170                  goto computerr;
171          dp = getpict(m->oargs.sarg[3]);
172          for (i = 0; i < 3; i++)
# Line 163 | Line 177 | p_pdata(                       /* interpolate picture data */
177                          colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
178                  else
179                          colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
180 <        if (errno == EDOM || errno == ERANGE)
180 >        if ((errno == EDOM) | (errno == ERANGE))
181                  goto computerr;
182 <        multcolor(r->pcol, cval);
182 >        smultcolor(r->pcol, cval);
183          return(0);
184  
185   computerr:
186          objerror(m, WARNING, "compute error");
187 +        return(0);
188 + }
189 +
190 +
191 + int
192 + p_spectrum(                     /* simple constant spectrum */
193 +        OBJREC  *m,
194 +        RAY  *r
195 + )
196 + {
197 +        COLORV  *scval;
198 +
199 +        if ((scval = (COLORV *)m->os) == NULL) {
200 +                COLORV  *sinp;
201 +                double  hstep;
202 +                int     i;
203 +                if (m->oargs.nfargs < 5)
204 +                        objerror(m, USER, "bad # arguments");
205 +                sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2));
206 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
207 +                if ((sinp == NULL) | (scval == NULL))
208 +                        objerror(m, SYSTEM, "out of memory");
209 +                for (i = m->oargs.nfargs-2; i--; )
210 +                        sinp[i] = (COLORV)m->oargs.farg[i+2];
211 +                hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) /
212 +                                (m->oargs.nfargs-3.0);
213 +                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
214 +                                sinp, m->oargs.nfargs-2,
215 +                                m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep);
216 +                free(sinp);
217 +                m->os = (void *)scval;
218 +        }
219 +        smultscolor(r->pcol, scval);
220 +        return(0);
221 + }
222 +
223 +
224 + int
225 + p_specfile(                     /* constant spectrum from 1-D data file */
226 +        OBJREC  *m,
227 +        RAY  *r
228 + )
229 + {
230 +        COLORV  *scval;
231 +
232 +        if ((scval = (COLORV *)m->os) == NULL) {
233 +                DATARRAY        *dp;
234 +                COLORV          *sinp;
235 +                double          step;
236 +                int             i;
237 +                if (m->oargs.nsargs != 1)
238 +                        objerror(m, USER, "bad # arguments");
239 +                dp = getdata(m->oargs.sarg[0]);
240 +                if (dp->nd != 1)
241 +                        objerror(m, USER, "data file must be 1-dimensional");
242 +
243 +                sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
244 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
245 +                if ((sinp == NULL) | (scval == NULL))
246 +                        objerror(m, SYSTEM, "out of memory");
247 +                step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
248 +                for (i = dp->dim[0].ne; i-- > 0; ) {
249 +                        double  wl = dp->dim[0].org + i*step;
250 +                        sinp[i] = (COLORV)datavalue(dp, &wl);
251 +                }
252 +                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
253 +                                sinp, dp->dim[0].ne, dp->dim[0].org-.5*step,
254 +                                dp->dim[0].org+dp->dim[0].siz+.5*step);
255 +                free(sinp);
256 +                m->os = (void *)scval;
257 +        }
258 +        smultscolor(r->pcol, scval);
259          return(0);
260   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines