ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_data.c
Revision: 1.7
Committed: Thu Aug 8 11:29:56 1991 UTC (32 years, 8 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +1 -2 lines
Log Message:
added contexts to function files

File Contents

# Content
1 /* Copyright (c) 1990 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * t_data.c - routine for stored textures
9 *
10 * 6/4/86
11 */
12
13 #include "ray.h"
14
15 #include "data.h"
16
17 /*
18 * A stored texture is specified as follows:
19 *
20 * modifier texdata name
21 * 8+ xfunc yfunc zfunc xdfname ydfname zdfname vfname v0 v1 .. xf
22 * 0
23 * n A1 A2 .. An
24 *
25 * Vfname is the name of the file where the variable definitions
26 * can be found. The list of real arguments can be accessed by
27 * definitions in the file. The dfnames are the data file
28 * names. The dimensions of the data files and the number
29 * of variables must match. The funcs take three arguments to produce
30 * interpolated values from the file. The xf is a transformation
31 * to get from the original coordinates to the current coordinates.
32 */
33
34
35 t_data(m, r) /* interpolate texture data */
36 register OBJREC *m;
37 RAY *r;
38 {
39 extern double varvalue(), funvalue(), datavalue();
40 extern int errno;
41 int nv;
42 FVECT dval, disp;
43 double pt[MAXDIM];
44 double d;
45 DATARRAY *dp;
46 register FULLXF *mxf;
47 register char **sa;
48 register int i;
49
50 if (m->oargs.nsargs < 8)
51 objerror(m, USER, "bad # arguments");
52 sa = m->oargs.sarg;
53
54 for (i = 7; i < m->oargs.nsargs && sa[i][0] != '-'; i++)
55 ;
56 nv = i-7;
57 if ((mxf = (FULLXF *)m->os) == NULL) {
58 mxf = (FULLXF *)malloc(sizeof(FULLXF));
59 if (mxf == NULL)
60 goto memerr;
61 if (fullxf(mxf, m->oargs.nsargs-i, sa+i) != m->oargs.nsargs-i)
62 objerror(m, USER, "bad transform");
63 if (mxf->f.sca < 0.0)
64 mxf->f.sca = -mxf->f.sca;
65 if (mxf->b.sca < 0.0)
66 mxf->b.sca = -mxf->b.sca;
67 m->os = (char *)mxf;
68 }
69
70 setmap(m, r, &mxf->b);
71
72 if (nv > MAXDIM)
73 goto dimerr;
74 funcfile(sa[6]);
75 errno = 0;
76 for (i = 0; i < nv; i++)
77 pt[i] = varvalue(sa[i+7]);
78 if (errno)
79 goto computerr;
80 for (i = 0; i < 3; i++) {
81 dp = getdata(sa[i+3]);
82 if (dp->nd != nv)
83 goto dimerr;
84 dval[i] = datavalue(dp, pt);
85 }
86 errno = 0;
87 for (i = 0; i < 3; i++)
88 disp[i] = funvalue(sa[i], 3, dval);
89 if (errno)
90 goto computerr;
91
92 multv3(disp, disp, mxf->f.xfm);
93 if (r->rox != NULL) {
94 multv3(disp, disp, r->rox->f.xfm);
95 d = 1.0 / (mxf->f.sca * r->rox->f.sca);
96 } else
97 d = 1.0 / mxf->f.sca;
98 for (i = 0; i < 3; i++)
99 r->pert[i] += disp[i] * d;
100 return;
101 dimerr:
102 objerror(m, USER, "dimension error");
103 memerr:
104 error(SYSTEM, "out of memory in t_data");
105 computerr:
106 objerror(m, WARNING, "compute error");
107 return;
108 }