Back to index

radiance  4R0+20100331
mx_func.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: mx_func.c,v 2.8 2004/03/30 16:13:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  mx_func.c - routine for mixture functions.
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "ray.h"
00011 #include  "func.h"
00012 #include  "rtotypes.h"
00013 
00014 /*
00015  *     A mixture function is specified:
00016  *
00017  *     modifier mixfunc name
00018  *     4+ foremod backmod varname vfname xf
00019  *     0
00020  *     n A1 A2 ..
00021  *
00022  *  Vfname is the name of the file where the variable definition
00023  *  can be found.  The list of real arguments can be accessed by
00024  *  definitions in the file.  The xf is a transformation
00025  *  to get from the original coordinates to the current coordinates.
00026  */
00027 
00028 
00029 extern int
00030 mx_func(                    /* compute mixture function */
00031        register OBJREC  *m,
00032        RAY  *r
00033 )
00034 {
00035        OBJECT obj;
00036        register int  i;
00037        double  coef;
00038        OBJECT  mod[2];
00039        register MFUNC  *mf;
00040 
00041        if (m->oargs.nsargs < 4)
00042               objerror(m, USER, "bad # arguments");
00043        obj = objndx(m);
00044        for (i = 0; i < 2; i++)
00045               if (!strcmp(m->oargs.sarg[i], VOIDID))
00046                      mod[i] = OVOID;
00047               else if ((mod[i] = lastmod(obj, m->oargs.sarg[i])) == OVOID) {
00048                      sprintf(errmsg, "undefined modifier \"%s\"",
00049                                    m->oargs.sarg[i]);
00050                      objerror(m, USER, errmsg);
00051               }
00052        mf = getfunc(m, 3, 0x4, 0);
00053        setfunc(m, r);
00054        errno = 0;
00055        coef = evalue(mf->ep[0]);
00056        if (errno == EDOM || errno == ERANGE) {
00057               objerror(m, WARNING, "compute error");
00058               return(0);
00059        }
00060        if (raymixture(r, mod[0], mod[1], coef)) {
00061               if (m->omod != OVOID)
00062                      objerror(m, USER, "inappropriate modifier");
00063               return(1);
00064        }
00065        return(0);
00066 }