Back to index

radiance  4R0+20100331
t_data.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: t_data.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  t_data.c - routine for stored textures
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "ray.h"
00011 #include  "data.h"
00012 #include  "func.h"
00013 #include  "rtotypes.h"
00014 
00015 /*
00016  *     A stored texture is specified as follows:
00017  *
00018  *     modifier texdata name
00019  *     8+ xfunc yfunc zfunc xdfname ydfname zdfname vfname v0 v1 .. xf
00020  *     0
00021  *     n A1 A2 .. An
00022  *
00023  *  Vfname is the name of the file where the variable definitions
00024  *  can be found.  The list of real arguments can be accessed by
00025  *  definitions in the file.  The dfnames are the data file
00026  *  names.  The dimensions of the data files and the number
00027  *  of variables must match.  The funcs take three arguments to produce
00028  *  interpolated values from the file.  The xf is a transformation
00029  *  to get from the original coordinates to the current coordinates.
00030  */
00031 
00032 
00033 extern int
00034 t_data(                     /* interpolate texture data */
00035        register OBJREC  *m,
00036        RAY  *r
00037 )
00038 {
00039        int  nv;
00040        FVECT  disp;
00041        double  dval[3], pt[MAXDIM];
00042        double  d;
00043        DATARRAY  *dp;
00044        register MFUNC  *mf;
00045        register int  i;
00046 
00047        if (m->oargs.nsargs < 8)
00048               objerror(m, USER, "bad # arguments");
00049        dp = getdata(m->oargs.sarg[3]);
00050        i = (1 << (nv = dp->nd)) - 1;
00051        mf = getfunc(m, 6, i<<7, 1);
00052        setfunc(m, r);
00053        errno = 0;
00054        for (i = 0; i < nv; i++)
00055               pt[i] = evalue(mf->ep[i]);
00056        if (errno == EDOM || errno == ERANGE)
00057               goto computerr;
00058        dval[0] = datavalue(dp, pt);
00059        for (i = 1; i < 3; i++) {
00060               dp = getdata(m->oargs.sarg[i+3]);
00061               if (dp->nd != nv)
00062                      objerror(m, USER, "dimension error");
00063               dval[i] = datavalue(dp, pt);
00064        }
00065        errno = 0;
00066        for (i = 0; i < 3; i++)
00067               disp[i] = funvalue(m->oargs.sarg[i], 3, dval);
00068        if (errno == EDOM || errno == ERANGE)
00069               goto computerr;
00070        if (mf->f != &unitxf)
00071               multv3(disp, disp, mf->f->xfm);
00072        if (r->rox != NULL) {
00073               multv3(disp, disp, r->rox->f.xfm);
00074               d = 1.0 / (mf->f->sca * r->rox->f.sca);
00075        } else
00076               d = 1.0 / mf->f->sca;
00077        for (i = 0; i < 3; i++)
00078               r->pert[i] += disp[i] * d;
00079        return(0);
00080 computerr:
00081        objerror(m, WARNING, "compute error");
00082        return(0);
00083 }