1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.9 |
static const char RCSid[] = "$Id: p_func.c,v 2.8 2014/07/08 18:25:00 greg Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* p_func.c - routine for procedural patterns. |
6 |
greg |
2.4 |
*/ |
7 |
|
|
|
8 |
greg |
2.5 |
#include "copyright.h" |
9 |
greg |
1.1 |
|
10 |
|
|
#include "ray.h" |
11 |
greg |
2.2 |
#include "func.h" |
12 |
schorsch |
2.7 |
#include "rtotypes.h" |
13 |
greg |
2.2 |
|
14 |
greg |
1.1 |
/* |
15 |
|
|
* A procedural pattern can either be a brightness or a |
16 |
|
|
* color function. A brightness function is given as: |
17 |
|
|
* |
18 |
|
|
* modifier brightfunc name |
19 |
|
|
* 2+ bvarname filename xf |
20 |
|
|
* 0 |
21 |
|
|
* n A1 A2 .. |
22 |
|
|
* |
23 |
|
|
* A color function is given as: |
24 |
|
|
* |
25 |
|
|
* modifier colorfunc name |
26 |
|
|
* 4+ rvarname gvarname bvarname filename xf |
27 |
|
|
* 0 |
28 |
|
|
* n A1 A2 .. |
29 |
|
|
* |
30 |
greg |
2.9 |
* 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 |
greg |
1.1 |
* 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 |
greg |
2.9 |
* 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 |
greg |
1.1 |
*/ |
45 |
|
|
|
46 |
|
|
|
47 |
greg |
2.8 |
int |
48 |
schorsch |
2.7 |
p_bfunc( /* compute brightness pattern */ |
49 |
|
|
OBJREC *m, |
50 |
|
|
RAY *r |
51 |
|
|
) |
52 |
greg |
1.1 |
{ |
53 |
|
|
double bval; |
54 |
greg |
2.8 |
MFUNC *mf; |
55 |
greg |
1.1 |
|
56 |
|
|
if (m->oargs.nsargs < 2) |
57 |
|
|
objerror(m, USER, "bad # arguments"); |
58 |
greg |
2.2 |
mf = getfunc(m, 1, 0x1, 0); |
59 |
|
|
setfunc(m, r); |
60 |
greg |
1.1 |
errno = 0; |
61 |
greg |
2.2 |
bval = evalue(mf->ep[0]); |
62 |
greg |
2.9 |
if ((errno == EDOM) | (errno == ERANGE)) { |
63 |
greg |
1.1 |
objerror(m, WARNING, "compute error"); |
64 |
greg |
2.3 |
return(0); |
65 |
greg |
1.1 |
} |
66 |
greg |
2.9 |
scalescolor(r->pcol, bval); |
67 |
greg |
2.3 |
return(0); |
68 |
greg |
1.1 |
} |
69 |
|
|
|
70 |
|
|
|
71 |
greg |
2.8 |
int |
72 |
schorsch |
2.7 |
p_cfunc( /* compute color pattern */ |
73 |
|
|
OBJREC *m, |
74 |
|
|
RAY *r |
75 |
|
|
) |
76 |
greg |
1.1 |
{ |
77 |
greg |
2.9 |
SCOLOR scval; |
78 |
greg |
2.8 |
MFUNC *mf; |
79 |
greg |
1.1 |
|
80 |
|
|
if (m->oargs.nsargs < 4) |
81 |
|
|
objerror(m, USER, "bad # arguments"); |
82 |
greg |
2.2 |
mf = getfunc(m, 3, 0x7, 0); |
83 |
|
|
setfunc(m, r); |
84 |
greg |
1.1 |
errno = 0; |
85 |
greg |
2.9 |
setscolor(scval, evalue(mf->ep[0]), |
86 |
greg |
2.2 |
evalue(mf->ep[1]), |
87 |
|
|
evalue(mf->ep[2])); |
88 |
greg |
2.9 |
if ((errno == EDOM) | (errno == ERANGE)) { |
89 |
greg |
1.1 |
objerror(m, WARNING, "compute error"); |
90 |
greg |
2.3 |
return(0); |
91 |
greg |
1.1 |
} |
92 |
greg |
2.9 |
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 |
greg |
2.3 |
return(0); |
143 |
greg |
1.1 |
} |