ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_data.c
Revision: 1.5
Committed: Thu Oct 5 07:23:19 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +0 -4 lines
Log Message:
Eliminated need to initialize matrix for call to xf() and invxf()

File Contents

# Content
1 /* Copyright (c) 1989 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 typedef struct {
35 struct {
36 double sca; /* scale factor */
37 double xfm[4][4]; /* transformation matrix */
38 } fore, back;
39 } XFORM;
40
41
42 t_data(m, r) /* interpolate texture data */
43 register OBJREC *m;
44 RAY *r;
45 {
46 extern double varvalue(), funvalue(), datavalue();
47 extern int errno;
48 int nv;
49 FVECT dval, disp;
50 double pt[MAXDIM];
51 double d;
52 DATARRAY *dp;
53 register XFORM *mxf;
54 register char **sa;
55 register int i;
56
57 if (m->oargs.nsargs < 8)
58 objerror(m, USER, "bad # arguments");
59 sa = m->oargs.sarg;
60
61 for (i = 7; i < m->oargs.nsargs && sa[i][0] != '-'; i++)
62 ;
63 nv = i-7;
64 if ((mxf = (XFORM *)m->os) == NULL) {
65 mxf = (XFORM *)malloc(sizeof(XFORM));
66 if (mxf == NULL)
67 goto memerr;
68 if (xf(mxf->fore.xfm, &mxf->fore.sca,
69 m->oargs.nsargs-i, sa+i) != m->oargs.nsargs-i)
70 objerror(m, USER, "bad transform");
71 if (mxf->fore.sca < 0.0)
72 mxf->fore.sca = -mxf->fore.sca;
73 invxf(mxf->back.xfm, &mxf->back.sca,
74 m->oargs.nsargs-i, sa+i);
75 if (mxf->back.sca < 0.0)
76 mxf->back.sca = -mxf->back.sca;
77 m->os = (char *)mxf;
78 }
79
80 setmap(m, r, mxf->back.xfm, mxf->back.sca);
81
82 if (nv > MAXDIM)
83 goto dimerr;
84 if (!vardefined(sa[7]))
85 loadfunc(sa[6]);
86 errno = 0;
87 for (i = 0; i < nv; i++)
88 pt[i] = varvalue(sa[i+7]);
89 if (errno)
90 goto computerr;
91 for (i = 0; i < 3; i++) {
92 dp = getdata(sa[i+3]);
93 if (dp->nd != nv)
94 goto dimerr;
95 dval[i] = datavalue(dp, pt);
96 }
97 errno = 0;
98 for (i = 0; i < 3; i++)
99 disp[i] = funvalue(sa[i], 3, dval);
100 if (errno)
101 goto computerr;
102
103 multv3(disp, disp, mxf->fore.xfm);
104 multv3(disp, disp, r->rofx);
105 d = 1.0 / (mxf->fore.sca * r->rofs);
106 for (i = 0; i < 3; i++)
107 r->pert[i] += disp[i] * d;
108 return;
109 dimerr:
110 objerror(m, USER, "dimension error");
111 memerr:
112 error(SYSTEM, "out of memory in t_data");
113 computerr:
114 objerror(m, WARNING, "compute error");
115 return;
116 }