Back to index

radiance  4R0+20100331
mx_data.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: mx_data.c,v 2.9 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  mx_data.c - routine for stored mixtures.
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 mixture is specified:
00017  *
00018  *     modifier mixdata name
00019  *     6+ foremod backmod func dfname vfname v0 v1 .. xf
00020  *     0
00021  *     n A1 A2 ..
00022  *
00023  *  A picture mixture is specified as:
00024  *
00025  *     modifier mixpict name
00026  *     7+ foremod backmod func pfname vfname vx vy xf
00027  *     0
00028  *     n A1 A2 ..
00029  *
00030  *
00031  *  Vfname is the name of the file where the variable definitions
00032  *  can be found.  The list of real arguments can be accessed by
00033  *  definitions in the file.  Dfname is the data file.
00034  *  (Pfname is a picture file.)
00035  *  The dimensions of the data files and the number
00036  *  of variables must match.  The func is a single argument
00037  *  function in the case of mixdata (three argument in the case
00038  *  of mixpict), which returns the corrected data value given the
00039  *  interpolated value from the file.  The xf is a transformation
00040  *  to get from the original coordinates to the current coordinates.
00041  */
00042 
00043 
00044 extern int
00045 mx_data(                    /* interpolate mixture data */
00046        register OBJREC  *m,
00047        RAY  *r
00048 )
00049 {
00050        OBJECT obj;
00051        double  coef;
00052        double  pt[MAXDIM];
00053        DATARRAY  *dp;
00054        OBJECT  mod[2];
00055        register MFUNC  *mf;
00056        register int  i;
00057 
00058        if (m->oargs.nsargs < 6)
00059               objerror(m, USER, "bad # arguments");
00060        obj = objndx(m);
00061        for (i = 0; i < 2; i++)
00062               if (!strcmp(m->oargs.sarg[i], VOIDID))
00063                      mod[i] = OVOID;
00064               else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
00065                      sprintf(errmsg, "undefined modifier \"%s\"",
00066                                    m->oargs.sarg[i]);
00067                      objerror(m, USER, errmsg);
00068               }
00069        dp = getdata(m->oargs.sarg[3]);
00070        i = (1 << dp->nd) - 1;
00071        mf = getfunc(m, 4, i<<5, 0);
00072        setfunc(m, r);
00073        errno = 0;
00074        for (i = 0; i < dp->nd; i++) {
00075               pt[i] = evalue(mf->ep[i]);
00076               if (errno == EDOM || errno == ERANGE)
00077                      goto computerr;
00078        }
00079        coef = datavalue(dp, pt);
00080        errno = 0;
00081        coef = funvalue(m->oargs.sarg[2], 1, &coef);
00082        if (errno == EDOM || errno == ERANGE)
00083               goto computerr;
00084        if (raymixture(r, mod[0], mod[1], coef)) {
00085               if (m->omod != OVOID)
00086                      objerror(m, USER, "inappropriate modifier");
00087               return(1);
00088        }
00089        return(0);
00090 computerr:
00091        objerror(m, WARNING, "compute error");
00092        return(0);
00093 }
00094 
00095 
00096 extern int
00097 mx_pdata(                   /* interpolate mixture picture */
00098        register OBJREC  *m,
00099        RAY  *r
00100 )
00101 {
00102        OBJECT obj;
00103        double col[3], coef;
00104        double  pt[MAXDIM];
00105        DATARRAY  *dp;
00106        OBJECT  mod[2];
00107        register MFUNC  *mf;
00108        register int  i;
00109 
00110        if (m->oargs.nsargs < 7)
00111               objerror(m, USER, "bad # arguments");
00112        obj = objndx(m);
00113        for (i = 0; i < 2; i++)
00114               if (!strcmp(m->oargs.sarg[i], VOIDID))
00115                      mod[i] = OVOID;
00116               else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
00117                      sprintf(errmsg, "undefined modifier \"%s\"",
00118                                    m->oargs.sarg[i]);
00119                      objerror(m, USER, errmsg);
00120               }
00121        dp = getpict(m->oargs.sarg[3]);
00122        mf = getfunc(m, 4, 0x3<<5, 0);
00123        setfunc(m, r);
00124        errno = 0;
00125        pt[1] = evalue(mf->ep[0]);  /* y major ordering */
00126        pt[0] = evalue(mf->ep[1]);
00127        if (errno == EDOM || errno == ERANGE)
00128               goto computerr;
00129        for (i = 0; i < 3; i++)            /* get pixel from picture */
00130               col[i] = datavalue(dp+i, pt);
00131        errno = 0;                  /* evaluate function on pixel */
00132        coef = funvalue(m->oargs.sarg[2], 3, col);
00133        if (errno == EDOM || errno == ERANGE)
00134               goto computerr;
00135        if (raymixture(r, mod[0], mod[1], coef)) {
00136               if (m->omod != OVOID)
00137                      objerror(m, USER, "inappropriate modifier");
00138               return(1);
00139        }
00140        return(0);
00141 computerr:
00142        objerror(m, WARNING, "compute error");
00143        return(0);
00144 }