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.10 by greg, Wed Nov 15 18:02:53 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   *  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  
62  
63 < p_bdata(m, r)                   /* interpolate brightness data */
64 < register OBJREC  *m;
65 < RAY  *r;
63 > int
64 > p_bdata(                        /* interpolate brightness data */
65 >        OBJREC  *m,
66 >        RAY  *r
67 > )
68   {
69          double  bval;
70 <        double  pt[MAXDIM];
70 >        double  pt[MAXDDIM];
71          DATARRAY  *dp;
72 <        register MFUNC  *mf;
73 <        register int  i;
72 >        MFUNC  *mf;
73 >        int  i;
74  
75          if (m->oargs.nsargs < 4)
76                  objerror(m, USER, "bad # arguments");
# Line 121 | Line 81 | RAY  *r;
81          errno = 0;
82          for (i = dp->nd; i-- > 0; ) {
83                  pt[i] = evalue(mf->ep[i]);
84 <                if (errno)
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)
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 137 | Line 97 | computerr:
97   }
98  
99  
100 < p_cdata(m, r)                   /* interpolate color data */
101 < register OBJREC  *m;
102 < RAY  *r;
100 > int
101 > p_cdata(                        /* interpolate color data */
102 >        OBJREC  *m,
103 >        RAY  *r
104 > )
105   {
106          double  col[3];
107          COLOR  cval;
108 <        double  pt[MAXDIM];
108 >        double  pt[MAXDDIM];
109          int  nv;
110          DATARRAY  *dp;
111 <        register MFUNC  *mf;
112 <        register int  i;
111 >        MFUNC  *mf;
112 >        int  i;
113  
114          if (m->oargs.nsargs < 8)
115                  objerror(m, USER, "bad # arguments");
# Line 158 | Line 120 | RAY  *r;
120          errno = 0;
121          for (i = 0; i < nv; i++) {
122                  pt[i] = evalue(mf->ep[i]);
123 <                if (errno)
123 >                if ((errno == EDOM) | (errno == ERANGE))
124                          goto computerr;
125          }
126          col[0] = datavalue(dp, pt);
# Line 174 | Line 136 | RAY  *r;
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)
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 184 | Line 146 | computerr:
146   }
147  
148  
149 < p_pdata(m, r)                   /* interpolate picture data */
150 < register OBJREC  *m;
151 < RAY  *r;
149 > int
150 > p_pdata(                        /* interpolate picture data */
151 >        OBJREC  *m,
152 >        RAY  *r
153 > )
154   {
155          double  col[3];
156          COLOR  cval;
157          double  pt[2];
158          DATARRAY  *dp;
159 <        register MFUNC  *mf;
160 <        register int  i;
159 >        MFUNC  *mf;
160 >        int  i;
161  
162          if (m->oargs.nsargs < 7)
163                  objerror(m, USER, "bad # arguments");
# Line 202 | Line 166 | RAY  *r;
166          errno = 0;
167          pt[1] = evalue(mf->ep[0]);      /* y major ordering */
168          pt[0] = evalue(mf->ep[1]);
169 <        if (errno)
169 >        if ((errno == EDOM) | (errno == ERANGE))
170                  goto computerr;
171          dp = getpict(m->oargs.sarg[3]);
172          for (i = 0; i < 3; i++)
# Line 213 | Line 177 | RAY  *r;
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)
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