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