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.5 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.11 by greg, Wed Dec 13 23:26:16 2023 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  p_data.c - routine for stored patterns.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10   #include  "ray.h"
66
11   #include  "data.h"
68
12   #include  "func.h"
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 91 | 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 + *  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 transformation
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  
79 < p_bdata(m, r)                   /* interpolate brightness data */
80 < register OBJREC  *m;
81 < RAY  *r;
79 > int
80 > p_bdata(                        /* interpolate brightness data */
81 >        OBJREC  *m,
82 >        RAY  *r
83 > )
84   {
85          double  bval;
86 <        double  pt[MAXDIM];
86 >        double  pt[MAXDDIM];
87          DATARRAY  *dp;
88 <        register MFUNC  *mf;
89 <        register int  i;
88 >        MFUNC  *mf;
89 >        int  i;
90  
91          if (m->oargs.nsargs < 4)
92                  objerror(m, USER, "bad # arguments");
# Line 121 | Line 97 | RAY  *r;
97          errno = 0;
98          for (i = dp->nd; i-- > 0; ) {
99                  pt[i] = evalue(mf->ep[i]);
100 <                if (errno)
100 >                if ((errno == EDOM) | (errno == ERANGE))
101                          goto computerr;
102          }
103          bval = datavalue(dp, pt);
104          errno = 0;
105          bval = funvalue(m->oargs.sarg[0], 1, &bval);
106 <        if (errno)
106 >        if ((errno == EDOM) | (errno == ERANGE))
107                  goto computerr;
108 <        scalecolor(r->pcol, bval);
108 >        scalescolor(r->pcol, bval);
109          return(0);
110   computerr:
111          objerror(m, WARNING, "compute error");
# Line 137 | Line 113 | computerr:
113   }
114  
115  
116 < p_cdata(m, r)                   /* interpolate color data */
117 < register OBJREC  *m;
118 < RAY  *r;
116 > int
117 > p_cdata(                        /* interpolate color data */
118 >        OBJREC  *m,
119 >        RAY  *r
120 > )
121   {
122          double  col[3];
123          COLOR  cval;
124 <        double  pt[MAXDIM];
124 >        double  pt[MAXDDIM];
125          int  nv;
126          DATARRAY  *dp;
127 <        register MFUNC  *mf;
128 <        register int  i;
127 >        MFUNC  *mf;
128 >        int  i;
129  
130          if (m->oargs.nsargs < 8)
131                  objerror(m, USER, "bad # arguments");
# Line 158 | Line 136 | RAY  *r;
136          errno = 0;
137          for (i = 0; i < nv; i++) {
138                  pt[i] = evalue(mf->ep[i]);
139 <                if (errno)
139 >                if ((errno == EDOM) | (errno == ERANGE))
140                          goto computerr;
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);
155 <        if (errno)
155 >        if ((errno == EDOM) | (errno == ERANGE))
156                  goto computerr;
157 <        multcolor(r->pcol, cval);
157 >        smultcolor(r->pcol, cval);
158          return(0);
159   computerr:
160          objerror(m, WARNING, "compute error");
# Line 184 | Line 162 | computerr:
162   }
163  
164  
165 < p_pdata(m, r)                   /* interpolate picture data */
166 < register OBJREC  *m;
167 < RAY  *r;
165 > int
166 > p_pdata(                        /* interpolate picture data */
167 >        OBJREC  *m,
168 >        RAY  *r
169 > )
170   {
171          double  col[3];
172          COLOR  cval;
173          double  pt[2];
174          DATARRAY  *dp;
175 <        register MFUNC  *mf;
176 <        register int  i;
175 >        MFUNC  *mf;
176 >        int  i;
177  
178          if (m->oargs.nsargs < 7)
179                  objerror(m, USER, "bad # arguments");
# Line 202 | Line 182 | RAY  *r;
182          errno = 0;
183          pt[1] = evalue(mf->ep[0]);      /* y major ordering */
184          pt[0] = evalue(mf->ep[1]);
185 <        if (errno)
185 >        if ((errno == EDOM) | (errno == ERANGE))
186                  goto computerr;
187          dp = getpict(m->oargs.sarg[3]);
188          for (i = 0; i < 3; i++)
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);
196 <        if (errno)
196 >        if ((errno == EDOM) | (errno == ERANGE))
197                  goto computerr;
198 <        multcolor(r->pcol, cval);
198 >        smultcolor(r->pcol, cval);
199          return(0);
200  
201 + computerr:
202 +        objerror(m, WARNING, "compute error");
203 +        return(0);
204 + }
205 +
206 +
207 + int
208 + p_spectrum(                     /* simple constant spectrum */
209 +        OBJREC  *m,
210 +        RAY  *r
211 + )
212 + {
213 +        COLORV  *scval;
214 +
215 +        if ((scval = (COLORV *)m->os) == NULL) {
216 +                COLORV  *sinp;
217 +                double  hstep;
218 +                int     i;
219 +                if (m->oargs.nfargs < 5)
220 +                        objerror(m, USER, "bad # arguments");
221 +                sinp = (COLORV *)malloc(sizeof(COLORV)*(m->oargs.nfargs-2));
222 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
223 +                if ((sinp == NULL) | (scval == NULL))
224 +                        objerror(m, SYSTEM, "out of memory");
225 +                for (i = m->oargs.nfargs-2; i--; )
226 +                        sinp[i] = (COLORV)m->oargs.farg[i+2];
227 +                hstep = 0.5 * (m->oargs.farg[1] - m->oargs.farg[0]) /
228 +                                (m->oargs.nfargs-3.0);
229 +                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
230 +                                sinp, m->oargs.nfargs-2,
231 +                                m->oargs.farg[0]-hstep, m->oargs.farg[1]+hstep);
232 +                free(sinp);
233 +                m->os = (void *)scval;
234 +        }
235 +        smultscolor(r->pcol, scval);
236 +        return(0);
237 + }
238 +
239 +
240 + int
241 + p_specfile(                     /* constant spectrum from 1-D data file */
242 +        OBJREC  *m,
243 +        RAY  *r
244 + )
245 + {
246 +        COLORV  *scval;
247 +
248 +        if ((scval = (COLORV *)m->os) == NULL) {
249 +                DATARRAY        *dp;
250 +                COLORV          *sinp;
251 +                double          step;
252 +                int             i;
253 +                if (m->oargs.nsargs != 1)
254 +                        objerror(m, USER, "bad # arguments");
255 +                dp = getdata(m->oargs.sarg[0]);
256 +                if (dp->nd != 1)
257 +                        objerror(m, USER, "data file must be 1-dimensional");
258 +
259 +                sinp = (COLORV *)malloc(sizeof(COLORV)*dp->dim[0].ne);
260 +                scval = (COLORV *)malloc(sizeof(COLORV)*NCSAMP);
261 +                if ((sinp == NULL) | (scval == NULL))
262 +                        objerror(m, SYSTEM, "out of memory");
263 +                step = dp->dim[0].siz / (dp->dim[0].ne - 1.0);
264 +                for (i = dp->dim[0].ne; i-- > 0; ) {
265 +                        double  wl = dp->dim[0].org + i*step;
266 +                        sinp[i] = (COLORV)datavalue(dp, &wl);
267 +                }
268 +                convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
269 +                                sinp, dp->dim[0].ne, dp->dim[0].org-.5*step,
270 +                                dp->dim[0].org+dp->dim[0].siz+.5*step);
271 +                free(sinp);
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);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines