| 1 |
greg |
1.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 |
greg |
1.4 |
double d;
|
| 52 |
greg |
1.1 |
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 |
greg |
1.2 |
for (i = 7; i < m->oargs.nsargs && sa[i][0] != '-'; i++)
|
| 62 |
|
|
;
|
| 63 |
|
|
nv = i-7;
|
| 64 |
greg |
1.1 |
if ((mxf = (XFORM *)m->os) == NULL) {
|
| 65 |
|
|
mxf = (XFORM *)malloc(sizeof(XFORM));
|
| 66 |
|
|
if (mxf == NULL)
|
| 67 |
|
|
goto memerr;
|
| 68 |
|
|
mxf->fore.sca = 1.0;
|
| 69 |
|
|
setident4(mxf->fore.xfm);
|
| 70 |
|
|
if (xf(mxf->fore.xfm, &mxf->fore.sca,
|
| 71 |
|
|
m->oargs.nsargs-i, sa+i) != m->oargs.nsargs-i)
|
| 72 |
|
|
objerror(m, USER, "bad transform");
|
| 73 |
|
|
if (mxf->fore.sca < 0.0)
|
| 74 |
|
|
mxf->fore.sca = -mxf->fore.sca;
|
| 75 |
|
|
mxf->back.sca = 1.0;
|
| 76 |
|
|
setident4(mxf->back.xfm);
|
| 77 |
|
|
invxf(mxf->back.xfm, &mxf->back.sca,
|
| 78 |
|
|
m->oargs.nsargs-i, sa+i);
|
| 79 |
|
|
if (mxf->back.sca < 0.0)
|
| 80 |
|
|
mxf->back.sca = -mxf->back.sca;
|
| 81 |
|
|
m->os = (char *)mxf;
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
setmap(m, r, mxf->back.xfm, mxf->back.sca);
|
| 85 |
|
|
|
| 86 |
|
|
if (nv > MAXDIM)
|
| 87 |
|
|
goto dimerr;
|
| 88 |
|
|
if (!vardefined(sa[7]))
|
| 89 |
|
|
loadfunc(sa[6]);
|
| 90 |
|
|
errno = 0;
|
| 91 |
|
|
for (i = 0; i < nv; i++)
|
| 92 |
|
|
pt[i] = varvalue(sa[i+7]);
|
| 93 |
|
|
if (errno)
|
| 94 |
|
|
goto computerr;
|
| 95 |
|
|
for (i = 0; i < 3; i++) {
|
| 96 |
|
|
dp = getdata(sa[i+3]);
|
| 97 |
|
|
if (dp->nd != nv)
|
| 98 |
|
|
goto dimerr;
|
| 99 |
|
|
dval[i] = datavalue(dp, pt);
|
| 100 |
|
|
}
|
| 101 |
|
|
errno = 0;
|
| 102 |
|
|
for (i = 0; i < 3; i++)
|
| 103 |
|
|
disp[i] = funvalue(sa[i], 3, dval);
|
| 104 |
|
|
if (errno)
|
| 105 |
|
|
goto computerr;
|
| 106 |
|
|
|
| 107 |
greg |
1.3 |
multv3(disp, disp, mxf->fore.xfm);
|
| 108 |
|
|
multv3(disp, disp, r->rofx);
|
| 109 |
greg |
1.4 |
d = 1.0 / (mxf->fore.sca * r->rofs);
|
| 110 |
greg |
1.1 |
for (i = 0; i < 3; i++)
|
| 111 |
greg |
1.4 |
r->pert[i] += disp[i] * d;
|
| 112 |
greg |
1.1 |
return;
|
| 113 |
|
|
dimerr:
|
| 114 |
|
|
objerror(m, USER, "dimension error");
|
| 115 |
|
|
memerr:
|
| 116 |
|
|
error(SYSTEM, "out of memory in t_data");
|
| 117 |
|
|
computerr:
|
| 118 |
|
|
objerror(m, WARNING, "compute error");
|
| 119 |
|
|
return;
|
| 120 |
|
|
}
|