Back to index

radiance  4R0+20100331
p_data.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: p_data.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  p_data.c - routine for stored patterns.
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 pattern can either be brightness or
00017  *  color data.  Brightness data is specified as:
00018  *
00019  *     modifier brightdata name
00020  *     4+ func dfname vfname v0 v1 .. xf
00021  *     0
00022  *     n A1 A2 ..
00023  *
00024  *  Color data is specified as:
00025  *
00026  *     modifier colordata name
00027  *     8+ rfunc gfunc bfunc rdfname gdfname bdfname vfname v0 v1 .. xf
00028  *     0
00029  *     n A1 A2 ..
00030  *
00031  *  Color picture data is specified as:
00032  *
00033  *     modifier colorpict name
00034  *     7+ rfunc gfunc bfunc pfname vfname vx vy xf
00035  *     0
00036  *     n A1 A2 ..
00037  *
00038  *  Vfname is the name of the file where the variable definitions
00039  *  can be found.  The list of real arguments can be accessed by
00040  *  definitions in the file.  The dfnames are the data file
00041  *  names.  The dimensions of the data files and the number
00042  *  of variables must match.  The funcs take a single argument
00043  *  for brightdata, and three for colordata and colorpict to produce
00044  *  interpolated values from the file.  The xf is a transformation
00045  *  to get from the original coordinates to the current coordinates.
00046  */
00047 
00048 
00049 extern int
00050 p_bdata(                    /* interpolate brightness data */
00051        register OBJREC  *m,
00052        RAY  *r
00053 )
00054 {
00055        double  bval;
00056        double  pt[MAXDIM];
00057        DATARRAY  *dp;
00058        register MFUNC  *mf;
00059        register int  i;
00060 
00061        if (m->oargs.nsargs < 4)
00062               objerror(m, USER, "bad # arguments");
00063        dp = getdata(m->oargs.sarg[1]);
00064        i = (1 << dp->nd) - 1;
00065        mf = getfunc(m, 2, i<<3, 0);
00066        setfunc(m, r);
00067        errno = 0;
00068        for (i = dp->nd; i-- > 0; ) {
00069               pt[i] = evalue(mf->ep[i]);
00070               if (errno == EDOM || errno == ERANGE)
00071                      goto computerr;
00072        }
00073        bval = datavalue(dp, pt);
00074        errno = 0;
00075        bval = funvalue(m->oargs.sarg[0], 1, &bval);
00076        if (errno == EDOM || errno == ERANGE)
00077               goto computerr;
00078        scalecolor(r->pcol, bval);
00079        return(0);
00080 computerr:
00081        objerror(m, WARNING, "compute error");
00082        return(0);
00083 }
00084 
00085 
00086 extern int
00087 p_cdata(                    /* interpolate color data */
00088        register OBJREC  *m,
00089        RAY  *r
00090 )
00091 {
00092        double  col[3];
00093        COLOR  cval;
00094        double  pt[MAXDIM];
00095        int  nv;
00096        DATARRAY  *dp;
00097        register MFUNC  *mf;
00098        register int  i;
00099 
00100        if (m->oargs.nsargs < 8)
00101               objerror(m, USER, "bad # arguments");
00102        dp = getdata(m->oargs.sarg[3]);
00103        i = (1 << (nv = dp->nd)) - 1;
00104        mf = getfunc(m, 6, i<<7, 0);
00105        setfunc(m, r);
00106        errno = 0;
00107        for (i = 0; i < nv; i++) {
00108               pt[i] = evalue(mf->ep[i]);
00109               if (errno == EDOM || errno == ERANGE)
00110                      goto computerr;
00111        }
00112        col[0] = datavalue(dp, pt);
00113        for (i = 1; i < 3; i++) {
00114               dp = getdata(m->oargs.sarg[i+3]);
00115               if (dp->nd != nv)
00116                      objerror(m, USER, "dimension error");
00117               col[i] = datavalue(dp, pt);
00118        }
00119        errno = 0;
00120        for (i = 0; i < 3; i++)
00121               if (fundefined(m->oargs.sarg[i]) < 3)
00122                      colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
00123               else
00124                      colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
00125        if (errno == EDOM || errno == ERANGE)
00126               goto computerr;
00127        multcolor(r->pcol, cval);
00128        return(0);
00129 computerr:
00130        objerror(m, WARNING, "compute error");
00131        return(0);
00132 }
00133 
00134 
00135 extern int
00136 p_pdata(                    /* interpolate picture data */
00137        register OBJREC  *m,
00138        RAY  *r
00139 )
00140 {
00141        double  col[3];
00142        COLOR  cval;
00143        double  pt[2];
00144        DATARRAY  *dp;
00145        register MFUNC  *mf;
00146        register int  i;
00147 
00148        if (m->oargs.nsargs < 7)
00149               objerror(m, USER, "bad # arguments");
00150        mf = getfunc(m, 4, 0x3<<5, 0);
00151        setfunc(m, r);
00152        errno = 0;
00153        pt[1] = evalue(mf->ep[0]);  /* y major ordering */
00154        pt[0] = evalue(mf->ep[1]);
00155        if (errno == EDOM || errno == ERANGE)
00156               goto computerr;
00157        dp = getpict(m->oargs.sarg[3]);
00158        for (i = 0; i < 3; i++)
00159               col[i] = datavalue(dp+i, pt);
00160        errno = 0;
00161        for (i = 0; i < 3; i++)
00162               if (fundefined(m->oargs.sarg[i]) < 3)
00163                      colval(cval,i) = funvalue(m->oargs.sarg[i], 1, col+i);
00164               else
00165                      colval(cval,i) = funvalue(m->oargs.sarg[i], 3, col);
00166        if (errno == EDOM || errno == ERANGE)
00167               goto computerr;
00168        multcolor(r->pcol, cval);
00169        return(0);
00170 
00171 computerr:
00172        objerror(m, WARNING, "compute error");
00173        return(0);
00174 }