ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/mx_data.c
(Generate patch)

Comparing ray/src/rt/mx_data.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:08:29 1991 UTC vs.
Revision 2.6 by greg, Sat Feb 22 02:07:28 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1988 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  mx_data.c - routine for stored mixtures.
6 + */
7 +
8 + /* ====================================================================
9 + * The Radiance Software License, Version 1.0
10   *
11 < *     11/2/88
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   */
64  
65   #include  "ray.h"
66  
67   #include  "data.h"
68  
69 + #include  "func.h"
70 +
71   /*
72 < *      A stored mixture is specified:
72 > *  A stored mixture is specified:
73   *
74   *      modifier mixdata name
75   *      6+ foremod backmod func dfname vfname v0 v1 .. xf
76   *      0
77   *      n A1 A2 ..
78   *
79 + *  A picture mixture is specified as:
80 + *
81 + *      modifier mixpict name
82 + *      7+ foremod backmod func pfname vfname vx vy xf
83 + *      0
84 + *      n A1 A2 ..
85 + *
86 + *
87   *  Vfname is the name of the file where the variable definitions
88   *  can be found.  The list of real arguments can be accessed by
89   *  definitions in the file.  Dfname is the data file.
90 + *  (Pfname is a picture file.)
91   *  The dimensions of the data files and the number
92   *  of variables must match.  The func is a single argument
93 < *  function which returns the corrected data value given the
93 > *  function in the case of mixdata (three argument in the case
94 > *  of mixpict), which returns the corrected data value given the
95   *  interpolated value from the file.  The xf is a transformation
96   *  to get from the original coordinates to the current coordinates.
97   */
# Line 37 | Line 101 | mx_data(m, r)                  /* interpolate mixture data */
101   register OBJREC  *m;
102   RAY  *r;
103   {
104 <        extern double  varvalue(), funvalue(), datavalue();
41 <        extern int  errno;
42 <        register int  i;
104 >        OBJECT  obj;
105          double  coef;
106          double  pt[MAXDIM];
107          DATARRAY  *dp;
108          OBJECT  mod[2];
109 <        register char  **sa;
109 >        register MFUNC  *mf;
110 >        register int  i;
111  
49        setfunc(m, r);
50
51        sa = m->oargs.sarg;
52
112          if (m->oargs.nsargs < 6)
113                  objerror(m, USER, "bad # arguments");
114 +        obj = objndx(m);
115          for (i = 0; i < 2; i++)
116 <                if (!strcmp(sa[i], VOIDID))
116 >                if (!strcmp(m->oargs.sarg[i], VOIDID))
117                          mod[i] = OVOID;
118 <                else if ((mod[i] = modifier(sa[i])) == OVOID) {
119 <                        sprintf(errmsg, "undefined modifier \"%s\"", sa[i]);
118 >                else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
119 >                        sprintf(errmsg, "undefined modifier \"%s\"",
120 >                                        m->oargs.sarg[i]);
121                          objerror(m, USER, errmsg);
122                  }
123 <        funcfile(sa[4]);
124 <        for (i = 0; i+5 < m->oargs.nsargs &&
125 <                        sa[i+5][0] != '-'; i++) {
126 <                if (i >= MAXDIM)
127 <                        objerror(m, USER, "dimension error");
128 <                errno = 0;
129 <                pt[i] = varvalue(sa[i+5]);
123 >        dp = getdata(m->oargs.sarg[3]);
124 >        i = (1 << dp->nd) - 1;
125 >        mf = getfunc(m, 4, i<<5, 0);
126 >        setfunc(m, r);
127 >        errno = 0;
128 >        for (i = 0; i < dp->nd; i++) {
129 >                pt[i] = evalue(mf->ep[i]);
130                  if (errno)
131                          goto computerr;
132          }
72        dp = getdata(sa[3]);
73        if (dp->nd != i)
74                objerror(m, USER, "dimension error");
133          coef = datavalue(dp, pt);
134          errno = 0;
135 <        coef = funvalue(sa[2], 1, &coef);
135 >        coef = funvalue(m->oargs.sarg[2], 1, &coef);
136          if (errno)
137                  goto computerr;
138 <        raymixture(r, mod[0], mod[1], coef);
139 <        return;
138 >        if (raymixture(r, mod[0], mod[1], coef)) {
139 >                if (m->omod != OVOID)
140 >                        objerror(m, USER, "inappropriate modifier");
141 >                return(1);
142 >        }
143 >        return(0);
144 > computerr:
145 >        objerror(m, WARNING, "compute error");
146 >        return(0);
147 > }
148  
149 +
150 + mx_pdata(m, r)                  /* interpolate mixture picture */
151 + register OBJREC  *m;
152 + RAY  *r;
153 + {
154 +        OBJECT  obj;
155 +        double  col[3], coef;
156 +        double  pt[MAXDIM];
157 +        DATARRAY  *dp;
158 +        OBJECT  mod[2];
159 +        register MFUNC  *mf;
160 +        register int  i;
161 +
162 +        if (m->oargs.nsargs < 7)
163 +                objerror(m, USER, "bad # arguments");
164 +        obj = objndx(m);
165 +        for (i = 0; i < 2; i++)
166 +                if (!strcmp(m->oargs.sarg[i], VOIDID))
167 +                        mod[i] = OVOID;
168 +                else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
169 +                        sprintf(errmsg, "undefined modifier \"%s\"",
170 +                                        m->oargs.sarg[i]);
171 +                        objerror(m, USER, errmsg);
172 +                }
173 +        dp = getpict(m->oargs.sarg[3]);
174 +        mf = getfunc(m, 4, 0x3<<5, 0);
175 +        setfunc(m, r);
176 +        errno = 0;
177 +        pt[1] = evalue(mf->ep[0]);      /* y major ordering */
178 +        pt[0] = evalue(mf->ep[1]);
179 +        if (errno)
180 +                goto computerr;
181 +        for (i = 0; i < 3; i++)         /* get pixel from picture */
182 +                col[i] = datavalue(dp+i, pt);
183 +        errno = 0;                      /* evaluate function on pixel */
184 +        coef = funvalue(m->oargs.sarg[2], 3, col);
185 +        if (errno)
186 +                goto computerr;
187 +        if (raymixture(r, mod[0], mod[1], coef)) {
188 +                if (m->omod != OVOID)
189 +                        objerror(m, USER, "inappropriate modifier");
190 +                return(1);
191 +        }
192 +        return(0);
193   computerr:
194          objerror(m, WARNING, "compute error");
195 +        return(0);
196   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines