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

Comparing ray/src/rt/func.c (file contents):
Revision 1.1 by greg, Thu Feb 2 10:41:23 1989 UTC vs.
Revision 1.19 by greg, Wed Jun 19 15:08:39 1991 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 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";
# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include  "otypes.h"
16  
17  
18 < typedef struct {
19 <        double  sca;                    /* scalefactor */
20 <        double  xfm[4][4];              /* transform matrix */
21 < }  XF;
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 < static OBJREC  *fobj;           /* current function object */
27 < static RAY  *fray;              /* current function ray */
28 < static XF  fxf;                 /* current transformation */
26 > XF  funcxf;                     /* current transformation */
27 > static OBJREC  *fobj = NULL;    /* current function object */
28 > static RAY  *fray = NULL;       /* current function ray */
29  
30  
31 < setmap(m, r, sca, xfm)          /* set channels for function call */
31 > setmap(m, r, bx)                /* set channels for function call */
32   OBJREC  *m;
33   register RAY  *r;
34 < double  sca;
32 < double  xfm[4][4];
34 > XF  *bx;
35   {
36 <        extern double  l_noise3(), l_noise3a(), l_noise3b(), l_noise3c();
35 <        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 <
39 >        static long  lastrno = -1;
40 >                                        /* check to see if already set */
41 >        if (m == fobj && r->rno == lastrno)
42 >                return(0);
43 >                                        /* initialize if first call */
44          if (initfile != NULL) {
45                  loadfunc(initfile);
46 <                scompile(NULL, "Dx=$1;Dy=$2;Dz=$3;");
47 <                scompile(NULL, "Nx=$4;Ny=$5;Nz=$6;");
48 <                scompile(NULL, "Px=$7;Py=$8;Pz=$9;");
49 <                scompile(NULL, "T=$10;Rdot=$11;");
50 <                funset("arg", 1, l_arg);
51 <                funset("noise3", 3, l_noise3);
52 <                funset("noise3a", 3, l_noise3a);
53 <                funset("noise3b", 3, l_noise3b);
54 <                funset("noise3c", 3, l_noise3c);
55 <                funset("hermite", 5, l_hermite);
56 <                funset("fnoise3", 3, l_fnoise3);
46 >                scompile("Dx=$1;Dy=$2;Dz=$3;", NULL, 0);
47 >                scompile("Nx=$4;Ny=$5;Nz=$6;", NULL, 0);
48 >                scompile("Px=$7;Py=$8;Pz=$9;", NULL, 0);
49 >                scompile("T=$10;Rdot=$11;", NULL, 0);
50 >                scompile("S=$12;Tx=$13;Ty=$14;Tz=$15;", NULL, 0);
51 >                scompile("Ix=$16;Iy=$17;Iz=$18;", NULL, 0);
52 >                scompile("Jx=$19;Jy=$20;Jz=$21;", NULL, 0);
53 >                scompile("Kx=$22;Ky=$23;Kz=$24;", NULL, 0);
54 >                funset("arg", 1, '=', l_arg);
55 >                funset("erf", 1, ':', l_erf);
56 >                funset("erfc", 1, ':', l_erfc);
57 >                setnoisefuncs();
58                  initfile = NULL;
59          }
60          fobj = m;
61          fray = r;
62 <        fxf.sca = r->ros * sca;
63 <        multmat4(fxf.xfm, r->rox, xfm);
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  
# Line 63 | Line 77 | setfunc(m, r)                          /* simplified interface to setmap */
77   register OBJREC  *m;
78   RAY  *r;
79   {
80 < #define  mxf    ((XF *)m->os)
80 >        register XF  *mxf;
81  
82 <        if (mxf == NULL) {
83 <                register int  n = m->oargs.nsargs;
84 <                register char  **sa = m->oargs.sarg;
82 >        if ((mxf = (XF *)m->os) == NULL) {
83 >                register int  n;
84 >                register char  **sa;
85  
86 <                while (n > 0 && **sa != '-') {
87 <                        n--;
88 <                        sa++;
86 >                for (n = m->oargs.nsargs, sa = m->oargs.sarg;
87 >                                n > 0 && **sa != '-'; n--, sa++)
88 >                        ;
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 <                mxf = (XF *)malloc(sizeof(XF));
77 <                if (mxf == NULL)
78 <                        goto memerr;
79 <                mxf->sca = 1.0;
80 <                setident4(mxf->xfm);
81 <                if (invxf(mxf->xfm, &mxf->sca, n, sa) != n)
82 <                        objerror(m, USER, "bad transform");
83 <                if (mxf->sca < 0.0)
84 <                        mxf->sca = -mxf->sca;
100 >                m->os = (char *)mxf;
101          }
102 <        setmap(m, r, mxf->sca, mxf->xfm);
87 <        return;
102 >        return(setmap(m, r, mxf));
103   memerr:
104          error(SYSTEM, "out of memory in setfunc");
90 #undef  mxf
105   }
106  
107  
# Line 97 | Line 111 | char  *fname;
111          extern char  *libpath;          /* library search path */
112          char  *ffname;
113  
114 <        if ((ffname = getpath(fname, libpath)) == NULL) {
114 >        if ((ffname = getpath(fname, libpath, R_OK)) == NULL) {
115                  sprintf(errmsg, "cannot find function file \"%s\"", fname);
116                  error(USER, errmsg);
117          }
# Line 125 | Line 139 | l_arg()                                /* return nth real argument */
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   {
163 <        double  res;
163 >        double  sum;
164          register RAY  *r;
165  
166 <        n--;                                    /* for convenience */
166 >        if (--n < 0)
167 >                goto badchan;
168  
169 <        if (n < 0 || n > 10)
137 <                error(USER, "illegal channel number");
169 >        if (n < 3)                      /* ray direction */
170  
171 <        if (n == 9) {                           /* distance */
171 >                return( (       fray->rdir[0]*funcxf.xfm[0][n] +
172 >                                fray->rdir[1]*funcxf.xfm[1][n] +
173 >                                fray->rdir[2]*funcxf.xfm[2][n]  )
174 >                         / funcxf.sca );
175  
176 <                res = fray->rot;
142 <                for (r = fray->parent; r != NULL; r = r->parent)
143 <                        res += r->rot;
144 <                res *= fxf.sca;
176 >        if (n < 6)                      /* surface normal */
177  
178 <        } else if (n == 10) {                   /* dot product */
178 >                return( (       fray->ron[0]*funcxf.xfm[0][n-3] +
179 >                                fray->ron[1]*funcxf.xfm[1][n-3] +
180 >                                fray->ron[2]*funcxf.xfm[2][n-3] )
181 >                         / funcxf.sca );
182  
183 <                res = fray->rod;
183 >        if (n < 9)                      /* intersection */
184  
185 <        } else if (n < 3) {                     /* ray direction */
186 <                        res = ( fray->rdir[0]*fxf.xfm[0][n] +
187 <                                        fray->rdir[1]*fxf.xfm[1][n] +
188 <                                        fray->rdir[2]*fxf.xfm[2][n]     )
189 <                                 / fxf.sca ;
190 <        } else if (n < 6) {                     /* surface normal */
191 <                        res = ( fray->ron[0]*fxf.xfm[0][n-3] +
192 <                                        fray->ron[1]*fxf.xfm[1][n-3] +
193 <                                        fray->ron[2]*fxf.xfm[2][n-3]    )
194 <                                 / fxf.sca ;
195 <        } else {                                /* intersection */
196 <                        res =   fray->rop[0]*fxf.xfm[0][n-6] +
162 <                                        fray->rop[1]*fxf.xfm[1][n-6] +
163 <                                        fray->rop[2]*fxf.xfm[2][n-6] +
164 <                                                     fxf.xfm[3][n-6] ;
185 >                return( fray->rop[0]*funcxf.xfm[0][n-6] +
186 >                                fray->rop[1]*funcxf.xfm[1][n-6] +
187 >                                fray->rop[2]*funcxf.xfm[2][n-6] +
188 >                                             funcxf.xfm[3][n-6] );
189 >
190 >        if (n == 9) {                   /* distance */
191 >
192 >                sum = fray->rot;
193 >                for (r = fray->parent; r != NULL; r = r->parent)
194 >                        sum += r->rot;
195 >                return(sum * funcxf.sca);
196 >
197          }
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 <        return(res);
203 >        if (n == 11)                    /* scale */
204 >                return(funcxf.sca);
205 >
206 >        if (n < 15)                     /* origin */
207 >                return(funcxf.xfm[3][n-12]);
208 >
209 >        if (n < 18)                     /* i unit vector */
210 >                return(funcxf.xfm[0][n-15] / funcxf.sca);
211 >
212 >        if (n < 21)                     /* j unit vector */
213 >                return(funcxf.xfm[1][n-15] / funcxf.sca);
214 >
215 >        if (n < 24)                     /* k unit vector */
216 >                return(funcxf.xfm[2][n-21] / funcxf.sca);
217 > badchan:
218 >        error(USER, "illegal channel number");
219   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines