ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/t_data.c
Revision: 2.8
Committed: Tue Mar 30 16:13:01 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R0, rad3R6, rad3R6P1, rad3R8, rad3R9
Changes since 2.7: +7 -6 lines
Log Message:
Continued ANSIfication. There are only bits and pieces left now.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.8 static const char RCSid[] = "$Id: t_data.c,v 2.7 2003/03/05 16:16:53 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * t_data.c - routine for stored textures
6 greg 2.5 */
7    
8 greg 2.6 #include "copyright.h"
9 greg 1.1
10     #include "ray.h"
11     #include "data.h"
12 greg 2.2 #include "func.h"
13 schorsch 2.8 #include "rtotypes.h"
14 greg 2.2
15 greg 1.1 /*
16     * A stored texture is specified as follows:
17     *
18     * modifier texdata name
19     * 8+ xfunc yfunc zfunc xdfname ydfname zdfname vfname v0 v1 .. xf
20     * 0
21     * n A1 A2 .. An
22     *
23     * Vfname is the name of the file where the variable definitions
24     * can be found. The list of real arguments can be accessed by
25     * definitions in the file. The dfnames are the data file
26     * names. The dimensions of the data files and the number
27     * of variables must match. The funcs take three arguments to produce
28     * interpolated values from the file. The xf is a transformation
29     * to get from the original coordinates to the current coordinates.
30     */
31    
32    
33 schorsch 2.8 extern int
34     t_data( /* interpolate texture data */
35     register OBJREC *m,
36     RAY *r
37     )
38 greg 1.1 {
39     int nv;
40 greg 2.3 FVECT disp;
41     double dval[3], pt[MAXDIM];
42 greg 1.4 double d;
43 greg 1.1 DATARRAY *dp;
44 greg 2.2 register MFUNC *mf;
45 greg 1.1 register int i;
46    
47     if (m->oargs.nsargs < 8)
48     objerror(m, USER, "bad # arguments");
49 greg 2.2 dp = getdata(m->oargs.sarg[3]);
50     i = (1 << (nv = dp->nd)) - 1;
51     mf = getfunc(m, 6, i<<7, 1);
52     setfunc(m, r);
53     errno = 0;
54 greg 2.3 for (i = 0; i < nv; i++)
55 greg 2.2 pt[i] = evalue(mf->ep[i]);
56 greg 2.7 if (errno == EDOM || errno == ERANGE)
57 greg 2.3 goto computerr;
58 greg 2.2 dval[0] = datavalue(dp, pt);
59     for (i = 1; i < 3; i++) {
60     dp = getdata(m->oargs.sarg[i+3]);
61 greg 1.1 if (dp->nd != nv)
62 greg 2.2 objerror(m, USER, "dimension error");
63 greg 1.1 dval[i] = datavalue(dp, pt);
64     }
65     errno = 0;
66 greg 2.3 for (i = 0; i < 3; i++)
67 greg 2.2 disp[i] = funvalue(m->oargs.sarg[i], 3, dval);
68 greg 2.7 if (errno == EDOM || errno == ERANGE)
69 greg 2.3 goto computerr;
70 greg 2.2 if (mf->f != &unitxf)
71     multv3(disp, disp, mf->f->xfm);
72 greg 1.6 if (r->rox != NULL) {
73     multv3(disp, disp, r->rox->f.xfm);
74 greg 2.2 d = 1.0 / (mf->f->sca * r->rox->f.sca);
75 greg 1.6 } else
76 greg 2.2 d = 1.0 / mf->f->sca;
77 greg 1.1 for (i = 0; i < 3; i++)
78 greg 1.4 r->pert[i] += disp[i] * d;
79 greg 2.4 return(0);
80 greg 1.1 computerr:
81     objerror(m, WARNING, "compute error");
82 greg 2.4 return(0);
83 greg 1.1 }