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

Comparing ray/src/rt/p_func.c (file contents):
Revision 2.4 by greg, Sat Feb 22 02:07:29 2003 UTC vs.
Revision 2.9 by greg, Wed Nov 15 18:02:53 2023 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  p_func.c - routine for procedural 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  "func.h"
12 + #include  "rtotypes.h"
13  
14   /*
15   *      A procedural pattern can either be a brightness or a
# Line 82 | Line 27 | static const char      RCSid[] = "$Id$";
27   *      0
28   *      n A1 A2 ..
29   *
30 + *  A spectral function is given as:
31 + *
32 + *      modifier specfunc name
33 + *      2+ sval filename xf
34 + *      0
35 + *      2+ nmA nmB A3 ..
36 + *
37   *  Filename is the name of the file where the variable definitions
38   *  can be found.  The list of real arguments can be accessed by
39   *  definitions in the file.  The xf is a transformation
40   *  to get from the original coordinates to the current coordinates.
41 + *  For the "specfunc" primitive, sval(nm) is a function of wavelength
42 + *  and must be defined from nmA to nmB, and should average to 1 over
43 + *  its range.
44   */
45  
46  
47 < p_bfunc(m, r)                   /* compute brightness pattern */
48 < OBJREC  *m;
49 < RAY  *r;
47 > int
48 > p_bfunc(                        /* compute brightness pattern */
49 >        OBJREC  *m,
50 >        RAY  *r
51 > )
52   {
53          double  bval;
54 <        register MFUNC  *mf;
54 >        MFUNC  *mf;
55  
56          if (m->oargs.nsargs < 2)
57                  objerror(m, USER, "bad # arguments");
# Line 102 | Line 59 | RAY  *r;
59          setfunc(m, r);
60          errno = 0;
61          bval = evalue(mf->ep[0]);
62 <        if (errno) {
62 >        if ((errno == EDOM) | (errno == ERANGE)) {
63                  objerror(m, WARNING, "compute error");
64                  return(0);
65          }
66 <        scalecolor(r->pcol, bval);
66 >        scalescolor(r->pcol, bval);
67          return(0);
68   }
69  
70  
71 < p_cfunc(m, r)                   /* compute color pattern */
72 < OBJREC  *m;
73 < RAY  *r;
71 > int
72 > p_cfunc(                        /* compute color pattern */
73 >        OBJREC  *m,
74 >        RAY  *r
75 > )
76   {
77 <        COLOR  cval;
78 <        register MFUNC  *mf;
77 >        SCOLOR  scval;
78 >        MFUNC  *mf;
79  
80          if (m->oargs.nsargs < 4)
81                  objerror(m, USER, "bad # arguments");
82          mf = getfunc(m, 3, 0x7, 0);
83          setfunc(m, r);
84          errno = 0;
85 <        setcolor(cval, evalue(mf->ep[0]),
85 >        setscolor(scval, evalue(mf->ep[0]),
86                          evalue(mf->ep[1]),
87                          evalue(mf->ep[2]));
88 <        if (errno) {
88 >        if ((errno == EDOM) | (errno == ERANGE)) {
89                  objerror(m, WARNING, "compute error");
90                  return(0);
91          }
92 <        multcolor(r->pcol, cval);
92 >        smultscolor(r->pcol, scval);
93 >        return(0);
94 > }
95 >
96 >
97 > int
98 > p_specfunc(                     /* compute spectral pattern */
99 >        OBJREC  *m,
100 >        RAY  *r
101 > )
102 > {
103 >        SCOLOR  scsamp;
104 >        SCOLOR  scval;
105 >        double  wl, wlmin, wlmax, wlstep;
106 >        int     ns, i;
107 >        MFUNC   *mf;
108 >
109 >        if ((m->oargs.nsargs < 2) | (m->oargs.nfargs < 2))
110 >                objerror(m, USER, "bad # arguments");
111 >        if (m->oargs.farg[0] < m->oargs.farg[1]) {
112 >                wlmin = m->oargs.farg[0];
113 >                wlmax = m->oargs.farg[1];
114 >        } else {
115 >                wlmin = m->oargs.farg[1];
116 >                wlmax = m->oargs.farg[0];
117 >        }
118 >        if (wlmin < WLPART[3]) wlmin = WLPART[3];
119 >        if (wlmax > WLPART[0]) wlmax = WLPART[0];
120 >        if (wlmin >= wlmax) {
121 >                objerror(m, WARNING, "incompatible wavelength sampling");
122 >                return(0);
123 >        }
124 >        wlstep = (wlmax - wlmin)/(double)MAXCSAMP;
125 >        if (wlstep*(5.*NCSAMP) < WLPART[0] - WLPART[3])
126 >                wlstep = (WLPART[0] - WLPART[3])/(5.*NCSAMP);
127 >        mf = getfunc(m, 1, 0, 0);
128 >        setfunc(m, r);
129 >        errno = 0;
130 >        ns = (wlmax - wlmin)/wlstep + .1;
131 >        wl = wlmax - .5*wlstep;
132 >        for (i = ns; i-- > 0; wl -= wlstep) {
133 >                scsamp[i] = funvalue(m->oargs.sarg[0], 1, &wl);
134 >                if ((errno == EDOM) | (errno == ERANGE)) {
135 >                        objerror(m, WARNING, "compute error");
136 >                        return(0);
137 >                }
138 >        }
139 >        convertscolor(scval, NCSAMP, WLPART[0], WLPART[3],
140 >                        scsamp, ns, wlmin, wlmax);
141 >        smultscolor(r->pcol, scval);
142          return(0);
143   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines