ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/func.c
Revision: 1.15
Committed: Fri May 24 13:52:10 1991 UTC (32 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.14: +2 -8 lines
Log Message:
changed initialization for noise functions

File Contents

# User Rev Content
1 greg 1.13 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * func.c - interface to calcomp functions.
9     *
10     * 4/7/86
11     */
12    
13     #include "ray.h"
14    
15     #include "otypes.h"
16    
17    
18 greg 1.13 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 greg 1.12 XF funcxf; /* current transformation */
27     static OBJREC *fobj = NULL; /* current function object */
28     static RAY *fray = NULL; /* current function ray */
29 greg 1.1
30    
31 greg 1.12 setmap(m, r, bx) /* set channels for function call */
32 greg 1.1 OBJREC *m;
33     register RAY *r;
34 greg 1.12 XF *bx;
35 greg 1.1 {
36 greg 1.15 extern double l_arg();
37 greg 1.1 extern long eclock;
38     static char *initfile = "rayinit.cal";
39 greg 1.12 /* initialize if first call */
40 greg 1.1 if (initfile != NULL) {
41     loadfunc(initfile);
42 greg 1.9 scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
43     scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0);
44     scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0);
45     scompile("T=$10;Rdot=$11;", NULL, 0);
46     scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0);
47     scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0);
48     scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0);
49     scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0);
50 greg 1.14 funset("arg", 1, '=', l_arg);
51 greg 1.15 setnoisefuncs();
52 greg 1.1 initfile = NULL;
53     }
54     fobj = m;
55     fray = r;
56 greg 1.13 if (r->rox != NULL)
57     if (bx != &unitxf) {
58     funcxf.sca = r->rox->b.sca * bx->sca;
59     multmat4(funcxf.xfm, r->rox->b.xfm, bx->xfm);
60     } else
61     copystruct(&funcxf, &r->rox->b);
62     else
63 greg 1.12 copystruct(&funcxf, bx);
64 greg 1.1 eclock++; /* notify expression evaluator */
65     }
66    
67    
68     setfunc(m, r) /* simplified interface to setmap */
69     register OBJREC *m;
70     RAY *r;
71     {
72 greg 1.2 register XF *mxf;
73 greg 1.1
74 greg 1.2 if ((mxf = (XF *)m->os) == NULL) {
75 greg 1.5 register int n;
76     register char **sa;
77 greg 1.1
78 greg 1.5 for (n = m->oargs.nsargs, sa = m->oargs.sarg;
79     n > 0 && **sa != '-'; n--, sa++)
80     ;
81 greg 1.13 if (n == 0)
82     mxf = &unitxf;
83     else {
84     mxf = (XF *)malloc(sizeof(XF));
85     if (mxf == NULL)
86     goto memerr;
87     if (invxf(mxf, n, sa) != n)
88     objerror(m, USER, "bad transform");
89     if (mxf->sca < 0.0)
90     mxf->sca = -mxf->sca;
91     }
92 greg 1.2 m->os = (char *)mxf;
93 greg 1.1 }
94 greg 1.12 setmap(m, r, mxf);
95 greg 1.1 return;
96     memerr:
97     error(SYSTEM, "out of memory in setfunc");
98     }
99    
100    
101     loadfunc(fname) /* load definition file */
102     char *fname;
103     {
104     extern char *libpath; /* library search path */
105     char *ffname;
106    
107 greg 1.6 if ((ffname = getpath(fname, libpath, R_OK)) == NULL) {
108 greg 1.1 sprintf(errmsg, "cannot find function file \"%s\"", fname);
109     error(USER, errmsg);
110     }
111     fcompile(ffname);
112     }
113    
114    
115     double
116     l_arg() /* return nth real argument */
117     {
118     extern double argument();
119     register int n;
120    
121     n = argument(1) + .5; /* round to integer */
122    
123     if (n < 1)
124     return(fobj->oargs.nfargs);
125    
126     if (n > fobj->oargs.nfargs) {
127     sprintf(errmsg, "missing real argument %d", n);
128     objerror(fobj, USER, errmsg);
129     }
130     return(fobj->oargs.farg[n-1]);
131     }
132    
133    
134     double
135     chanvalue(n) /* return channel n to calcomp */
136     register int n;
137     {
138 greg 1.8 double sum;
139 greg 1.1 register RAY *r;
140    
141 greg 1.10 if (--n < 0)
142     goto badchan;
143 greg 1.1
144 greg 1.8 if (n < 3) /* ray direction */
145 greg 1.1
146 greg 1.12 return( ( fray->rdir[0]*funcxf.xfm[0][n] +
147     fray->rdir[1]*funcxf.xfm[1][n] +
148     fray->rdir[2]*funcxf.xfm[2][n] )
149     / funcxf.sca );
150 greg 1.1
151 greg 1.8 if (n < 6) /* surface normal */
152    
153 greg 1.12 return( ( fray->ron[0]*funcxf.xfm[0][n-3] +
154     fray->ron[1]*funcxf.xfm[1][n-3] +
155     fray->ron[2]*funcxf.xfm[2][n-3] )
156     / funcxf.sca );
157 greg 1.8
158     if (n < 9) /* intersection */
159    
160 greg 1.12 return( fray->rop[0]*funcxf.xfm[0][n-6] +
161     fray->rop[1]*funcxf.xfm[1][n-6] +
162     fray->rop[2]*funcxf.xfm[2][n-6] +
163     funcxf.xfm[3][n-6] );
164 greg 1.8
165 greg 1.10 if (n == 9) { /* distance */
166    
167     sum = fray->rot;
168     for (r = fray->parent; r != NULL; r = r->parent)
169     sum += r->rot;
170 greg 1.12 return(sum * funcxf.sca);
171 greg 1.10
172     }
173     if (n == 10) /* dot product */
174     return(fray->rod);
175    
176 greg 1.8 if (n == 11) /* scale */
177 greg 1.12 return(funcxf.sca);
178 greg 1.8
179     if (n < 15) /* origin */
180 greg 1.12 return(funcxf.xfm[3][n-12]);
181 greg 1.8
182     if (n < 18) /* i unit vector */
183 greg 1.12 return(funcxf.xfm[0][n-15] / funcxf.sca);
184 greg 1.8
185     if (n < 21) /* j unit vector */
186 greg 1.12 return(funcxf.xfm[1][n-15] / funcxf.sca);
187 greg 1.8
188     if (n < 24) /* k unit vector */
189 greg 1.12 return(funcxf.xfm[2][n-21] / funcxf.sca);
190 greg 1.10 badchan:
191     error(USER, "illegal channel number");
192 greg 1.1 }