1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
15 |
|
#include "otypes.h" |
16 |
|
|
17 |
|
|
18 |
+ |
XF unitxf = { /* identity transform */ |
19 |
+ |
1.0, 0.0, 0.0, 0.0, |
20 |
+ |
0.0, 1.0, 0.0, 0.0, |
21 |
+ |
0.0, 0.0, 1.0, 0.0, |
22 |
+ |
0.0, 0.0, 0.0, 1.0, |
23 |
+ |
1.0 |
24 |
+ |
}; |
25 |
+ |
|
26 |
|
XF funcxf; /* current transformation */ |
27 |
|
static OBJREC *fobj = NULL; /* current function object */ |
28 |
|
static RAY *fray = NULL; /* current function ray */ |
33 |
|
register RAY *r; |
34 |
|
XF *bx; |
35 |
|
{ |
36 |
< |
extern double l_noise3(), l_noise3a(), l_noise3b(), l_noise3c(); |
29 |
< |
extern double l_hermite(), l_fnoise3(), l_arg(); |
36 |
> |
extern double l_arg(), l_erf(), l_erfc(); |
37 |
|
extern long eclock; |
38 |
|
static char *initfile = "rayinit.cal"; |
39 |
|
static long lastrno = -1; |
40 |
|
/* check to see if already set */ |
41 |
|
if (m == fobj && r->rno == lastrno) |
42 |
< |
return; |
42 |
> |
return(0); |
43 |
|
/* initialize if first call */ |
44 |
|
if (initfile != NULL) { |
38 |
– |
loadfunc(initfile); |
45 |
|
scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0); |
46 |
|
scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0); |
47 |
|
scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0); |
50 |
|
scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0); |
51 |
|
scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0); |
52 |
|
scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0); |
53 |
< |
funset("arg", 1, l_arg); |
54 |
< |
funset("noise3", 3, l_noise3); |
55 |
< |
funset("noise3a", 3, l_noise3a); |
56 |
< |
funset("noise3b", 3, l_noise3b); |
57 |
< |
funset("noise3c", 3, l_noise3c); |
52 |
< |
funset("hermite", 5, l_hermite); |
53 |
< |
funset("fnoise3", 3, l_fnoise3); |
53 |
> |
funset("arg", 1, '=', l_arg); |
54 |
> |
funset("erf", 1, ':', l_erf); |
55 |
> |
funset("erfc", 1, ':', l_erfc); |
56 |
> |
setnoisefuncs(); |
57 |
> |
loadfunc(initfile); |
58 |
|
initfile = NULL; |
59 |
|
} |
60 |
|
fobj = m; |
61 |
|
fray = r; |
62 |
< |
lastrno = r->rno; |
63 |
< |
if (r->rox != NULL) { |
64 |
< |
funcxf.sca = r->rox->b.sca * bx->sca; |
65 |
< |
multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm); |
66 |
< |
} else |
62 |
> |
if (r->rox != NULL) |
63 |
> |
if (bx != &unitxf) { |
64 |
> |
funcxf.sca = r->rox->b.sca * bx->sca; |
65 |
> |
multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm); |
66 |
> |
} else |
67 |
> |
copystruct(&funcxf, &r->rox->b); |
68 |
> |
else |
69 |
|
copystruct(&funcxf, bx); |
70 |
+ |
lastrno = r->rno; |
71 |
|
eclock++; /* notify expression evaluator */ |
72 |
+ |
return(1); |
73 |
|
} |
74 |
|
|
75 |
|
|
86 |
|
for (n = m->oargs.nsargs, sa = m->oargs.sarg; |
87 |
|
n > 0 && **sa != '-'; n--, sa++) |
88 |
|
; |
89 |
< |
mxf = (XF *)malloc(sizeof(XF)); |
90 |
< |
if (mxf == NULL) |
91 |
< |
goto memerr; |
92 |
< |
if (invxf(mxf, n, sa) != n) |
93 |
< |
objerror(m, USER, "bad transform"); |
94 |
< |
if (mxf->sca < 0.0) |
95 |
< |
mxf->sca = -mxf->sca; |
89 |
> |
if (n == 0) |
90 |
> |
mxf = &unitxf; |
91 |
> |
else { |
92 |
> |
mxf = (XF *)malloc(sizeof(XF)); |
93 |
> |
if (mxf == NULL) |
94 |
> |
goto memerr; |
95 |
> |
if (invxf(mxf, n, sa) != n) |
96 |
> |
objerror(m, USER, "bad transform"); |
97 |
> |
if (mxf->sca < 0.0) |
98 |
> |
mxf->sca = -mxf->sca; |
99 |
> |
} |
100 |
|
m->os = (char *)mxf; |
101 |
|
} |
102 |
< |
setmap(m, r, mxf); |
91 |
< |
return; |
102 |
> |
return(setmap(m, r, mxf)); |
103 |
|
memerr: |
104 |
|
error(SYSTEM, "out of memory in setfunc"); |
105 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
double |
142 |
+ |
l_erf() /* error function */ |
143 |
+ |
{ |
144 |
+ |
extern double erf(); |
145 |
+ |
|
146 |
+ |
return(erf(argument(1))); |
147 |
+ |
} |
148 |
+ |
|
149 |
+ |
|
150 |
+ |
double |
151 |
+ |
l_erfc() /* cumulative error function */ |
152 |
+ |
{ |
153 |
+ |
extern double erfc(); |
154 |
+ |
|
155 |
+ |
return(erfc(argument(1))); |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
|
159 |
+ |
double |
160 |
|
chanvalue(n) /* return channel n to calcomp */ |
161 |
|
register int n; |
162 |
|
{ |
195 |
|
return(sum * funcxf.sca); |
196 |
|
|
197 |
|
} |
198 |
< |
if (n == 10) /* dot product */ |
199 |
< |
return(fray->rod); |
198 |
> |
if (n == 10) /* dot product (range [-1,1]) */ |
199 |
> |
return( fray->rod <= -1.0 ? -1.0 : |
200 |
> |
fray->rod >= 1.0 ? 1.0 : |
201 |
> |
fray->rod ); |
202 |
|
|
203 |
|
if (n == 11) /* scale */ |
204 |
|
return(funcxf.sca); |